aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-12-27 22:42:55 -0600
committerGanesh Viswanathan <dev@genotrance.com>2018-12-27 22:42:55 -0600
commit21bd2d4112e5bf40d3fe52435cc15ccd5d4ad71a (patch)
tree0d3fb8f8f5f45943309e2bcf7327b1cbd57b2f04 /tests
parentc7a3c7b7d606b00fa1c676e244c39002b8fc1609 (diff)
downloadnimterop-21bd2d4112e5bf40d3fe52435cc15ccd5d4ad71a.tar.gz
nimterop-21bd2d4112e5bf40d3fe52435cc15ccd5d4ad71a.zip
Struct field function pointers, cstring, show toast error in cimport
Diffstat (limited to 'tests')
-rw-r--r--tests/include/test.c6
-rw-r--r--tests/include/test.h9
-rw-r--r--tests/tnimterop_c.nim11
3 files changed, 25 insertions, 1 deletions
diff --git a/tests/include/test.c b/tests/include/test.c
index d63c974..3a59ffc 100644
--- a/tests/include/test.c
+++ b/tests/include/test.c
@@ -48,4 +48,10 @@ unsigned char test_call_param6(UNION2 param1) {
int test_call_param7(union UNION1 param1) {
return param1.field1;
+}
+
+float test_call_param8(int *param1) {
+ *param1 = 5 * *param1;
+
+ return 1.0 * *param1;
} \ No newline at end of file
diff --git a/tests/include/test.h b/tests/include/test.h
index e040d7f..29181c5 100644
--- a/tests/include/test.h
+++ b/tests/include/test.h
@@ -52,6 +52,12 @@ typedef struct {
ENUM4 *field5[TEST_INT];
} STRUCT4;
+typedef struct STRUCT5 {
+ int (*tci)();
+ struct STRUCT1 (*tcp)(int);
+ float (*tcp8)(int *i);
+} STRUCT5;
+
union UNION1 {
int field1;
float field2;
@@ -69,4 +75,5 @@ STRUCT2 test_call_param3(int param1, struct STRUCT1 param2);
ENUM2 test_call_param4(enum ENUM param1);
union UNION1 test_call_param5(float param1);
unsigned char test_call_param6(UNION2 param1);
-int test_call_param7(union UNION1 param1); \ No newline at end of file
+int test_call_param7(union UNION1 param1);
+float test_call_param8(int *param1); \ No newline at end of file
diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim
index deef7d2..69f8105 100644
--- a/tests/tnimterop_c.nim
+++ b/tests/tnimterop_c.nim
@@ -21,6 +21,7 @@ var
s2: STRUCT2
s3: STRUCT3
s4: STRUCT4
+ s5: STRUCT5
e: ENUM
e2: ENUM2 = enum5
@@ -33,6 +34,8 @@ var
u: UNION1
u2: UNION2
+ i: int
+
pt = 3
ct = 4
@@ -41,12 +44,18 @@ s2.field1 = 6
s3.field1 = 7
s4.field2[2] = 5
s4.field3[3] = enum1
+s5.tci = test_call_int
+s5.tcp = test_call_param
+s5.tcp8 = test_call_param8
+check s5.tci() == 5
e = enum1
e2 = enum4
u2.field2 = 'c'
+i = 5
+
check test_call_int() == 5
check test_call_param(5).field1 == 5
check test_call_param2(5, s2).field1 == 11
@@ -56,6 +65,8 @@ check test_call_param5(5.0).field2 == 5.0
check test_call_param6(u2) == 'c'
u.field1 = 4
check test_call_param7(u) == 4
+check test_call_param8(addr i) == 25.0
+check i == 25
check e3 == enum7
check e4 == enum11