---
Tests/base/Functions/propertyAttrs.m | 147 ++++++++++++++++++++++++++++-------
1 file changed, 120 insertions(+), 27 deletions(-)
diff --git a/Tests/base/Functions/propertyAttrs.m b/Tests/base/Functions/propertyAttrs.m
index 80b4346..0588db7 100644
--- a/Tests/base/Functions/propertyAttrs.m
+++ b/Tests/base/Functions/propertyAttrs.m
@@ -39,11 +39,15 @@ union MoneyUnion { float alone; double down; };
int intReadonlyGetter;
int intReadwrite;
int intAssign;
+ id idDefault;
id idRetain;
id idCopy;
+ id idWeak;
+ id idStrong;
int intNonatomic;
id idReadonlyCopyNonatomic;
id idReadonlyRetainNonatomic;
+ id idReadonlyWeakNonatomic;
}
@property char charDefault;
@property double doubleDefault;
@@ -65,11 +69,16 @@ union MoneyUnion { float alone; double down; };
@property(getter=isIntReadOnlyGetter, readonly) int intReadonlyGetter;
@property(readwrite) int intReadwrite;
@property(assign) int intAssign;
+@property id idDefault;
@property(retain) id idRetain;
@property(copy) id idCopy;
+@property(weak) id idWeak;
+@property(strong) id idStrong;
@property(nonatomic) int intNonatomic;
@property(nonatomic, readonly, copy) id idReadonlyCopyNonatomic;
@property(nonatomic, readonly, retain) id idReadonlyRetainNonatomic;
+@property(nonatomic, readonly, weak) id idReadonlyWeakNonatomic;
+@property(retain) id idDynamic;
@end
@implementation PropertyTest
@@ -93,15 +102,24 @@ union MoneyUnion { float alone; double down; };
@synthesize intReadonlyGetter;
@synthesize intReadwrite;
@synthesize intAssign;
+@synthesize idDefault;
@synthesize idRetain;
@synthesize idCopy;
+@synthesize idWeak;
+@synthesize idStrong;
@synthesize intNonatomic;
@synthesize idReadonlyCopyNonatomic;
@synthesize idReadonlyRetainNonatomic;
+@synthesize idReadonlyWeakNonatomic;
+@dynamic idDynamic;
@end
-void testProperty(const char *name, const char *types)
+#define ATTR(n, v) (objc_property_attribute_t){(n), (v)}
+#define ATTRS(...) (objc_property_attribute_t[]){ __VA_ARGS__ }, \
+ sizeof((objc_property_attribute_t[]){ __VA_ARGS__ }) / sizeof(objc_property_attribute_t)
+
+void testProperty(const char *name, const char *types, objc_property_attribute_t* list, unsigned int size)
{
objc_property_t p = class_getProperty(objc_getClass("PropertyTest"), name);
if (0 == p )
@@ -115,42 +133,117 @@ void testProperty(const char *name, const char *types)
"Proprety name should be '%s' was '%s'", name, property_getName(p));
pass((strcmp(types, attrs) == 0),
"Property attributes for %s should be '%s' was '%s'", name, types, attrs);
+ unsigned int attrsCount = 0;
+ objc_property_attribute_t* attrsList = property_copyAttributeList(p, &attrsCount);
+ if (attrsList != NULL)
+ {
+ pass((attrsCount == size),
+ "Property attributes list size for %s should be %u was %u", name, size, attrsCount);
+ for (unsigned int index=0; index<size; index++)
+ {
+ int found = 0;
+ for (unsigned int attrsIndex=0; attrsIndex<attrsCount; attrsIndex++)
+ {
+ if (strcmp(attrsList[attrsIndex].name, list[index].name) == 0)
+ {
+ pass((strcmp(attrsList[attrsIndex].value, list[index].value) == 0),
+ "Property attribute '%s' for %s should be '%s' was '%s'", list[index].name, name, list[index].value, attrsList[attrsIndex].value);
+ found = 1;
+ }
+ }
+ if (!found)
+ {
+ pass(0, "Missing attribute '%s' for %s", list[index].name, name);
+ }
+ }
+ }
+ else
+ {
+ pass(0, "Failed to get attributes list for %s", name);
+ }
+ for (unsigned int index=0; index<size; index++)
+ {
+ const char* value = property_copyAttributeValue(p, list[index].name);
+ if (value == NULL)
+ {
+ pass(0, "Failed to get value for attribute '%s' for %s", list[index].name, name);
+ continue;
+ }
+ pass((strcmp(value, list[index].value) == 0),
+ "Property attribute '%s' for %s should be '%s' was '%s'", list[index].name, name, list[index].value, value);
+ }
}
int main(void)
{
- testProperty("charDefault", "Tc,VcharDefault");
- testProperty("doubleDefault", "Td,VdoubleDefault");
- testProperty("enumDefault", "Ti,VenumDefault");
- testProperty("floatDefault", "Tf,VfloatDefault");
- testProperty("intDefault", "Ti,VintDefault");
+ testProperty("charDefault", "Tc,VcharDefault", ATTRS(ATTR("T", "c"), ATTR("V", "charDefault")));
+ testProperty("doubleDefault", "Td,VdoubleDefault", ATTRS(ATTR("T", "d"), ATTR("V", "doubleDefault")));
+ testProperty("enumDefault", "Ti,VenumDefault", ATTRS(ATTR("T", "i"), ATTR("V", "enumDefault")));
+ testProperty("floatDefault", "Tf,VfloatDefault", ATTRS(ATTR("T", "f"), ATTR("V", "floatDefault")));
+ testProperty("intDefault", "Ti,VintDefault", ATTRS(ATTR("T", "i"), ATTR("V", "intDefault")));
if (sizeof(long) == 4)
{
- testProperty("longDefault", "Tl,VlongDefault");
+ testProperty("longDefault", "Tl,VlongDefault", ATTRS(ATTR("T", "l"), ATTR("V", "longDefault")));
}
else
{
- testProperty("longDefault", "Tq,VlongDefault");
+ testProperty("longDefault", "Tq,VlongDefault", ATTRS(ATTR("T", "q"), ATTR("V", "longDefault")));
}
- testProperty("shortDefault", "Ts,VshortDefault");
- testProperty("signedDefault", "Ti,VsignedDefault");
- testProperty("structDefault", "T{YorkshireTeaStruct=ic},VstructDefault");
- testProperty("typedefDefault", "T{YorkshireTeaStruct=ic},VtypedefDefault");
- testProperty("unionDefault", "T(MoneyUnion=fd),VunionDefault");
- testProperty("unsignedDefault", "TI,VunsignedDefault");
- testProperty("functionPointerDefault", "T^?,VfunctionPointerDefault");
- testProperty("intPointer", "T^i,VintPointer");
- testProperty("voidPointerDefault", "T^v,VvoidPointerDefault");
- testProperty("intSetterGetter", "Ti,GintGetFoo,SintSetFoo:,VintSetterGetter");
- testProperty("intReadonly", "Ti,R,VintReadonly");
- testProperty("intReadonlyGetter", "Ti,R,GisIntReadOnlyGetter,VintReadonlyGetter");
- testProperty("intReadwrite", "Ti,VintReadwrite");
- testProperty("intAssign", "Ti,VintAssign");
- testProperty("idRetain", "T@,&,VidRetain");
- testProperty("idCopy", "T@,C,VidCopy");
- testProperty("intNonatomic", "Ti,N,VintNonatomic");
- testProperty("idReadonlyCopyNonatomic", "T@,R,C,N,VidReadonlyCopyNonatomic");
- testProperty("idReadonlyRetainNonatomic", "T@,R,&,N,VidReadonlyRetainNonatomic");
+ testProperty("shortDefault", "Ts,VshortDefault", ATTRS(ATTR("T", "s"), ATTR("V", "shortDefault")));
+ testProperty("signedDefault", "Ti,VsignedDefault", ATTRS(ATTR("T", "i"), ATTR("V", "signedDefault")));
+ testProperty("structDefault", "T{YorkshireTeaStruct=ic},VstructDefault", ATTRS(ATTR("T", "{YorkshireTeaStruct=ic}"),
+ ATTR("V", "structDefault")));
+ testProperty("typedefDefault", "T{YorkshireTeaStruct=ic},VtypedefDefault", ATTRS(ATTR("T", "{YorkshireTeaStruct=ic}"),
+ ATTR("V", "typedefDefault")));
+ testProperty("unionDefault", "T(MoneyUnion=fd),VunionDefault", ATTRS(ATTR("T", "(MoneyUnion=fd)"),
+ ATTR("V", "unionDefault")));
+ testProperty("unsignedDefault", "TI,VunsignedDefault", ATTRS(ATTR("T", "I"), ATTR("V", "unsignedDefault")));
+ testProperty("functionPointerDefault", "T^?,VfunctionPointerDefault", ATTRS(ATTR("T", "^?"), ATTR("V", "functionPointerDefault")));
+ testProperty("intPointer", "T^i,VintPointer", ATTRS(ATTR("T", "^i"), ATTR("V", "intPointer")));
+ testProperty("voidPointerDefault", "T^v,VvoidPointerDefault", ATTRS(ATTR("T", "^v"), ATTR("V", "voidPointerDefault")));
+ testProperty("intSetterGetter", "Ti,GintGetFoo,SintSetFoo:,VintSetterGetter", ATTRS(ATTR("T", "i"),
+ ATTR("G", "intGetFoo"),
+ ATTR("S", "intSetFoo:"),
+ ATTR("V", "intSetterGetter")));
+ testProperty("intReadonly", "Ti,R,VintReadonly", ATTRS(ATTR("T", "i"),
+ ATTR("R", ""),
+ ATTR("V", "intReadonly")));
+ testProperty("intReadonlyGetter", "Ti,R,GisIntReadOnlyGetter,VintReadonlyGetter", ATTRS(ATTR("T", "i"),
+ ATTR("R", ""),
+ ATTR("G", "isIntReadOnlyGetter"),
+ ATTR("V", "intReadonlyGetter")));
+ testProperty("intReadwrite", "Ti,VintReadwrite", ATTRS(ATTR("T", "i"), ATTR("V", "intReadwrite")));
+ testProperty("intAssign", "Ti,VintAssign", ATTRS(ATTR("T", "i"), ATTR("V", "intAssign")));
+ testProperty("idDefault", "T@,VidDefault", ATTRS(ATTR("T", "@"),
+ ATTR("V", "idDefault")));
+ testProperty("idRetain", "T@,&,VidRetain", ATTRS(ATTR("T", "@"),
+ ATTR("&", ""),
+ ATTR("V", "idRetain")));
+ testProperty("idCopy", "T@,C,VidCopy", ATTRS(ATTR("T", "@"),
+ ATTR("C", ""),
+ ATTR("V", "idCopy")));
+ testProperty("idWeak", "T@,W,VidWeak", ATTRS(ATTR("T", "@"),
+ ATTR("W", ""),
+ ATTR("V", "idWeak")));
+ testProperty("idStrong", "T@,&,VidStrong", ATTRS(ATTR("T", "@"),
+ ATTR("&", ""),
+ ATTR("V", "idStrong")));
+ testProperty("intNonatomic", "Ti,N,VintNonatomic", ATTRS(ATTR("T", "i"),
+ ATTR("N", ""),
+ ATTR("V", "intNonatomic")));
+ testProperty("idReadonlyCopyNonatomic", "T@,R,N,VidReadonlyCopyNonatomic", ATTRS(ATTR("T", "@"),
+ ATTR("R", ""),
+ ATTR("N", ""),
+ ATTR("V", "idReadonlyCopyNonatomic")));
+ testProperty("idReadonlyRetainNonatomic", "T@,R,N,VidReadonlyRetainNonatomic", ATTRS(ATTR("T", "@"),
+ ATTR("R", ""),
+ ATTR("N", ""),
+ ATTR("V", "idReadonlyRetainNonatomic")));
+ testProperty("idReadonlyWeakNonatomic", "T@,R,N,VidReadonlyWeakNonatomic", ATTRS(ATTR("T", "@"),
+ ATTR("R", ""),
+ ATTR("N", ""),
+ ATTR("V", "idReadonlyWeakNonatomic")));
+ testProperty("idDynamic", "T@,&,D", ATTRS(ATTR("T", "@"), ATTR("&", ""), ATTR("D", "")));
return 0;
}
#else
_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev