nopool.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // TEST_CONFIG MEM=mrc
  2. #include "test.h"
  3. #include "testroot.i"
  4. @implementation TestRoot (Loader)
  5. +(void)load
  6. {
  7. [[TestRoot new] autorelease];
  8. testassert(TestRootAutorelease == 1);
  9. testassert(TestRootDealloc == 0);
  10. }
  11. @end
  12. int main()
  13. {
  14. // +load's autoreleased object should have deallocated
  15. testassert(TestRootDealloc == 1);
  16. [[TestRoot new] autorelease];
  17. testassert(TestRootAutorelease == 2);
  18. objc_autoreleasePoolPop(objc_autoreleasePoolPush());
  19. [[TestRoot new] autorelease];
  20. testassert(TestRootAutorelease == 3);
  21. testonthread(^{
  22. [[TestRoot new] autorelease];
  23. testassert(TestRootAutorelease == 4);
  24. testassert(TestRootDealloc == 1);
  25. });
  26. // thread's autoreleased object should have deallocated
  27. testassert(TestRootDealloc == 2);
  28. // Test no-pool autorelease after a pool was pushed and popped.
  29. // The simplest POOL_SENTINEL check during pop gets this wrong.
  30. testonthread(^{
  31. objc_autoreleasePoolPop(objc_autoreleasePoolPush());
  32. [[TestRoot new] autorelease];
  33. testassert(TestRootAutorelease == 5);
  34. testassert(TestRootDealloc == 2);
  35. });
  36. testassert(TestRootDealloc == 3
  37. );
  38. succeed(__FILE__);
  39. }