diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-07-24 09:13:21 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-07-24 09:13:21 +0200 |
commit | b0396809c19f436e051430d5e81d59a725611195 (patch) | |
tree | 29e374c30aef241b4edfa604a131b4c33ecedc3f /libgenx/tests/basics/driver.c | |
parent | d19d20fbd638c3edb0e2dea1589455546a309382 (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/driver.c')
-rw-r--r-- | libgenx/tests/basics/driver.c | 41 |
1 files changed, 41 insertions, 0 deletions
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; +} |