This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
@@ -0,0 +1,57 @@
/* Copyright 2009 JetBrains
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Revision: 50800 $
*/
#ifndef H_TEAMCITY_MESSAGES
#define H_TEAMCITY_MESSAGES
#include <string>
#include <iostream>
namespace JetBrains {
bool underTeamcity();
struct TeamcityFormatterRegistrar {
TeamcityFormatterRegistrar();
};
class TeamcityMessages {
std::ostream *m_out;
protected:
std::string escape(std::string s);
void openMsg(const std::string &name);
void writeProperty(std::string name, std::string value);
void closeMsg();
public:
TeamcityMessages();
void setOutput(std::ostream &);
void suiteStarted(std::string name);
void suiteFinished(std::string name);
void testStarted(std::string name);
void testFailed(std::string name, std::string message, std::string details = "");
void testIgnored(std::string name, std::string message = "");
void testFinished(std::string name, unsigned long elapsed);
};
}
#endif /* H_TEAMCITY_MESSAGES */
@@ -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 )