2017-04-24 17:39:58 +02:00
|
|
|
#ifndef _TESTGLOBALS_HPP_
|
|
|
|
#define _TESTGLOBALS_HPP_
|
2013-12-12 11:58:14 +01:00
|
|
|
|
2018-08-30 17:37:27 +02:00
|
|
|
#ifdef _MSC_VER
|
2018-12-12 13:53:32 +01:00
|
|
|
#pragma warning(disable : 4305)
|
2018-08-30 17:37:27 +02:00
|
|
|
#endif
|
2017-10-31 04:05:12 +01:00
|
|
|
#include <btBulletDynamicsCommon.h>
|
2018-08-30 17:37:27 +02:00
|
|
|
#ifdef _MSC_VER
|
2018-12-12 13:53:32 +01:00
|
|
|
#pragma warning(default : 4305)
|
2018-08-30 17:37:27 +02:00
|
|
|
#endif
|
|
|
|
|
2018-02-27 23:25:05 +01:00
|
|
|
#include <SDL.h>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <GameWindow.hpp>
|
2017-02-20 18:01:53 +01:00
|
|
|
#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>
|
2016-04-15 02:06:10 +02:00
|
|
|
#include <engine/GameState.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <engine/GameWorld.hpp>
|
2018-09-05 00:14:27 +02:00
|
|
|
#include <objects/GameObject.hpp>
|
2014-05-29 10:10:08 +02:00
|
|
|
#include <glm/gtx/string_cast.hpp>
|
2013-12-12 11:58:14 +01:00
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#define DATA_TEST_PREDICATE * boost::unit_test_framework::label("data-test")\
|
|
|
|
* boost::unit_test_framework::disabled()
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
std::ostream& operator<<(std::ostream& stream, glm::vec3 const& v);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-05-19 22:09:08 +02:00
|
|
|
// 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 }
|
2016-05-19 22:09:08 +02:00
|
|
|
#else
|
2016-09-09 22:13:22 +02:00
|
|
|
#define BOOST_NS_MAGIC
|
|
|
|
#define BOOST_NS_MAGIC_CLOSING
|
2016-05-19 22:09:08 +02:00
|
|
|
#endif
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
namespace boost {
|
|
|
|
namespace test_tools {
|
|
|
|
BOOST_NS_MAGIC
|
|
|
|
template <>
|
2014-05-29 10:10:08 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-05-29 10:10:08 +02:00
|
|
|
};
|
2017-04-24 17:39:58 +02:00
|
|
|
BOOST_NS_MAGIC_CLOSING
|
2016-09-09 22:13:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-24 17:39:58 +02:00
|
|
|
#if BOOST_VERSION < 106400
|
2016-09-09 22:13:22 +02:00
|
|
|
namespace boost {
|
|
|
|
namespace test_tools {
|
|
|
|
BOOST_NS_MAGIC
|
|
|
|
template <>
|
2014-08-11 18:58:43 +02:00
|
|
|
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
|
|
|
};
|
2017-04-24 17:39:58 +02:00
|
|
|
BOOST_NS_MAGIC_CLOSING
|
2016-09-09 22:13:22 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-24 17:39:58 +02:00
|
|
|
#endif
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace test_tools {
|
|
|
|
BOOST_NS_MAGIC
|
|
|
|
template <>
|
2016-08-16 01:53:27 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-08-16 01:53:27 +02:00
|
|
|
};
|
2017-04-24 17:39:58 +02:00
|
|
|
BOOST_NS_MAGIC_CLOSING
|
2016-09-09 22:13:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-16 01:53:27 +02:00
|
|
|
|
2016-05-19 22:09:08 +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;
|
|
|
|
GameData* d;
|
|
|
|
GameWorld* e;
|
|
|
|
GameState* s;
|
2019-01-18 02:29:59 +01:00
|
|
|
std::unique_ptr<GameData> d_;
|
|
|
|
std::unique_ptr<GameWorld> e_;
|
|
|
|
std::unique_ptr<GameState> s_;
|
2016-09-09 22:13:22 +02:00
|
|
|
Logger log;
|
2016-06-16 22:11:55 +02:00
|
|
|
|
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-06-22 12:29:39 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
window.create("Tests", 800, 600, false);
|
|
|
|
window.hideCursor();
|
2016-06-22 12:29:39 +02:00
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
d_ = std::make_unique<GameData>(&log, getGamePath());
|
|
|
|
d = d_.get();
|
2016-05-02 18:38:04 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
d->load();
|
2016-05-02 18:38:04 +02:00
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
e_ = std::make_unique<GameWorld>(&log, d);
|
|
|
|
e = e_.get();
|
|
|
|
s_ = std::make_unique<GameState>();
|
|
|
|
s = s_.get();
|
2016-09-09 22:13:22 +02:00
|
|
|
e->state = s;
|
2014-02-28 12:23:51 +01:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
e->dynamicsWorld->setGravity(btVector3(0.f, 0.f, 0.f));
|
|
|
|
}
|
2013-12-12 11:58:14 +01:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
~Global() {
|
|
|
|
window.close();
|
|
|
|
}
|
2014-05-25 23:30:50 +02:00
|
|
|
|
2017-02-20 18:07:54 +01:00
|
|
|
static std::string getGamePath();
|
2016-06-22 12:29:39 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
static Global& get() {
|
|
|
|
static Global g;
|
|
|
|
return g;
|
|
|
|
}
|
2013-12-12 11:58:14 +01:00
|
|
|
};
|
|
|
|
|
2016-06-22 12:29:39 +02:00
|
|
|
#endif
|