Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
self_test.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2010 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * helpers for built-in self tests
25  */
26 
27 #include "precompiled.h"
28 
29 #if 0
30 
31 #include "lib/self_test.h"
32 #include "lib/timer.h"
33 
34 // checked by debug_OnAssertionFailure; disables asserts if true (see above).
35 // set/cleared by self_test_run.
36 bool self_test_active = false;
37 
38 // trampoline that sets self_test_active and returns a dummy value;
39 // used by SELF_TEST_RUN.
40 int self_test_run(void (*func)())
41 {
42  self_test_active = true;
43  func();
44  self_test_active = false;
45  return 0; // assigned to dummy at file scope
46 }
47 
48 
49 static const SelfTestRecord* registered_tests;
50 
51 int self_test_register(SelfTestRecord* r)
52 {
53  // SELF_TEST_REGISTER has already initialized r->func.
54  r->next = registered_tests;
55  registered_tests = r;
56  return 0; // assigned to dummy at file scope
57 }
58 
59 
60 void self_test_run_all()
61 {
62  debug_printf(L"SELF TESTS:\n");
63  const double t0 = timer_Time();
64 
65  // someone somewhere may want to run self-tests twice (e.g. to help
66  // track down memory corruption), so don't destroy the list while
67  // iterating over it.
68  const SelfTestRecord* r = registered_tests;
69  while(r)
70  {
71  self_test_run(r->func);
72  r = r->next;
73  }
74 
75  const double dt = timer_Time() - t0;
76  debug_printf(L"-- done (elapsed time %.0f ms)\n", dt*1e3);
77 }
78 
79 #endif
double timer_Time()
Definition: timer.cpp:98
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
Definition: debug.cpp:142