Exemple #1
0
    public static void Main()
    {
        Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");

        if (k1.getLabel() != "first")
        {
            throw new Exception("wrong object label");
        }

        Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");

        if (Klass.getTotal_count() != 2)
        {
            throw new Exception("number of objects should be 2");
        }

        k1 = null;
        WaitForGC();

        if (Klass.getTotal_count() != 1)
        {
            throw new Exception("number of objects should be 1");
        }

        if (k2.getLabel() != "second")
        {
            throw new Exception("wrong object label");
        }

        k2 = null;
        WaitForGC();

        if (Klass.getTotal_count() != 0)
        {
            throw new Exception("no objects should be left");
        }
    }
    static void Main()
    {
        if (debug)
        {
            Console.WriteLine("Started");
        }

        li_boost_shared_ptr.debug_shared = debug;

        // Change loop count to run for a long time to monitor memory
        const int loopCount = 1; //50000;

        for (int i = 0; i < loopCount; i++)
        {
            new runme().runtest();
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
            if (i % 100 == 0)
            {
                System.Threading.Thread.Sleep(1); // give some time to the lower priority finalizer thread
            }
        }

        if (debug)
        {
            Console.WriteLine("Nearly finished");
        }

        {
            int countdown     = 500;
            int expectedCount = 1;
            while (true)
            {
                WaitForGC();
                if (--countdown == 0)
                {
                    break;
                }
                if (Klass.getTotal_count() == expectedCount) // Expect the one global variable (GlobalValue)
                {
                    break;
                }
            }
            int actualCount = Klass.getTotal_count();
            if (actualCount != expectedCount)
            {
                throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
            }
        }

        int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();

        if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING)
        {
            if (wrapper_count != 1) // Expect the one global variable (GlobalSmartValue)
            {
                throw new ApplicationException("shared_ptr wrapper count=" + wrapper_count);
            }
        }

        if (debug)
        {
            Console.WriteLine("Finished");
        }
    }
Exemple #3
0
    public static void Main()
    {
        Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");

        if (k1.getLabel() != "first")
        {
            throw new Exception("wrong object label");
        }

        Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");

        if (Klass.getTotal_count() != 2)
        {
            throw new Exception("number of objects should be 2");
        }

        k1 = null;
        {
            int countdown     = 500;
            int expectedCount = 1;
            while (true)
            {
                WaitForGC();
                if (--countdown == 0)
                {
                    break;
                }
                if (Klass.getTotal_count() == expectedCount)
                {
                    break;
                }
            }
            ;
            int actualCount = Klass.getTotal_count();
            if (actualCount != expectedCount)
            {
                throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
            }
        }

        if (k2.getLabel() != "second")
        {
            throw new Exception("wrong object label");
        }

        k2 = null;
        {
            int countdown     = 500;
            int expectedCount = 0;
            while (true)
            {
                WaitForGC();
                if (--countdown == 0)
                {
                    break;
                }
                if (Klass.getTotal_count() == expectedCount)
                {
                    break;
                }
            }
            int actualCount = Klass.getTotal_count();
            if (actualCount != expectedCount)
            {
                throw new ApplicationException("Expected count: " + expectedCount + " Actual count: " + actualCount);
            }
        }
    }
    public static void Main()
    {
        Klass k1 = li_std_auto_ptr.makeKlassAutoPtr("first");

        if (k1.getLabel() != "first")
        {
            throw new Exception("wrong object label");
        }

        Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");

        if (Klass.getTotal_count() != 2)
        {
            throw new Exception("number of objects should be 2");
        }

        using (Klass k3 = li_std_auto_ptr.makeKlassAutoPtr("second")) {
            if (Klass.getTotal_count() != 3)
            {
                throw new Exception("number of objects should be 3");
            }
        }
        if (Klass.getTotal_count() != 2)
        {
            throw new Exception("number of objects should be 2");
        }

        k1 = null;
        {
            int countdown     = 500;
            int expectedCount = 1;
            while (true)
            {
                WaitForGC();
                if (--countdown == 0)
                {
                    break;
                }
                if (Klass.getTotal_count() == expectedCount)
                {
                    break;
                }
            }
            ;
            int actualCount = Klass.getTotal_count();
            if (actualCount != expectedCount)
            {
                Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
            }
        }

        if (k2.getLabel() != "second")
        {
            throw new Exception("wrong object label");
        }

        k2 = null;
        {
            int countdown     = 500;
            int expectedCount = 0;
            while (true)
            {
                WaitForGC();
                if (--countdown == 0)
                {
                    break;
                }
                if (Klass.getTotal_count() == expectedCount)
                {
                    break;
                }
            }
            int actualCount = Klass.getTotal_count();
            if (actualCount != expectedCount)
            {
                Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
            }
        }
    }