aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-10-21 21:42:09 -0500
committerGanesh Viswanathan <dev@genotrance.com>2019-10-21 21:42:09 -0500
commit5f9a59fcc676170bf465d95971e700ca16959385 (patch)
tree78c9facb1b3bd263f36f15c70ba27aefcee07426
parent9b6469ca97b8614e6634379e8b7290b7dc4c8606 (diff)
downloadnimterop-override.tar.gz
nimterop-override.zip
Test cases for cOverrideoverride
-rw-r--r--tests/include/test.c8
-rw-r--r--tests/include/test.h25
-rw-r--r--tests/tnimterop_c.nim41
3 files changed, 74 insertions, 0 deletions
diff --git a/tests/include/test.c b/tests/include/test.c
index 18e444f..e9cb2aa 100644
--- a/tests/include/test.c
+++ b/tests/include/test.c
@@ -75,3 +75,11 @@ void *multiline2(void) {
}
void multiline3(void) {}
+
+int weirdfunc(char ***apple) {
+ return 1;
+}
+
+int weirdfunc2(char **apple) {
+ return 2;
+}
diff --git a/tests/include/test.h b/tests/include/test.h
index d062277..667f384 100644
--- a/tests/include/test.h
+++ b/tests/include/test.h
@@ -167,6 +167,31 @@ enum
TDEFL_BOGUS_3 = TDEFL_OUT_BUF_SIZE / TDEFL_BOGUS_1
};
+// cOverride
+struct foo { int foo[8][1]; };
+
+typedef struct tagBITMAPINFOHEADER{
+ int biClrImportant;
+} BITMAPINFOHEADER, * pBITMAPINFOHEADER;
+
+#define BIT 123u
+
+#define BIT2 123u
+
+#define BIT3 123
+
+typedef int ABC;
+
+typedef int DEF;
+
+typedef struct {
+ int **f1;
+} GHI;
+
+struct JKL {
+ int **f1;
+};
+
#ifdef __cplusplus
}
#endif
diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim
index a289303..fb1505a 100644
--- a/tests/tnimterop_c.nim
+++ b/tests/tnimterop_c.nim
@@ -20,6 +20,27 @@ cPlugin:
else:
sym.name = sym.name.strip(chars={'_'})
+cOverride:
+ type
+ BITMAPINFOHEADER* {.bycopy.} = object
+ biClrImportant*: int
+
+ Random = object
+
+ ABC = pointer
+
+ GHI = object
+ f2: ptr ptr cint
+
+ JKL = object
+ f2: ptr ptr cint
+
+ const
+ BIT* = 1
+
+ proc weirdfunc(apple: ptr ptr ptr cchar): int {.importc.}
+ proc weirdfunc2(mango: ptr ptr cchar): int {.importc.}
+
cImport cSearchPath "test.h"
check TEST_INT == 512
@@ -183,3 +204,23 @@ var
arr: array[5, cint]
check test_array_param(arr) == nil
+
+# cOverride
+
+var
+ ca = weirdfunc
+ cb: BITMAPINFOHEADER
+ cc = weirdfunc2
+ cd: ABC
+ ce: DEF
+ cf: GHI
+ cg: JKL
+
+cd = nil
+ce = 5
+cf.f2 = nil
+cg.f2 = nil
+
+doAssert BIT == 1
+doAssert ca(nil) == 1
+doAssert cc(nil) == 2