Skip to content

Commit

Permalink
Fix Travis unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Sep 10, 2016
1 parent 9826d19 commit 45c72fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/game_launcher.cpp
Expand Up @@ -104,8 +104,13 @@ static lg::log_domain log_enginerefac("enginerefac");
#define LOG_RG LOG_STREAM(info, log_enginerefac)

game_launcher::game_launcher(const commandline_options& cmdline_opts, const char *appname) :
game_launcher(new CVideo(), cmdline_opts, appname)
{
}

game_launcher::game_launcher(CVideo* v, const commandline_options& cmdline_opts, const char *appname) :
cmdline_opts_(cmdline_opts),
video_(new CVideo()),
video_(v),
font_manager_(),
prefs_manager_(),
image_manager_(),
Expand Down Expand Up @@ -1013,4 +1018,7 @@ game_launcher::~game_launcher()
gui::dialog::delete_empty_menu();
sound::close_sound();
} catch (...) {}
if(!video_->faked()) {
delete video_;
}
}
5 changes: 4 additions & 1 deletion src/game_launcher.hpp
Expand Up @@ -99,6 +99,9 @@ class game_launcher

const commandline_options & opts() const { return cmdline_opts_; }
private:
// This friend declaration is for the unit tests
friend std::unique_ptr<game_launcher> make_fake_launcher();
game_launcher(CVideo* video, const commandline_options& cmdline_opts, const char* appname);
game_launcher(const game_launcher&);
void operator=(const game_launcher&);

Expand All @@ -108,7 +111,7 @@ class game_launcher

const commandline_options& cmdline_opts_;
//Never null.
const std::unique_ptr<CVideo> video_;
CVideo*const video_;

const font::manager font_manager_;
const preferences::manager prefs_manager_;
Expand Down
21 changes: 16 additions & 5 deletions src/tests/gui/test_gui2.cpp
Expand Up @@ -17,6 +17,7 @@

#include <boost/test/unit_test.hpp>

#include "global.hpp"
#include "config_assign.hpp"
#include "config_cache.hpp"
#include "editor/editor_display.hpp" // for dummy display context
Expand Down Expand Up @@ -153,6 +154,18 @@ tdialog* unit_test_mp_server_list()

} // namespace gui2

std::unique_ptr<game_launcher> make_fake_launcher() {
std::vector<std::string> args;
commandline_options opts(args);
CVideo& vid = test_utils::get_fake_display(-1, -1).video();
#ifdef HAVE_CXX14
return std::make_unique(&vid, opts, "unit_tests");
#else
using ptr = std::unique_ptr<game_launcher>;
return ptr(new game_launcher(&vid, opts, "unit_tests"));
#endif
}

namespace {

/** The main config, which contains the entire WML tree. */
Expand Down Expand Up @@ -1038,13 +1051,11 @@ struct twrapper<gui2::ttransient_message>
template<>
struct twrapper<gui2::ttitle_screen>
{
std::vector<std::string> args;
commandline_options opts;
game_launcher game;
twrapper() : opts(args), game(opts, "unit_tests") {}
std::unique_ptr<game_launcher> game;
twrapper() : game(make_fake_launcher()) {}
gui2::ttitle_screen* create()
{
return new gui2::ttitle_screen(game);
return new gui2::ttitle_screen(*game);
}
};

Expand Down

0 comments on commit 45c72fa

Please sign in to comment.