File: Game.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (73 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "RadiantTest.h"
#include "string/split.h"

namespace test
{

using GameTest = RadiantTest;

TEST_F(GameTest, GetCurrentGameConfig)
{
    // Check that we can get the game manager and current game without crashing or anything
    auto& mgr = GlobalGameManager();
    auto game = mgr.currentGame();
    ASSERT_TRUE(game);

    // RadiantTest sets up a test game type which should be exposed via the GameManager
    auto conf = mgr.getConfig();
    EXPECT_EQ(conf.gameType, RadiantTest::DEFAULT_GAME_TYPE);

    // The start of the engine path could be anywhere (depending on where the test binaries are
    // being run from), but it should end with "resources/tdm"
    auto pathComps = string::splitToVec(conf.enginePath, "/");
    EXPECT_GE(pathComps.size(), 2);
    EXPECT_EQ(pathComps.at(pathComps.size() - 1), "tdm");
    EXPECT_EQ(pathComps.at(pathComps.size() - 2), "resources");
}

TEST_F(GameTest, GetGameList)
{
    auto games = GlobalGameManager().getSortedGameList();
    ASSERT_TRUE(games.size() > 2);

    // The games are sorted by the "index" value in the .game XML file, placing TDM at the top,
    // followed by Doom 3 and its demo.
    EXPECT_EQ(games[0]->getName(), "The Dark Mod 2.0 (Standalone)");
    EXPECT_EQ(games[1]->getName(), "Doom 3");
    EXPECT_EQ(games[2]->getName(), "Doom 3 Demo");
}

TEST_F(GameTest, GetGameKeyValues)
{
    auto game = GlobalGameManager().currentGame();

    // Default game is darkmod.game
    EXPECT_EQ(game->getKeyValue("type"), "doom3");
    EXPECT_EQ(game->getKeyValue("name"), "The Dark Mod 2.0 (Standalone)");
    EXPECT_EQ(game->getKeyValue("index"), "10");
    EXPECT_EQ(game->getKeyValue("maptypes"), "mapdoom3");
}

TEST_F(GameTest, GetOptionalFeatures)
{
    auto games = GlobalGameManager().getSortedGameList();

    auto tdm = std::find_if(games.begin(), games.end(), [](game::IGamePtr g) {
        return g->getName() == "The Dark Mod 2.0 (Standalone)";
    });
    ASSERT_TRUE(tdm != games.end());
    auto q3 = std::find_if(games.begin(), games.end(), [](game::IGamePtr g) {
        return g->getName() == "Quake 3";
    });
    ASSERT_TRUE(q3 != games.end());

    // Only Quake 3 should have the "detail_brushes" feature
    EXPECT_FALSE((*tdm)->hasFeature("detail_brushes"));
    EXPECT_TRUE((*q3)->hasFeature("detail_brushes"));

    // Only Dark Mod should have the "hot_reload" feature
    EXPECT_TRUE((*tdm)->hasFeature("hot_reload"));
    EXPECT_FALSE((*q3)->hasFeature("hot_reload"));
}

}