objectCopy.m 820 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // TEST_CONFIG MEM=mrc
  2. #include "test.h"
  3. #include <objc/NSObject.h>
  4. @interface Test : NSObject {
  5. @public
  6. char bytes[32-sizeof(void*)];
  7. }
  8. @end
  9. @implementation Test
  10. @end
  11. int main()
  12. {
  13. Test *o0 = [Test new];
  14. [o0 retain];
  15. Test *o1 = class_createInstance([Test class], 32);
  16. [o1 retain];
  17. id o2 = object_copy(o0, 0);
  18. id o3 = object_copy(o1, 0);
  19. id o4 = object_copy(o1, 32);
  20. testassert(malloc_size(o0) == 32);
  21. testassert(malloc_size(o1) == 64);
  22. testassert(malloc_size(o2) == 32);
  23. testassert(malloc_size(o3) == 32);
  24. testassert(malloc_size(o4) == 64);
  25. testassert([o0 retainCount] == 2);
  26. testassert([o1 retainCount] == 2);
  27. testassert([o2 retainCount] == 1);
  28. testassert([o3 retainCount] == 1);
  29. testassert([o4 retainCount] == 1);
  30. succeed(__FILE__);
  31. }