1 module ut.allocator;
2 
3 ///
4 @system unittest
5 {
6     import stdx.allocator: theAllocator, make, makeArray, dispose;
7 
8     static int x;
9     static interface I
10     {
11         void method();
12     }
13     static class A : I
14     {
15         int y;
16         override void method() { x = 21; }
17         ~this() { x = 42; }
18     }
19     static class B : A
20     {
21     }
22     auto a = theAllocator.make!A;
23     a.method();
24     assert(x == 21);
25     theAllocator.dispose(a);
26     assert(x == 42);
27 
28     B b = theAllocator.make!B;
29     b.method();
30     assert(x == 21);
31     theAllocator.dispose(b);
32     assert(x == 42);
33 
34     I i = theAllocator.make!B;
35     i.method();
36     assert(x == 21);
37     theAllocator.dispose(i);
38     assert(x == 42);
39 
40     int[] arr = theAllocator.makeArray!int(43);
41     theAllocator.dispose(arr);
42 }
43 
44 ///
45 @system unittest //bugzilla 15721
46 {
47     import stdx.allocator: make, dispose;
48     import stdx.allocator.mallocator : Mallocator;
49 
50     interface Foo {}
51     class Bar: Foo {}
52 
53     Bar bar;
54     Foo foo;
55     bar = Mallocator.instance.make!Bar;
56     foo = cast(Foo) bar;
57     Mallocator.instance.dispose(foo);
58 }