1 /** 2 * Unit tests for systemMethodProvider.d 3 * 4 */ 5 module systemMethodProvider_test; 6 7 import ashd.core.system : System; 8 import ashd.fsm.dynamicSystemProvider: DynamicSystemProvider; 9 10 int main() 11 { 12 (new SystemMethodProviderTests).providerReturnsTheInstance(); 13 (new SystemMethodProviderTests).providersWithSameMethodHaveSameIdentifier(); 14 (new SystemMethodProviderTests).providersWithDifferentMethodHaveDifferentIdentifier(); 15 16 return 0; 17 } 18 19 20 21 22 23 public class SystemMethodProviderTests 24 { 25 public void providerReturnsTheInstance() 26 { 27 MockSystem instance = new MockSystem(); 28 Object providerMethod() { return instance; } 29 30 DynamicSystemProvider provider = new DynamicSystemProvider( &providerMethod ); 31 assert( provider.getSystem!MockSystem() is instance ); 32 } 33 34 public void providersWithSameMethodHaveSameIdentifier() 35 { 36 MockSystem instance = new MockSystem(); 37 Object providerMethod() { return instance; } 38 DynamicSystemProvider provider1 = new DynamicSystemProvider( &providerMethod ); 39 DynamicSystemProvider provider2 = new DynamicSystemProvider( &providerMethod ); 40 assert( provider1.identifier == provider2.identifier ); 41 } 42 43 public void providersWithDifferentMethodHaveDifferentIdentifier() 44 { 45 MockSystem instance = new MockSystem(); 46 Object providerMethod1() { return instance; } 47 Object providerMethod2() { return instance; } 48 49 DynamicSystemProvider provider1 = new DynamicSystemProvider( &providerMethod1 ); 50 DynamicSystemProvider provider2 = new DynamicSystemProvider( &providerMethod2 ); 51 assert( provider1.identifier != provider2.identifier ); 52 } 53 } 54 55 class MockSystem: System 56 { 57 uint dummy; 58 }