[K/N][Tests] Migrate dylib-interop-exe tests
^KT-61259
This commit is contained in:
committed by
Space Team
parent
83d851dd61
commit
2b2c685827
@@ -0,0 +1,3 @@
|
||||
language = Objective-C
|
||||
headerFilter = **/messaging.h
|
||||
linkerOpts = -lmessaging
|
||||
@@ -0,0 +1,68 @@
|
||||
#import <objc/NSObject.h>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@interface PrimitiveTestSubject : NSObject
|
||||
|
||||
+ (int)intFn;
|
||||
+ (float)floatFn;
|
||||
+ (double)doubleFn;
|
||||
+ (simd_float4)simdFn;
|
||||
|
||||
@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.
|
||||
|
||||
typedef struct {
|
||||
short s1;
|
||||
simd_float4 v2;
|
||||
float f3;
|
||||
int i4;
|
||||
} GeterogeneousSmall;
|
||||
|
||||
@interface AggregateTestSubject : NSObject
|
||||
|
||||
+ (SingleFloat)singleFloatFn;
|
||||
+ (SimplePacked)simplePackedFn;
|
||||
+ (EvenSmallerPacked)evenSmallerPackedFn;
|
||||
+ (HomogeneousSmall)homogeneousSmallFn;
|
||||
+ (HomogeneousBig)homogeneousBigFn;
|
||||
+ (simd_quatf)simd_quatfFn;
|
||||
+ (GeterogeneousSmall)geterogeneousSmallFn;
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,58 @@
|
||||
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())
|
||||
assertEquals(vectorOf(2f, 4f, 5f, 8f), PrimitiveTestSubject.simdFn())
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
AggregateTestSubject.simd_quatfFn().useContents {
|
||||
assertEquals(vectorOf(1f, 4f, 9f, 25f), vector)
|
||||
}
|
||||
AggregateTestSubject.geterogeneousSmallFn().useContents {
|
||||
assertEquals(1, s1)
|
||||
assertEquals(vectorOf(1f, 4f, 9f, 25f), v2)
|
||||
assertEquals(3f, f3)
|
||||
assertEquals(4, i4)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#import "messaging.h"
|
||||
|
||||
@implementation PrimitiveTestSubject
|
||||
|
||||
+ (int)intFn {
|
||||
return 42;
|
||||
}
|
||||
|
||||
+ (float)floatFn {
|
||||
return 3.14f;
|
||||
}
|
||||
|
||||
+ (double)doubleFn {
|
||||
return 3.14;
|
||||
}
|
||||
|
||||
+ (simd_float4)simdFn {
|
||||
simd_float4 v;
|
||||
v.x = 2;
|
||||
v.y = 4;
|
||||
v.z = 5;
|
||||
v.w = 8;
|
||||
return v;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
+ (GeterogeneousSmall)geterogeneousSmallFn {
|
||||
return (GeterogeneousSmall){1, {1, 4, 9, 25}, 3, 4};
|
||||
}
|
||||
|
||||
+ (simd_quatf)simd_quatfFn {
|
||||
return (simd_quatf){ {1, 4, 9, 25} };
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user