Home | History | Annotate | Line # | Download | only in libphobos.shared
      1 import lib;
      2 
      3 void testEH()
      4 {
      5     bool passed;
      6     try
      7         lib.throwException();
      8     catch (Exception e)
      9         passed = true;
     10     assert(passed); passed = false;
     11 
     12     assert(lib.collectException({throw new Exception(null);}) !is null);
     13     assert(lib.collectException({lib.throwException();}) !is null);
     14 }
     15 
     16 void testGC()
     17 {
     18     import core.memory;
     19     lib.alloc();
     20     lib.tls_alloc();
     21     lib.access();
     22     lib.tls_access();
     23     GC.collect();
     24     lib.tls_access();
     25     lib.access();
     26     lib.tls_free();
     27     lib.free();
     28 }
     29 
     30 import core.atomic : atomicOp;
     31 shared static this() { assert(lib.shared_static_ctor == 1); }
     32 shared static ~this() { assert(lib.shared_static_dtor == 0); }
     33 shared uint static_ctor, static_dtor;
     34 static this() { assert(lib.static_ctor == atomicOp!"+="(static_ctor, 1)); }
     35 static ~this() { assert(lib.static_dtor + 1 == atomicOp!"+="(static_dtor, 1)); }
     36 
     37 void testInit()
     38 {
     39     import core.thread;
     40 
     41     assert(lib.static_ctor == 1);
     42     assert(lib.static_dtor == 0);
     43     static void foo()
     44     {
     45         assert(lib.shared_static_ctor == 1);
     46         assert(lib.shared_static_dtor == 0);
     47         assert(lib.static_ctor == 2);
     48         assert(lib.static_dtor == 0);
     49     }
     50     auto thr = new Thread(&foo);
     51     thr.start();
     52     assert(thr.join() is null);
     53     assert(lib.shared_static_ctor == 1);
     54     assert(lib.shared_static_dtor == 0);
     55     assert(lib.static_ctor == 2);
     56     assert(lib.static_dtor == 1);
     57 }
     58 
     59 void main()
     60 {
     61     testEH();
     62     testGC();
     63     testInit();
     64 }
     65