summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-04 15:45:30 +0000
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-04 15:45:30 +0000
commit51805ddadc045bdaff71b6d592d0882d4b556e5a (patch)
treed228fafe8770052531669a915b7a45284ffac36f
parente8bc722355dbb39893619dc1a093abc4e1a55e7c (diff)
downloadgcc-51805ddadc045bdaff71b6d592d0882d4b556e5a.tar.gz
In gcc/testsuite/:
2011-03-04 Nicola Pero <nicola.pero@meta-innovation.com> * objc.dg/gnu-api-2-property.m: Added tests for property_getName() and property_getAttributes() if __OBJC2__. * obj-c++.dg/gnu-api-2-property.mm: Likewise. * objc.dg/property/property-encoding-1.m: New. * obj-c++.dg/property/property-encoding-1.mm: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170678 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm59
-rw-r--r--gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm183
-rw-r--r--gcc/testsuite/objc.dg/gnu-api-2-property.m59
-rw-r--r--gcc/testsuite/objc.dg/property/property-encoding-1.m183
5 files changed, 460 insertions, 32 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1e541053e13..9e88c468a82 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-04 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ * objc.dg/gnu-api-2-property.m: Added tests for property_getName()
+ and property_getAttributes() if __OBJC2__.
+ * obj-c++.dg/gnu-api-2-property.mm: Likewise.
+ * objc.dg/property/property-encoding-1.m: New.
+ * obj-c++.dg/property/property-encoding-1.mm: New.
+
2011-03-04 Jason Merrill <jason@redhat.com>
* g++.dg/template/pseudodtor6.C: New.
diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
index b74d0609d65..953e9bb156b 100644
--- a/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm
@@ -25,23 +25,18 @@
+ initialize { return self; }
@end
-@protocol MyProtocol
-- (id) variable;
-@end
-
-@protocol MySecondProtocol
-- (id) setVariable: (id)value;
-@end
-
-@interface MySubClass : MyRootClass <MyProtocol>
-{ id variable_ivar; }
-- (void) setVariable: (id)value;
-- (id) variable;
+@interface MySubClass : MyRootClass
+{
+ id propertyA;
+ id propertyB;
+}
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign, nonatomic) id propertyB;
@end
@implementation MySubClass
-- (void) setVariable: (id)value { variable_ivar = value; }
-- (id) variable { return variable_ivar; }
+@synthesize propertyA;
+@synthesize propertyB;
@end
@@ -49,7 +44,6 @@ int main ()
{
/* Functions are tested in alphabetical order. */
- /* TODO: Test new ABI (when available). */
std::cout << "Testing property_getAttributes () ...\n";
{
/* The Apple/NeXT runtime seems to crash on the following. */
@@ -57,9 +51,26 @@ int main ()
if (property_getAttributes (NULL) != NULL)
abort ();
#endif
+
+ /* The GNU runtime doesn't support looking up properties at
+ runtime yet. */
+#ifdef __OBJC2__
+ {
+ objc_property_t property;
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+ if (std::strcmp (property_getAttributes (property),
+ "T@,GgetP,SsetP:,VpropertyA") != 0)
+ abort ();
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+ if (std::strcmp (property_getAttributes (property),
+ "T@,N,VpropertyB") != 0)
+ abort ();
+ }
+#endif
}
- /* TODO: Test new ABI (when available). */
std::cout << "Testing property_getName () ...\n";
{
/* The Apple/NeXT runtime seems to crash on the following. */
@@ -68,6 +79,22 @@ int main ()
if (property_getName (NULL) != NULL)
abort ();
#endif
+
+ /* The GNU runtime doesn't support looking up properties at
+ runtime yet. */
+#ifdef __OBJC2__
+ {
+ objc_property_t property;
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+ if (std::strcmp (property_getName (property), "propertyA") != 0)
+ abort ();
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+ if (std::strcmp (property_getName (property), "propertyB") != 0)
+ abort ();
+ }
+#endif
}
return (0);
diff --git a/gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm b/gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm
new file mode 100644
index 00000000000..03f273c13b6
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/property/property-encoding-1.mm
@@ -0,0 +1,183 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, March 2011. */
+/* Test encoding properties. */
+/* { dg-do run } */
+/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
+
+#include <objc/runtime.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+@interface MyRootClass
+{ Class isa; }
++ alloc;
+- init;
++ initialize;
+@end
+
+@implementation MyRootClass
++ alloc { return class_createInstance (self, 0); }
+- init { return self; }
++ initialize { return self; }
+@end
+
+@interface MySubClass : MyRootClass
+{
+ char char_property;
+ short short_property;
+ int int_property;
+ long long_property;
+ float float_property;
+ double double_property;
+ int *int_pointer_property;
+
+ id propertyA;
+ id propertyB;
+ id propertyC;
+ id propertyD;
+ int propertyE;
+ id propertyF;
+
+ id other_variable;
+}
+@property char char_property;
+@property short short_property;
+@property int int_property;
+@property long long_property;
+@property float float_property;
+@property double double_property;
+@property int *int_pointer_property;
+
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign) id propertyB;
+@property (copy) id propertyC;
+@property (retain) id propertyD;
+@property (nonatomic) int propertyE;
+@property (nonatomic, readonly, copy) id propertyF;
+
+@property (assign) id propertyG;
+@property (assign, readonly, getter=X) id propertyH;
+@end
+
+@implementation MySubClass
+@synthesize char_property;
+@synthesize short_property;
+@synthesize int_property;
+@synthesize long_property;
+@synthesize float_property;
+@synthesize double_property;
+@synthesize int_pointer_property;
+
+@synthesize propertyA;
+@synthesize propertyB;
+@synthesize propertyC;
+@synthesize propertyD;
+@synthesize propertyE;
+@synthesize propertyF;
+
+@synthesize propertyG = other_variable;
+@dynamic propertyH;
+@end
+
+#ifdef __OBJC2__
+void error (objc_property_t p)
+{
+ printf ("Error - property_getAttributes (\"%s\") returns \"%s\"\n",
+ property_getName (p),
+ property_getAttributes (p));
+ abort ();
+}
+
+/* Concatenate 3 strings and return the result. */
+char *concat (char *a, char *b, char *c)
+{
+ /* We happily leak memory here. This is a test. */
+ char *x = malloc (sizeof (char) * 128);
+ snprintf (x, 128, "%s%s%s", a, b, c);
+ return x;
+}
+
+#endif
+
+int main(int argc, char **args)
+{
+#ifdef __OBJC2__
+ Class c = objc_getClass ("MySubClass");
+ objc_property_t p;
+ const char *expected_result;
+
+ p = class_getProperty (c, "char_property");
+ /* Usually we expect "Tc,Vchar_property", but if a char is of
+ different size, it may be encoded differently than "c". */
+ if (strcmp (concat ("T", @encode (char), ",Vchar_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "short_property");
+ if (strcmp (concat ("T", @encode (short), ",Vshort_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "int_property");
+ if (strcmp (concat ("T", @encode (int), ",Vint_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "long_property");
+ if (strcmp (concat ("T", @encode (long), ",Vlong_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "float_property");
+ if (strcmp (concat ("T", @encode (float), ",Vfloat_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "double_property");
+ if (strcmp (concat ("T", @encode (double), ",Vdouble_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "int_pointer_property");
+ if (strcmp (concat ("T", @encode (int *), ",Vint_pointer_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ /* Objects are always encoded as '@' hence the string does not
+ depend on the architecture. */
+ p = class_getProperty (c, "propertyA");
+ if (strcmp ("T@,GgetP,SsetP:,VpropertyA", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyB");
+ if (strcmp ("T@,VpropertyB", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyC");
+ if (strcmp ("T@,C,VpropertyC", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyD");
+ if (strcmp ("T@,&,VpropertyD", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyE");
+ if (strcmp (concat ("T", @encode (int), ",N,VpropertyE"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyF");
+ if (strcmp ("T@,R,C,N,VpropertyF", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyG");
+ if (strcmp ("T@,Vother_variable", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyH");
+ if (strcmp ("T@,R,D,GX", property_getAttributes (p)) != 0)
+ error (p);
+#endif
+
+ return 0;
+}
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-property.m b/gcc/testsuite/objc.dg/gnu-api-2-property.m
index 16307da77a0..12c0d8b98e3 100644
--- a/gcc/testsuite/objc.dg/gnu-api-2-property.m
+++ b/gcc/testsuite/objc.dg/gnu-api-2-property.m
@@ -25,23 +25,18 @@
+ initialize { return self; }
@end
-@protocol MyProtocol
-- (id) variable;
-@end
-
-@protocol MySecondProtocol
-- (id) setVariable: (id)value;
-@end
-
-@interface MySubClass : MyRootClass <MyProtocol>
-{ id variable_ivar; }
-- (void) setVariable: (id)value;
-- (id) variable;
+@interface MySubClass : MyRootClass
+{
+ id propertyA;
+ id propertyB;
+}
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign, nonatomic) id propertyB;
@end
@implementation MySubClass
-- (void) setVariable: (id)value { variable_ivar = value; }
-- (id) variable { return variable_ivar; }
+@synthesize propertyA;
+@synthesize propertyB;
@end
@@ -49,7 +44,6 @@ int main(int argc, void **args)
{
/* Functions are tested in alphabetical order. */
- /* TODO: Test new ABI (when available). */
printf ("Testing property_getAttributes () ...\n");
{
/* The Apple/NeXT runtime seems to crash on the following. */
@@ -57,9 +51,26 @@ int main(int argc, void **args)
if (property_getAttributes (NULL) != NULL)
abort ();
#endif
+
+ /* The GNU runtime doesn't support looking up properties at
+ runtime yet. */
+#ifdef __OBJC2__
+ {
+ objc_property_t property;
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+ if (strcmp (property_getAttributes (property),
+ "T@,GgetP,SsetP:,VpropertyA") != 0)
+ abort ();
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+ if (strcmp (property_getAttributes (property),
+ "T@,N,VpropertyB") != 0)
+ abort ();
+ }
+#endif
}
- /* TODO: Test new ABI (when available). */
printf ("Testing property_getName () ...\n");
{
/* The Apple/NeXT runtime seems to crash on the following. */
@@ -67,6 +78,22 @@ int main(int argc, void **args)
if (property_getName (NULL) != NULL)
abort ();
#endif
+
+ /* The GNU runtime doesn't support looking up properties at
+ runtime yet. */
+#ifdef __OBJC2__
+ {
+ objc_property_t property;
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
+ if (strcmp (property_getName (property), "propertyA") != 0)
+ abort ();
+
+ property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
+ if (strcmp (property_getName (property), "propertyB") != 0)
+ abort ();
+ }
+#endif
}
return 0;
diff --git a/gcc/testsuite/objc.dg/property/property-encoding-1.m b/gcc/testsuite/objc.dg/property/property-encoding-1.m
new file mode 100644
index 00000000000..64b35e7690e
--- /dev/null
+++ b/gcc/testsuite/objc.dg/property/property-encoding-1.m
@@ -0,0 +1,183 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, March 2011. */
+/* Test encoding properties. */
+/* { dg-do run } */
+/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
+
+#include <objc/runtime.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+@interface MyRootClass
+{ Class isa; }
++ alloc;
+- init;
++ initialize;
+@end
+
+@implementation MyRootClass
++ alloc { return class_createInstance (self, 0); }
+- init { return self; }
++ initialize { return self; }
+@end
+
+@interface MySubClass : MyRootClass
+{
+ char char_property;
+ short short_property;
+ int int_property;
+ long long_property;
+ float float_property;
+ double double_property;
+ int *int_pointer_property;
+
+ id propertyA;
+ id propertyB;
+ id propertyC;
+ id propertyD;
+ int propertyE;
+ id propertyF;
+
+ id other_variable;
+}
+@property char char_property;
+@property short short_property;
+@property int int_property;
+@property long long_property;
+@property float float_property;
+@property double double_property;
+@property int *int_pointer_property;
+
+@property (assign, getter=getP, setter=setP:) id propertyA;
+@property (assign) id propertyB;
+@property (copy) id propertyC;
+@property (retain) id propertyD;
+@property (nonatomic) int propertyE;
+@property (nonatomic, readonly, copy) id propertyF;
+
+@property (assign) id propertyG;
+@property (assign, readonly, getter=X) id propertyH;
+@end
+
+@implementation MySubClass
+@synthesize char_property;
+@synthesize short_property;
+@synthesize int_property;
+@synthesize long_property;
+@synthesize float_property;
+@synthesize double_property;
+@synthesize int_pointer_property;
+
+@synthesize propertyA;
+@synthesize propertyB;
+@synthesize propertyC;
+@synthesize propertyD;
+@synthesize propertyE;
+@synthesize propertyF;
+
+@synthesize propertyG = other_variable;
+@dynamic propertyH;
+@end
+
+#ifdef __OBJC2__
+void error (objc_property_t p)
+{
+ printf ("Error - property_getAttributes (\"%s\") returns \"%s\"\n",
+ property_getName (p),
+ property_getAttributes (p));
+ abort ();
+}
+
+/* Concatenate 3 strings and return the result. */
+char *concat (char *a, char *b, char *c)
+{
+ /* We happily leak memory here. This is a test. */
+ char *x = malloc (sizeof (char) * 128);
+ snprintf (x, 128, "%s%s%s", a, b, c);
+ return x;
+}
+
+#endif
+
+int main(int argc, void **args)
+{
+#ifdef __OBJC2__
+ Class c = objc_getClass ("MySubClass");
+ objc_property_t p;
+ const char *expected_result;
+
+ p = class_getProperty (c, "char_property");
+ /* Usually we expect "Tc,Vchar_property", but if a char is of
+ different size, it may be encoded differently than "c". */
+ if (strcmp (concat ("T", @encode (char), ",Vchar_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "short_property");
+ if (strcmp (concat ("T", @encode (short), ",Vshort_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "int_property");
+ if (strcmp (concat ("T", @encode (int), ",Vint_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "long_property");
+ if (strcmp (concat ("T", @encode (long), ",Vlong_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "float_property");
+ if (strcmp (concat ("T", @encode (float), ",Vfloat_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "double_property");
+ if (strcmp (concat ("T", @encode (double), ",Vdouble_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "int_pointer_property");
+ if (strcmp (concat ("T", @encode (int *), ",Vint_pointer_property"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ /* Objects are always encoded as '@' hence the string does not
+ depend on the architecture. */
+ p = class_getProperty (c, "propertyA");
+ if (strcmp ("T@,GgetP,SsetP:,VpropertyA", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyB");
+ if (strcmp ("T@,VpropertyB", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyC");
+ if (strcmp ("T@,C,VpropertyC", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyD");
+ if (strcmp ("T@,&,VpropertyD", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyE");
+ if (strcmp (concat ("T", @encode (int), ",N,VpropertyE"),
+ property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyF");
+ if (strcmp ("T@,R,C,N,VpropertyF", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyG");
+ if (strcmp ("T@,Vother_variable", property_getAttributes (p)) != 0)
+ error (p);
+
+ p = class_getProperty (c, "propertyH");
+ if (strcmp ("T@,R,D,GX", property_getAttributes (p)) != 0)
+ error (p);
+#endif
+
+ return 0;
+}