concurrentcat.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. TEST_BUILD
  3. $C{COMPILE} $DIR/concurrentcat.m -o concurrentcat.exe -framework Foundation
  4. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc1 -o cc1.bundle
  5. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc2 -o cc2.bundle
  6. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc3 -o cc3.bundle
  7. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc4 -o cc4.bundle
  8. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc5 -o cc5.bundle
  9. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc6 -o cc6.bundle
  10. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc7 -o cc7.bundle
  11. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc8 -o cc8.bundle
  12. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc9 -o cc9.bundle
  13. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc10 -o cc10.bundle
  14. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc11 -o cc11.bundle
  15. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc12 -o cc12.bundle
  16. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc13 -o cc13.bundle
  17. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc14 -o cc14.bundle
  18. $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc15 -o cc15.bundle
  19. END
  20. */
  21. #include "test.h"
  22. #include <objc/runtime.h>
  23. #include <objc/objc-auto.h>
  24. #include <dlfcn.h>
  25. #include <unistd.h>
  26. #include <pthread.h>
  27. #include <Foundation/Foundation.h>
  28. @interface TargetClass : NSObject
  29. @end
  30. @interface TargetClass(LoadedMethods)
  31. - (void) m0;
  32. - (void) m1;
  33. - (void) m2;
  34. - (void) m3;
  35. - (void) m4;
  36. - (void) m5;
  37. - (void) m6;
  38. - (void) m7;
  39. - (void) m8;
  40. - (void) m9;
  41. - (void) m10;
  42. - (void) m11;
  43. - (void) m12;
  44. - (void) m13;
  45. - (void) m14;
  46. - (void) m15;
  47. @end
  48. @implementation TargetClass
  49. - (void) m0 { fail("shoulda been loaded!"); }
  50. - (void) m1 { fail("shoulda been loaded!"); }
  51. - (void) m2 { fail("shoulda been loaded!"); }
  52. - (void) m3 { fail("shoulda been loaded!"); }
  53. - (void) m4 { fail("shoulda been loaded!"); }
  54. - (void) m5 { fail("shoulda been loaded!"); }
  55. - (void) m6 { fail("shoulda been loaded!"); }
  56. @end
  57. void *threadFun(void *aTargetClassName) {
  58. const char *className = (const char *)aTargetClassName;
  59. PUSH_POOL {
  60. Class targetSubclass = objc_getClass(className);
  61. testassert(targetSubclass);
  62. id target = [targetSubclass new];
  63. testassert(target);
  64. while(1) {
  65. [target m0];
  66. RETAIN(target);
  67. [target addObserver: target forKeyPath: @"m3" options: 0 context: NULL];
  68. [target addObserver: target forKeyPath: @"m4" options: 0 context: NULL];
  69. [target m1];
  70. RELEASE_VALUE(target);
  71. [target m2];
  72. AUTORELEASE(target);
  73. [target m3];
  74. RETAIN(target);
  75. [target removeObserver: target forKeyPath: @"m4"];
  76. [target addObserver: target forKeyPath: @"m5" options: 0 context: NULL];
  77. [target m4];
  78. RETAIN(target);
  79. [target m5];
  80. AUTORELEASE(target);
  81. [target m6];
  82. [target m7];
  83. [target m8];
  84. [target m9];
  85. [target m10];
  86. [target m11];
  87. [target m12];
  88. [target m13];
  89. [target m14];
  90. [target m15];
  91. [target removeObserver: target forKeyPath: @"m3"];
  92. [target removeObserver: target forKeyPath: @"m5"];
  93. }
  94. } POP_POOL;
  95. return NULL;
  96. }
  97. int main()
  98. {
  99. int i;
  100. void *dylib;
  101. for(i=1; i<16; i++) {
  102. pthread_t t;
  103. char dlName[100];
  104. sprintf(dlName, "cc%d.bundle", i);
  105. dylib = dlopen(dlName, RTLD_LAZY);
  106. char className[100];
  107. sprintf(className, "cc%d", i);
  108. pthread_create(&t, NULL, threadFun, strdup(className));
  109. testassert(dylib);
  110. }
  111. sleep(1);
  112. succeed(__FILE__);
  113. }