From: Tim Mayberry Date: Sat, 25 Jul 2015 06:43:24 +0000 (+1000) Subject: Add unit test to check that libxml2 expects utf-8 encoded file paths on Windows X-Git-Tag: 4.2~189 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=b2ff1e1734897cb9ee334ba82bd382c8e44b80f9;p=ardour.git Add unit test to check that libxml2 expects utf-8 encoded file paths on Windows --- diff --git a/libs/pbd/test/xml_test.cc b/libs/pbd/test/xml_test.cc new file mode 100644 index 0000000000..c32cf96d4d --- /dev/null +++ b/libs/pbd/test/xml_test.cc @@ -0,0 +1,79 @@ +#include "xml_test.h" + +#include +#include + +#include +#include + +#ifdef PLATFORM_WINDOWS +#include +#endif + +#include +#include +#include + +#include + +#include "pbd/file_utils.h" + +#include "test_common.h" + +using namespace std; +using namespace PBD; + +CPPUNIT_TEST_SUITE_REGISTRATION (XMLTest); + +namespace { + +xmlChar* xml_version = xmlCharStrdup("1.0"); + +bool +write_xml(const string& filename) +{ + xmlDocPtr doc; + int result; + + xmlKeepBlanksDefault(0); + doc = xmlNewDoc(xml_version); + + result = xmlSaveFormatFileEnc(filename.c_str(), doc, "UTF-8", 1); + + xmlFreeDoc(doc); + + if (result == -1) { + return false; + } + return true; +} + +} + +void +XMLTest::testXMLFilenameEncoding () +{ + vector i18n_files; + + Searchpath i18n_path(test_search_path()); + i18n_path.add_subdirectory_to_paths("i18n_test"); + + PBD::find_files_matching_pattern (i18n_files, i18n_path, "*.tst"); + + CPPUNIT_ASSERT (i18n_files.size() == 8); + + string output_dir = test_output_directory ("XMLFilenameEncodingUTF8"); + + // This is testing that libxml expects the filename encoding to be utf-8 + // on Windows and that writing the xml files should be successful for all + // the filenames in the test data set but it should also work for other + // platforms as well + for (vector::iterator i = i18n_files.begin (); i != i18n_files.end (); + ++i) { + string input_path = *i; + string output_filename = Glib::path_get_basename (input_path); + string output_path = Glib::build_filename (output_dir, output_filename); + + CPPUNIT_ASSERT (write_xml (output_path)); + } +} diff --git a/libs/pbd/test/xml_test.h b/libs/pbd/test/xml_test.h new file mode 100644 index 0000000000..43619d30ee --- /dev/null +++ b/libs/pbd/test/xml_test.h @@ -0,0 +1,12 @@ +#include +#include + +class XMLTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE (XMLTest); + CPPUNIT_TEST (testXMLFilenameEncoding); + CPPUNIT_TEST_SUITE_END (); + +public: + void testXMLFilenameEncoding (); +}; diff --git a/libs/pbd/wscript b/libs/pbd/wscript index 7d8155c712..b12210b542 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -162,6 +162,7 @@ def build(bld): test/timer_test.cc test/convert_test.cc test/filesystem_test.cc + test/xml_test.cc test/test_common.cc '''.split() testobj.target = 'run-tests'