summaryrefslogtreecommitdiffstats
path: root/tests/017
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-20 21:38:50 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-20 21:38:50 -0700
commit3fbc79ce6f249c527f63763c02ea384e51180f99 (patch)
tree18d4c5a41b6c58cdb879f32ecb47de6dc469af40 /tests/017
parent5fc47b3d24f1fa568ffb54db8e8054f190e2fb2b (diff)
downloadtxr-3fbc79ce6f249c527f63763c02ea384e51180f99.tar.gz
txr-3fbc79ce6f249c527f63763c02ea384e51180f99.tar.bz2
txr-3fbc79ce6f249c527f63763c02ea384e51180f99.zip
ffi: add two tests based on realpath.
The realpath function is called using FFI. One approach passes a null pointer, so that the function dynamically allocates. The return value is str-d, causing FFI to take ownership of the pointer, freeing it. The other approach is to pass a pointer to a large null-terminated character array, marked for ownership transfer to the function. FFI allocates it and puts the argument into it, which is just a dummy empty string. The function fills that buffer and returns it. The return is captured as a str-d, so FFI takes ownership back, and frees the buffer. * tests/017/realpath.tl: New function. * tests/017/realpath.expected: Likewise.
Diffstat (limited to 'tests/017')
-rw-r--r--tests/017/realpath.expected2
-rw-r--r--tests/017/realpath.tl12
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/017/realpath.expected b/tests/017/realpath.expected
new file mode 100644
index 00000000..659aa110
--- /dev/null
+++ b/tests/017/realpath.expected
@@ -0,0 +1,2 @@
+"/usr/bin"
+"/usr/bin"
diff --git a/tests/017/realpath.tl b/tests/017/realpath.tl
new file mode 100644
index 00000000..d920825f
--- /dev/null
+++ b/tests/017/realpath.tl
@@ -0,0 +1,12 @@
+(load "../common")
+
+(with-dyn-lib (libc)
+ (deffi realpath-null "realpath" str-d (str str))
+ (deffi realpath-buf "realpath" str-d (str (ptr-in-d (zarray 8192 char)))))
+
+(when (memq (os-symbol) '(:cygwin :solaris))
+ (put-string (file-get-string "tests/017/realpath.expected"))
+ (exit 0))
+
+(prinl (realpath-null "/usr/bin" nil))
+(prinl (realpath-buf "/usr/bin" (copy "")))