summaryrefslogtreecommitdiff
path: root/libgenx/tests/basics
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-07-24 09:13:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-07-24 09:13:21 +0200
commitb0396809c19f436e051430d5e81d59a725611195 (patch)
tree29e374c30aef241b4edfa604a131b4c33ecedc3f /libgenx/tests/basics
parentd19d20fbd638c3edb0e2dea1589455546a309382 (diff)
Convert to build2-based build
Also add symbol exporting, missing const in a few places in the API, as well as a basic test.
Diffstat (limited to 'libgenx/tests/basics')
-rw-r--r--libgenx/tests/basics/buildfile3
-rw-r--r--libgenx/tests/basics/driver.c41
-rw-r--r--libgenx/tests/basics/testscript3
3 files changed, 47 insertions, 0 deletions
diff --git a/libgenx/tests/basics/buildfile b/libgenx/tests/basics/buildfile
new file mode 100644
index 0000000..75fb5e8
--- /dev/null
+++ b/libgenx/tests/basics/buildfile
@@ -0,0 +1,3 @@
+import libs = libgenx%lib{genx}
+
+exe{driver}: {h c}{**} $libs testscript
diff --git a/libgenx/tests/basics/driver.c b/libgenx/tests/basics/driver.c
new file mode 100644
index 0000000..135d5ba
--- /dev/null
+++ b/libgenx/tests/basics/driver.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <libgenx/version.h>
+#include <libgenx/genx.h>
+
+static genxStatus
+genxSend(void * d, constUtf8 s)
+{
+ size_t n = strlen((const char*)s);
+ return fwrite(s, 1, n, (FILE*)d) == n ? GENX_SUCCESS : GENX_IO_ERROR;
+}
+
+static genxStatus
+genxSendBounded(void * d, constUtf8 start, constUtf8 end)
+{
+ size_t n = end - start;
+ return fwrite(start, 1, n, (FILE*)d) == n ? GENX_SUCCESS : GENX_IO_ERROR;
+}
+
+static genxStatus
+genxFlush(void * d)
+{
+ return fflush((FILE*)d) == 0 ? GENX_SUCCESS : GENX_IO_ERROR;
+}
+
+static const genxSender stdioSender = {&genxSend, &genxSendBounded, genxFlush};
+
+int main()
+{
+ genxWriter w = genxNew(NULL, NULL, stdout);
+ genxStartDocSender(w, &stdioSender);
+ genxStartElementLiteral(w, (utf8)"http://example.org/1", (utf8)"greeting");
+ genxAddAttributeLiteral(w, (utf8)"http://example.com/2", (utf8)"type", (utf8)"well-formed");
+ genxAddText(w, (utf8)"Hello world!");
+ genxEndElement(w);
+ genxEndDocument(w);
+ genxDispose(w);
+
+ return 0;
+}
diff --git a/libgenx/tests/basics/testscript b/libgenx/tests/basics/testscript
new file mode 100644
index 0000000..2bbfba1
--- /dev/null
+++ b/libgenx/tests/basics/testscript
@@ -0,0 +1,3 @@
+$* >>EOO
+<g1:greeting xmlns:g2="http://example.com/2" g2:type="well-formed" xmlns:g1="http://example.org/1">Hello world!</g1:greeting>
+EOO