Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 1 | Add 'install-ptest' rule. Print a standard result line for |
| 2 | each test. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3 | |
| 4 | Signed-off-by: Mihaela Sendrea <mihaela.sendrea@enea.com> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 5 | Signed-off-by: Andrej Valek <andrej.valek@siemens.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | Upstream-Status: Backport |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 8 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> |
| 9 | --- |
| 10 | Makefile.am | 9 ++++ |
| 11 | runsuite.c | 1 + |
| 12 | runtest.c | 2 + |
| 13 | runxmlconf.c | 1 + |
| 14 | testapi.c | 122 ++++++++++++++++++++++++++++++--------------- |
| 15 | testchar.c | 156 +++++++++++++++++++++++++++++++++++++++++----------------- |
| 16 | testdict.c | 1 + |
| 17 | testlimits.c | 1 + |
| 18 | testrecurse.c | 2 + |
| 19 | 9 files changed, 210 insertions(+), 85 deletions(-) |
| 20 | |
| 21 | diff --git a/Makefile.am b/Makefile.am |
| 22 | index 9c630be..7cfd04b 100644 |
| 23 | --- a/Makefile.am |
| 24 | +++ b/Makefile.am |
| 25 | @@ -202,6 +202,15 @@ runxmlconf_LDADD= $(LDADDS) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | #testOOM_DEPENDENCIES = $(DEPS) |
| 27 | #testOOM_LDADD= $(LDADDS) |
| 28 | |
| 29 | +install-ptest: |
| 30 | + @(if [ -d .libs ] ; then cd .libs; fi; \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 31 | + install $(check_PROGRAMS) $(DESTDIR)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | + cp -r $(srcdir)/test $(DESTDIR) |
| 33 | + cp -r $(srcdir)/result $(DESTDIR) |
| 34 | + cp -r $(srcdir)/python $(DESTDIR) |
| 35 | + cp Makefile $(DESTDIR) |
| 36 | + sed -i -e 's|^Makefile:|_Makefile:|' $(DESTDIR)/Makefile |
| 37 | + |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 38 | runtests: runtest$(EXEEXT) testrecurse$(EXEEXT) testapi$(EXEEXT) \ |
| 39 | testchar$(EXEEXT) testdict$(EXEEXT) runxmlconf$(EXEEXT) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | [ -d test ] || $(LN_S) $(srcdir)/test . |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 41 | diff --git a/runsuite.c b/runsuite.c |
| 42 | index aaab13e..9ba2c5d 100644 |
| 43 | --- a/runsuite.c |
| 44 | +++ b/runsuite.c |
| 45 | @@ -1162,6 +1162,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
| 47 | if (logfile != NULL) |
| 48 | fclose(logfile); |
| 49 | + printf("%s: runsuite\n\n", (ret == 0) ? "PASS" : "FAIL"); |
| 50 | return(ret); |
| 51 | } |
| 52 | #else /* !SCHEMAS */ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 53 | diff --git a/runtest.c b/runtest.c |
| 54 | index addda5c..8ba5d59 100644 |
| 55 | --- a/runtest.c |
| 56 | +++ b/runtest.c |
| 57 | @@ -4501,6 +4501,7 @@ launchTests(testDescPtr tst) { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 58 | xmlCharEncCloseFunc(ebcdicHandler); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 59 | xmlCharEncCloseFunc(eucJpHandler); |
| 60 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | + printf("%s: %s\n", (err == 0) ? "PASS" : "FAIL", tst->desc); |
| 62 | return(err); |
| 63 | } |
| 64 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 65 | @@ -4577,6 +4578,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | xmlCleanupParser(); |
| 67 | xmlMemoryDump(); |
| 68 | |
| 69 | + printf("%s: runtest\n\n", (ret == 0) ? "PASS" : "FAIL"); |
| 70 | return(ret); |
| 71 | } |
| 72 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 73 | diff --git a/runxmlconf.c b/runxmlconf.c |
| 74 | index cef20f4..4f291fb 100644 |
| 75 | --- a/runxmlconf.c |
| 76 | +++ b/runxmlconf.c |
| 77 | @@ -595,6 +595,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | |
| 79 | if (logfile != NULL) |
| 80 | fclose(logfile); |
| 81 | + printf("%s: runxmlconf\n", (ret == 0) ? "PASS" : "FAIL"); |
| 82 | return(ret); |
| 83 | } |
| 84 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 85 | diff --git a/testapi.c b/testapi.c |
| 86 | index 4a751e2..7ccc066 100644 |
| 87 | --- a/testapi.c |
| 88 | +++ b/testapi.c |
| 89 | @@ -1246,49 +1246,91 @@ static int |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | testlibxml2(void) |
| 91 | { |
| 92 | int test_ret = 0; |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 93 | - |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | - test_ret += test_HTMLparser(); |
| 95 | - test_ret += test_HTMLtree(); |
| 96 | - test_ret += test_SAX2(); |
| 97 | - test_ret += test_c14n(); |
| 98 | - test_ret += test_catalog(); |
| 99 | - test_ret += test_chvalid(); |
| 100 | - test_ret += test_debugXML(); |
| 101 | - test_ret += test_dict(); |
| 102 | - test_ret += test_encoding(); |
| 103 | - test_ret += test_entities(); |
| 104 | - test_ret += test_hash(); |
| 105 | - test_ret += test_list(); |
| 106 | - test_ret += test_nanoftp(); |
| 107 | - test_ret += test_nanohttp(); |
| 108 | - test_ret += test_parser(); |
| 109 | - test_ret += test_parserInternals(); |
| 110 | - test_ret += test_pattern(); |
| 111 | - test_ret += test_relaxng(); |
| 112 | - test_ret += test_schemasInternals(); |
| 113 | - test_ret += test_schematron(); |
| 114 | - test_ret += test_tree(); |
| 115 | - test_ret += test_uri(); |
| 116 | - test_ret += test_valid(); |
| 117 | - test_ret += test_xinclude(); |
| 118 | - test_ret += test_xmlIO(); |
| 119 | - test_ret += test_xmlautomata(); |
| 120 | - test_ret += test_xmlerror(); |
| 121 | - test_ret += test_xmlmodule(); |
| 122 | - test_ret += test_xmlreader(); |
| 123 | - test_ret += test_xmlregexp(); |
| 124 | - test_ret += test_xmlsave(); |
| 125 | - test_ret += test_xmlschemas(); |
| 126 | - test_ret += test_xmlschemastypes(); |
| 127 | - test_ret += test_xmlstring(); |
| 128 | - test_ret += test_xmlunicode(); |
| 129 | - test_ret += test_xmlwriter(); |
| 130 | - test_ret += test_xpath(); |
| 131 | - test_ret += test_xpathInternals(); |
| 132 | - test_ret += test_xpointer(); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 133 | + int ret = 0; |
| 134 | + |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | + test_ret += (ret = test_HTMLparser()); |
| 136 | + printf("%s: HTMLparser\n", (ret == 0) ? "PASS" : "FAIL"); |
| 137 | + test_ret += (ret = test_HTMLtree()); |
| 138 | + printf("%s: HTMLtree\n", (ret == 0) ? "PASS" : "FAIL"); |
| 139 | + test_ret += (ret = test_SAX2()); |
| 140 | + printf("%s: SAX2\n", (ret == 0) ? "PASS" : "FAIL"); |
| 141 | + test_ret += (ret = test_c14n()); |
| 142 | + printf("%s: c14n\n", (ret == 0) ? "PASS" : "FAIL"); |
| 143 | + test_ret += (ret = test_catalog()); |
| 144 | + printf("%s: catalog\n", (ret == 0) ? "PASS" : "FAIL"); |
| 145 | + test_ret += (ret = test_chvalid()); |
| 146 | + printf("%s: chvalid\n", (ret == 0) ? "PASS" : "FAIL"); |
| 147 | + test_ret += (ret = test_debugXML()); |
| 148 | + printf("%s: debugXML\n", (ret == 0) ? "PASS" : "FAIL"); |
| 149 | + test_ret += (ret = test_dict()); |
| 150 | + printf("%s: dict\n", (ret == 0) ? "PASS" : "FAIL"); |
| 151 | + test_ret += (ret = test_encoding()); |
| 152 | + printf("%s: encoding\n", (ret == 0) ? "PASS" : "FAIL"); |
| 153 | + test_ret += (ret = test_entities()); |
| 154 | + printf("%s: entities\n", (ret == 0) ? "PASS" : "FAIL"); |
| 155 | + test_ret += (ret = test_hash()); |
| 156 | + printf("%s: hash\n", (ret == 0) ? "PASS" : "FAIL"); |
| 157 | + test_ret += (ret = test_list()); |
| 158 | + printf("%s: list\n", (ret == 0) ? "PASS" : "FAIL"); |
| 159 | + test_ret += (ret = test_nanoftp()); |
| 160 | + printf("%s: nanoftp\n", (ret == 0) ? "PASS" : "FAIL"); |
| 161 | + test_ret += (ret = test_nanohttp()); |
| 162 | + printf("%s: nanohttp\n", (ret == 0) ? "PASS" : "FAIL"); |
| 163 | + test_ret += (ret = test_parser()); |
| 164 | + printf("%s: parser\n", (ret == 0) ? "PASS" : "FAIL"); |
| 165 | + test_ret += (ret = test_parserInternals()); |
| 166 | + printf("%s: parserInternals\n", (ret == 0) ? "PASS" : "FAIL"); |
| 167 | + test_ret += (ret = test_pattern()); |
| 168 | + printf("%s: pattern\n", (ret == 0) ? "PASS" : "FAIL"); |
| 169 | + test_ret += (ret = test_relaxng()); |
| 170 | + printf("%s: relaxng\n", (ret == 0) ? "PASS" : "FAIL"); |
| 171 | + test_ret += (ret = test_schemasInternals()); |
| 172 | + printf("%s: schemasInternals\n", (ret == 0) ? "PASS" : "FAIL"); |
| 173 | + test_ret += (ret = test_schematron()); |
| 174 | + printf("%s: schematron\n", (ret == 0) ? "PASS" : "FAIL"); |
| 175 | + test_ret += (ret = test_tree()); |
| 176 | + printf("%s: tree\n", (ret == 0) ? "PASS" : "FAIL"); |
| 177 | + test_ret += (ret = test_uri()); |
| 178 | + printf("%s: uri\n", (ret == 0) ? "PASS" : "FAIL"); |
| 179 | + test_ret += (ret = test_valid()); |
| 180 | + printf("%s: valid\n", (ret == 0) ? "PASS" : "FAIL"); |
| 181 | + test_ret += (ret = test_xinclude()); |
| 182 | + printf("%s: xinclude\n", (ret == 0) ? "PASS" : "FAIL"); |
| 183 | + test_ret += (ret = test_xmlIO()); |
| 184 | + printf("%s: xmlIO\n", (ret == 0) ? "PASS" : "FAIL"); |
| 185 | + test_ret += (ret = test_xmlautomata()); |
| 186 | + printf("%s: xmlautomata\n", (ret == 0) ? "PASS" : "FAIL"); |
| 187 | + test_ret += (ret = test_xmlerror()); |
| 188 | + printf("%s: xmlerror\n", (ret == 0) ? "PASS" : "FAIL"); |
| 189 | + test_ret += (ret = test_xmlmodule()); |
| 190 | + printf("%s: xmlmodule\n", (ret == 0) ? "PASS" : "FAIL"); |
| 191 | + test_ret += (ret = test_xmlreader()); |
| 192 | + printf("%s: xmlreader\n", (ret == 0) ? "PASS" : "FAIL"); |
| 193 | + test_ret += (ret = test_xmlregexp()); |
| 194 | + printf("%s: xmlregexp\n", (ret == 0) ? "PASS" : "FAIL"); |
| 195 | + test_ret += (ret = test_xmlsave()); |
| 196 | + printf("%s: xmlsave\n", (ret == 0) ? "PASS" : "FAIL"); |
| 197 | + test_ret += (ret = test_xmlschemas()); |
| 198 | + printf("%s: xmlschemas\n", (ret == 0) ? "PASS" : "FAIL"); |
| 199 | + test_ret += (ret = test_xmlschemastypes()); |
| 200 | + printf("%s: xmlschemastypes\n", (ret == 0) ? "PASS" : "FAIL"); |
| 201 | + test_ret += (ret = test_xmlstring()); |
| 202 | + printf("%s: xmlstring\n", (ret == 0) ? "PASS" : "FAIL"); |
| 203 | + test_ret += (ret = test_xmlunicode()); |
| 204 | + printf("%s: xmlunicode\n", (ret == 0) ? "PASS" : "FAIL"); |
| 205 | + test_ret += (ret = test_xmlwriter()); |
| 206 | + printf("%s: xmlwriter\n", (ret == 0) ? "PASS" : "FAIL"); |
| 207 | + test_ret += (ret = test_xpath()); |
| 208 | + printf("%s: xpath\n", (ret == 0) ? "PASS" : "FAIL"); |
| 209 | + test_ret += (ret = test_xpathInternals()); |
| 210 | + printf("%s: xpathInternals\n", (ret == 0) ? "PASS" : "FAIL"); |
| 211 | + test_ret += (ret = test_xpointer()); |
| 212 | + printf("%s: xpointer\n", (ret == 0) ? "PASS" : "FAIL"); |
| 213 | |
| 214 | printf("Total: %d functions, %d tests, %d errors\n", |
| 215 | function_tests, call_tests, test_ret); |
| 216 | + |
| 217 | + printf("%s: testapi\n\n", (test_ret == 0) ? "PASS" : "FAIL"); |
| 218 | return(test_ret); |
| 219 | } |
| 220 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 221 | diff --git a/testchar.c b/testchar.c |
| 222 | index 0d08792..f555d3b 100644 |
| 223 | --- a/testchar.c |
| 224 | +++ b/testchar.c |
| 225 | @@ -23,7 +23,7 @@ static void errorHandler(void *unused, xmlErrorPtr err) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | char document1[100] = "<doc>XXXX</doc>"; |
| 227 | char document2[100] = "<doc foo='XXXX'/>"; |
| 228 | |
| 229 | -static void testDocumentRangeByte1(xmlParserCtxtPtr ctxt, char *document, |
| 230 | +static int testDocumentRangeByte1(xmlParserCtxtPtr ctxt, char *document, |
| 231 | int len, char *data, int forbid1, int forbid2) { |
| 232 | int i; |
| 233 | xmlDocPtr res; |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 234 | @@ -37,33 +37,41 @@ static void testDocumentRangeByte1(xmlParserCtxtPtr ctxt, char *document, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 235 | res = xmlReadMemory(document, len, "test", NULL, 0); |
| 236 | |
| 237 | if ((i == forbid1) || (i == forbid2)) { |
| 238 | - if ((lastError == 0) || (res != NULL)) |
| 239 | + if ((lastError == 0) || (res != NULL)) { |
| 240 | fprintf(stderr, |
| 241 | "Failed to detect invalid char for Byte 0x%02X: %c\n", |
| 242 | i, i); |
| 243 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 244 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | else if ((i == '<') || (i == '&')) { |
| 248 | - if ((lastError == 0) || (res != NULL)) |
| 249 | + if ((lastError == 0) || (res != NULL)) { |
| 250 | fprintf(stderr, |
| 251 | "Failed to detect illegal char %c for Byte 0x%02X\n", i, i); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 252 | + return(1); |
| 253 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 254 | } |
| 255 | else if (((i < 0x20) || (i >= 0x80)) && |
| 256 | (i != 0x9) && (i != 0xA) && (i != 0xD)) { |
| 257 | - if ((lastError != XML_ERR_INVALID_CHAR) && (res != NULL)) |
| 258 | + if ((lastError != XML_ERR_INVALID_CHAR) && (res != NULL)) { |
| 259 | fprintf(stderr, |
| 260 | "Failed to detect invalid char for Byte 0x%02X\n", i); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 261 | + return(1); |
| 262 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 263 | } |
| 264 | else if (res == NULL) { |
| 265 | fprintf(stderr, |
| 266 | "Failed to parse valid char for Byte 0x%02X : %c\n", i, i); |
| 267 | + return(1); |
| 268 | } |
| 269 | if (res != NULL) |
| 270 | xmlFreeDoc(res); |
| 271 | } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 272 | + return(0); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | -static void testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
| 276 | +static int testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
| 277 | int len, char *data) { |
| 278 | int i, j; |
| 279 | xmlDocPtr res; |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 280 | @@ -80,10 +88,12 @@ static void testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | |
| 282 | /* if first bit of first char is set, then second bit must too */ |
| 283 | if ((i & 0x80) && ((i & 0x40) == 0)) { |
| 284 | - if ((lastError == 0) || (res != NULL)) |
| 285 | + if ((lastError == 0) || (res != NULL)) { |
| 286 | fprintf(stderr, |
| 287 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X\n", |
| 288 | i, j); |
| 289 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 290 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 294 | @@ -91,10 +101,12 @@ static void testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | * bits must be 10 |
| 296 | */ |
| 297 | else if ((i & 0x80) && ((j & 0xC0) != 0x80)) { |
| 298 | - if ((lastError == 0) || (res != NULL)) |
| 299 | + if ((lastError == 0) || (res != NULL)) { |
| 300 | fprintf(stderr, |
| 301 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X\n", |
| 302 | i, j); |
| 303 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 304 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 308 | @@ -102,10 +114,12 @@ static void testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 309 | * than 0x80, i.e. one of bits 5 to 1 of i must be set |
| 310 | */ |
| 311 | else if ((i & 0x80) && ((i & 0x1E) == 0)) { |
| 312 | - if ((lastError == 0) || (res != NULL)) |
| 313 | + if ((lastError == 0) || (res != NULL)) { |
| 314 | fprintf(stderr, |
| 315 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X\n", |
| 316 | i, j); |
| 317 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 318 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 322 | @@ -113,10 +127,12 @@ static void testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 323 | * at least 3 bytes, but we give only 2 ! |
| 324 | */ |
| 325 | else if ((i & 0xE0) == 0xE0) { |
| 326 | - if ((lastError == 0) || (res != NULL)) |
| 327 | + if ((lastError == 0) || (res != NULL)) { |
| 328 | fprintf(stderr, |
| 329 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x00\n", |
| 330 | i, j); |
| 331 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 332 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 336 | @@ -125,11 +141,13 @@ static void testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 337 | else if ((lastError != 0) || (res == NULL)) { |
| 338 | fprintf(stderr, |
| 339 | "Failed to parse document for Bytes 0x%02X 0x%02X\n", i, j); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 340 | + return(1); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 341 | } |
| 342 | if (res != NULL) |
| 343 | xmlFreeDoc(res); |
| 344 | } |
| 345 | } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 346 | + return(0); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /** |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 350 | @@ -141,9 +159,10 @@ static void testDocumentRangeByte2(xmlParserCtxtPtr ctxt, char *document, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | * CDATA in text or in attribute values. |
| 352 | */ |
| 353 | |
| 354 | -static void testDocumentRanges(void) { |
| 355 | +static int testDocumentRanges(void) { |
| 356 | xmlParserCtxtPtr ctxt; |
| 357 | char *data; |
| 358 | + int test_ret = 0; |
| 359 | |
| 360 | /* |
| 361 | * Set up a parsing context using the first document as |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 362 | @@ -152,7 +171,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 363 | ctxt = xmlNewParserCtxt(); |
| 364 | if (ctxt == NULL) { |
| 365 | fprintf(stderr, "Failed to allocate parser context\n"); |
| 366 | - return; |
| 367 | + return(1); |
| 368 | } |
| 369 | |
| 370 | printf("testing 1 byte char in document: 1"); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 371 | @@ -163,7 +182,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | data[2] = ' '; |
| 373 | data[3] = ' '; |
| 374 | /* test 1 byte injection at beginning of area */ |
| 375 | - testDocumentRangeByte1(ctxt, &document1[0], strlen(document1), |
| 376 | + test_ret += testDocumentRangeByte1(ctxt, &document1[0], strlen(document1), |
| 377 | data, -1, -1); |
| 378 | printf(" 2"); |
| 379 | fflush(stdout); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 380 | @@ -172,7 +191,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 381 | data[2] = ' '; |
| 382 | data[3] = ' '; |
| 383 | /* test 1 byte injection at end of area */ |
| 384 | - testDocumentRangeByte1(ctxt, &document1[0], strlen(document1), |
| 385 | + test_ret += testDocumentRangeByte1(ctxt, &document1[0], strlen(document1), |
| 386 | data + 3, -1, -1); |
| 387 | |
| 388 | printf(" 3"); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 389 | @@ -183,7 +202,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 390 | data[2] = ' '; |
| 391 | data[3] = ' '; |
| 392 | /* test 1 byte injection at beginning of area */ |
| 393 | - testDocumentRangeByte1(ctxt, &document2[0], strlen(document2), |
| 394 | + test_ret += testDocumentRangeByte1(ctxt, &document2[0], strlen(document2), |
| 395 | data, '\'', -1); |
| 396 | printf(" 4"); |
| 397 | fflush(stdout); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 398 | @@ -192,7 +211,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 399 | data[2] = ' '; |
| 400 | data[3] = ' '; |
| 401 | /* test 1 byte injection at end of area */ |
| 402 | - testDocumentRangeByte1(ctxt, &document2[0], strlen(document2), |
| 403 | + test_ret += testDocumentRangeByte1(ctxt, &document2[0], strlen(document2), |
| 404 | data + 3, '\'', -1); |
| 405 | printf(" done\n"); |
| 406 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 407 | @@ -204,7 +223,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 408 | data[2] = ' '; |
| 409 | data[3] = ' '; |
| 410 | /* test 2 byte injection at beginning of area */ |
| 411 | - testDocumentRangeByte2(ctxt, &document1[0], strlen(document1), |
| 412 | + test_ret += testDocumentRangeByte2(ctxt, &document1[0], strlen(document1), |
| 413 | data); |
| 414 | printf(" 2"); |
| 415 | fflush(stdout); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 416 | @@ -213,7 +232,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 417 | data[2] = ' '; |
| 418 | data[3] = ' '; |
| 419 | /* test 2 byte injection at end of area */ |
| 420 | - testDocumentRangeByte2(ctxt, &document1[0], strlen(document1), |
| 421 | + test_ret += testDocumentRangeByte2(ctxt, &document1[0], strlen(document1), |
| 422 | data + 2); |
| 423 | |
| 424 | printf(" 3"); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 425 | @@ -224,7 +243,7 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 426 | data[2] = ' '; |
| 427 | data[3] = ' '; |
| 428 | /* test 2 byte injection at beginning of area */ |
| 429 | - testDocumentRangeByte2(ctxt, &document2[0], strlen(document2), |
| 430 | + test_ret += testDocumentRangeByte2(ctxt, &document2[0], strlen(document2), |
| 431 | data); |
| 432 | printf(" 4"); |
| 433 | fflush(stdout); |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 434 | @@ -233,14 +252,15 @@ static void testDocumentRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 435 | data[2] = ' '; |
| 436 | data[3] = ' '; |
| 437 | /* test 2 byte injection at end of area */ |
| 438 | - testDocumentRangeByte2(ctxt, &document2[0], strlen(document2), |
| 439 | + test_ret += testDocumentRangeByte2(ctxt, &document2[0], strlen(document2), |
| 440 | data + 2); |
| 441 | printf(" done\n"); |
| 442 | |
| 443 | xmlFreeParserCtxt(ctxt); |
| 444 | + return(test_ret); |
| 445 | } |
| 446 | |
| 447 | -static void testCharRangeByte1(xmlParserCtxtPtr ctxt, char *data) { |
| 448 | +static int testCharRangeByte1(xmlParserCtxtPtr ctxt, char *data) { |
| 449 | int i = 0; |
| 450 | int len, c; |
| 451 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 452 | @@ -255,19 +275,25 @@ static void testCharRangeByte1(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 453 | c = xmlCurrentChar(ctxt, &len); |
| 454 | if ((i == 0) || (i >= 0x80)) { |
| 455 | /* we must see an error there */ |
| 456 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 457 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 458 | fprintf(stderr, |
| 459 | "Failed to detect invalid char for Byte 0x%02X\n", i); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 460 | + return(1); |
| 461 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 462 | } else if (i == 0xD) { |
| 463 | - if ((c != 0xA) || (len != 1)) |
| 464 | + if ((c != 0xA) || (len != 1)) { |
| 465 | fprintf(stderr, "Failed to convert char for Byte 0x%02X\n", i); |
| 466 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 467 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 468 | } else if ((c != i) || (len != 1)) { |
| 469 | fprintf(stderr, "Failed to parse char for Byte 0x%02X\n", i); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 470 | + return(1); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 471 | } |
| 472 | } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 473 | + return(0); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | -static void testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
| 477 | +static int testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
| 478 | int i, j; |
| 479 | int len, c; |
| 480 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 481 | @@ -284,10 +310,12 @@ static void testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 482 | |
| 483 | /* if first bit of first char is set, then second bit must too */ |
| 484 | if ((i & 0x80) && ((i & 0x40) == 0)) { |
| 485 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 486 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 487 | fprintf(stderr, |
| 488 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X\n", |
| 489 | i, j); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 490 | + return(1); |
| 491 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 495 | @@ -295,10 +323,12 @@ static void testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 496 | * bits must be 10 |
| 497 | */ |
| 498 | else if ((i & 0x80) && ((j & 0xC0) != 0x80)) { |
| 499 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 500 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 501 | fprintf(stderr, |
| 502 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X: %d\n", |
| 503 | i, j, c); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 504 | + return(1); |
| 505 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 509 | @@ -306,10 +336,12 @@ static void testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 510 | * than 0x80, i.e. one of bits 5 to 1 of i must be set |
| 511 | */ |
| 512 | else if ((i & 0x80) && ((i & 0x1E) == 0)) { |
| 513 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 514 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 515 | fprintf(stderr, |
| 516 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X: %d\n", |
| 517 | i, j, c); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 518 | + return(1); |
| 519 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 523 | @@ -317,10 +349,12 @@ static void testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 524 | * at least 3 bytes, but we give only 2 ! |
| 525 | */ |
| 526 | else if ((i & 0xE0) == 0xE0) { |
| 527 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 528 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 529 | fprintf(stderr, |
| 530 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x00\n", |
| 531 | i, j); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 532 | + return(1); |
| 533 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 537 | @@ -329,6 +363,7 @@ static void testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 538 | else if ((lastError != 0) || (len != 2)) { |
| 539 | fprintf(stderr, |
| 540 | "Failed to parse char for Bytes 0x%02X 0x%02X\n", i, j); |
| 541 | + return(1); |
| 542 | } |
| 543 | |
| 544 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 545 | @@ -338,12 +373,14 @@ static void testCharRangeByte2(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 546 | fprintf(stderr, |
| 547 | "Failed to parse char for Bytes 0x%02X 0x%02X: expect %d got %d\n", |
| 548 | i, j, ((j & 0x3F) + ((i & 0x1F) << 6)), c); |
| 549 | + return(1); |
| 550 | } |
| 551 | } |
| 552 | } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 553 | + return(0); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | -static void testCharRangeByte3(xmlParserCtxtPtr ctxt, char *data) { |
| 557 | +static int testCharRangeByte3(xmlParserCtxtPtr ctxt, char *data) { |
| 558 | int i, j, k, K; |
| 559 | int len, c; |
| 560 | unsigned char lows[6] = {0, 0x80, 0x81, 0xC1, 0xFF, 0xBF}; |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 561 | @@ -368,20 +405,24 @@ static void testCharRangeByte3(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 562 | * at least 4 bytes, but we give only 3 ! |
| 563 | */ |
| 564 | if ((i & 0xF0) == 0xF0) { |
| 565 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 566 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 567 | fprintf(stderr, |
| 568 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X\n", |
| 569 | i, j, K, data[3]); |
| 570 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 571 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /* |
| 575 | * The second and the third bytes must start with 10 |
| 576 | */ |
| 577 | else if (((j & 0xC0) != 0x80) || ((K & 0xC0) != 0x80)) { |
| 578 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 579 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 580 | fprintf(stderr, |
| 581 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X\n", |
| 582 | i, j, K); |
| 583 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 584 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 588 | @@ -390,10 +431,12 @@ static void testCharRangeByte3(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 589 | * the 6th byte of data[1] must be set |
| 590 | */ |
| 591 | else if (((i & 0xF) == 0) && ((j & 0x20) == 0)) { |
| 592 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 593 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 594 | fprintf(stderr, |
| 595 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X\n", |
| 596 | i, j, K); |
| 597 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 598 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 602 | @@ -401,10 +444,12 @@ static void testCharRangeByte3(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 603 | */ |
| 604 | else if (((value > 0xD7FF) && (value <0xE000)) || |
| 605 | ((value > 0xFFFD) && (value <0x10000))) { |
| 606 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 607 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 608 | fprintf(stderr, |
| 609 | "Failed to detect invalid char 0x%04X for Bytes 0x%02X 0x%02X 0x%02X\n", |
| 610 | value, i, j, K); |
| 611 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 612 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 616 | @@ -414,6 +459,7 @@ static void testCharRangeByte3(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 617 | fprintf(stderr, |
| 618 | "Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X\n", |
| 619 | i, j, K); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 620 | + return(1); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 624 | @@ -423,13 +469,15 @@ static void testCharRangeByte3(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 625 | fprintf(stderr, |
| 626 | "Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X: expect %d got %d\n", |
| 627 | i, j, data[2], value, c); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 628 | + return(1); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | } |
| 632 | } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 633 | + return(0); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | -static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
| 637 | +static int testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
| 638 | int i, j, k, K, l, L; |
| 639 | int len, c; |
| 640 | unsigned char lows[6] = {0, 0x80, 0x81, 0xC1, 0xFF, 0xBF}; |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 641 | @@ -458,10 +506,12 @@ static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 642 | * at least 5 bytes, but we give only 4 ! |
| 643 | */ |
| 644 | if ((i & 0xF8) == 0xF8) { |
| 645 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 646 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 647 | fprintf(stderr, |
| 648 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X\n", |
| 649 | i, j, K, data[3]); |
| 650 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 651 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 655 | @@ -469,10 +519,12 @@ static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 656 | */ |
| 657 | else if (((j & 0xC0) != 0x80) || ((K & 0xC0) != 0x80) || |
| 658 | ((L & 0xC0) != 0x80)) { |
| 659 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 660 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 661 | fprintf(stderr, |
| 662 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X\n", |
| 663 | i, j, K, L); |
| 664 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 665 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 669 | @@ -481,10 +533,12 @@ static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 670 | * the 6 or 5th byte of j must be set |
| 671 | */ |
| 672 | else if (((i & 0x7) == 0) && ((j & 0x30) == 0)) { |
| 673 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 674 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 675 | fprintf(stderr, |
| 676 | "Failed to detect invalid char for Bytes 0x%02X 0x%02X 0x%02X 0x%02X\n", |
| 677 | i, j, K, L); |
| 678 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 679 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 683 | @@ -493,10 +547,12 @@ static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 684 | else if (((value > 0xD7FF) && (value <0xE000)) || |
| 685 | ((value > 0xFFFD) && (value <0x10000)) || |
| 686 | (value > 0x10FFFF)) { |
| 687 | - if (lastError != XML_ERR_INVALID_CHAR) |
| 688 | + if (lastError != XML_ERR_INVALID_CHAR) { |
| 689 | fprintf(stderr, |
| 690 | "Failed to detect invalid char 0x%04X for Bytes 0x%02X 0x%02X 0x%02X 0x%02X\n", |
| 691 | value, i, j, K, L); |
| 692 | + return(1); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 693 | + } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 697 | @@ -506,6 +562,7 @@ static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 698 | fprintf(stderr, |
| 699 | "Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X\n", |
| 700 | i, j, K); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 701 | + return(1); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /* |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 705 | @@ -515,11 +572,13 @@ static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 706 | fprintf(stderr, |
| 707 | "Failed to parse char for Bytes 0x%02X 0x%02X 0x%02X: expect %d got %d\n", |
| 708 | i, j, data[2], value, c); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 709 | + return(1); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 715 | + return(0); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | /** |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 719 | @@ -530,11 +589,12 @@ static void testCharRangeByte4(xmlParserCtxtPtr ctxt, char *data) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 720 | * cover the full range of UTF-8 chars accepted by XML-1.0 |
| 721 | */ |
| 722 | |
| 723 | -static void testCharRanges(void) { |
| 724 | +static int testCharRanges(void) { |
| 725 | char data[5]; |
| 726 | xmlParserCtxtPtr ctxt; |
| 727 | xmlParserInputBufferPtr buf; |
| 728 | xmlParserInputPtr input; |
| 729 | + int test_ret = 0; |
| 730 | |
| 731 | memset(data, 0, 5); |
| 732 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 733 | @@ -545,17 +605,19 @@ static void testCharRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 734 | ctxt = xmlNewParserCtxt(); |
| 735 | if (ctxt == NULL) { |
| 736 | fprintf(stderr, "Failed to allocate parser context\n"); |
| 737 | - return; |
| 738 | + return(1); |
| 739 | } |
| 740 | buf = xmlParserInputBufferCreateStatic(data, sizeof(data), |
| 741 | XML_CHAR_ENCODING_NONE); |
| 742 | if (buf == NULL) { |
| 743 | fprintf(stderr, "Failed to allocate input buffer\n"); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 744 | + test_ret = 1; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 745 | goto error; |
| 746 | } |
| 747 | input = xmlNewInputStream(ctxt); |
| 748 | if (input == NULL) { |
| 749 | xmlFreeParserInputBuffer(buf); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 750 | + test_ret = 1; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 751 | goto error; |
| 752 | } |
| 753 | input->filename = NULL; |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 754 | @@ -567,25 +629,28 @@ static void testCharRanges(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 755 | |
| 756 | printf("testing char range: 1"); |
| 757 | fflush(stdout); |
| 758 | - testCharRangeByte1(ctxt, data); |
| 759 | + test_ret += testCharRangeByte1(ctxt, data); |
| 760 | printf(" 2"); |
| 761 | fflush(stdout); |
| 762 | - testCharRangeByte2(ctxt, data); |
| 763 | + test_ret += testCharRangeByte2(ctxt, data); |
| 764 | printf(" 3"); |
| 765 | fflush(stdout); |
| 766 | - testCharRangeByte3(ctxt, data); |
| 767 | + test_ret += testCharRangeByte3(ctxt, data); |
| 768 | printf(" 4"); |
| 769 | fflush(stdout); |
| 770 | - testCharRangeByte4(ctxt, data); |
| 771 | + test_ret += testCharRangeByte4(ctxt, data); |
| 772 | printf(" done\n"); |
| 773 | fflush(stdout); |
| 774 | |
| 775 | error: |
| 776 | xmlFreeParserCtxt(ctxt); |
| 777 | + return(test_ret); |
| 778 | } |
| 779 | |
| 780 | int main(void) { |
| 781 | |
| 782 | + int ret = 0; |
| 783 | + |
| 784 | /* |
| 785 | * this initialize the library and check potential ABI mismatches |
| 786 | * between the version it was compiled for and the actual shared |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 787 | @@ -602,8 +667,9 @@ int main(void) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 788 | /* |
| 789 | * Run the tests |
| 790 | */ |
| 791 | - testCharRanges(); |
| 792 | - testDocumentRanges(); |
| 793 | + ret += testCharRanges(); |
| 794 | + ret += testDocumentRanges(); |
| 795 | + printf("%s: testchar\n\n", (ret == 0) ? "PASS" : "FAIL"); |
| 796 | |
| 797 | /* |
| 798 | * Cleanup function for the XML library. |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 799 | diff --git a/testdict.c b/testdict.c |
| 800 | index 40bebd0..114b934 100644 |
| 801 | --- a/testdict.c |
| 802 | +++ b/testdict.c |
| 803 | @@ -440,5 +440,6 @@ int main(void) |
| 804 | clean_strings(); |
| 805 | xmlCleanupParser(); |
| 806 | xmlMemoryDump(); |
| 807 | + printf("%s: testdict\n\n", (ret == 0) ? "PASS" : "FAIL"); |
| 808 | return(ret); |
| 809 | } |
| 810 | diff --git a/testlimits.c b/testlimits.c |
| 811 | index 68c94db..1584434 100644 |
| 812 | --- a/testlimits.c |
| 813 | +++ b/testlimits.c |
| 814 | @@ -1634,5 +1634,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 815 | xmlCleanupParser(); |
| 816 | xmlMemoryDump(); |
| 817 | |
| 818 | + printf("%s: testlimits\n", (ret == 0) ? "PASS" : "FAIL"); |
| 819 | return(ret); |
| 820 | } |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 821 | diff --git a/testrecurse.c b/testrecurse.c |
| 822 | index f95ae1c..74c8f8b 100644 |
| 823 | --- a/testrecurse.c |
| 824 | +++ b/testrecurse.c |
| 825 | @@ -892,6 +892,7 @@ launchTests(testDescPtr tst) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 826 | err++; |
| 827 | } |
| 828 | } |
| 829 | + printf("%s: %s\n", (err == 0) ? "PASS" : "FAIL", tst->desc); |
| 830 | return(err); |
| 831 | } |
| 832 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 833 | @@ -961,5 +962,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 834 | xmlCleanupParser(); |
| 835 | xmlMemoryDump(); |
| 836 | |
| 837 | + printf("%s: testrecurse\n\n", (ret == 0) ? "PASS" : "FAIL"); |
| 838 | return(ret); |
| 839 | } |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 840 | -- |
| 841 | 2.7.4 |
| 842 | |