future.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. TEST_BUILD
  3. $C{COMPILE} $DIR/future0.m -o future0.dylib -dynamiclib
  4. $C{COMPILE} $DIR/future2.m -x none future0.dylib -o future2.dylib -dynamiclib
  5. $C{COMPILE} $DIR/future.m -x none future0.dylib -o future.exe
  6. END
  7. */
  8. #include "test.h"
  9. #if __has_feature(objc_arc)
  10. int main()
  11. {
  12. testwarn("rdar://10041403 future class API is not ARC-compatible");
  13. succeed(__FILE__);
  14. }
  15. #else
  16. #include <objc/runtime.h>
  17. #include <malloc/malloc.h>
  18. #include <string.h>
  19. #include <dlfcn.h>
  20. #include "future.h"
  21. @implementation Sub2
  22. +(int)method {
  23. return 2;
  24. }
  25. +(Class)classref {
  26. return [Sub2 class];
  27. }
  28. @end
  29. @implementation SubSub2
  30. +(int)method {
  31. return 1 + [super method];
  32. }
  33. @end
  34. int main()
  35. {
  36. Class oldTestRoot;
  37. Class oldSub1;
  38. Class newSub1;
  39. // objc_getFutureClass with existing class
  40. oldTestRoot = objc_getFutureClass("TestRoot");
  41. testassert(oldTestRoot == [TestRoot class]);
  42. testassert(! _class_isFutureClass(oldTestRoot));
  43. // objc_getFutureClass with missing class
  44. oldSub1 = objc_getFutureClass("Sub1");
  45. testassert(oldSub1);
  46. testassert(malloc_size((__bridge void*)oldSub1) > 0);
  47. testassert(objc_getClass("Sub1") == Nil);
  48. testassert(_class_isFutureClass(oldSub1));
  49. testassert(0 == strcmp(class_getName(oldSub1), "Sub1"));
  50. testassert(object_getClass(oldSub1) == Nil); // CF expects this
  51. // objc_getFutureClass a second time
  52. testassert(oldSub1 == objc_getFutureClass("Sub1"));
  53. // Load class Sub1
  54. dlopen("future2.dylib", 0);
  55. // Verify use of future class
  56. newSub1 = objc_getClass("Sub1");
  57. testassert(oldSub1 == newSub1);
  58. testassert(newSub1 == [newSub1 classref]);
  59. testassert(newSub1 == class_getSuperclass(objc_getClass("SubSub1")));
  60. testassert(! _class_isFutureClass(newSub1));
  61. testassert(1 == [oldSub1 method]);
  62. testassert(1 == [newSub1 method]);
  63. succeed(__FILE__);
  64. }
  65. #endif