Skip to content

Commit

Permalink
Add tests for the various objc_msgSend_* functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Jul 11, 2015
1 parent 867d547 commit 929b56c
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/runnable/extra-files/objc_objc_msgSend.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#import <Foundation/Foundation.h>

typedef struct
{
int a, b, c, d, e;
} Struct;

@interface stret : NSObject
-(Struct) getValue;
@end

@implementation stret
-(Struct) getValue
{
Struct s = { 3, 3, 3, 3, 3 };
return s;
}
@end

@interface fp2ret : NSObject
-(_Complex long double) getValue;
@end

@implementation fp2ret
-(_Complex long double) getValue
{
return 1+3i;
}
@end

@interface fpret : NSObject
-(long double) getValue;
@end

@implementation fpret
-(long double) getValue
{
return 0.000000000000000002L;
}
@end

@interface float32 : NSObject
-(float) getValue;
@end

@implementation float32
-(float) getValue
{
return 0.2f;
}
@end

@interface double64 : NSObject
-(double) getValue;
@end

@implementation double64
-(double) getValue
{
return 0.2;
}
@end
108 changes: 108 additions & 0 deletions test/runnable/objc_objc_msgSend.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// EXTRA_OBJC_SOURCES: objc_objc_msgSend.m
// REQUIRED_ARGS: -L-framework -LFoundation

extern (C) Class objc_lookUpClass(in char* name);

struct Struct
{
int a, b, c, d, e;
}

extern (Objective-C)
interface Class
{
stret alloc_stret() @selector("alloc");
fp2ret alloc_fp2ret() @selector("alloc");
fpret alloc_fpret() @selector("alloc");
float32 alloc_float32() @selector("alloc");
double64 alloc_double64() @selector("alloc");
}

extern (Objective-C)
interface stret
{
stret init() @selector("init");
Struct getValue() @selector("getValue");
void release() @selector("release");
}

extern (Objective-C)
interface fp2ret
{
fp2ret init() @selector("init");
creal getValue() @selector("getValue");
void release() @selector("release");
}

extern (Objective-C)
interface fpret
{
fpret init() @selector("init");
real getValue() @selector("getValue");
void release() @selector("release");
}

extern (Objective-C)
interface float32
{
float32 init() @selector("init");
float getValue() @selector("getValue");
void release() @selector("release");
}

extern (Objective-C)
interface double64
{
double64 init() @selector("init");
double getValue() @selector("getValue");
void release() @selector("release");
}

void test_stret()
{
auto c = objc_lookUpClass("stret");
auto o = c.alloc_stret().init();
assert(o.getValue() == Struct(3, 3, 3, 3, 3));
o.release();
}

void test_fp2ret()
{
auto c = objc_lookUpClass("fp2ret");
auto o = c.alloc_fp2ret().init();
assert(o.getValue() == 1+3i);
o.release();
}

void test_fpret()
{
auto c = objc_lookUpClass("fpret");
auto o = c.alloc_fpret().init();
assert(o.getValue() == 0.000000000000000002L);
o.release();
}

void test_float32()
{
auto c = objc_lookUpClass("float32");
auto o = c.alloc_float32.init();
assert(o.getValue == 0.2f);
o.release();
}

void test_double64()
{
auto c = objc_lookUpClass("double64");
auto o = c.alloc_double64.init();
assert(o.getValue == 0.2);
o.release();
}

void main()
{
// test_stret();
// test_fp2ret();
test_fpret();
test_float32();
test_double64();
}

0 comments on commit 929b56c

Please sign in to comment.