1 /** 2 * Unit tests for systemState.d 3 * 4 */ 5 module systemState_test; 6 7 8 import ashd.core.system : System; 9 import ashd.fsm.engineState : EngineState; 10 import ashd.fsm.ISystemProvider : ISystemProvider; 11 12 13 14 int main() 15 { 16 (new SystemStateTests).addInstanceCreatesInstanceProvider(); 17 (new SystemStateTests).addSingletonCreatesSingletonProvider(); 18 (new SystemStateTests).addMethodCreatesMethodProvider(); 19 (new SystemStateTests).withPrioritySetsPriorityOnProvider(); 20 21 22 return 0; 23 } 24 25 26 27 28 29 30 public class SystemStateTests 31 { 32 private EngineState mState; 33 34 this() 35 { 36 mState = new EngineState(); 37 } 38 39 public void addInstanceCreatesInstanceProvider() 40 { 41 MockSystem system1 = new MockSystem(); 42 mState.addInstance!MockSystem( system1 ); 43 assert( mState.providers().length == 1 ); 44 ISystemProvider[ClassInfo] providers = mState.providers; 45 assert( MockSystem.classinfo in providers ); 46 assert( providers[MockSystem.classinfo].getSystem!MockSystem() is system1 ); 47 } 48 49 public void addSingletonCreatesSingletonProvider() 50 { 51 mState.addSingleton( typeid(MockSystem) ); 52 ISystemProvider[ClassInfo] providers = mState.providers; 53 assert( MockSystem.classinfo in providers ); 54 assert( providers[MockSystem.classinfo].getSystem!MockSystem().classinfo == MockSystem.classinfo ); 55 } 56 57 public void addMethodCreatesMethodProvider() 58 { 59 MockSystem system = new MockSystem(); 60 MockSystem methodProvider() { return new MockSystem(); } 61 62 mState.addMethod( &methodProvider ); 63 ISystemProvider[ClassInfo] providers = mState.providers; 64 assert( MockSystem.classinfo in providers ); 65 assert( providers[MockSystem.classinfo].getSystem!MockSystem().classinfo == MockSystem.classinfo ); 66 } 67 68 public void withPrioritySetsPriorityOnProvider() 69 { 70 int priority = 10; 71 mState.addSingleton( typeid(MockSystem)).withPriority( priority ); 72 ISystemProvider[ClassInfo] providers = mState.providers; 73 assert( MockSystem.classinfo in providers ); 74 assert( providers[MockSystem.classinfo].priority == priority ); 75 } 76 } 77 78 79 class MockSystem: System 80 { 81 float dummy; 82 }