Add tests for objc_msgSend* family.
This commit is contained in:
committed by
Sergey Bogolepov
parent
12c7725cc0
commit
a50a828d81
@@ -3305,6 +3305,12 @@ if (PlatformInfo.isAppleTarget(project)) {
|
||||
it.headers "$projectDir/interop/objc_with_initializer/objc_misc.h"
|
||||
it.linkerOpts "-L$buildDir", "-lobjcmisc"
|
||||
}
|
||||
|
||||
createInterop("objcMessaging") {
|
||||
it.defFile 'interop/objc/msg_send/messaging.def'
|
||||
it.headers "$projectDir/interop/objc/msg_send/messaging.h"
|
||||
it.linkerOpts "-L$buildDir", "-lobjcmessaging"
|
||||
}
|
||||
}
|
||||
|
||||
createInterop("withSpaces") {
|
||||
@@ -3528,6 +3534,23 @@ interopTest("interop_objc_global_initializer") {
|
||||
}
|
||||
}
|
||||
|
||||
interopTest("interop_objc_msg_send") {
|
||||
disabled = !isAppleTarget(project)
|
||||
|
||||
source = "interop/objc/msg_send/main.kt"
|
||||
interop = 'objcMessaging'
|
||||
|
||||
doBefore {
|
||||
execKonanClang(project.target) {
|
||||
args "$projectDir/interop/objc/msg_send/messaging.m"
|
||||
args "-lobjc", '-fobjc-arc'
|
||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcmessaging.dylib"
|
||||
}
|
||||
if (project.target instanceof KonanTarget.IOS_X64) {
|
||||
UtilsKt.codesign(project, "$buildDir/libobjcmessaging.dylib")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
standaloneTest("jsinterop_math") {
|
||||
doBefore {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import messaging.*
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
autoreleasepool {
|
||||
primitives()
|
||||
aggregates()
|
||||
}
|
||||
}
|
||||
|
||||
private fun primitives() {
|
||||
assertEquals(3.14f, PrimitiveTestSubject.floatFn())
|
||||
assertEquals(3.14, PrimitiveTestSubject.doubleFn())
|
||||
assertEquals(42, PrimitiveTestSubject.intFn())
|
||||
}
|
||||
|
||||
private fun aggregates() {
|
||||
AggregateTestSubject.singleFloatFn().useContents {
|
||||
assertEquals(3.14f, f)
|
||||
}
|
||||
AggregateTestSubject.simplePackedFn().useContents {
|
||||
assertEquals('0'.toByte(), f1)
|
||||
assertEquals(111, f2)
|
||||
}
|
||||
AggregateTestSubject.evenSmallerPackedFn().useContents {
|
||||
assertEquals('x'.toByte(), x)
|
||||
assertEquals(169, y)
|
||||
assertEquals('z'.toByte(), z)
|
||||
}
|
||||
AggregateTestSubject.homogeneousBigFn().useContents {
|
||||
assertEquals(1.0f, f1)
|
||||
assertEquals(2.0f, f2)
|
||||
assertEquals(3.0f, f3)
|
||||
assertEquals(4.0f, f4)
|
||||
assertEquals(5.0f, f5)
|
||||
assertEquals(6.0f, f6)
|
||||
assertEquals(7.0f, f7)
|
||||
assertEquals(8.0f, f8)
|
||||
}
|
||||
AggregateTestSubject.homogeneousSmallFn().useContents {
|
||||
assertEquals(1.0f, f1)
|
||||
assertEquals(2.0f, f2)
|
||||
assertEquals(3.0f, f3)
|
||||
assertEquals(4.0f, f4)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
language = Objective-C
|
||||
headerFilter = **/messaging.h
|
||||
@@ -0,0 +1,56 @@
|
||||
#import <objc/NSObject.h>
|
||||
|
||||
@interface PrimitiveTestSubject : NSObject
|
||||
|
||||
+ (int)intFn;
|
||||
+ (float)floatFn;
|
||||
+ (double)doubleFn;
|
||||
|
||||
@end;
|
||||
|
||||
typedef struct {
|
||||
float f;
|
||||
} SingleFloat;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
char f1;
|
||||
short f2;
|
||||
char f3;
|
||||
char f4;
|
||||
} SimplePacked;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
char x;
|
||||
short y;
|
||||
char z;
|
||||
} EvenSmallerPacked;
|
||||
|
||||
typedef struct {
|
||||
float f1;
|
||||
float f2;
|
||||
float f3;
|
||||
float f4;
|
||||
} HomogeneousSmall;
|
||||
|
||||
typedef struct {
|
||||
float f1;
|
||||
float f2;
|
||||
float f3;
|
||||
float f4;
|
||||
float f5;
|
||||
float f6;
|
||||
float f7;
|
||||
float f8;
|
||||
} HomogeneousBig;
|
||||
|
||||
// TODO: Add more cases later: SIMD, bitfields.
|
||||
|
||||
@interface AggregateTestSubject : NSObject
|
||||
|
||||
+ (SingleFloat)singleFloatFn;
|
||||
+ (SimplePacked)simplePackedFn;
|
||||
+ (EvenSmallerPacked)evenSmallerPackedFn;
|
||||
+ (HomogeneousSmall)homogeneousSmallFn;
|
||||
+ (HomogeneousBig)homogeneousBigFn;
|
||||
|
||||
@end;
|
||||
@@ -0,0 +1,64 @@
|
||||
#import "messaging.h"
|
||||
|
||||
@implementation PrimitiveTestSubject
|
||||
|
||||
+ (int)intFn {
|
||||
return 42;
|
||||
}
|
||||
|
||||
+ (float)floatFn {
|
||||
return 3.14f;
|
||||
}
|
||||
|
||||
+ (double)doubleFn {
|
||||
return 3.14;
|
||||
}
|
||||
|
||||
@end;
|
||||
|
||||
@implementation AggregateTestSubject
|
||||
|
||||
+ (SingleFloat)singleFloatFn {
|
||||
SingleFloat s;
|
||||
s.f = 3.14f;
|
||||
return s;
|
||||
}
|
||||
|
||||
+ (SimplePacked)simplePackedFn {
|
||||
SimplePacked s;
|
||||
s.f1 = '0';
|
||||
s.f2 = 111;
|
||||
return s;
|
||||
}
|
||||
|
||||
+ (EvenSmallerPacked)evenSmallerPackedFn {
|
||||
EvenSmallerPacked s;
|
||||
s.x = 'x';
|
||||
s.y = 169;
|
||||
s.z = 'z';
|
||||
return s;
|
||||
}
|
||||
|
||||
+ (HomogeneousSmall)homogeneousSmallFn {
|
||||
HomogeneousSmall s;
|
||||
s.f1 = 1.0f;
|
||||
s.f2 = 2.0f;
|
||||
s.f3 = 3.0f;
|
||||
s.f4 = 4.0f;
|
||||
return s;
|
||||
}
|
||||
|
||||
+ (HomogeneousBig)homogeneousBigFn {
|
||||
HomogeneousBig s;
|
||||
s.f1 = 1.0f;
|
||||
s.f2 = 2.0f;
|
||||
s.f3 = 3.0f;
|
||||
s.f4 = 4.0f;
|
||||
s.f5 = 5.0f;
|
||||
s.f6 = 6.0f;
|
||||
s.f7 = 7.0f;
|
||||
s.f8 = 8.0f;
|
||||
return s;
|
||||
}
|
||||
|
||||
@end;
|
||||
Reference in New Issue
Block a user