From b84eb7bdba7cb56b880c62a83eadd14108cac2db Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Mon, 20 Sep 2010 20:14:38 +0000 Subject: tests: Added load_file/save_file tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@742 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_document.cpp | 70 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-) (limited to 'tests/test_document.cpp') diff --git a/tests/test_document.cpp b/tests/test_document.cpp index bb86992..d67f646 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -1,4 +1,5 @@ #define _CRT_SECURE_NO_WARNINGS +#define _SCL_SECURE_NO_WARNINGS #define _CRT_NONSTDC_NO_DEPRECATE 0 #include // because Borland's STL is braindead, we have to include _before_ in order to get memcpy @@ -14,6 +15,7 @@ #include #include +#include #ifdef __MINGW32__ # include // for unlink in C++0x mode @@ -210,6 +212,14 @@ TEST(document_load_file_error_previous) CHECK(!doc.first_child()); } +TEST(document_load_file_wide_ascii) +{ + pugi::xml_document doc; + + CHECK(doc.load_file(L"tests/data/small.xml")); + CHECK_NODE(doc, STR("")); +} + TEST_XML(document_save, "") { xml_writer_string writer; @@ -313,29 +323,57 @@ TEST_XML(document_save_declaration_present_last, "") CHECK(writer.as_string() == STR("\n\n\n")); } -TEST_XML(document_save_file, "") +struct temp_file { -#ifdef __unix - char path[] = "/tmp/pugiXXXXXX"; + char path[512]; + int fd; + + temp_file(): fd(0) + { + #ifdef __unix + strcpy(path, "/tmp/pugiXXXXXX"); + + fd = mkstemp(path); + CHECK(fd != -1); + #elif defined(__CELLOS_LV2__) + path[0] = 0; // no temporary file support + #else + tmpnam(path); + #endif + } - int fd = mkstemp(path); - CHECK(fd != -1); -#elif defined(__CELLOS_LV2__) - const char* path = ""; // no temporary file support -#else - const char* path = tmpnam(0); -#endif + ~temp_file() + { + CHECK(unlink(path) == 0); + + #ifdef __unix + CHECK(close(fd) == 0); + #endif + } +}; + +TEST_XML(document_save_file, "") +{ + temp_file f; - CHECK(doc.save_file(path)); + CHECK(doc.save_file(f.path)); - CHECK(doc.load_file(path, pugi::parse_default | pugi::parse_declaration)); + CHECK(doc.load_file(f.path, pugi::parse_default | pugi::parse_declaration)); CHECK_NODE(doc, STR("")); +} - CHECK(unlink(path) == 0); +TEST_XML(document_save_file_wide, "") +{ + temp_file f; -#ifdef __unix - CHECK(close(fd) == 0); -#endif + // widen the path + wchar_t wpath[32]; + std::copy(f.path, f.path + strlen(f.path) + 1, wpath + 0); + + CHECK(doc.save_file(wpath)); + + CHECK(doc.load_file(f.path, pugi::parse_default | pugi::parse_declaration)); + CHECK_NODE(doc, STR("")); } TEST_XML(document_save_file_error, "") -- cgit v1.2.3