Esempio n. 1
0
    public static int Main()
    {
        WeakReferenceTarget test = new WeakReferenceTarget();

        TestLibrary.TestFramework.BeginTestCase("WeakReferenceTarget");

        if (test.RunTests())
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("PASS");
            return 100;
        }
        else
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("FAIL");
            return 0;
        }
    }
Esempio n. 2
0
    private bool GenerateUnusedData2(string errorNo)
    {
        bool retVal = true;

        object obj = new object();
        string str = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
        Byte[] randBytes = new Byte[c_MAX_STRING_LENGTH];
        TestLibrary.Generator.GetBytes(-55, randBytes);

        TestStruct ts = new TestStruct();
        ts.IntValue = TestLibrary.Generator.GetInt32(-55);

        WeakReferenceTarget thisClass = new WeakReferenceTarget();
        DisposableClass dc = new DisposableClass();
        IntPtr ptr = new IntPtr(TestLibrary.Generator.GetInt32(-55));

        Object[] objs = new object[] {
            obj,
            str,
            randBytes,
            thisClass,
            dc,
            ptr,
            IntPtr.Zero
        };

        m_References = new WeakReference[objs.Length];
        for (int i = 0; i < objs.Length; ++i)
        {
            m_References[i] = new WeakReference(objs[i], true);
        }

        for (int i = 0; i < m_References.Length; ++i)
        {
            if (!m_References[i].Target.Equals(objs[i]))
            {
                TestLibrary.TestFramework.LogError(errorNo, "Target returns wrong value for weak references");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] i = " + i.ToString() +
                                                                                                                  ", m_References[i].Target = " + m_References[i].Target.ToString() +
                                                                                                                  ", objs[i] = " + objs[i].ToString());
                retVal = false;
            }
        }

        return retVal;
    }
Esempio n. 3
0
    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: Call set_Target on long weak reference to instance of an object before GC");

        try
        {
            // Reclaim memories
            GC.Collect();
            GC.WaitForPendingFinalizers();

            retVal = GenerateUnusedData2("004.1") && retVal;

            object obj = new object();
            string str = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
            Byte[] randBytes = new Byte[c_MAX_STRING_LENGTH];
            TestLibrary.Generator.GetBytes(-55, randBytes);

            WeakReferenceTarget thisClass = new WeakReferenceTarget();
            DisposableClass dc = new DisposableClass();
            IntPtr ptr = new IntPtr(TestLibrary.Generator.GetInt32(-55));

            Object[] objs = new object[] {
                obj,
                str,
                randBytes,
                thisClass,
                dc,
                ptr,
                IntPtr.Zero
            };

            for (int i = 0; i < m_References.Length; ++i)
            {
                m_References[i].Target = objs[i];

                if (!m_References[i].Target.Equals(objs[i]))
                {
                    TestLibrary.TestFramework.LogError("004.2", "Target is not set correctly");
                    TestLibrary.TestFramework.LogInformation("WARNING: m_References[i].Target = " + m_References[i].Target.ToString() +
                                                                                                                  ", objs = " + objs[i].ToString() +
                                                                                                                  ", i = " + i.ToString());
                    retVal = false;
                }
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004.3", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }
        finally
        {
            m_References = null;
        }

        return retVal;
    }