[llvm-commits] [test-suite] r76142 - in /test-suite/trunk/SingleSource/UnitTests/ObjC: constant-strings.m dot-syntax-1.m dot-syntax-2.m dot-syntax.m exceptions.m for-in.m messages-2.m messages.m parameter-passing.m predefined-expr-in-method.m property.m protocols.m synchronized.m
Daniel Dunbar
daniel at zuster.org
Thu Jul 16 19:17:02 PDT 2009
Author: ddunbar
Date: Thu Jul 16 21:16:57 2009
New Revision: 76142
URL: http://llvm.org/viewvc/llvm-project?rev=76142&view=rev
Log:
Add a number of new ObjC test cases.
Added:
test-suite/trunk/SingleSource/UnitTests/ObjC/constant-strings.m
test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-1.m
test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-2.m
test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax.m
test-suite/trunk/SingleSource/UnitTests/ObjC/exceptions.m
test-suite/trunk/SingleSource/UnitTests/ObjC/for-in.m
test-suite/trunk/SingleSource/UnitTests/ObjC/messages-2.m
test-suite/trunk/SingleSource/UnitTests/ObjC/messages.m
test-suite/trunk/SingleSource/UnitTests/ObjC/predefined-expr-in-method.m
test-suite/trunk/SingleSource/UnitTests/ObjC/property.m
test-suite/trunk/SingleSource/UnitTests/ObjC/protocols.m
test-suite/trunk/SingleSource/UnitTests/ObjC/synchronized.m
Modified:
test-suite/trunk/SingleSource/UnitTests/ObjC/parameter-passing.m
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/constant-strings.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/constant-strings.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/constant-strings.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/constant-strings.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+id a = @"Hello World!";
+
+int main() {
+ printf("a: %s\n", [a cString]);
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-1.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-1.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-1.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-1.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,255 @@
+#include <Foundation/NSObject.h>
+#include <stdio.h>
+
+// Property above methods...
+
+ at interface Top0 : NSObject
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at interface Bot0 : Top0
+-(int) x;
+-(void) setX: (int) arg;
+ at end
+
+ at implementation Top0
+-(int) _getX {
+ printf("-[ Top0 _getX ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Top0 _setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot0
+-(int) x {
+ printf("-[ Bot0 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Bot0 _setX: %d ]\n", arg);
+}
+ at end
+
+// Methods above property...
+
+ at interface Top1 : NSObject
+-(int) x;
+-(void) setX: (int) arg;
+ at end
+
+ at interface Bot1 : Top1
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at implementation Top1
+-(int) x {
+ printf("-[ Top1 x ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Top1 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot1
+-(int) _getX {
+ printf("-[ Bot1 _getX ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Bot1 _setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 1)
+
+ at interface Top2 : NSObject
+-(int) x;
+-(void) _setX: (int) arg;
+ at end
+
+ at interface Bot2 : Top2
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at implementation Top2
+-(int) x {
+ printf("-[ Top2 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Top2 _setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot2
+-(int) _getX {
+ printf("-[ Bot2 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Bot2 setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 2)
+
+ at interface Top3 : NSObject
+-(int) _getX;
+-(void) setX: (int) arg;
+ at end
+
+ at interface Bot3 : Top3
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at implementation Top3
+-(int) _getX {
+ printf("-[ Top3 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Top3 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot3
+-(int) x {
+ printf("-[ Bot3 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Bot3 _setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 3)
+
+ at interface Top4 : NSObject
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at interface Bot4 : Top4
+-(int) _getX;
+-(void) setX: (int) arg;
+ at end
+
+ at implementation Top4
+-(int) x {
+ printf("-[ Top4 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Top4 _setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot4
+-(int) _getX {
+ printf("-[ Bot4 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Bot4 setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed setter & getter (variant 4)
+
+ at interface Top5 : NSObject
+ at property(getter=_getX,setter=_setX:) int x;
+ at end
+
+ at interface Bot5 : Top5
+-(int) x;
+-(void) _setX: (int) arg;
+ at end
+
+ at implementation Top5
+-(int) _getX {
+ printf("-[ Top5 _getX ]\n");
+ return 0;
+}
+-(void) setX: (int) arg {
+ printf("-[ Top5 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot5
+-(int) x {
+ printf("-[ Bot5 x ]\n");
+ return 0;
+}
+-(void) _setX: (int) arg {
+ printf("-[ Bot5 _setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed level calls (variant 1)
+
+ at interface Top6 : NSObject
+-(int) x;
+ at end
+
+ at interface Bot6 : Top6
+-(void) setX: (int) arg;
+ at end
+
+ at implementation Top6
+-(int) x {
+ printf("-[ Top6 x ]\n");
+ return 0;
+}
+ at end
+
+ at implementation Bot6
+-(void) setX: (int) arg {
+ printf("-[ Bot5 setX: %d ]\n", arg);
+}
+ at end
+
+// Mixed level calls (variant 1)
+
+ at interface Top7 : NSObject
+-(void) setX: (int) arg;
+ at end
+
+ at interface Bot7 : Top7
+-(int) x;
+ at end
+
+ at implementation Top7
+-(void) setX: (int) arg {
+ printf("-[ Top7 setX: %d ]\n", arg);
+}
+ at end
+
+ at implementation Bot7
+-(int) x {
+ printf("-[ Bot7 x ]\n");
+ return 0;
+}
+ at end
+
+//
+
+int main() {
+#define test(N) { \
+ Bot##N *ob = [[Bot##N alloc] init]; \
+ int x = ob.x; \
+ ob.x = 10; }
+
+ test(0);
+ test(1);
+ test(2);
+ test(3);
+ test(4);
+ test(5);
+ test(6);
+ test(7);
+
+ return 0;
+}
+
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-2.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-2.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-2.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax-2.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,34 @@
+#include <Foundation/NSObject.h>
+#include <stdio.h>
+
+ at interface A : NSObject {
+ int x;
+ char y;
+}
+
+ at property int x;
+ at property char y;
+ at end
+
+ at implementation A
+-(int) x {
+ return x + 2;
+}
+
+-(void) setX: (int) arg {
+ x = arg * 3 + 1;
+}
+
+ at synthesize y;
+ at end
+
+int main() {
+ A *a = [[A alloc] init];
+ int res = (a.x += 1);
+ printf("res: %d\n", res);
+
+ res = (a.y = 0xFFFF);
+ printf("res: %d\n", res);
+
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/dot-syntax.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,89 @@
+#include <Foundation/NSObject.h>
+#include <stdio.h>
+
+typedef struct {
+ float x, y, z[2];
+} S;
+
+ at interface A : NSObject {
+ int myX;
+ _Complex int myY;
+ S myZ;
+}
+
+ at property int x;
+ at property __complex int y;
+ at property S z;
+ at end
+
+ at implementation A
+-(int) x {
+ printf("-[A x] = %d\n", myX);
+ return myX;
+}
+-(void) setX: (int) arg {
+ myX = arg;
+ printf("-[A setX: %d]\n", myX);
+}
+
+-(__complex int) y {
+ printf("-[A y] = (%d, %d)\n", __real myY, __imag myY);
+ return myY;
+}
+-(void) setY: (__complex int) arg {
+ myY = arg;
+ printf("-[A setY: (%d, %d)]\n", __real myY, __imag myY);
+}
+
+-(S) z {
+ printf("-[A z] = { %f, %f, { %f, %f } }\n",
+ myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
+ return myZ;
+}
+-(void) setZ: (S) arg {
+ myZ = arg;
+ printf("-[A setZ: { %f, %f, { %f, %f } } ]\n",
+ myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
+}
+
+ at end
+
+int main() {
+#define SWAP(T,a,b) { T a_tmp = a; a = b; b = a_tmp; }
+ A *a = [[A alloc] init];
+ A *b = [[A alloc] init];
+ int a0 = 23;
+ _Complex int a1 = 25 + 10i;
+ S a2 = { 246, 458, {275, 12} };
+ int b0 = 42673;
+ _Complex int b1 = 15 + 13i;
+ S b2 = { 26, 2, {367, 13} };
+
+ a.x = a0;
+ a.y = a1;
+ a.z = a2;
+
+ a.x += a0;
+ a.y += a1;
+ // Yay, no compound assign of structures. A GCC extension in the
+ // works, perhaps?
+
+ b.x = b0;
+ b.y = b1;
+ b.z = b2;
+
+ int x0 = (b.x = b0);
+ printf("(b.x = b0): %d\n", x0);
+
+ int x1 = __real (b.y = b1);
+ printf("__real (b.y = b1) = %d\n", x1);
+
+ float x2 = (b.z = b2).x;
+ printf("(b.z = b2).x: %f\n", x2);
+
+ SWAP(int, a.x, b.x);
+ SWAP(__complex int, a.y, b.y);
+ SWAP(S, a.z, b.z);
+
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/exceptions.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/exceptions.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/exceptions.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/exceptions.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,156 @@
+#include <Foundation/NSObject.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define D() printf("%s:%d\n", __FILE__, __LINE__)
+
+ at interface A @end
+ at implementation A @end
+
+void f0() {
+ @throw(@"hi");
+}
+
+int f1(int return_in_finally) {
+ @try {
+ D();
+ f0();
+ D();
+ return 0;
+ } @finally {
+ D();
+ if (return_in_finally)
+ return 1;
+ }
+ return 2;
+}
+
+int f2(int return_in_catch) {
+ @try {
+ D();
+ f0();
+ D();
+ return 0;
+ } @catch(A *x) {
+ } @catch(...) {
+ D();
+ if (return_in_catch)
+ return 1;
+ }
+ return 2;
+}
+
+int f3() {
+ @try {
+ D();
+ f0();
+ D();
+ return 0;
+ } @catch(...) {
+ D();
+ @throw(@"hello");
+ D();
+ }
+ return 2;
+}
+
+void t1() {
+ @try {
+ D();
+ printf("f1() = %d\n", f1(1));
+ D();
+ printf("f1() = %d\n", f1(0));
+ D();
+ } @catch(id e) {
+ D();
+ } @finally {
+ D();
+ }
+ D();
+}
+
+void t2() {
+ @try {
+ D();
+ printf("f2() = %d\n", f2(1));
+ D();
+ printf("f2() = %d\n", f2(0));
+ D();
+ } @catch(id e) {
+ D();
+ } @finally {
+ D();
+ }
+ D();
+}
+
+void t3() {
+ @try {
+ D();
+ printf("f3() = %d\n", f3());
+ D();
+ } @catch(id e) {
+ D();
+ } @finally {
+ D();
+ }
+ D();
+}
+
+void t4() {
+ int i;
+
+ @try {
+ for (i=0; i<10; ++i) {
+ @try {
+ printf("i=%d\n", i);
+ // These all end up being a continue due to the finally block.
+ if (i==2) return;
+ D();
+ if (i==3) @throw(@"x");
+ D();
+ if (i==4) break;
+ D();
+ if (i==5) @throw([[NSObject alloc] init]);
+ D();
+ if (i==6) continue;
+ D();
+ } @catch (NSString *e) {
+ D();
+ @throw;
+ } @catch (id e) {
+ D();
+ @throw;
+ } @finally {
+ D();
+ if (i==8)
+ return;
+ D();
+ continue;
+ }
+ }
+ } @finally {
+ D();
+ }
+}
+
+void t5() {
+ @try {
+ return;
+ } @finally {
+ D();
+ }
+}
+
+int main() {
+ t1();
+ t2();
+ t3();
+ // Unfortunately, gcc gets the semantics wrong on x86_64.
+#if !defined(__x86_64__) && !defined(_M_AMD64)
+ t4();
+#endif
+ t5();
+
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/for-in.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/for-in.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/for-in.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/for-in.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,42 @@
+#import <Cocoa/Cocoa.h>
+
+#define S(n) @#n
+#define L1(n) S(n+0),S(n+1)
+#define L2(n) L1(n+0),L1(n+2)
+#define L3(n) L2(n+0),L2(n+4)
+#define L4(n) L3(n+0),L3(n+8)
+#define L5(n) L4(n+0),L4(n+16)
+#define L6(n) L5(n+0),L5(n+32)
+
+void t0() {
+ NSArray *array = [NSArray arrayWithObjects: L1(0), nil];
+
+ printf("array.length: %d\n", (int) [array count]);
+ unsigned index = 0;
+ for (NSString *i in array) {
+ printf("element %d: %s\n", index++, [i cString]);
+ }
+}
+
+void t1() {
+ NSArray *array = [NSArray arrayWithObjects: L6(0), nil];
+
+ printf("array.length: %d\n", (int) [array count]);
+ unsigned index = 0;
+ for (NSString *i in array) {
+ index++;
+ if (index == 10)
+ continue;
+ printf("element %d: %s\n", index, [i cString]);
+ if (index == 55)
+ break;
+ }
+}
+
+int main() {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ t0();
+ t1();
+ [pool release];
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/messages-2.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/messages-2.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/messages-2.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/messages-2.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,205 @@
+#include <Foundation/NSObject.h>
+#include <Foundation/NSGeometry.h>
+#include <stdio.h>
+
+typedef struct {
+ int x, y, z[10];
+} MyPoint;
+
+ at interface A : NSObject
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3;
++(float) returnAFloat;
++(double) returnADouble;
++(MyPoint) returnAPoint;
++(void) printThisSize: (NSSize) arg0;
++(NSSize) returnASize;
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3;
+-(float) returnAFloat;
+-(double) returnADouble;
+-(MyPoint) returnAPoint;
+-(void) printThisSize: (NSSize) arg0;
+-(NSSize) returnASize;
+ at end
+ at interface B : A
+ at end
+
+ at implementation A
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ printf("(CLASS) theInt: %d, theFloat: %f, theDouble: %f, thePoint: { %d, %d }\n",
+ arg0, arg1, arg2, arg3.x, arg3.y);
+}
++(float) returnAFloat {
+ return 15.;
+}
++(double) returnADouble {
+ return 25.;
+}
++(MyPoint) returnAPoint {
+ MyPoint x = { 35, 45 };
+ return x;
+}
++(void) printThisSize: (NSSize) arg0 {
+ printf("(CLASS) theSize: { %f, %f }\n",
+ arg0.width, arg0.height);
+}
++(NSSize) returnASize {
+ NSSize x = { 32, 44 };
+ return x;
+}
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ printf("theInt: %d, theFloat: %f, theDouble: %f, thePoint: { %d, %d }\n",
+ arg0, arg1, arg2, arg3.x, arg3.y);
+}
+-(float) returnAFloat {
+ return 10.;
+}
+-(double) returnADouble {
+ return 20.;
+}
+-(MyPoint) returnAPoint {
+ MyPoint x = { 30, 40 };
+ return x;
+}
+-(void) printThisSize: (NSSize) arg0 {
+ printf("theSize: { %f, %f }\n",
+ arg0.width, arg0.height);
+}
+-(NSSize) returnASize {
+ NSSize x = { 22, 34 };
+ return x;
+}
+ at end
+
+ at implementation B
++(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ arg3.x *= 2;
+ arg3.y *= 2;
+ [ super printThisInt: arg0*2 andThatFloat: arg1*2 andADouble: arg2*2 andAPoint: arg3 ];
+}
++(void) printThisSize: (NSSize) arg0 {
+ arg0.width *= 2;
+ arg0.height *= 2;
+ [ super printThisSize: arg0 ];
+}
++(float) returnAFloat {
+ return [ super returnAFloat ]*2;// FIXME: + super.returnAFloat;
+}
++(double) returnADouble {
+ return [ super returnADouble ]*2;
+}
++(MyPoint) returnAPoint {
+ MyPoint x = [ super returnAPoint ];
+ x.x *= 2;
+ x.y *= 2;
+ return x;
+}
++(NSSize) returnASize {
+ NSSize x = [ super returnASize ];
+ x.width *= 2;
+ x.height *= 2;
+ return x;
+}
+
+-(void) printThisInt: (int) arg0 andThatFloat: (float) arg1 andADouble: (double) arg2 andAPoint: (MyPoint) arg3 {
+ arg3.x *= 2;
+ arg3.y *= 2;
+ [ super printThisInt: arg0*2 andThatFloat: arg1*2 andADouble: arg2*2 andAPoint: arg3 ];
+}
+-(void) printThisSize: (NSSize) arg0 {
+ arg0.width *= 2;
+ arg0.height *= 2;
+ [ super printThisSize: arg0 ];
+}
+-(float) returnAFloat {
+ return [ super returnAFloat ]*2;
+}
+-(double) returnADouble {
+ return [ super returnADouble ]*2;
+}
+-(MyPoint) returnAPoint {
+ MyPoint x = [ super returnAPoint ];
+ x.x *= 2;
+ x.y *= 2;
+ return x;
+}
+-(NSSize) returnASize {
+ NSSize x = [ super returnASize ];
+ x.width *= 2;
+ x.height *= 2;
+ return x;
+}
+ at end
+
+void test(A *a) {
+ MyPoint pt = { 33, 52 };
+ NSSize size = { 44, 55 };
+
+ [ a printThisInt: 1 andThatFloat: 2.0 andADouble: 3.0 andAPoint: pt ];
+ [ a printThisSize: size ] ;
+
+ printf("A returned float: %f\n", [ a returnAFloat ]);
+
+ printf("A returned double: %f\n", [ a returnADouble ]);
+
+ MyPoint x = [ a returnAPoint ];
+ printf("A returned struct: { %d, %d }\n", x.x, x.y);
+
+ printf("A returned struct (%d)\n", [ a returnAPoint ].x);
+
+ NSSize y = [ a returnASize ];
+ printf("A returned size: { %f, %f }\n", y.width, y.height);
+}
+
+void test2() {
+ MyPoint pt = { 33, 52 };
+ NSSize size = { 44, 55 };
+
+ [ A printThisInt: 1 andThatFloat: 2.0 andADouble: 3.0 andAPoint: pt ];
+ [ A printThisSize: size ] ;
+
+ printf("A returned float: %f\n", [ A returnAFloat ]);
+
+ printf("A returned double: %f\n", [ A returnADouble ]);
+
+ MyPoint x = [ A returnAPoint ];
+ printf("A returned struct: { %d, %d }\n", x.x, x.y);
+
+ printf("A returned struct (%d)\n", [ A returnAPoint].x);
+
+ NSSize y = [ A returnASize ];
+ printf("A returned size: { %f, %f }\n", y.width, y.height);
+}
+
+void test3() {
+ MyPoint pt = { 33, 52 };
+ NSSize size = { 44, 55 };
+
+ [ B printThisInt: 1 andThatFloat: 2.0 andADouble: 3.0 andAPoint: pt ];
+ [ B printThisSize: size ] ;
+
+ printf("B returned float: %f\n", [ B returnAFloat ]);
+
+ printf("B returned double: %f\n", [ B returnADouble ]);
+
+ MyPoint x = [ B returnAPoint ];
+ printf("B returned struct: { %d, %d }\n", x.x, x.y);
+
+ printf("B returned struct (%d)\n", [ B returnAPoint ].x);
+
+ NSSize y = [ B returnASize ];
+ printf("B returned size: { %f, %f }\n", y.width, y.height);
+}
+
+int main() {
+ A *a = [[A alloc] init];
+ test(a);
+ A *b = [[B alloc] init];
+ test(b);
+
+ test2();
+ test3();
+
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/messages.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/messages.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/messages.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/messages.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,97 @@
+#import <Foundation/NSObject.h>
+#include <stdio.h>
+
+typedef struct {
+ int x;
+ int y;
+ int z[10];
+} MyPoint;
+
+ at interface A : NSObject {
+}
+
+-(id) print0;
+-(id) print1: (int) a0;
+-(id) print2: (int) a0 and: (char*) a1 and: (double) a2;
+-(id) takeStruct: (MyPoint) p;
+ at end
+
+void foo(id a) {
+ int i;
+ MyPoint pt = { 1, 2};
+
+ [a print0];
+ [a print1: 10];
+ [a print2: 10 and: "hello" and: 2.2];
+ [a takeStruct: pt ];
+
+ void *s = @selector(print0);
+ for (i=0; i<2; ++i)
+ [a performSelector:s];
+}
+
+ at implementation A
+-(id) print0 {
+ printf("I am A! Hear me roar!\n");
+ return nil;
+}
+
+-(id) print1: (int) a0 {
+ printf("I AM A! HEAR ME ROAR (%d TIMES LOUDER)!\n", a0);
+ return nil;
+}
+
+-(id) print2: (int) a0 and: (char*) a1 and: (double) a2{
+ printf("I AM A! I CAN ROAR WITH ARGUMENTS LIKE %d, %s, and %f!\n", a0, a1, a2);
+ return nil;
+}
+
+-(id) print2: (int) arg {
+ printf("By golly you set x to %d\n", arg);
+ return nil;
+}
+
+-(id) takeStruct: (MyPoint) p {
+ printf("Struct: { %d, %d }\n", p.x, p.y);
+ return nil;
+}
+
+ at end
+
+ at interface C : NSObject
+ at end
+ at interface D : C
+ at end
+
+ at implementation C
++(void) classMessage {
+ printf("C classMessage\n");
+}
+-(void) instanceMessage {
+ printf("C instanceMessage\n");
+}
+ at end
+
+ at implementation D
++(void) classMessage {
+ printf("D classMessage\n");
+ [ super classMessage ];
+}
+-(void) instanceMessage {
+ printf("D instanceMessage\n");
+ [ super instanceMessage ];
+}
+ at end
+
+int main() {
+ A *a = [[A alloc] init];
+ foo(a);
+ [a release];
+
+ [ C classMessage ];
+ [[[C alloc] init] instanceMessage];
+ [ D classMessage ];
+ [[[D alloc] init] instanceMessage];
+
+ return 0;
+}
Modified: test-suite/trunk/SingleSource/UnitTests/ObjC/parameter-passing.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/parameter-passing.m?rev=76142&r1=76141&r2=76142&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/parameter-passing.m (original)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/parameter-passing.m Thu Jul 16 21:16:57 2009
@@ -16,10 +16,8 @@
long long _ll_ivar;
float _f_ivar;
double _d_ivar;
-#ifdef TEST_COMPLEX
_Complex int _i_complex_ivar;
_Complex float _f_complex_ivar;
-#endif
IntPair _i_pair_ivar;
FloatPair _f_pair_ivar;
}
@@ -30,10 +28,8 @@
@property (assign) long long ll_ivar;
@property (assign) float f_ivar;
@property (assign) double d_ivar;
-#ifdef TEST_COMPLEX
@property (assign) _Complex int i_complex_ivar;
@property (assign) _Complex float f_complex_ivar;
-#endif
@property (assign) IntPair i_pair_ivar;
@property (assign) FloatPair f_pair_ivar;
@@ -48,12 +44,10 @@
-(float) return_f;
-(void) unary_d: (double) a0;
-(double) return_d;
-#ifdef TEST_COMPLEX
-(void) unary_i_complex: (_Complex int) a0;
-(_Complex int) return_i_complex;
-(void) unary_f_complex: (_Complex float) a0;
-(_Complex float) return_f_complex;
-#endif
-(void) unary_i_pair: (IntPair) a0;
-(IntPair) return_i_pair;
-(void) unary_f_pair: (FloatPair) a0;
@@ -66,10 +60,8 @@
@synthesize ll_ivar = _ll_ivar;
@synthesize f_ivar = _f_ivar;
@synthesize d_ivar = _d_ivar;
-#ifdef TEST_COMPLEX
@synthesize i_complex_ivar = _i_complex_ivar;
@synthesize f_complex_ivar = _f_complex_ivar;
-#endif
@synthesize i_pair_ivar = _i_pair_ivar;
@synthesize f_pair_ivar = _f_pair_ivar;
@@ -129,7 +121,6 @@
return rv;
}
-#ifdef TEST_COMPLEX
-(void) unary_i_complex: (_Complex int) a0 {
D(__FUNCTION__);
printf("\ta0: %d + %dj\n", __real a0, __imag a0);
@@ -155,7 +146,6 @@
printf("\t returning: (%f, %f)\n", __real rv, __imag rv);
return rv;
}
-#endif
-(void) unary_i_pair: (IntPair) a0 {
D(__FUNCTION__);
@@ -194,10 +184,8 @@
long long ll_test_var = 0xABCDABCDABCDABCDLL;
float f_test_var = 52.5;
double d_test_var = 25.2;
-#ifdef TEST_COMPLEX
_Complex int i_complex_test_var = 123 + 456j;
_Complex float f_complex_test_var = 123.4 + 678.5j;
-#endif
IntPair i_pair_test_var = { 0xABCDABCD, 0xDBCADBCA };
FloatPair f_pair_test_var = { 25.2, 52.5 };
@@ -206,10 +194,8 @@
[a unary_ll: ll_test_var];
[a unary_f: f_test_var];
[a unary_d: d_test_var];
-#ifdef TEST_COMPLEX
[a unary_i_complex: i_complex_test_var];
[a unary_f_complex: f_complex_test_var];
-#endif
[a unary_i_pair: i_pair_test_var];
[a unary_f_pair: f_pair_test_var];
@@ -233,7 +219,6 @@
printf("\tresult: %f\n\n", rv);
assert(rv == d_test_var);
}
-#ifdef TEST_COMPLEX
{
_Complex int rv = [a return_i_complex];
printf("\tresult: (%d, %d)\n\n", __real rv, __imag rv);
@@ -244,7 +229,6 @@
printf("\tresult: (%f, %f)\n\n", __real rv, __imag rv);
assert(rv == f_complex_test_var);
}
-#endif
{
IntPair rv = [a return_i_pair];
printf("\tresult: (%d, %d)\n\n", rv.first, rv.second);
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/predefined-expr-in-method.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/predefined-expr-in-method.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/predefined-expr-in-method.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/predefined-expr-in-method.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,17 @@
+#include <Foundation/NSObject.h>
+#include <stdio.h>
+
+ at interface A : NSObject
+ at end
+ at implementation A
++(void) foo {
+ printf("__func__: %s\n", __func__);
+ printf("__FUNCTION__: %s\n", __FUNCTION__);
+ printf("__PRETTY_FUNCTION__: %s\n", __PRETTY_FUNCTION__);
+}
+ at end
+
+int main() {
+ [A foo];
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/property.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/property.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/property.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/property.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,152 @@
+#include <Cocoa/Cocoa.h>
+
+struct S {
+ int f0, f1;
+};
+
+ at interface A : NSObject <NSCopying> {
+ int x, _y, z, ro;
+ id ob0, ob1, ob2, ob3, ob4;
+}
+ at property int x;
+ at property int y;
+ at property int z;
+ at property(readonly) int ro;
+ at property(assign) id ob0;
+ at property(retain) id ob1;
+ at property(copy) id ob2;
+ at property(retain, nonatomic) id ob3;
+ at property(copy, nonatomic) id ob4;
+
+-(id) copyWithZone: (NSZone*) zone;
+ at end
+
+ at implementation A
+ at synthesize x;
+ at synthesize y = _y;
+ at synthesize z;
+ at synthesize ro;
+ at synthesize ob0;
+ at synthesize ob1;
+ at synthesize ob2;
+ at synthesize ob3;
+ at synthesize ob4;
+-(int) y {
+ return x + 1;
+}
+-(void) setZ: (int) arg {
+ x = arg - 1;
+}
+
+-(id) copyWithZone: (NSZone*) zone {
+ [self retain];
+ return self;
+}
+ at end
+
+ at interface A (Cat)
+ at property int moo;
+ at end
+
+ at implementation A (Cat)
+-(int) moo {
+ return 10;
+}
+-(void) setMoo: (int) arg {
+ printf("You set moo to %d. How quaint.\n", arg);
+}
+ at end
+
+ at interface I0 : NSObject {
+ at public
+ _Complex float iv0;
+}
+
+ at property(assign) _Complex float p0;
+
+-(_Complex float) im0;
+-(void) setIm0: (_Complex float) a0;
+ at end
+
+ at implementation I0
+ at dynamic p0;
+
+-(id) init {
+ self->iv0 = 5.0 + 2.0i;
+ return self;
+}
+
+-(_Complex float) im0 {
+ printf("im0: %.2f + %.2fi\n", __real iv0, __imag iv0);
+ return iv0 + (.1 + .2i);
+}
+-(void) setIm0: (_Complex float) a0 {
+ printf("setIm0: %.2f + %.2fi\n", __real a0, __imag a0);
+ iv0 = a0 + (.3 + .4i);
+}
+
+-(_Complex float) p0 {
+ printf("p0: %.2f + %.2fi\n", __real iv0, __imag iv0);
+ return iv0 + (.5 + .6i);
+}
+-(void) setP0: (_Complex float) a0 {
+ printf("setP0: %.2f + %.2fi\n", __real a0, __imag a0);
+ iv0 = a0 + (.7 + .8i);
+}
+ at end
+
+void f0(I0 *a0) {
+ float l0 = __real a0.im0;
+ float l1 = __imag a0->iv0;
+ _Complex float l2 = (a0.im0 = a0.im0);
+ _Complex float l3 = a0->iv0;
+ _Complex float l4 = (a0->iv0 = a0->iv0);
+ _Complex float l5 = a0->iv0;
+ _Complex float l6 = (a0.p0 = a0.p0);
+ _Complex float l7 = a0->iv0;
+ _Complex float l8 = [a0 im0];
+ printf("l0: %.2f + %.2fi\n", __real l0, __imag l0);
+ printf("l1: %.2f + %.2fi\n", __real l1, __imag l1);
+ printf("l2: %.2f + %.2fi\n", __real l2, __imag l2);
+ printf("l3: %.2f + %.2fi\n", __real l3, __imag l3);
+ printf("l4: %.2f + %.2fi\n", __real l4, __imag l4);
+ printf("l5: %.2f + %.2fi\n", __real l5, __imag l5);
+ printf("l6: %.2f + %.2fi\n", __real l6, __imag l6);
+ printf("l7: %.2f + %.2fi\n", __real l7, __imag l7);
+ printf("l8: %.2f + %.2fi\n", __real l8, __imag l8);
+}
+
+#define PRINT1(e0,t0) printf(#e0 ": %" #t0 "\n", e0)
+int main() {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ A *a = [[A alloc] init];
+
+ PRINT1([a x], d);
+ PRINT1([a y], d);
+ PRINT1([a z], d);
+ PRINT1([a ro], d);
+ PRINT1([a moo], d);
+
+ PRINT1(([a setX: 12], [a x]), d);
+ PRINT1(([a setY: 23], [a y]), d);
+ PRINT1(([a setZ: 4623], [a z]), d);
+ PRINT1(([a setMoo: 22.3], [a moo]), d);
+
+ PRINT1([a ob1], p);
+ PRINT1(([a setOb1: a], [a ob1] == a), d);
+
+ PRINT1([a ob2], p);
+ PRINT1(([a setOb2: a], [a ob2] == a), d);
+
+ PRINT1([a ob3], p);
+ PRINT1(([a setOb3: a], [a ob3] == a), d);
+
+ PRINT1([a ob4], p);
+ PRINT1(([a setOb4: a], [a ob4] == a), d);
+
+ [a release];
+
+ f0([[I0 alloc] init]);
+
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/protocols.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/protocols.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/protocols.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/protocols.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,62 @@
+#include <Foundation/NSObject.h>
+#include <objc/Object.h>
+#include <objc/runtime.h>
+#include <stdio.h>
+
+ at interface X
+-(unsigned char) conformsTo;
+ at end
+
+ at protocol P0;
+
+ at protocol P1
++(void) classMethodReq0;
+-(void) methodReq0;
+ at optional
++(void) classMethodOpt1;
+-(void) methodOpt1;
+ at required
++(void) classMethodReq2;
+-(void) methodReq2;
+ at end
+
+ at protocol P2
+//@property(readwrite) int x;
+ at end
+
+ at protocol P3<P1, P2>
+-(id <P1>) print0;
+-(void) print1;
+ at end
+
+ at interface A : NSObject <P0>
++(Class) getClass;
+ at end
+
+ at implementation A
++(Class) getClass { return self; }
+ at end
+
+void foo(const id a) {
+ void *p = @protocol(P3);
+}
+
+int main() {
+ Protocol *P0 = @protocol(P0);
+ Protocol *P1 = @protocol(P1);
+ Protocol *P2 = @protocol(P2);
+ Protocol *P3 = @protocol(P3);
+
+#define Pbool(X) printf(#X ": %s\n", X ? "yes" : "no");
+ Pbool([P0 conformsTo: P1]);
+ Pbool([P1 conformsTo: P0]);
+ Pbool([P1 conformsTo: P2]);
+ Pbool([P2 conformsTo: P1]);
+ Pbool([P3 conformsTo: P1]);
+ Pbool([P1 conformsTo: P3]);
+ Pbool([A getClass] != 0);
+ Pbool(class_conformsToProtocol([A getClass], @protocol(P0)));
+ Pbool(class_conformsToProtocol([A getClass], @protocol(P1)));
+
+ return 0;
+}
Added: test-suite/trunk/SingleSource/UnitTests/ObjC/synchronized.m
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/UnitTests/ObjC/synchronized.m?rev=76142&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/UnitTests/ObjC/synchronized.m (added)
+++ test-suite/trunk/SingleSource/UnitTests/ObjC/synchronized.m Thu Jul 16 21:16:57 2009
@@ -0,0 +1,40 @@
+#include <Cocoa/Cocoa.h>
+#include <stdio.h>
+
+ at interface A : NSThread
+-(void) main;
+ at end
+
+#define kNumThreads 10
+#define kLoopCount 10
+unsigned numThreads = kNumThreads;
+unsigned sum = 0;
+
+ at implementation A
+-(void) addToSum: (int) n {
+ @synchronized([self class]) {
+ int tmp = sum + n;
+ [NSThread sleepForTimeInterval: .001];
+ sum = tmp;
+ }
+}
+
+-(void) main {
+ unsigned i;
+ for (i = 0; i < kLoopCount; ++i)
+ [self addToSum: i];
+ --numThreads;
+}
+ at end
+
+int main() {
+ unsigned i;
+ numThreads = 10;
+ for (i = 0; i < numThreads; ++i) {
+ [[[A alloc] init] start];
+ }
+ while (numThreads) ;
+ printf("sum: %d\n", sum);
+ assert(sum == 10 * (kLoopCount * (kLoopCount - 1)) / 2);
+ return 0;
+}
More information about the llvm-commits
mailing list