cacheflush.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. TEST_BUILD
  3. $C{COMPILE} $DIR/cacheflush0.m -o cacheflush0.dylib -dynamiclib
  4. $C{COMPILE} $DIR/cacheflush2.m -x none cacheflush0.dylib -o cacheflush2.dylib -dynamiclib
  5. $C{COMPILE} $DIR/cacheflush3.m -x none cacheflush0.dylib -o cacheflush3.dylib -dynamiclib
  6. $C{COMPILE} $DIR/cacheflush.m -x none cacheflush0.dylib -o cacheflush.exe
  7. END
  8. */
  9. #include "test.h"
  10. #include <objc/runtime.h>
  11. #include <dlfcn.h>
  12. #include "cacheflush.h"
  13. @interface Sub : TestRoot @end
  14. @implementation Sub @end
  15. int main()
  16. {
  17. TestRoot *sup = [TestRoot new];
  18. Sub *sub = [Sub new];
  19. // Fill method cache
  20. testassert(1 == [TestRoot classMethod]);
  21. testassert(1 == [sup instanceMethod]);
  22. testassert(1 == [TestRoot classMethod]);
  23. testassert(1 == [sup instanceMethod]);
  24. testassert(1 == [Sub classMethod]);
  25. testassert(1 == [sub instanceMethod]);
  26. testassert(1 == [Sub classMethod]);
  27. testassert(1 == [sub instanceMethod]);
  28. // Dynamically load a category
  29. dlopen("cacheflush2.dylib", 0);
  30. // Make sure old cache results are gone
  31. testassert(2 == [TestRoot classMethod]);
  32. testassert(2 == [sup instanceMethod]);
  33. testassert(2 == [Sub classMethod]);
  34. testassert(2 == [sub instanceMethod]);
  35. // Dynamically load another category
  36. dlopen("cacheflush3.dylib", 0);
  37. // Make sure old cache results are gone
  38. testassert(3 == [TestRoot classMethod]);
  39. testassert(3 == [sup instanceMethod]);
  40. testassert(3 == [Sub classMethod]);
  41. testassert(3 == [sub instanceMethod]);
  42. // fixme test subclasses
  43. // fixme test objc_flush_caches(), class_addMethod(), class_addMethods()
  44. succeed(__FILE__);
  45. }