0ad/source/lib/self_test.cpp
janwas 9542ecdd7e # boatload of fixes to get self-tests to compile+mostly run
refs #117

stub_impl_hack: defines a function otherwise provided by main.cpp

remove old self_test.h contents (e.g. TEST); superceded by cxxtestgen
TS_ASSERT etc.
only include self_test from a test (otherwise, cxxtest include dir won't
be set)
cxxtest won't run tests named only "test"; add more descriptive name

FIXES uncovered by self tests
lib: infinite loop in log2
lockfree: incorrect params

This was SVN commit r3979.
2006-06-08 19:03:43 +00:00

75 lines
1.8 KiB
C++

/**
* =========================================================================
* File : self_test.cpp
* Project : 0 A.D.
* Description : helpers for built-in self tests
*
* @author Jan.Wassenberg@stud.uni-karlsruhe.de
* =========================================================================
*/
/*
* Copyright (c) 2005 Jan Wassenberg
*
* Redistribution and/or modification are also permitted under the
* terms of the GNU General Public License as published by the
* Free Software Foundation (version 2 or later, at your option).
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "precompiled.h"
#include "timer.h"
/*/*
// checked by debug_assert_failed; disables asserts if true (see above).
// set/cleared by self_test_run.
bool self_test_active = false;
// trampoline that sets self_test_active and returns a dummy value;
// used by SELF_TEST_RUN.
int self_test_run(void (*func)())
{
self_test_active = true;
func();
self_test_active = false;
return 0; // assigned to dummy at file scope
}
static const SelfTestRecord* registered_tests;
int self_test_register(SelfTestRecord* r)
{
// SELF_TEST_REGISTER has already initialized r->func.
r->next = registered_tests;
registered_tests = r;
return 0; // assigned to dummy at file scope
}
void self_test_run_all()
{
debug_printf("SELF TESTS:\n");
const double t0 = get_time();
// someone somewhere may want to run self-tests twice (e.g. to help
// track down memory corruption), so don't destroy the list while
// iterating over it.
const SelfTestRecord* r = registered_tests;
while(r)
{
self_test_run(r->func);
r = r->next;
}
const double dt = get_time() - t0;
debug_printf("-- done (elapsed time %.0f ms)\n", dt*1e3);
}
*/