Exemplo n.º 1
0
    public void Type_Equals()
    {
        TestUtility.CreateInstances <WebAssemblyType>(out var a, out var b);
        a.Form = (FunctionType)1;
        TestUtility.AreNotEqual(a, b);
        b.Form = (FunctionType)1;
        TestUtility.AreEqual(a, b);

        a.Parameters = new WebAssemblyValueType[] { };
        TestUtility.AreEqual(a, b);
        a.Parameters = new[] { WebAssemblyValueType.Int32 };
        TestUtility.AreNotEqual(a, b);
        b.Parameters = new[] { WebAssemblyValueType.Int32 };
        TestUtility.AreEqual(a, b);
        a.Parameters = new[] { WebAssemblyValueType.Int32, WebAssemblyValueType.Float32 };
        TestUtility.AreNotEqual(a, b);
        b.Parameters = new[] { WebAssemblyValueType.Int32, WebAssemblyValueType.Float64 };
        TestUtility.AreNotEqual(a, b);
        b.Parameters = new[] { WebAssemblyValueType.Int32, WebAssemblyValueType.Float32 };
        TestUtility.AreEqual(a, b);

        a.Returns = new WebAssemblyValueType[] { };
        TestUtility.AreEqual(a, b);
        a.Returns = new[] { WebAssemblyValueType.Int32 };
        TestUtility.AreNotEqual(a, b);
        b.Returns = new[] { WebAssemblyValueType.Int32 };
        TestUtility.AreEqual(a, b);
        a.Returns = new[] { WebAssemblyValueType.Int32, WebAssemblyValueType.Float32 };
        TestUtility.AreNotEqual(a, b);
        b.Returns = new[] { WebAssemblyValueType.Int32, WebAssemblyValueType.Float64 };
        TestUtility.AreNotEqual(a, b);
        b.Returns = new[] { WebAssemblyValueType.Int32, WebAssemblyValueType.Float32 };
        TestUtility.AreEqual(a, b);
    }
Exemplo n.º 2
0
 public void Call_Equals()
 {
     TestUtility.CreateInstances <Call>(out var a, out var b);
     a.Index = 1;
     TestUtility.AreNotEqual(a, b);
     b.Index = 1;
     TestUtility.AreEqual(a, b);
 }
Exemplo n.º 3
0
        public void CallIndirect_Equals()
        {
            TestUtility.CreateInstances <CallIndirect>(out var a, out var b);

            a.Type = 1;
            TestUtility.AreNotEqual(a, b);
            b.Type = 1;
            TestUtility.AreEqual(a, b);

            a.Reserved = 1;
            TestUtility.AreNotEqual(a, b);
            b.Reserved = 1;
            TestUtility.AreEqual(a, b);
        }
Exemplo n.º 4
0
        public void Float32Load_Equals()
        {
            TestUtility.CreateInstances <Float32Load>(out var a, out var b);

            a.Flags = MemoryImmediateInstruction.Options.Align2;
            TestUtility.AreNotEqual(a, b);
            b.Flags = MemoryImmediateInstruction.Options.Align2;
            TestUtility.AreEqual(a, b);

            a.Offset = 1;
            TestUtility.AreNotEqual(a, b);
            b.Offset = 1;
            TestUtility.AreEqual(a, b);
        }
Exemplo n.º 5
0
        public void BranchTable_Equals()
        {
            TestUtility.CreateInstances<BranchTable>(out var a, out var b);

            a.DefaultLabel = 2;
            b.DefaultLabel = 1;
            TestUtility.AreNotEqual(a, b);
            b.DefaultLabel = 2;
            TestUtility.AreEqual(a, b);

            b.Labels = new uint[] { };
            TestUtility.AreEqual(a, b);
            b.Labels = new uint[] { 1 };
            TestUtility.AreNotEqual(a, b);
            a.Labels = new uint[] { 1 };
            TestUtility.AreEqual(a, b);
            a.Labels = new uint[] { 1, 2 };
            TestUtility.AreNotEqual(a, b);
        }
Exemplo n.º 6
0
    public void Module_FunctionBodyRoundTrip()
    {
        var source = new Module
        {
            Codes = new[]
            {
                new FunctionBody
                {
                    Locals = new[]
                    {
                        new Local
                        {
                            Count = 2,
                            Type  = WebAssemblyValueType.Float64
                        }
                    },
                    Code = new Instruction[]
                    {
                        new Instructions.End()
                    }
                }
            }
        };

        Module destination;

        using (var stream = new MemoryStream())
        {
            source.WriteToBinary(stream);
            stream.Position = 0;

            destination = Module.ReadFromBinary(stream);
        }

        Assert.IsNotNull(destination.Codes);
        Assert.AreNotSame(source.Codes, destination.Codes);
        TestUtility.AreEqual(source.Codes[0], destination.Codes[0]);
    }