mirror of
https://github.com/copyrighttxt/watrbx-game-engine.git
synced 2026-09-05 05:07:48 +00:00
GEEKING
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rbx/test/test_tools.h"
|
||||
#include "boost/test/test_observer.hpp"
|
||||
#include "boost/test/framework.hpp"
|
||||
|
||||
namespace RBX { namespace Test {
|
||||
|
||||
class BaseGlobalFixture : public boost::unit_test::test_observer
|
||||
{
|
||||
static rbx::atomic<int> assertCount;
|
||||
|
||||
virtual void test_unit_finish( boost::unit_test::test_unit const&, unsigned long /* elapsed */ )
|
||||
{
|
||||
assertCount = 0;
|
||||
}
|
||||
|
||||
static bool tooManyAssertionsCheck();
|
||||
static bool handleDebugAssert(const char* expression, const char* filename, int lineNumber);
|
||||
static bool handleFailure(const char* expression, const char* filename, int lineNumber);
|
||||
public:
|
||||
|
||||
static bool fflagsAllOn;
|
||||
static bool fflagsAllOff;
|
||||
|
||||
static void setAreAssertsTested(bool value)
|
||||
{
|
||||
FLog::Asserts = value ? 1 : 0;
|
||||
}
|
||||
|
||||
BaseGlobalFixture();
|
||||
|
||||
~BaseGlobalFixture()
|
||||
{
|
||||
boost::unit_test::framework::deregister_observer(*this);
|
||||
}
|
||||
|
||||
// returns true if the arg is processed
|
||||
static bool processArg(const std::string arg);
|
||||
};
|
||||
|
||||
|
||||
class PerformanceTestFixture
|
||||
{
|
||||
const FLog::Channel oldValue;
|
||||
public:
|
||||
PerformanceTestFixture()
|
||||
:oldValue(FLog::Asserts)
|
||||
{
|
||||
BOOST_MESSAGE("Running performance test");
|
||||
BOOST_CHECK(true); // to prevent "Test case doesn't include any assertions"
|
||||
|
||||
FLog::Asserts = 0;
|
||||
}
|
||||
~PerformanceTestFixture()
|
||||
{
|
||||
FLog::Asserts = oldValue;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/standardout.h"
|
||||
|
||||
namespace RBX { namespace Test {
|
||||
|
||||
class CaptureErrorLogs
|
||||
{
|
||||
rbx::signals::scoped_connection connection;
|
||||
static void onMessage(const RBX::StandardOutMessage& message)
|
||||
{
|
||||
BOOST_CHECK_MESSAGE(message.type != RBX::MESSAGE_ERROR, message.message);
|
||||
// ??? BOOST_WARN_MESSAGE(message.type != RBX::MESSAGE_WARNING, message.message);
|
||||
}
|
||||
public:
|
||||
CaptureErrorLogs()
|
||||
{
|
||||
connection = RBX::StandardOut::singleton()->messageOut.connect(&CaptureErrorLogs::onMessage);
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
// FOR TESTS ONLY.
|
||||
// DO NOT USE THIS IN ANY NON-TEST CODE
|
||||
// THIS HAS NO THREADING GUARANTEES, AND IS UNSUITABLE FOR PRODUCTION
|
||||
|
||||
// Most tests will not need this. Instead, the command line option
|
||||
// --fflags can be used to run tests with different flags enabled / disabled.
|
||||
|
||||
// Because FastFlags are static (process scoped), it can be difficult to
|
||||
// know exactly when in the execution a FastFlag is read. For this reason,
|
||||
// be extra careful to examine the uses of a FastFlag before setting it
|
||||
// in a unit test. Beware, some flags are only read at startup time, and
|
||||
// the effects of the flag are not changed if the flag value is subsequently
|
||||
// changed.
|
||||
|
||||
#include "FastLog.h"
|
||||
#include "rbx/Debug.h"
|
||||
|
||||
struct ScopedFastFlagSetting {
|
||||
private:
|
||||
bool success;
|
||||
std::string oldValue;
|
||||
const char* flagName;
|
||||
public:
|
||||
ScopedFastFlagSetting(const char* flagName, bool value) : flagName(flagName) {
|
||||
success = false;
|
||||
success = FLog::GetValue(flagName, oldValue)
|
||||
&& FLog::SetValue(flagName, value ? "True" : "False", FASTVARTYPE_ANY, false);
|
||||
RBXASSERT(success);
|
||||
}
|
||||
~ScopedFastFlagSetting() {
|
||||
if (success) {
|
||||
FLog::SetValue(flagName, oldValue, FASTVARTYPE_ANY, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct ScopedFastIntSetting {
|
||||
private:
|
||||
bool success;
|
||||
std::string oldValue;
|
||||
const char* flagName;
|
||||
public:
|
||||
ScopedFastIntSetting(const char* flagName, int value) : flagName(flagName) {
|
||||
success = false;
|
||||
std::string newValueString = convertToString(value);
|
||||
success = FLog::GetValue(flagName, oldValue)
|
||||
&& FLog::SetValue(flagName, newValueString, FASTVARTYPE_ANY, false);
|
||||
RBXASSERT(success);
|
||||
}
|
||||
~ScopedFastIntSetting() {
|
||||
if (success) {
|
||||
FLog::SetValue(flagName, oldValue, FASTVARTYPE_ANY, false);
|
||||
}
|
||||
}
|
||||
|
||||
std::string convertToString(int a)
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4996)
|
||||
char temp[200];
|
||||
snprintf(temp, 200-1, "%d", a);
|
||||
return temp;
|
||||
#pragma warning(pop)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
namespace RBX { namespace Test {
|
||||
|
||||
template<int timeout>
|
||||
class TimeoutFixture
|
||||
{
|
||||
boost::thread thread;
|
||||
volatile bool done;
|
||||
boost::condition_variable cond;
|
||||
boost::mutex mut;
|
||||
|
||||
void monitor()
|
||||
{
|
||||
boost::system_time const time = boost::get_system_time() + boost::posix_time::seconds(timeout);
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(mut);
|
||||
if (!done)
|
||||
BOOST_REQUIRE_MESSAGE(cond.timed_wait(lock, time), "Timeout reached!");
|
||||
}
|
||||
}
|
||||
public:
|
||||
TimeoutFixture()
|
||||
:done(false)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(mut);
|
||||
thread = boost::thread(boost::bind(&TimeoutFixture::monitor, this));
|
||||
}
|
||||
|
||||
~TimeoutFixture()
|
||||
{
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(mut);
|
||||
done = true;
|
||||
cond.notify_one();
|
||||
}
|
||||
thread.join();
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "boost/test/test_tools.hpp"
|
||||
#include "rbx/Debug.h"
|
||||
#include "rbx/atomic.h"
|
||||
#include "rbx/rbxTime.h"
|
||||
#include "boost/thread.hpp"
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
#define RBX_TEST_WITH_TIMEOUT(F, T) testWithTimeout(F, T, BOOST_STRINGIZE(F))
|
||||
|
||||
static void checkNoThrow(boost::function<void()> f, std::string stringized)
|
||||
{
|
||||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch(RBX::base_exception& ex)
|
||||
{
|
||||
BOOST_CHECK_IMPL( false, RBX::format("exception '%s' thrown by %s", ex.what(), stringized.c_str() ), CHECK, CHECK_MSG );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
BOOST_CHECK_IMPL( false, RBX::format("exception thrown by %s", stringized.c_str() ), CHECK, CHECK_MSG );
|
||||
}
|
||||
}
|
||||
|
||||
static void testWithTimeout(boost::function<void()> f, RBX::Time::Interval timeout, std::string stringized)
|
||||
{
|
||||
boost::thread t(boost::bind(&checkNoThrow, f, stringized));
|
||||
|
||||
BOOST_CHECK_MESSAGE(
|
||||
t.timed_join(boost::posix_time::milliseconds((int)(timeout.seconds()*1000.0))),
|
||||
RBX::format("Timeout of '%s' after %g seconds", stringized.c_str(), timeout.seconds())
|
||||
);
|
||||
}
|
||||
|
||||
#define RBX_CHECK_NO_EXECEPTION_IMPL( S, TL ) \
|
||||
try { \
|
||||
S; \
|
||||
BOOST_CHECK_IMPL( true, "no exceptions thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); } \
|
||||
catch(RBX::base_exception& ex) { \
|
||||
std::string message = ex.what(); \
|
||||
message += " thrown by " BOOST_STRINGIZE( S ); \
|
||||
BOOST_CHECK_IMPL( false, ex.what(), TL, CHECK_MSG ); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
#define RBX_WARN_NO_EXECEPTION( S ) RBX_CHECK_NO_EXECEPTION_IMPL( S, WARN )
|
||||
#define RBX_CHECK_NO_EXECEPTION( S ) RBX_CHECK_NO_EXECEPTION_IMPL( S, CHECK )
|
||||
#define RBX_REQUIRE_NO_EXECEPTION( S ) RBX_CHECK_NO_EXECEPTION_IMPL( S, REQUIRE )
|
||||
|
||||
#define BOOST_TEST_TOOL_IMPL2( func, P, check_descr, TL, CT, F, L ) \
|
||||
::boost::test_tools::tt_detail::func( \
|
||||
P, \
|
||||
::boost::unit_test::lazy_ostream::instance() << check_descr, \
|
||||
F, \
|
||||
(std::size_t)L, \
|
||||
::boost::test_tools::tt_detail::TL, \
|
||||
::boost::test_tools::tt_detail::CT \
|
||||
/**/
|
||||
|
||||
#define BOOST_CHECK_IMPL2( P, check_descr, TL, CT, F, L ) \
|
||||
do { \
|
||||
BOOST_TEST_PASSPOINT(); \
|
||||
BOOST_TEST_TOOL_IMPL2( check_impl, P, check_descr, TL, CT, F, L ), 0 );\
|
||||
} while( ::boost::test_tools::dummy_cond ) \
|
||||
/**/
|
||||
|
||||
#define BOOST_CHECK_MESSAGE_SOURCE( P, M, F, L ) BOOST_CHECK_IMPL2( (P), M, CHECK, CHECK_MSG, F, L )
|
||||
#define BOOST_REQUIRE_MESSAGE_SOURCE( P, M, F, L ) BOOST_CHECK_IMPL2( (P), M, REQUIRE, CHECK_MSG, F, L )
|
||||
|
||||
Reference in New Issue
Block a user