1/* 2TEST_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.out 7END 8*/ 9 10#include "test.h" 11#include <objc/runtime.h> 12#include <dlfcn.h> 13 14#include "cacheflush.h" 15 16@interface Sub : TestRoot @end 17@implementation Sub @end 18 19 20int main() 21{ 22 TestRoot *sup = [TestRoot new]; 23 Sub *sub = [Sub new]; 24 25 // Fill method cache 26 testassert(1 == [TestRoot classMethod]); 27 testassert(1 == [sup instanceMethod]); 28 testassert(1 == [TestRoot classMethod]); 29 testassert(1 == [sup instanceMethod]); 30 31 testassert(1 == [Sub classMethod]); 32 testassert(1 == [sub instanceMethod]); 33 testassert(1 == [Sub classMethod]); 34 testassert(1 == [sub instanceMethod]); 35 36 // Dynamically load a category 37 dlopen("cacheflush2.dylib", 0); 38 39 // Make sure old cache results are gone 40 testassert(2 == [TestRoot classMethod]); 41 testassert(2 == [sup instanceMethod]); 42 43 testassert(2 == [Sub classMethod]); 44 testassert(2 == [sub instanceMethod]); 45 46 // Dynamically load another category 47 dlopen("cacheflush3.dylib", 0); 48 49 // Make sure old cache results are gone 50 testassert(3 == [TestRoot classMethod]); 51 testassert(3 == [sup instanceMethod]); 52 53 testassert(3 == [Sub classMethod]); 54 testassert(3 == [sub instanceMethod]); 55 56 // fixme test subclasses 57 58 // fixme test objc_flush_caches(), class_addMethod(), class_addMethods() 59 60 succeed(__FILE__); 61} 62