setSuper.m 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // TEST_CONFIG
  2. #include "test.h"
  3. #include "testroot.i"
  4. #include <objc/runtime.h>
  5. @interface Super1 : TestRoot @end
  6. @implementation Super1
  7. +(int)classMethod { return 1; }
  8. -(int)instanceMethod { return 10000; }
  9. @end
  10. @interface Super2 : TestRoot @end
  11. @implementation Super2
  12. +(int)classMethod { return 2; }
  13. -(int)instanceMethod { return 20000; }
  14. @end
  15. @interface Sub : Super1 @end
  16. @implementation Sub
  17. +(int)classMethod { return [super classMethod] + 100; }
  18. -(int)instanceMethod {
  19. return [super instanceMethod] + 1000000;
  20. }
  21. @end
  22. int main()
  23. {
  24. Class cls;
  25. Sub *obj = [Sub new];
  26. testassert(101 == [[Sub class] classMethod]);
  27. testassert(1010000 == [obj instanceMethod]);
  28. cls = class_setSuperclass([Sub class], [Super2 class]);
  29. testassert(cls == [Super1 class]);
  30. testassert(object_getClass(cls) == object_getClass([Super1 class]));
  31. testassert(102 == [[Sub class] classMethod]);
  32. testassert(1020000 == [obj instanceMethod]);
  33. succeed(__FILE__);
  34. }