From 31ba3b958d4850d1568e4b77ea9c16bf7a609cc9 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 9 Jun 2020 22:20:24 +0100 Subject: [PATCH] Add tests/t1001-rcxml-nodenames-simple.c --- src/config/rcxml.c | 6 ++-- tests/meson.build | 8 +++++ tests/t1001-rcxml-nodenames-simple.c | 47 ++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/t1001-rcxml-nodenames-simple.c diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 599b2069..c917e6ab 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -52,8 +52,10 @@ static void entry(xmlNode *node, char *nodename, char *content) if (is_attribute) buf_add(nodename_buffer, "@"); buf_add(nodename_buffer, nodename); - buf_add(nodename_buffer, ": "); - buf_add(nodename_buffer, content); + if (content) { + buf_add(nodename_buffer, ": "); + buf_add(nodename_buffer, content); + } buf_add(nodename_buffer, "\n"); } if (!content) diff --git a/tests/meson.build b/tests/meson.build index 3d438375..f0b9c89f 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -13,3 +13,11 @@ t1000 = executable( link_with: rcxml_lib, ) test('t1000', t1000) + +t1001 = executable( + 't1001-rcxml-nodenames-simple', + sources: ['t1001-rcxml-nodenames-simple.c', 'tap.c'], + include_directories: [labwc_inc], + link_with: rcxml_lib, +) +test('t1001', t1001) diff --git a/tests/t1001-rcxml-nodenames-simple.c b/tests/t1001-rcxml-nodenames-simple.c new file mode 100644 index 00000000..23089659 --- /dev/null +++ b/tests/t1001-rcxml-nodenames-simple.c @@ -0,0 +1,47 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include +#include + +#include "rcxml.h" +#include "tap.h" + +struct rcxml rc = { 0 }; + +static char src[] = +"\n" +"\n" +"\n" +" yes\n" +"\n" +"\n"; + +static char expect[] = +"openbox_config\n" +"lab\n" +"csd.lab\n" +"csd.lab: yes\n"; + +int main(int argc, char **argv) +{ + struct buf actual, source; + + buf_init(&actual); + buf_init(&source); + buf_add(&source, src); + + plan(1); + diag("Parse simple rc.xml and read nodenames"); + + rcxml_init(&rc); + rcxml_get_nodenames(&actual); + rcxml_parse_xml(&source); + printf("%s\n", actual.buf); + printf("%s\n", expect); + + ok1(!strcmp(expect, actual.buf)); + free(actual.buf); + return exit_status(); +}