tests: Write temporary files to executable folder.
Temp folder is the root folder on Windows; writing to the folder may require administrator rights. We can't use current folder for temporaries because tests from different configurations can be running in parallel, but executable folder is always safe since we only run each executable once. git-svn-id: https://pugixml.googlecode.com/svn/trunk@984 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
cb99aa5065
commit
bd960159dd
@ -6,6 +6,8 @@
|
|||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
#ifndef PUGIXML_NO_EXCEPTIONS
|
||||||
# include <exception>
|
# include <exception>
|
||||||
#endif
|
#endif
|
||||||
@ -20,6 +22,7 @@ test_runner* test_runner::_tests = 0;
|
|||||||
size_t test_runner::_memory_fail_threshold = 0;
|
size_t test_runner::_memory_fail_threshold = 0;
|
||||||
jmp_buf test_runner::_failure_buffer;
|
jmp_buf test_runner::_failure_buffer;
|
||||||
const char* test_runner::_failure_message;
|
const char* test_runner::_failure_message;
|
||||||
|
const char* test_runner::_temp_path;
|
||||||
|
|
||||||
static size_t g_memory_total_size = 0;
|
static size_t g_memory_total_size = 0;
|
||||||
static size_t g_memory_total_count = 0;
|
static size_t g_memory_total_count = 0;
|
||||||
@ -134,15 +137,18 @@ void std::exception::_Raise() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32_WCE
|
int main(int, char** argv)
|
||||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|
||||||
#else
|
|
||||||
int main()
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
_control87(MCW_EM | PC_53, MCW_EM | MCW_PC);
|
_control87(MCW_EM | PC_53, MCW_EM | MCW_PC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// setup temp path as the executable folder
|
||||||
|
std::string temp = argv[0];
|
||||||
|
std::string::size_type slash = temp.find_last_of("\\/");
|
||||||
|
temp.erase((slash != std::string::npos) ? slash + 1 : 0);
|
||||||
|
|
||||||
|
test_runner::_temp_path = temp.c_str();
|
||||||
|
|
||||||
replace_memory_management();
|
replace_memory_management();
|
||||||
|
|
||||||
@ -166,3 +172,10 @@ int main()
|
|||||||
|
|
||||||
return failed;
|
return failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32_WCE
|
||||||
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||||
|
{
|
||||||
|
return main(1, "");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -25,6 +25,8 @@ struct test_runner
|
|||||||
static size_t _memory_fail_threshold;
|
static size_t _memory_fail_threshold;
|
||||||
static jmp_buf _failure_buffer;
|
static jmp_buf _failure_buffer;
|
||||||
static const char* _failure_message;
|
static const char* _failure_message;
|
||||||
|
|
||||||
|
static const char* _temp_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool test_string_equal(const pugi::char_t* lhs, const pugi::char_t* rhs);
|
bool test_string_equal(const pugi::char_t* lhs, const pugi::char_t* rhs);
|
||||||
|
@ -408,35 +408,20 @@ TEST_XML(document_save_declaration_latin1, "<node/>")
|
|||||||
CHECK(writer.as_narrow() == "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<node />\n");
|
CHECK(writer.as_narrow() == "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<node />\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define USE_MKSTEMP defined(__unix) || defined(__QNX__) || defined(ANDROID)
|
|
||||||
|
|
||||||
struct temp_file
|
struct temp_file
|
||||||
{
|
{
|
||||||
char path[512];
|
char path[512];
|
||||||
int fd;
|
|
||||||
|
|
||||||
temp_file(): fd(0)
|
temp_file()
|
||||||
{
|
{
|
||||||
#if USE_MKSTEMP
|
static int index = 0;
|
||||||
strcpy(path, "/tmp/pugiXXXXXX");
|
sprintf(path, "%stempfile%d", test_runner::_temp_path, index++);
|
||||||
|
|
||||||
fd = mkstemp(path);
|
|
||||||
CHECK(fd != -1);
|
|
||||||
#elif defined(__CELLOS_LV2__) || defined(_WIN32_WCE)
|
|
||||||
path[0] = 0; // no temporary file support
|
|
||||||
#else
|
|
||||||
tmpnam(path);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~temp_file()
|
~temp_file()
|
||||||
{
|
{
|
||||||
#ifndef _WIN32_WCE
|
#ifndef _WIN32_WCE
|
||||||
CHECK(unlink(path) == 0);
|
CHECK(unlink(path) == 0);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if USE_MKSTEMP
|
|
||||||
CHECK(close(fd) == 0);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -456,7 +441,7 @@ TEST_XML(document_save_file_wide, "<node/>")
|
|||||||
temp_file f;
|
temp_file f;
|
||||||
|
|
||||||
// widen the path
|
// widen the path
|
||||||
wchar_t wpath[32];
|
wchar_t wpath[sizeof(f.path)];
|
||||||
std::copy(f.path, f.path + strlen(f.path) + 1, wpath + 0);
|
std::copy(f.path, f.path + strlen(f.path) + 1, wpath + 0);
|
||||||
|
|
||||||
CHECK(doc.save_file(wpath));
|
CHECK(doc.save_file(wpath));
|
||||||
@ -486,7 +471,7 @@ TEST_XML(document_save_file_wide_text, "<node/>")
|
|||||||
temp_file f;
|
temp_file f;
|
||||||
|
|
||||||
// widen the path
|
// widen the path
|
||||||
wchar_t wpath[32];
|
wchar_t wpath[sizeof(f.path)];
|
||||||
std::copy(f.path, f.path + strlen(f.path) + 1, wpath + 0);
|
std::copy(f.path, f.path + strlen(f.path) + 1, wpath + 0);
|
||||||
|
|
||||||
CHECK(doc.save_file(wpath, STR(""), pugi::format_no_declaration | pugi::format_save_file_text));
|
CHECK(doc.save_file(wpath, STR(""), pugi::format_no_declaration | pugi::format_save_file_text));
|
||||||
|
Loading…
Reference in New Issue
Block a user