1 /**
2  * Unit tests for systemSingletonProvider.d
3  *
4  */
5 module systemSingletonProvider_test;
6 
7 import ashd.core.system                : System;
8 import ashd.fsm.systemSingletonProvider: SystemSingletonProvider;
9 
10 int main()
11 {
12     (new SystemSingletonProviderTests).providerReturnsAnInstanceOfSystem();
13     (new SystemSingletonProviderTests).providerReturnsSameInstanceEachTime();
14     (new SystemSingletonProviderTests).providersWithSameSystemHaveDifferentIdentifier();
15     (new SystemSingletonProviderTests).providersWithDifferentSystemsHaveDifferentIdentifier();
16 
17     return 0;
18 }
19 
20 
21 
22 
23 public class SystemSingletonProviderTests
24 {
25     public void providerReturnsAnInstanceOfSystem()
26     {
27         SystemSingletonProvider provider = new SystemSingletonProvider( typeid(MockSystem) );
28         assert( provider.getSystem!MockSystem.classinfo == MockSystem.classinfo );
29     }
30 
31     public void providerReturnsSameInstanceEachTime()
32     {
33         SystemSingletonProvider provider = new SystemSingletonProvider( typeid(MockSystem) );
34         assert( provider.getSystem!MockSystem.classinfo == provider.getSystem!MockSystem.classinfo );
35     }
36 
37     public void providersWithSameSystemHaveDifferentIdentifier()
38     {
39         SystemSingletonProvider provider1 = new SystemSingletonProvider( typeid(MockSystem) );
40         SystemSingletonProvider provider2 = new SystemSingletonProvider( typeid(MockSystem) );
41         assert( provider1.identifier != provider2.identifier );
42     }
43 
44     public void providersWithDifferentSystemsHaveDifferentIdentifier()
45     {
46         SystemSingletonProvider provider1 = new SystemSingletonProvider( typeid(MockSystem) );
47         SystemSingletonProvider provider2 = new SystemSingletonProvider( typeid(MockSystem2) );
48         assert( provider1.identifier != provider2.identifier );
49     }
50 }
51 
52 
53 class MockSystem: System
54 {
55     public int value;
56 }
57 
58 class MockSystem2: System
59 {
60     public string value;
61 }