tests.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #import <UIKit/UIKit.h>
  2. #import "rocketbootstrap.h"
  3. @implementation NSObject (rocketbootstrap)
  4. + (kern_return_t)rocketbootstrap_unlock:(NSString *)name
  5. {
  6. return rocketbootstrap_unlock([name UTF8String]);
  7. }
  8. static CFDataRef messagePortCallback(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info)
  9. {
  10. NSLog(@"rockettest_messageport_server: received %@", data);
  11. return CFDataCreate(kCFAllocatorDefault, (const UInt8 *)"bootstrap", 9);
  12. }
  13. + (kern_return_t)rockettest_messageport_server
  14. {
  15. static CFMessagePortRef messagePort;
  16. if (messagePort)
  17. return 0;
  18. messagePort = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("rockettest_messageport"), messagePortCallback, NULL, NULL);
  19. CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, messagePort, 0);
  20. CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
  21. CFRunLoopAddSource(CFRunLoopGetCurrent(), source, (CFStringRef)UITrackingRunLoopMode);
  22. return rocketbootstrap_cfmessageportexposelocal(messagePort);
  23. }
  24. + (NSData *)rockettest_messageport_client
  25. {
  26. CFMessagePortRef remote = rocketbootstrap_cfmessageportcreateremote(kCFAllocatorDefault, CFSTR("rockettest_messageport"));
  27. if (!remote)
  28. return nil;
  29. CFDataRef request = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)"rocket", 6);
  30. CFDataRef response = NULL;
  31. CFMessagePortSendRequest(remote, 0, request, 10, 10, CFSTR("rocketboostrap_wait"), &response);
  32. CFRelease(remote);
  33. CFRelease(request);
  34. return [(NSData *)response autorelease];
  35. }
  36. @end