diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-04 23:37:08 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-04 23:37:08 -0600 |
| commit | dfe06fd9d474c368cb6c724902dd20369d68f1b6 (patch) | |
| tree | e6cae42e79eba3b9c3d77c6e7f92f7de2320b257 /tests | |
| parent | cb1c7f28cbff8ac4e588266b8aa953a6f7f44563 (diff) | |
| download | nimterop-dfe06fd9d474c368cb6c724902dd20369d68f1b6.tar.gz nimterop-dfe06fd9d474c368cb6c724902dd20369d68f1b6.zip | |
Support for unions
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/include/test.c | 38 | ||||
| -rw-r--r-- | tests/include/test.h | 21 | ||||
| -rw-r--r-- | tests/tnimterop_c.nim | 17 |
3 files changed, 57 insertions, 19 deletions
diff --git a/tests/include/test.c b/tests/include/test.c index 885723e..d63c974 100644 --- a/tests/include/test.c +++ b/tests/include/test.c @@ -1,35 +1,51 @@ #include "test.h" int test_call_int() { - return 5; + return 5; } #ifdef FORCE -struct STRUCT1 _test_call_int_param_(int param1) { +struct STRUCT1 _test_call_param_(int param1) { struct STRUCT1 s; - + s.field1 = param1; - + return s; } #endif -STRUCT2 test_call_int_param2(int param1, STRUCT2 param2) { +STRUCT2 test_call_param2(int param1, STRUCT2 param2) { STRUCT2 s; - + s.field1 = param1 + param2.field1; - + return s; } -STRUCT2 test_call_int_param3(int param1, struct STRUCT1 param2) { +STRUCT2 test_call_param3(int param1, struct STRUCT1 param2) { STRUCT2 s; - + s.field1 = param1 + param2.field1; - + return s; } -ENUM2 test_call_int_param4(enum ENUM param1) { +ENUM2 test_call_param4(enum ENUM param1) { return enum4; +} + +union UNION1 test_call_param5(float param1) { + union UNION1 u; + + u.field2 = param1; + + return u; +} + +unsigned char test_call_param6(UNION2 param1) { + return param1.field2; +} + +int test_call_param7(union UNION1 param1) { + return param1.field1; }
\ No newline at end of file diff --git a/tests/include/test.h b/tests/include/test.h index 6138ca3..af7eeb8 100644 --- a/tests/include/test.h +++ b/tests/include/test.h @@ -36,8 +36,21 @@ typedef struct { int *field; } STRUCT4; +union UNION1 { + int field1; + float field2; +}; + +typedef union { + double field1; + unsigned char field2; +} UNION2; + int test_call_int(); -struct STRUCT1 _test_call_int_param_(int param1); -STRUCT2 test_call_int_param2(int param1, STRUCT2 param2); -STRUCT2 test_call_int_param3(int param1, struct STRUCT1 param2); -ENUM2 test_call_int_param4(enum ENUM param1); +struct STRUCT1 _test_call_param_(int param1); +STRUCT2 test_call_param2(int param1, STRUCT2 param2); +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 diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim index eff7039..2477e61 100644 --- a/tests/tnimterop_c.nim +++ b/tests/tnimterop_c.nim @@ -28,6 +28,9 @@ var vptr: VOIDPTR iptr: INTPTR + u: UNION1 + u2: UNION2 + pt = 3 ct = 4 @@ -38,10 +41,16 @@ s3.field1 = 7 e = enum1 e2 = enum4 +u2.field2 = 'c' + check test_call_int() == 5 -check test_call_int_param(5).field1 == 5 -check test_call_int_param2(5, s2).field1 == 11 -check test_call_int_param3(5, s).field1 == 10 -check test_call_int_param4(e) == e2 +check test_call_param(5).field1 == 5 +check test_call_param2(5, s2).field1 == 11 +check test_call_param3(5, s).field1 == 10 +check test_call_param4(e) == e2 +check test_call_param5(5.0).field2 == 5.0 +check test_call_param6(u2) == 'c' +u.field1 = 4 +check test_call_param7(u) == 4 cAddStdDir() |
