Ejemplo n.º 1
0
    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: Get size of an instance of struct contains multiple fields");

        try
        {
            TestMultiMemberStruct1 obj = new TestMultiMemberStruct1();
            obj.TestInt    = TestLibrary.Generator.GetInt32(-55);
            obj.TestDouble = TestLibrary.Generator.GetDouble(-55);
            int expectedSize = 16; // sizeof(double) + sizeof(int) + padding

            int actualSize = Marshal.SizeOf(obj);

            if (expectedSize != actualSize)
            {
                TestLibrary.TestFramework.LogError("004.1", "Get size of an instance of struct contains multiple fields returns wrong size");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] expectedSize = " + expectedSize + ", actualSize = " + actualSize + ", obj.TestInt = " + obj.TestInt + ", obj.TestDouble = " + obj.TestDouble);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Ejemplo n.º 2
0
    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: Get size of an instance of struct contains multiple fields");

        try
        {
            TestMultiMemberStruct1 obj = new TestMultiMemberStruct1();
            obj.TestInt    = TestLibrary.Generator.GetInt32(-55);
            obj.TestDouble = TestLibrary.Generator.GetDouble(-55);
            int expectedSize;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86))
            {
                expectedSize = 16; // sizeof(double) + sizeof(int) + padding
            }
            else
            {
                // The System V ABI for i386 defines double as having 4-byte alignment
                expectedSize = 12; // sizeof(double) + sizeof(int)
            }

            int actualSize = Marshal.SizeOf(obj);

            if (expectedSize != actualSize)
            {
                TestLibrary.TestFramework.LogError("004.1", "Get size of an instance of struct contains multiple fields returns wrong size");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] expectedSize = " + expectedSize + ", actualSize = " + actualSize + ", obj.TestInt = " + obj.TestInt + ", obj.TestDouble = " + obj.TestDouble);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }