1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00
openrw/tests/test_Globals.hpp

127 lines
2.4 KiB
C++
Raw Normal View History

#ifndef _TESTGLOBALS_HPP_
#define _TESTGLOBALS_HPP_
2013-12-12 11:58:14 +01:00
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <SDL.h>
2016-09-09 22:13:22 +02:00
#include <GameWindow.hpp>
#include <boost/test/unit_test.hpp>
2016-09-09 22:13:22 +02:00
#include <core/Logger.hpp>
2015-04-18 02:11:17 +02:00
#include <engine/GameData.hpp>
#include <engine/GameState.hpp>
2016-09-09 22:13:22 +02:00
#include <engine/GameWorld.hpp>
#include <glm/gtx/string_cast.hpp>
2013-12-12 11:58:14 +01:00
2016-09-09 22:13:22 +02:00
std::ostream& operator<<(std::ostream& stream, glm::vec3 const& v);
// Boost moved the print_log_value struct in version 1.59
// TODO: use another testing library
#if BOOST_VERSION >= 105900
2016-09-09 22:13:22 +02:00
#define BOOST_NS_MAGIC namespace tt_detail {
#define BOOST_NS_MAGIC_CLOSING }
#else
2016-09-09 22:13:22 +02:00
#define BOOST_NS_MAGIC
#define BOOST_NS_MAGIC_CLOSING
#endif
2016-09-09 22:13:22 +02:00
namespace boost {
namespace test_tools {
BOOST_NS_MAGIC
template <>
struct print_log_value<glm::vec3> {
2016-09-09 22:13:22 +02:00
void operator()(std::ostream& s, glm::vec3 const& v) {
s << glm::to_string(v);
}
};
BOOST_NS_MAGIC_CLOSING
2016-09-09 22:13:22 +02:00
}
}
#if BOOST_VERSION < 106400
2016-09-09 22:13:22 +02:00
namespace boost {
namespace test_tools {
BOOST_NS_MAGIC
template <>
struct print_log_value<std::nullptr_t> {
2016-09-09 22:13:22 +02:00
void operator()(std::ostream& s, std::nullptr_t) {
s << "nullptr";
}
2014-05-29 12:12:40 +02:00
};
BOOST_NS_MAGIC_CLOSING
2016-09-09 22:13:22 +02:00
}
}
#endif
2016-09-09 22:13:22 +02:00
namespace boost {
namespace test_tools {
BOOST_NS_MAGIC
template <>
struct print_log_value<GameString> {
2016-09-09 22:13:22 +02:00
void operator()(std::ostream& s, GameString const& v) {
for (GameString::size_type i = 0u; i < v.size(); ++i) {
2018-07-27 22:53:35 +02:00
s << static_cast<char>(v[i]);
2016-09-09 22:13:22 +02:00
}
}
};
BOOST_NS_MAGIC_CLOSING
2016-09-09 22:13:22 +02:00
}
}
#undef BOOST_NS_MAGIC
#undef BOOST_NS_MAGIC_CLOSING
2014-05-29 12:12:40 +02:00
2016-09-09 22:13:22 +02:00
class Global {
2013-12-12 11:58:14 +01:00
public:
2016-09-09 22:13:22 +02:00
GameWindow window;
#if RW_TEST_WITH_DATA
2016-09-09 22:13:22 +02:00
GameData* d;
GameWorld* e;
GameState* s;
Logger log;
#endif
2016-09-09 22:13:22 +02:00
Global() {
if (SDL_Init(SDL_INIT_VIDEO) < 0)
throw std::runtime_error("Failed to initialize SDL2!");
2016-09-09 22:13:22 +02:00
window.create("Tests", 800, 600, false);
window.hideCursor();
#if RW_TEST_WITH_DATA
2016-12-02 01:56:38 +01:00
d = new GameData(&log, getGamePath());
2016-09-09 22:13:22 +02:00
d->load();
2016-12-02 01:56:38 +01:00
e = new GameWorld(&log, d);
2016-09-09 22:13:22 +02:00
s = new GameState;
e->state = s;
2016-09-09 22:13:22 +02:00
e->dynamicsWorld->setGravity(btVector3(0.f, 0.f, 0.f));
#endif
2016-09-09 22:13:22 +02:00
}
2013-12-12 11:58:14 +01:00
2016-09-09 22:13:22 +02:00
~Global() {
window.close();
#if RW_TEST_WITH_DATA
2016-09-09 22:13:22 +02:00
delete e;
#endif
2016-09-09 22:13:22 +02:00
}
2014-05-25 23:30:50 +02:00
#if RW_TEST_WITH_DATA
static std::string getGamePath();
#endif
2016-09-09 22:13:22 +02:00
static Global& get() {
static Global g;
return g;
}
2013-12-12 11:58:14 +01:00
};
#endif