use pbd's gstdio compatibility wrapper
[ardour.git] / libs / pbd / test / xml_test.cc
1 #include "xml_test.h"
2
3 #include <glib.h>
4 #include <pbd/gstdio_compat.h>
5
6 #include <unistd.h>
7 #include <stdlib.h>
8
9 #ifdef PLATFORM_WINDOWS
10 #include <fcntl.h>
11 #endif
12
13 #include <glibmm/miscutils.h>
14 #include <glibmm/fileutils.h>
15 #include <glibmm/convert.h>
16
17 #include <libxml/xpath.h>
18
19 #include "pbd/file_utils.h"
20
21 #include "test_common.h"
22
23 using namespace std;
24 using namespace PBD;
25
26 CPPUNIT_TEST_SUITE_REGISTRATION (XMLTest);
27
28 namespace {
29
30 xmlChar* xml_version = xmlCharStrdup("1.0");
31
32 bool
33 write_xml(const string& filename)
34 {
35         xmlDocPtr doc;
36         int result;
37
38         xmlKeepBlanksDefault(0);
39         doc = xmlNewDoc(xml_version);
40
41         result = xmlSaveFormatFileEnc(filename.c_str(), doc, "UTF-8", 1);
42
43         xmlFreeDoc(doc);
44
45         if (result == -1) {
46                 return false;
47         }
48         return true;
49 }
50
51 }
52
53 void
54 XMLTest::testXMLFilenameEncoding ()
55 {
56         vector<string> i18n_files;
57
58         Searchpath i18n_path(test_search_path());
59         i18n_path.add_subdirectory_to_paths("i18n_test");
60
61         PBD::find_files_matching_pattern (i18n_files, i18n_path, "*.tst");
62
63         CPPUNIT_ASSERT (i18n_files.size() == 8);
64
65         string output_dir = test_output_directory ("XMLFilenameEncodingUTF8");
66
67         // This is testing that libxml expects the filename encoding to be utf-8
68         // on Windows and that writing the xml files should be successful for all
69         // the filenames in the test data set but it should also work for other
70         // platforms as well
71         for (vector<string>::iterator i = i18n_files.begin (); i != i18n_files.end ();
72              ++i) {
73                 string input_path = *i;
74                 string output_filename = Glib::path_get_basename (input_path);
75                 string output_path = Glib::build_filename (output_dir, output_filename);
76
77                 CPPUNIT_ASSERT (write_xml (output_path));
78         }
79 }