1 module tests.memory.no_gc_class; 2 3 import unit_threaded; 4 import evael.lib.memory; 5 6 @Setup 7 void setup() 8 { 9 defaultAllocator = CustomStatsCollector(); 10 } 11 12 @Name("New correctly sets `instantiatedWithGC = false` on class") 13 unittest 14 { 15 auto foo = MemoryHelper.create!Foo(1337); 16 17 foo.instantiatedWithGC.shouldEqual(false); 18 } 19 20 @Name("New correctly sets `instantiatedWithGC = true` on class") 21 unittest 22 { 23 auto foo = new Foo(1337); 24 25 foo.instantiatedWithGC.shouldEqual(true); 26 } 27 28 @Name("New correctly sets `instantiatedWithGC = false` on interface") 29 unittest 30 { 31 IFoo foo = MemoryHelper.create!Foo(1337); 32 (cast(NoGCClass) foo).instantiatedWithGC.shouldEqual(false); 33 } 34 35 @Name("New correctly sets `instantiatedWithGC = true` on interface") 36 unittest 37 { 38 IFoo foo = new Foo(1337); 39 (cast(NoGCClass) foo).instantiatedWithGC.shouldEqual(true); 40 } 41 42 @Name("Delete dont free memory of GC class`") 43 unittest 44 { 45 auto foo = new Foo(1337); 46 auto foo2 = foo; 47 MemoryHelper.dispose(foo); 48 foo.shouldBeNull(); 49 foo2.a.shouldEqual(1337); 50 } 51 52 interface IFoo : NoGCInterface 53 { 54 55 } 56 57 class Foo : NoGCClass, IFoo 58 { 59 public int a; 60 public bool b; 61 62 @nogc 63 public this(int a) 64 { 65 this.a = a; 66 } 67 }