File: gameexe_test.cc

package info (click to toggle)
rlvm 0.14-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,920 kB
  • ctags: 33,581
  • sloc: cpp: 91,570; ansic: 39,346; perl: 768; python: 181; sh: 170; makefile: 8
file content (138 lines) | stat: -rw-r--r-- 4,821 bytes parent folder | download | duplicates (6)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi:tw=80:et:ts=2:sts=2
//
// -----------------------------------------------------------------------
//
// This file is part of RLVM, a RealLive virtual machine clone.
//
// -----------------------------------------------------------------------
//
// Copyright (C) 2006 Elliot Glaysher
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// -----------------------------------------------------------------------

#include "libreallive/gameexe.h"

#include "gtest/gtest.h"

#include "test_utils.h"

#include <string>
#include <vector>

using namespace std;

TEST(GameexeUnit, ReadAllKeys) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  EXPECT_EQ(26, ini.size()) << "Wrong number of keys";
}

// Make sure #CAPTION exists and that we read its value correctly.
TEST(GameexeUnit, ReadsCaption) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  EXPECT_TRUE(ini("CAPTION").Exists()) << "#CAPTION exists";
  EXPECT_EQ(string("Canon: A firearm"), ini("CAPTION").ToString())
      << "Wrong value for CAPTION";
}

// Make sure #RANDOM_KEY doesn't exist.
TEST(GameexeUnit, RandomKeyDoesntExist) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  EXPECT_FALSE(ini("RANDOM_KEY").Exists()) << "#RANDOM_KEY does not exist";
}

// Test ToIntVector() parsing.
TEST(GameexeUnit, IntVectorParsing) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  EXPECT_TRUE(ini("WINDOW_ATTR").Exists()) << "#WINDOW_ATTR exists!";

  vector<int> ints = ini("WINDOW_ATTR").ToIntVector();
  for (int i = 0; i < 5; ++i) {
    EXPECT_EQ(i + 1, ints.at(i));
  }
}

// Make sure operator() works with multiple keys...
TEST(GameexeUnit, MultipleKeys) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  EXPECT_EQ(1, ini("IMAGINE", "ONE"));
  EXPECT_EQ(2, ini("IMAGINE", "TWO"));
  EXPECT_EQ(3, ini("IMAGINE", "THREE"));
}

// Make sure GameexeInterpretObject chaining works correctly.
TEST(GameexeUnit, ChainingWorks) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  GameexeInterpretObject imagine = ini("IMAGINE");
  EXPECT_EQ(1, imagine("ONE"));
  EXPECT_EQ(2, imagine("TWO"));
  EXPECT_EQ(3, imagine("THREE"));
}

TEST(GameexeUnit, FilteringIterators) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  GameexeFilteringIterator it = ini.filtering_begin("IMAGINE");
  GameexeFilteringIterator end = ini.filtering_end();
  for (; it != end; ++it) {
    if (it->key() != "IMAGINE.ONE" && it->key() != "IMAGINE.TWO" &&
        it->key() != "IMAGINE.THREE") {
      FAIL() << "Failed to filter keys in GameexeFilteringIterator. Has key "
             << it->key();
    }
  }
}

TEST(GameexeUnit, KeyParts) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe.ini"));
  GameexeInterpretObject gio = ini("WINDOW.000.ATTR_MOD");
  vector<string> pieces = gio.GetKeyParts();
  EXPECT_EQ(3, pieces.size());
  EXPECT_EQ("WINDOW", pieces[0]);
  EXPECT_EQ("000", pieces[1]);
  EXPECT_EQ("ATTR_MOD", pieces[2]);
}

// A demo on the Princess Bride Box Set does something weird with its \#DSTRACK
// keys. While all other games space the entries like this:
//
//   #DSTRACK = 00000000 - 99999999 - 00269364 = "BGM01"  = "BGM01"
//
// this game does not:
//
//   #DSTRACK=00000000-10998934-00000000="dcbgm000"="dcbgm000"
//
// and this runs afoul of the gameexe tokenization
// code. (00000000-10998934-00000000 is treated as a single token.)
//
// This test ensures that the gameexe parser can handle both.
TEST(GameexeUnit, DstrackRegression) {
  Gameexe ini(locateTestCase("Gameexe_data/Gameexe_tokenization.ini"));

  GameexeInterpretObject clannad = ini("CLANNADDSTRACK");
  EXPECT_EQ(0, clannad.GetIntAt(0));
  EXPECT_EQ(99999999, clannad.GetIntAt(1));
  EXPECT_EQ(269364, clannad.GetIntAt(2));
  EXPECT_EQ("BGM01", clannad.GetStringAt(3));
  EXPECT_EQ("BGM01", clannad.GetStringAt(4));

  GameexeInterpretObject dc = ini("DCDSTRACK");
  EXPECT_EQ(0, dc.GetIntAt(0));
  EXPECT_EQ(10998934, dc.GetIntAt(1));
  EXPECT_EQ(0, dc.GetIntAt(2));
  EXPECT_EQ("dcbgm000", dc.GetStringAt(3));
  EXPECT_EQ("dcbgm000", dc.GetStringAt(4));
}