diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-07-14 23:04:17 -0700 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-07-14 23:04:17 -0700 |
commit | 525b2fe5c3c304cbc2bec030b04539ab193e5dcd (patch) | |
tree | 94aac6c6029f3222cd26caf5e570e5cbddc6defa | |
parent | 70d7c7904e63f71e5f1b8960df6dc0a3c9087ff2 (diff) |
tests: Add tests for latin1 detection
-rw-r--r-- | tests/test_document.cpp | 2 | ||||
-rw-r--r-- | tests/test_parse.cpp | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp index b442126..73a36f5 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -915,7 +915,7 @@ TEST(document_contents_preserve_latin1) { // parse into document (preserve comments, declaration and whitespace pcdata) xml_document doc; - CHECK(doc.load_buffer(files[src].data, files[src].size, parse_default | parse_ws_pcdata | parse_declaration | parse_comments, files[src].encoding)); + CHECK(doc.load_buffer(files[src].data, files[src].size, parse_default | parse_ws_pcdata | parse_declaration | parse_comments)); // compare saved document with the original (raw formatting, without extra declaration, write bom if it was in original file) CHECK(test_save_narrow(doc, format_raw | format_no_declaration | format_write_bom, files[dst].encoding, files[dst].data, files[dst].size)); diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index dc709a2..62fbbce 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -1182,3 +1182,27 @@ TEST(parse_embed_pcdata) CHECK_NODE_EX(doc, STR("<node>\n\t<key>value</key>\n\t<child>\n\t\t<inner1>value1</inner1>\n\t\t<inner2>value2</inner2>outer</child>\n\t<two>text<data />\n\t</two>\n</node>\n"), STR("\t"), format_indent); } } + +TEST(parse_encoding_detect) +{ + char test[] = "<?xml version='1.0' encoding='utf-8'?><n/>"; + + xml_document doc; + CHECK(doc.load_buffer(test, sizeof(test))); +} + +TEST(parse_encoding_detect_latin1) +{ + char test0[] = "<?xml version='1.0' encoding='utf-8'?><n/>"; + char test1[] = "<?xml version='1.0' encoding='iso-8859-1'?><n/>"; + char test2[] = "<?xml version='1.0' encoding = \"latin1\"?><n/>"; + char test3[] = "<?xml version='1.0' encoding='ISO-8859-1'?><n/>"; + char test4[] = "<?xml version='1.0' encoding = \"LATIN1\"?><n/>"; + + xml_document doc; + CHECK(doc.load_buffer(test0, sizeof(test0)).encoding == encoding_utf8); + CHECK(doc.load_buffer(test1, sizeof(test1)).encoding == encoding_latin1); + CHECK(doc.load_buffer(test2, sizeof(test2)).encoding == encoding_latin1); + CHECK(doc.load_buffer(test3, sizeof(test3)).encoding == encoding_latin1); + CHECK(doc.load_buffer(test4, sizeof(test4)).encoding == encoding_latin1); +}
\ No newline at end of file |