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:
parent
3fc3e60db4
commit
b84eb7bdba
@ -1,4 +1,5 @@
|
|||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#define _SCL_SECURE_NO_WARNINGS
|
||||||
#define _CRT_NONSTDC_NO_DEPRECATE 0
|
#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
|
#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 <sstream>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
# include <io.h> // for unlink in C++0x mode
|
# include <io.h> // for unlink in C++0x mode
|
||||||
@ -210,6 +212,14 @@ TEST(document_load_file_error_previous)
|
|||||||
CHECK(!doc.first_child());
|
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/>")
|
TEST_XML(document_save, "<node/>")
|
||||||
{
|
{
|
||||||
xml_writer_string writer;
|
xml_writer_string writer;
|
||||||
@ -313,30 +323,58 @@ TEST_XML(document_save_declaration_present_last, "<node/>")
|
|||||||
CHECK(writer.as_string() == STR("<?xml version=\"1.0\"?>\n<node />\n<?xml encoding=\"utf8\"?>\n"));
|
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
|
||||||
|
{
|
||||||
|
char path[512];
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
temp_file(): fd(0)
|
||||||
{
|
{
|
||||||
#ifdef __unix
|
#ifdef __unix
|
||||||
char path[] = "/tmp/pugiXXXXXX";
|
strcpy(path, "/tmp/pugiXXXXXX");
|
||||||
|
|
||||||
int fd = mkstemp(path);
|
fd = mkstemp(path);
|
||||||
CHECK(fd != -1);
|
CHECK(fd != -1);
|
||||||
#elif defined(__CELLOS_LV2__)
|
#elif defined(__CELLOS_LV2__)
|
||||||
const char* path = ""; // no temporary file support
|
path[0] = 0; // no temporary file support
|
||||||
#else
|
#else
|
||||||
const char* path = tmpnam(0);
|
tmpnam(path);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
CHECK(doc.save_file(path));
|
~temp_file()
|
||||||
|
{
|
||||||
CHECK(doc.load_file(path, pugi::parse_default | pugi::parse_declaration));
|
|
||||||
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><node />"));
|
|
||||||
|
|
||||||
CHECK(unlink(path) == 0);
|
CHECK(unlink(path) == 0);
|
||||||
|
|
||||||
#ifdef __unix
|
#ifdef __unix
|
||||||
CHECK(close(fd) == 0);
|
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/>")
|
TEST_XML(document_save_file_error, "<node/>")
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user