summaryrefslogtreecommitdiff
path: root/tests/main.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-07-19 09:57:32 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-07-19 09:57:32 +0000
commit7d24b9b5655d584b6dc8b89df7cbd58d2e940a81 (patch)
tree0301baa043cd688068f6ffa11ad56d284031e664 /tests/main.cpp
parent86ac39edb09647b83784c078f9ea3bd3b7a7d4e8 (diff)
Set svn:eol-style to native for all text files
git-svn-id: http://pugixml.googlecode.com/svn/trunk@607 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/main.cpp')
-rw-r--r--tests/main.cpp298
1 files changed, 149 insertions, 149 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index 4330009..021c253 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,149 +1,149 @@
-#include "test.hpp"
-#include "allocator.hpp"
-
-#include <exception>
-#include <stdio.h>
-#include <float.h>
-
-test_runner* test_runner::_tests = 0;
-size_t test_runner::_memory_fail_threshold = 0;
-jmp_buf test_runner::_failure_buffer;
-const char* test_runner::_failure_message;
-
-static size_t g_memory_total_size = 0;
-static size_t g_memory_total_count = 0;
-
-static void* custom_allocate(size_t size)
-{
- if (test_runner::_memory_fail_threshold > 0 && test_runner::_memory_fail_threshold < g_memory_total_size + size)
- return 0;
- else
- {
- void* ptr = memory_allocate(size);
-
- g_memory_total_size += memory_size(ptr);
- g_memory_total_count++;
-
- return ptr;
- }
-}
-
-static void custom_deallocate(void* ptr)
-{
- if (ptr)
- {
- g_memory_total_size -= memory_size(ptr);
- g_memory_total_count--;
-
- memory_deallocate(ptr);
- }
-}
-
-static void replace_memory_management()
-{
- // create some document to touch original functions
- {
- pugi::xml_document doc;
- doc.append_child().set_name(STR("node"));
- }
-
- // replace functions
- pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
-}
-
-#if defined(_MSC_VER) && _MSC_VER > 1200 && _MSC_VER < 1400 && !defined(__INTEL_COMPILER) && !defined(__DMC__)
-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;
- g_memory_total_count = 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_buffer);
-
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
-
- if (result)
- {
- printf("Test %s failed: %s\n", test->_name, test_runner::_failure_message);
- return false;
- }
-
- test->run();
-
- if (g_memory_total_size != 0 || g_memory_total_count != 0)
- {
- printf("Test %s failed: memory leaks found (%u bytes in %u allocations)\n", test->_name, (unsigned int)g_memory_total_size, (unsigned int)g_memory_total_count);
- return false;
- }
-
- return true;
-#ifndef PUGIXML_NO_EXCEPTIONS
- }
- catch (const std::exception& e)
- {
- printf("Test %s failed: exception %s\n", test->_name, e.what());
- return false;
- }
- catch (...)
- {
- printf("Test %s failed for unknown reason\n", test->_name);
- return false;
- }
-#endif
-}
-
-#if defined(__CELLOS_LV2__) && defined(PUGIXML_NO_EXCEPTIONS) && !defined(__SNC__)
-#include <stdlib.h>
-
-void std::exception::_Raise() const
-{
- abort();
-}
-#endif
-
-int main()
-{
-#ifdef __BORLANDC__
- _control87(MCW_EM | PC_53, MCW_EM | MCW_PC);
-#endif
-
- replace_memory_management();
-
- unsigned int total = 0;
- unsigned int passed = 0;
-
- test_runner* test = 0; // gcc3 "variable might be used uninitialized in this function" bug workaround
-
- for (test = test_runner::_tests; test; test = test->_next)
- {
- total++;
- passed += run_test(test);
- }
-
- unsigned int failed = total - passed;
-
- if (failed != 0)
- printf("FAILURE: %u out of %u tests failed.\n", failed, total);
- else
- printf("Success: %u tests passed.\n", total);
-
- return failed;
-}
+#include "test.hpp"
+#include "allocator.hpp"
+
+#include <exception>
+#include <stdio.h>
+#include <float.h>
+
+test_runner* test_runner::_tests = 0;
+size_t test_runner::_memory_fail_threshold = 0;
+jmp_buf test_runner::_failure_buffer;
+const char* test_runner::_failure_message;
+
+static size_t g_memory_total_size = 0;
+static size_t g_memory_total_count = 0;
+
+static void* custom_allocate(size_t size)
+{
+ if (test_runner::_memory_fail_threshold > 0 && test_runner::_memory_fail_threshold < g_memory_total_size + size)
+ return 0;
+ else
+ {
+ void* ptr = memory_allocate(size);
+
+ g_memory_total_size += memory_size(ptr);
+ g_memory_total_count++;
+
+ return ptr;
+ }
+}
+
+static void custom_deallocate(void* ptr)
+{
+ if (ptr)
+ {
+ g_memory_total_size -= memory_size(ptr);
+ g_memory_total_count--;
+
+ memory_deallocate(ptr);
+ }
+}
+
+static void replace_memory_management()
+{
+ // create some document to touch original functions
+ {
+ pugi::xml_document doc;
+ doc.append_child().set_name(STR("node"));
+ }
+
+ // replace functions
+ pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
+}
+
+#if defined(_MSC_VER) && _MSC_VER > 1200 && _MSC_VER < 1400 && !defined(__INTEL_COMPILER) && !defined(__DMC__)
+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;
+ g_memory_total_count = 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_buffer);
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+ if (result)
+ {
+ printf("Test %s failed: %s\n", test->_name, test_runner::_failure_message);
+ return false;
+ }
+
+ test->run();
+
+ if (g_memory_total_size != 0 || g_memory_total_count != 0)
+ {
+ printf("Test %s failed: memory leaks found (%u bytes in %u allocations)\n", test->_name, (unsigned int)g_memory_total_size, (unsigned int)g_memory_total_count);
+ return false;
+ }
+
+ return true;
+#ifndef PUGIXML_NO_EXCEPTIONS
+ }
+ catch (const std::exception& e)
+ {
+ printf("Test %s failed: exception %s\n", test->_name, e.what());
+ return false;
+ }
+ catch (...)
+ {
+ printf("Test %s failed for unknown reason\n", test->_name);
+ return false;
+ }
+#endif
+}
+
+#if defined(__CELLOS_LV2__) && defined(PUGIXML_NO_EXCEPTIONS) && !defined(__SNC__)
+#include <stdlib.h>
+
+void std::exception::_Raise() const
+{
+ abort();
+}
+#endif
+
+int main()
+{
+#ifdef __BORLANDC__
+ _control87(MCW_EM | PC_53, MCW_EM | MCW_PC);
+#endif
+
+ replace_memory_management();
+
+ unsigned int total = 0;
+ unsigned int passed = 0;
+
+ test_runner* test = 0; // gcc3 "variable might be used uninitialized in this function" bug workaround
+
+ for (test = test_runner::_tests; test; test = test->_next)
+ {
+ total++;
+ passed += run_test(test);
+ }
+
+ unsigned int failed = total - passed;
+
+ if (failed != 0)
+ printf("FAILURE: %u out of %u tests failed.\n", failed, total);
+ else
+ printf("Success: %u tests passed.\n", total);
+
+ return failed;
+}