]> git.saurik.com Git - apple/objc4.git/blobdiff - test/property.m
objc4-437.tar.gz
[apple/objc4.git] / test / property.m
diff --git a/test/property.m b/test/property.m
new file mode 100644 (file)
index 0000000..d62f45f
--- /dev/null
@@ -0,0 +1,65 @@
+#include "test.h"
+#include <stdint.h>
+#include <string.h>
+#include <objc/objc-runtime.h>
+
+@interface Super { 
+  @public
+    id isa;
+    char superIvar;
+}
+
+@property(readonly) char superProp;
+@end
+
+@implementation Super 
+@synthesize superProp = superIvar;
++(void)initialize { } 
++class { return self; }
+@end
+
+
+@interface Sub : Super {
+  @public 
+    uintptr_t subIvar;
+}
+@property(readonly) uintptr_t subProp;
+@end
+
+@implementation Sub 
+@synthesize subProp = subIvar;
+@end
+
+int main()
+{
+    /* 
+       Runtime layout of Sub:
+         [0] isa
+         [1] superIvar
+         [2] subIvar
+    */
+    
+    objc_property_t prop;
+
+    prop = class_getProperty([Sub class], "subProp");
+    testassert(prop);
+
+    prop = class_getProperty([Super class], "superProp");
+    testassert(prop);
+    testassert(prop == class_getProperty([Sub class], "superProp"));
+
+    prop = class_getProperty([Super class], "subProp");
+    testassert(!prop);
+
+    prop = class_getProperty([Sub class]->isa, "subProp");
+    testassert(!prop);
+
+
+    testassert(NULL == class_getProperty(NULL, "foo"));
+    testassert(NULL == class_getProperty([Sub class], NULL));
+    testassert(NULL == class_getProperty(NULL, NULL));
+
+    succeed(__FILE__);
+    return 0;
+}