react-native-navigation的迁移库

RNNCommandsHandlerTest.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #import <XCTest/XCTest.h>
  2. #import <objc/runtime.h>
  3. #import "RNNCommandsHandler.m"
  4. @interface RNNCommandsHandlerTest : XCTestCase
  5. @end
  6. @implementation RNNCommandsHandlerTest
  7. - (void)setUp {
  8. [super setUp];
  9. }
  10. - (void)testAssertReadyForEachMethodThrowsExceptoins {
  11. RNNStore *store = [RNNStore new];
  12. [store setReadyToReceiveCommands:NO];
  13. RNNCommandsHandler *uut = [[RNNCommandsHandler alloc] initWithStore:store controllerFactory:nil];
  14. NSArray* methods = [self getPublicMethodNamesForObject:uut];
  15. for (NSString* methodName in methods) {
  16. SEL s = NSSelectorFromString(methodName);
  17. XCTAssertThrowsSpecificNamed([uut performSelector:s withObject:nil], NSException, @"BridgeNotLoadedError");
  18. }
  19. }
  20. -(NSArray*) getPublicMethodNamesForObject:(NSObject*)obj{
  21. NSMutableArray* skipMethods = [NSMutableArray new];
  22. [skipMethods addObject:@"initWithStore:controllerFactory:"];
  23. [skipMethods addObject:@"assertReady"];
  24. [skipMethods addObject:@".cxx_destruct"];
  25. NSMutableArray* result = [NSMutableArray new];
  26. // count and names:
  27. int i=0;
  28. unsigned int mc = 0;
  29. Method * mlist = class_copyMethodList(object_getClass(obj), &mc);
  30. for(i=0; i<mc; i++) {
  31. NSString *methodName = [NSString stringWithUTF8String:sel_getName(method_getName(mlist[i]))];
  32. // filter skippedMethods
  33. if (![skipMethods containsObject:methodName]) {
  34. [result addObject:methodName];
  35. }
  36. }
  37. return result;
  38. }
  39. @end