load.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // TEST_CONFIG
  2. #include "test.h"
  3. #include "testroot.i"
  4. int state = 0;
  5. int catstate = 0;
  6. int deallocstate = 0;
  7. @interface Deallocator : TestRoot @end
  8. @implementation Deallocator
  9. -(void)dealloc {
  10. deallocstate = 1;
  11. SUPER_DEALLOC();
  12. }
  13. @end
  14. @interface Super : TestRoot @end
  15. @implementation Super
  16. +(void)initialize {
  17. if (self == [Super class]) {
  18. testprintf("in +[Super initialize]\n");
  19. testassert(state == 2);
  20. state = 3;
  21. } else {
  22. testprintf("in +[Super initialize] on behalf of Sub\n");
  23. testassert(state == 3);
  24. state = 4;
  25. }
  26. }
  27. -(void)load { fail("-[Super load] called!"); }
  28. +(void)load {
  29. testprintf("in +[Super load]\n");
  30. testassert(state == 0);
  31. state = 1;
  32. }
  33. @end
  34. @interface Sub : Super { } @end
  35. @implementation Sub
  36. +(void)load {
  37. testprintf("in +[Sub load]\n");
  38. testassert(state == 1);
  39. state = 2;
  40. }
  41. -(void)load { fail("-[Sub load] called!"); }
  42. @end
  43. @interface SubNoLoad : Super { } @end
  44. @implementation SubNoLoad @end
  45. @interface Super (Category) @end
  46. @implementation Super (Category)
  47. -(void)load { fail("-[Super(Category) load called!"); }
  48. +(void)load {
  49. testprintf("in +[Super(Category) load]\n");
  50. testassert(state >= 1);
  51. catstate++;
  52. }
  53. @end
  54. @interface Sub (Category) @end
  55. @implementation Sub (Category)
  56. -(void)load { fail("-[Sub(Category) load called!"); }
  57. +(void)load {
  58. testprintf("in +[Sub(Category) load]\n");
  59. testassert(state >= 2);
  60. catstate++;
  61. // test autorelease pool
  62. __autoreleasing id x;
  63. x = AUTORELEASE([Deallocator new]);
  64. }
  65. @end
  66. @interface SubNoLoad (Category) @end
  67. @implementation SubNoLoad (Category)
  68. -(void)load { fail("-[SubNoLoad(Category) load called!"); }
  69. +(void)load {
  70. testprintf("in +[SubNoLoad(Category) load]\n");
  71. testassert(state >= 1);
  72. catstate++;
  73. }
  74. @end
  75. int main()
  76. {
  77. testassert(state == 2);
  78. testassert(catstate == 3);
  79. testassert(deallocstate == 1);
  80. [Sub class];
  81. testassert(state == 4);
  82. testassert(catstate == 3);
  83. succeed(__FILE__);
  84. }