0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-28 23:03:00 +08:00

tests: Added load_file/save_file tests

git-svn-id: http://pugixml.googlecode.com/svn/trunk@742 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
arseny.kapoulkine 2010-09-20 20:14:38 +00:00
parent 3fc3e60db4
commit b84eb7bdba

View File

@ -1,4 +1,5 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_NONSTDC_NO_DEPRECATE 0
#include <string.h> // because Borland's STL is braindead, we have to include <string.h> _before_ <string> in order to get memcpy
@ -14,6 +15,7 @@
#include <sstream>
#include <string>
#include <algorithm>
#ifdef __MINGW32__
# include <io.h> // 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("<node />"));
}
TEST_XML(document_save, "<node/>")
{
xml_writer_string writer;
@ -313,29 +323,57 @@ TEST_XML(document_save_declaration_present_last, "<node/>")
CHECK(writer.as_string() == STR("<?xml version=\"1.0\"?>\n<node />\n<?xml encoding=\"utf8\"?>\n"));
}
TEST_XML(document_save_file, "<node/>")
struct temp_file
{
#ifdef __unix
char path[] = "/tmp/pugiXXXXXX";
char path[512];
int fd;
int fd = mkstemp(path);
temp_file(): fd(0)
{
#ifdef __unix
strcpy(path, "/tmp/pugiXXXXXX");
fd = mkstemp(path);
CHECK(fd != -1);
#elif defined(__CELLOS_LV2__)
const char* path = ""; // no temporary file support
#else
const char* path = tmpnam(0);
#endif
CHECK(doc.save_file(path));
CHECK(doc.load_file(path, pugi::parse_default | pugi::parse_declaration));
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><node />"));
#elif defined(__CELLOS_LV2__)
path[0] = 0; // no temporary file support
#else
tmpnam(path);
#endif
}
~temp_file()
{
CHECK(unlink(path) == 0);
#ifdef __unix
#ifdef __unix
CHECK(close(fd) == 0);
#endif
#endif
}
};
TEST_XML(document_save_file, "<node/>")
{
temp_file f;
CHECK(doc.save_file(f.path));
CHECK(doc.load_file(f.path, pugi::parse_default | pugi::parse_declaration));
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><node />"));
}
TEST_XML(document_save_file_wide, "<node/>")
{
temp_file f;
// 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("<?xml version=\"1.0\"?><node />"));
}
TEST_XML(document_save_file_error, "<node/>")