nsobject.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // TEST_CONFIG MEM=mrc
  2. #include "test.h"
  3. #import <Foundation/NSObject.h>
  4. @interface Sub : NSObject @end
  5. @implementation Sub
  6. +(id)allocWithZone:(NSZone *)zone {
  7. testprintf("in +[Sub alloc]\n");
  8. return [super allocWithZone:zone];
  9. }
  10. -(void)dealloc {
  11. testprintf("in -[Sub dealloc]\n");
  12. [super dealloc];
  13. }
  14. @end
  15. // These declarations and definitions can be used
  16. // to check the compile-time type of an object.
  17. @interface NSObject (Checker)
  18. // fixme this isn't actually enforced
  19. +(void)NSObjectInstance __attribute__((unavailable));
  20. @end
  21. @implementation NSObject (Checker)
  22. -(void)NSObjectInstance { }
  23. +(void)NSObjectClass { }
  24. @end
  25. @interface Sub (Checker)
  26. -(void)NSObjectInstance __attribute__((unavailable));
  27. +(void)NSObjectClass __attribute__((unavailable));
  28. @end
  29. @implementation Sub (Checker)
  30. -(void)SubInstance { }
  31. +(void)SubClass { }
  32. @end
  33. int main()
  34. {
  35. PUSH_POOL {
  36. [[Sub new] autorelease];
  37. } POP_POOL;
  38. // Verify that dot syntax on class objects works with some instance methods
  39. // (void)NSObject.self; fixme
  40. (void)NSObject.class;
  41. (void)NSObject.superclass;
  42. (void)NSObject.hash;
  43. (void)NSObject.description;
  44. (void)NSObject.debugDescription;
  45. // Verify that some methods return the correct type.
  46. Class cls;
  47. NSObject *nsobject = nil;
  48. Sub *subobject = nil;
  49. cls = [NSObject self];
  50. cls = [Sub self];
  51. nsobject = [nsobject self];
  52. subobject = [subobject self];
  53. [[NSObject self] NSObjectClass];
  54. [[nsobject self] NSObjectInstance];
  55. [[Sub self] SubClass];
  56. [[subobject self] SubInstance];
  57. // fixme
  58. // cls = NSObject.self;
  59. // cls = Sub.self;
  60. // [NSObject.self NSObjectClass];
  61. // [nsobject.self NSObjectInstance];
  62. // [Sub.self SubClass];
  63. // [subobject.self SubInstance];
  64. cls = [NSObject class];
  65. cls = [nsobject class];
  66. cls = [Sub class];
  67. cls = [subobject class];
  68. [[NSObject class] NSObjectClass];
  69. [[nsobject class] NSObjectClass];
  70. [[Sub class] SubClass];
  71. [[subobject class] SubClass];
  72. cls = NSObject.class;
  73. cls = nsobject.class;
  74. cls = Sub.class;
  75. cls = subobject.class;
  76. [NSObject.class NSObjectClass];
  77. [nsobject.class NSObjectClass];
  78. [Sub.class SubClass];
  79. [subobject.class SubClass];
  80. cls = [NSObject superclass];
  81. cls = [nsobject superclass];
  82. cls = [Sub superclass];
  83. cls = [subobject superclass];
  84. [[NSObject superclass] NSObjectClass];
  85. [[nsobject superclass] NSObjectClass];
  86. [[Sub superclass] NSObjectClass];
  87. [[subobject superclass] NSObjectClass];
  88. cls = NSObject.superclass;
  89. cls = nsobject.superclass;
  90. cls = Sub.superclass;
  91. cls = subobject.superclass;
  92. [NSObject.superclass NSObjectClass];
  93. [nsobject.superclass NSObjectClass];
  94. [Sub.superclass NSObjectClass];
  95. [subobject.superclass NSObjectClass];
  96. succeed(__FILE__);
  97. }