1 /**
2  * Unit tests for entityState.d
3  *
4  */
5 module entityState_test;
6 
7 import ashd.fsm.componentTypeProvider: ComponentTypeProvider;
8 import ashd.fsm.entityState          : EntityState;
9 import ashd.fsm.IComponentProvider   : IComponentProvider;
10 
11 
12 
13 int main()
14 {
15     (new EntityStateTests).addWithNoQualifierCreatesTypeProvider();
16     (new EntityStateTests).addWithTypeQualifierCreatesTypeProvider();
17     (new EntityStateTests).addWithInstanceQualifierCreatesInstanceProvider();
18     (new EntityStateTests).addWithSingletonQualifierCreatesSingletonProvider();
19     (new EntityStateTests).addWithMethodQualifierCreatesDynamicProvider();
20 
21     return 0;
22 }
23 
24 
25 
26 public class EntityStateTests
27 {
28     EntityState           mState;
29 
30     public this()
31     {
32         mState = new EntityState( );
33     }
34 
35     public void addWithNoQualifierCreatesTypeProvider()
36     {
37         mState.add( typeid(MockComponent) );
38         IComponentProvider provider = mState.get( typeid(MockComponent) );
39         assert( (provider.getComponent!MockComponent()).classinfo == MockComponent.classinfo );
40     }
41 
42 
43     public void addWithTypeQualifierCreatesTypeProvider()
44     {
45         mState.add( typeid(MockComponent) ).withType( typeid(MockComponent2) );
46         IComponentProvider provider = mState.get( typeid(MockComponent) );
47         assert( (provider.getComponent!MockComponent2()).classinfo == MockComponent2.classinfo );
48     }
49 
50     public void addWithInstanceQualifierCreatesInstanceProvider()
51     {
52         MockComponent component = new MockComponent();
53         mState.add( typeid(MockComponent) ).withInstance!MockComponent( component );
54         IComponentProvider provider = mState.get( typeid(MockComponent) );
55         assert( provider.getComponent!MockComponent() is component );
56     }
57 
58     public void addWithSingletonQualifierCreatesSingletonProvider()
59     {
60         mState.add( typeid(MockComponent) ).withSingleton( typeid(MockComponent) );
61         IComponentProvider provider = mState.get( typeid(MockComponent) );
62         assert( (provider.getComponent!MockComponent()).classinfo == MockComponent.classinfo );
63     }
64 
65     public void addWithMethodQualifierCreatesDynamicProvider()
66     {
67         MockComponent dynamicProvider() { return new MockComponent(); }
68         mState.add( typeid(MockComponent) ).withMethod!MockComponent( &dynamicProvider );
69         IComponentProvider provider = mState.get( typeid(MockComponent ) );
70         assert( (provider.getComponent!MockComponent()).classinfo == MockComponent.classinfo );
71     }
72 
73 
74 }
75 
76 class MockComponent
77 {
78     public int value;
79 }
80 
81 class MockComponent2: MockComponent
82 {
83     
84 }
85 
86 
87