load-image-notification.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. TEST_BUILD
  3. $C{COMPILE} -DCLASSNAME=Class1 $DIR/load-image-notification-dylib.m -o load-image-notification1.dylib -dynamiclib
  4. $C{COMPILE} -DCLASSNAME=Class2 $DIR/load-image-notification-dylib.m -o load-image-notification2.dylib -dynamiclib
  5. $C{COMPILE} -DCLASSNAME=Class3 $DIR/load-image-notification-dylib.m -o load-image-notification3.dylib -dynamiclib
  6. $C{COMPILE} -DCLASSNAME=Class4 $DIR/load-image-notification-dylib.m -o load-image-notification4.dylib -dynamiclib
  7. $C{COMPILE} -DCLASSNAME=Class5 $DIR/load-image-notification-dylib.m -o load-image-notification5.dylib -dynamiclib
  8. $C{COMPILE} $DIR/load-image-notification.m -o load-image-notification.exe
  9. END
  10. */
  11. #include "test.h"
  12. #include <dlfcn.h>
  13. #define ADD_IMAGE_CALLBACK(n) \
  14. int called ## n = 0; \
  15. static void add_image ## n(const struct mach_header * mh __unused) { \
  16. called ## n++; \
  17. }
  18. ADD_IMAGE_CALLBACK(1)
  19. ADD_IMAGE_CALLBACK(2)
  20. ADD_IMAGE_CALLBACK(3)
  21. ADD_IMAGE_CALLBACK(4)
  22. ADD_IMAGE_CALLBACK(5)
  23. int main()
  24. {
  25. objc_addLoadImageFunc(add_image1);
  26. testassert(called1 > 0);
  27. int oldcalled = called1;
  28. void *handle = dlopen("load-image-notification1.dylib", RTLD_LAZY);
  29. testassert(handle);
  30. testassert(called1 > oldcalled);
  31. objc_addLoadImageFunc(add_image2);
  32. testassert(called2 == called1);
  33. oldcalled = called1;
  34. handle = dlopen("load-image-notification2.dylib", RTLD_LAZY);
  35. testassert(handle);
  36. testassert(called1 > oldcalled);
  37. testassert(called2 == called1);
  38. objc_addLoadImageFunc(add_image3);
  39. testassert(called3 == called1);
  40. oldcalled = called1;
  41. handle = dlopen("load-image-notification3.dylib", RTLD_LAZY);
  42. testassert(handle);
  43. testassert(called1 > oldcalled);
  44. testassert(called2 == called1);
  45. testassert(called3 == called1);
  46. objc_addLoadImageFunc(add_image4);
  47. testassert(called4 == called1);
  48. oldcalled = called1;
  49. handle = dlopen("load-image-notification4.dylib", RTLD_LAZY);
  50. testassert(handle);
  51. testassert(called1 > oldcalled);
  52. testassert(called2 == called1);
  53. testassert(called3 == called1);
  54. testassert(called4 == called1);
  55. objc_addLoadImageFunc(add_image5);
  56. testassert(called5 == called1);
  57. oldcalled = called1;
  58. handle = dlopen("load-image-notification5.dylib", RTLD_LAZY);
  59. testassert(handle);
  60. testassert(called1 > oldcalled);
  61. testassert(called2 == called1);
  62. testassert(called3 == called1);
  63. testassert(called4 == called1);
  64. testassert(called5 == called1);
  65. succeed(__FILE__);
  66. }