From 63afde339fdcc5cbd9df5e3e8419e62a0ad1e579 Mon Sep 17 00:00:00 2001 From: Daniel Burke Date: Mon, 5 Sep 2011 18:48:04 +0930 Subject: [PATCH] ttxml: ccanlint fixes finished Meets all of the requirements of ccanlint. Code coverage of the tests covers everything except for a malloc() failure. Added some xml files for the tests to work on. --- ccan/ttxml/test/run.c | 95 +++++++++++++++++++++++++++++++++++++++ ccan/ttxml/test/test.xml1 | 9 ++++ ccan/ttxml/test/test.xml2 | 9 ++++ ccan/ttxml/test/test.xml3 | 1 + ccan/ttxml/test/test.xml4 | 1 + 5 files changed, 115 insertions(+) create mode 100644 ccan/ttxml/test/run.c create mode 100644 ccan/ttxml/test/test.xml1 create mode 100644 ccan/ttxml/test/test.xml2 create mode 100644 ccan/ttxml/test/test.xml3 create mode 100644 ccan/ttxml/test/test.xml4 diff --git a/ccan/ttxml/test/run.c b/ccan/ttxml/test/run.c new file mode 100644 index 00000000..682bf35d --- /dev/null +++ b/ccan/ttxml/test/run.c @@ -0,0 +1,95 @@ +#include +/* Include the C files directly. */ +#include +#include + +/* print out the heirarchy of an XML file, useful for debugging */ + +static void xp(XmlNode *x, int level, int max) +{ + int i; + char text[] = "text"; + char *name = text; + if(level > max)return; + if(!x)return; + if(x->name)name = x->name; + for(i=0; iname) + for(i=0; inattrib; i++) + printf("%s=\"%s\",", x->attrib[i*2], x->attrib[i*2+1]); + else printf("%s", x->attrib[0]); + printf("\n"); + if(x->child)xp(x->child, level+1, max); + if(x->next)xp(x->next, level, max); +} + + + +static int test_load(const char * filename) +{ + XmlNode *xml = xml_load(filename); + if(!xml) return 0; + + xml_free(xml); + return 1; +} + +static int test_find(void) +{ + char *ctmp; + XmlNode *xtmp, *xml = xml_load("./test/test.xml2"); + if(!xml)return 0; + + xp(xml, 0, 20); + + + xtmp = xml_find(xml, "one"); + if(!xtmp) + { + printf("Failed to find node\n"); + return 0; + } + printf("node is...\n"); + xp(xtmp, 0, 20); + + ctmp = xml_attr(xtmp, "barfoo"); + if(!ctmp) + { + printf("Failed to find attribute\n"); + return 0; + } + + return 1; +} + +int main(void) +{ + XmlNode *x, *t; + /* This is how many tests you plan to run */ + plan_tests(13); + + ok1(x = xml_load("./test/test.xml2")); + ok1(!xml_find(x, "Doesn't Exist")); + ok1(t = xml_find(x, "one")); + ok1(xml_find(t, "two")); + ok1(!xml_attr(t, "foobar")); + ok1(!xml_attr(t, "Doesn't Exist")); + ok1(xml_attr(t, "barfoo")); + xml_free(x); + /* Simple thing we expect to succeed */ + ok1(!test_load("does not exist")); /* A file that doesn't exist */ + ok1(test_load("./test/test.xml")); /* A very large xml file. */ + ok1(test_load("./test/test.xml2")); /* A basic xml file. */ + ok1(test_load("./test/test.xml3")); /* Very small well-formed xml file. */ + ok1(test_load("./test/test.xml4")); /* Smallest well-formed xml file. */ + ok1(test_load("./test/test.xml5")); /* A single unclosed tag. */ + /* Same, with an explicit description of the test. */ +// ok(some_test(), "%s with no args should return 1", "some_test") + /* How to print out messages for debugging. */ +// diag("Address of some_test is %p", &some_test) + /* Conditional tests must be explicitly skipped. */ + + /* This exits depending on whether all tests passed */ + return exit_status(); +} diff --git a/ccan/ttxml/test/test.xml1 b/ccan/ttxml/test/test.xml1 new file mode 100644 index 00000000..b87c39ea --- /dev/null +++ b/ccan/ttxml/test/test.xml1 @@ -0,0 +1,9 @@ + + foobar + + + + + + + diff --git a/ccan/ttxml/test/test.xml2 b/ccan/ttxml/test/test.xml2 new file mode 100644 index 00000000..b87c39ea --- /dev/null +++ b/ccan/ttxml/test/test.xml2 @@ -0,0 +1,9 @@ + + foobar + + + + + + + diff --git a/ccan/ttxml/test/test.xml3 b/ccan/ttxml/test/test.xml3 new file mode 100644 index 00000000..ded336e6 --- /dev/null +++ b/ccan/ttxml/test/test.xml3 @@ -0,0 +1 @@ + diff --git a/ccan/ttxml/test/test.xml4 b/ccan/ttxml/test/test.xml4 new file mode 100644 index 00000000..86378fe9 --- /dev/null +++ b/ccan/ttxml/test/test.xml4 @@ -0,0 +1 @@ + -- 2.39.2