mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-27 13:33:17 +08:00
tests: Tests can work without exceptions now
git-svn-id: http://pugixml.googlecode.com/svn/trunk@194 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
6210c21984
commit
1fdd096c80
@ -64,6 +64,10 @@ else if ( $(toolset:I=^msvc) )
|
||||
{
|
||||
CCFLAGS += /EHsc ;
|
||||
}
|
||||
else
|
||||
{
|
||||
CCFLAGS += /D_HAS_EXCEPTIONS=0 ;
|
||||
}
|
||||
|
||||
actions ObjectAction
|
||||
{
|
||||
@ -136,14 +140,14 @@ else if ( $(toolset:I=^dmc) )
|
||||
CCFLAGS += -DNDEBUG ;
|
||||
}
|
||||
|
||||
if ( !(PUGIXML_NO_EXCEPTIONS in $(defines)) )
|
||||
if ( ! ( PUGIXML_NO_EXCEPTIONS in $(defines) ) )
|
||||
{
|
||||
CCFLAGS += -Ae ;
|
||||
}
|
||||
|
||||
actions ObjectAction
|
||||
{
|
||||
"%$(toolset)_PATH%\bin\dmc.exe" -c -f -wx $(>) -o$(<)
|
||||
"%$(toolset)_PATH%\bin\dmc.exe" -c -f -wx $(>) -o$(<) $(CCFLAGS)
|
||||
}
|
||||
|
||||
actions LibraryAction
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
test_runner* test_runner::_tests = 0;
|
||||
size_t test_runner::_memory_fail_threshold = 0;
|
||||
jmp_buf test_runner::_failure;
|
||||
|
||||
static size_t g_memory_total_size = 0;
|
||||
|
||||
@ -46,33 +47,58 @@ static void replace_memory_management()
|
||||
pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER > 1200 && _MSC_VER < 1400 && !defined(__INTEL_COMPILER)
|
||||
namespace std
|
||||
{
|
||||
_CRTIMP2 _Prhand _Raise_handler;
|
||||
_CRTIMP2 void __cdecl _Throw(const exception&) {}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool run_test(test_runner* test)
|
||||
{
|
||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
g_memory_total_size = 0;
|
||||
test_runner::_memory_fail_threshold = 0;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4611) // interaction between _setjmp and C++ object destruction is non-portable
|
||||
#endif
|
||||
|
||||
volatile int result = setjmp(test_runner::_failure);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
if (result)
|
||||
{
|
||||
printf("Test %s failed: %s\n", test->_name, (const char*)(intptr_t)result);
|
||||
return false;
|
||||
}
|
||||
|
||||
test->run();
|
||||
|
||||
if (g_memory_total_size != 0) throw "Memory leaks found";
|
||||
if (g_memory_total_size != 0) longjmp(test_runner::_failure, (int)(intptr_t)"Memory leaks found");
|
||||
|
||||
return true;
|
||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
printf("Test %s failed: exception %s\n", test->_name, e.what());
|
||||
}
|
||||
catch (const char* e)
|
||||
{
|
||||
printf("Test %s failed: %s\n", test->_name, e);
|
||||
return false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("Test %s failed for unknown reason\n", test->_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@ -1,12 +1,18 @@
|
||||
#ifndef HEADER_TEST_HPP
|
||||
#define HEADER_TEST_HPP
|
||||
|
||||
#include "../src/pugixml.hpp"
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER==1200) || defined(__DMC__)
|
||||
typedef int intptr_t;
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <string>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "../src/pugixml.hpp"
|
||||
#include <string>
|
||||
|
||||
inline bool test_string_equal(const char* lhs, const char* rhs)
|
||||
{
|
||||
@ -103,6 +109,7 @@ struct test_runner
|
||||
|
||||
static test_runner* _tests;
|
||||
static size_t _memory_fail_threshold;
|
||||
static jmp_buf _failure;
|
||||
};
|
||||
|
||||
struct dummy_fixture {};
|
||||
@ -147,7 +154,7 @@ struct dummy_fixture {};
|
||||
|
||||
#define CHECK_JOIN(text, file, line) text file #line
|
||||
#define CHECK_JOIN2(text, file, line) CHECK_JOIN(text, file, line)
|
||||
#define CHECK_TEXT(condition, text) if (condition) ; else throw CHECK_JOIN2(text, " at "__FILE__ ":", __LINE__)
|
||||
#define CHECK_TEXT(condition, text) if (condition) ; else longjmp(test_runner::_failure, (int)(intptr_t)(CHECK_JOIN2(text, " at "__FILE__ ":", __LINE__)))
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER == 1200
|
||||
# define STR(value) "??" // MSVC 6.0 has troubles stringizing stuff with strings w/escaping inside
|
||||
|
@ -29,8 +29,6 @@ TEST(custom_memory_management)
|
||||
// replace functions
|
||||
set_memory_management_functions(allocate, deallocate);
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
// parse document
|
||||
xml_document doc;
|
||||
@ -54,13 +52,4 @@ TEST(custom_memory_management)
|
||||
|
||||
// restore old functions
|
||||
set_memory_management_functions(old_allocate, old_deallocate);
|
||||
}
|
||||
catch (const char* error)
|
||||
{
|
||||
// restore old functions
|
||||
set_memory_management_functions(old_allocate, old_deallocate);
|
||||
|
||||
// rethrow
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user