File: medium_object_promotion.cc

package info (click to toggle)
rlvm 0.14-5.2
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 17,104 kB
  • sloc: cpp: 91,574; ansic: 39,346; perl: 768; sh: 320; python: 181; makefile: 8
file content (288 lines) | stat: -rw-r--r-- 11,369 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// -*- 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) 2009 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 "gtest/gtest.h"

#include <string>
#include <tuple>
#include <vector>

#include "libreallive/archive.h"
#include "machine/rlmachine.h"
#include "modules/module_grp.h"
#include "systems/base/graphics_object.h"
#include "systems/base/graphics_text_object.h"
#include "test_system/test_machine.h"
#include "test_system/test_system.h"

#include "test_utils.h"

using namespace boost;

using std::get;

// A test suite that tests that certain graphical commands promote the object
// layer... and tests that others that are known to not promote objects don't.
typedef std::tuple<std::string,               // function name
                   int,                       // overload number
                   TestMachine::ExeArgument,  // function arguments
                   bool                       // Should bg layer be promoted?
                   > PromotionData;

class PromotionTest : public ::testing::TestWithParam<PromotionData> {
 public:
  PromotionTest()
      : arc(locateTestCase("Module_Str_SEEN/strcpy_0.TXT")),
        system(locateTestCase("Gameexe_data/Gameexe.ini")),
        rlmachine(system, arc) {
    rlmachine.AttachModule(new GrpModule);
  }

  // Use any old test case; it isn't getting executed
  libreallive::Archive arc;
  TestSystem system;
  TestMachine rlmachine;
};

enum CommandProperties { NONE = 0, SHOULD_PROMOTE_BG = 1 };

// Tests whether a certain command will promote an object from the background
// layer to the foreground.
TEST_P(PromotionTest, BgLayerPromotion) {
  PromotionData data = GetParam();
  GraphicsSystem& gs = system.graphics();

  // Build a dummy object into the background slot.
  GraphicsObject& obj = gs.GetObject(OBJ_BG, 0);
  obj.SetTextText("String");
  obj.SetObjectData(new GraphicsTextObject(system));

  // Run the graphics command.
  rlmachine.Exe(get<0>(data), get<1>(data), get<2>(data));

  // Whether the object was promoted to the fg layer.
  EXPECT_EQ(get<3>(data) & SHOULD_PROMOTE_BG,
            !gs.GetObject(OBJ_FG, 0).is_cleared());
}

std::vector<PromotionData> data = {
    // These commands shouldn't promote:
    std::make_tuple("grpLoad", 0, TestMachine::Arg("file", 0), NONE),
    std::make_tuple("grpLoad", 1, TestMachine::Arg("file", 0, 255), NONE),
    std::make_tuple("grpLoad",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    NONE),
    std::make_tuple("grpLoad",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    NONE),
    std::make_tuple("recLoad", 0, TestMachine::Arg("file", 0), NONE),
    std::make_tuple("recLoad", 1, TestMachine::Arg("file", 0, 255), NONE),
    std::make_tuple("recLoad",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    NONE),
    std::make_tuple("recLoad",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    NONE),
    std::make_tuple("grpMaskLoad", 0, TestMachine::Arg("file", 0), NONE),
    std::make_tuple("grpMaskLoad", 1, TestMachine::Arg("file", 0, 255), NONE),
    std::make_tuple("grpMaskLoad",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    NONE),
    std::make_tuple("grpMaskLoad",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    NONE),
    std::make_tuple("recMaskLoad", 0, TestMachine::Arg("file", 0), NONE),
    std::make_tuple("recMaskLoad", 1, TestMachine::Arg("file", 0, 255), NONE),
    std::make_tuple("recMaskLoad",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    NONE),
    std::make_tuple("recMaskLoad",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    NONE),
    std::make_tuple("grpCopy", 0, TestMachine::Arg(1, 0), NONE),
    std::make_tuple("grpCopy", 1, TestMachine::Arg(1, 0, 255), NONE),
    std::make_tuple("grpCopy",
                    2,
                    TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0),
                    NONE),
    std::make_tuple("grpCopy",
                    3,
                    TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0, 255),
                    NONE),
    std::make_tuple("recCopy", 0, TestMachine::Arg(1, 0), NONE),
    std::make_tuple("recCopy", 1, TestMachine::Arg(1, 0, 255), NONE),
    std::make_tuple("recCopy",
                    2,
                    TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0),
                    NONE),
    std::make_tuple("recCopy",
                    3,
                    TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0, 255),
                    NONE),

    // These commands should promote:
    std::make_tuple("grpDisplay", 0, TestMachine::Arg(0, 5), SHOULD_PROMOTE_BG),
    std::make_tuple("grpDisplay",
                    1,
                    TestMachine::Arg(0, 5, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpDisplay",
                    2,
                    TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpDisplay",
                    3,
                    TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recDisplay", 0, TestMachine::Arg(0, 5), SHOULD_PROMOTE_BG),
    std::make_tuple("recDisplay",
                    1,
                    TestMachine::Arg(0, 5, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recDisplay",
                    2,
                    TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recDisplay",
                    3,
                    TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpenBg",
                    0,
                    TestMachine::Arg("file", 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpenBg",
                    1,
                    TestMachine::Arg("file", 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpenBg",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpenBg",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpenBg",
                    0,
                    TestMachine::Arg("file", 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpenBg",
                    1,
                    TestMachine::Arg("file", 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpenBg",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpenBg",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpMaskOpen",
                    0,
                    TestMachine::Arg("file", 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpMaskOpen",
                    1,
                    TestMachine::Arg("file", 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpMaskOpen",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpMaskOpen",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recMaskOpen",
                    0,
                    TestMachine::Arg("file", 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recMaskOpen",
                    1,
                    TestMachine::Arg("file", 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recMaskOpen",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recMaskOpen",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recMulti",
                    0,
                    TestMachine::Arg("file", 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recMulti",
                    1,
                    TestMachine::Arg("file", 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpen",
                    0,
                    TestMachine::Arg("file", 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpen",
                    1,
                    TestMachine::Arg("file", 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpen",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("grpOpen",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpen",
                    0,
                    TestMachine::Arg("file", 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpen",
                    1,
                    TestMachine::Arg("file", 0, 255),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpen",
                    2,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
                    SHOULD_PROMOTE_BG),
    std::make_tuple("recOpen",
                    3,
                    TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
                    SHOULD_PROMOTE_BG)};

INSTANTIATE_TEST_CASE_P(MediumObjectPoromotion,
                        PromotionTest,
                        ::testing::ValuesIn(data));