atomicProperty.mm 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // TEST_CONFIG
  2. #include "test.h"
  3. #include <objc/runtime.h>
  4. #include <objc/objc-internal.h>
  5. #import <Foundation/NSObject.h>
  6. class SerialNumber {
  7. size_t _number;
  8. public:
  9. SerialNumber() : _number(42) {}
  10. SerialNumber(const SerialNumber &number) : _number(number._number + 1) {}
  11. SerialNumber &operator=(const SerialNumber &number) { _number = number._number + 1; return *this; }
  12. int operator==(const SerialNumber &number) { return _number == number._number; }
  13. int operator!=(const SerialNumber &number) { return _number != number._number; }
  14. };
  15. @interface TestAtomicProperty : NSObject {
  16. SerialNumber number;
  17. }
  18. @property(atomic) SerialNumber number;
  19. @end
  20. @implementation TestAtomicProperty
  21. @synthesize number;
  22. @end
  23. int main()
  24. {
  25. PUSH_POOL {
  26. SerialNumber number;
  27. TestAtomicProperty *test = [TestAtomicProperty new];
  28. test.number = number;
  29. testassert(test.number != number);
  30. } POP_POOL;
  31. succeed(__FILE__);
  32. }