File: li_std_auto_ptr_runme.cs

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (57 lines) | stat: -rw-r--r-- 1,868 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using li_std_auto_ptrNamespace;

public class li_std_auto_ptr_runme {
    private static void WaitForGC()
    {
        System.GC.Collect(); 
        System.GC.WaitForPendingFinalizers();
        System.Threading.Thread.Sleep(10);
    }

    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)
            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
        }
    }
}