File: medium_object_promotion.cpp

package info (click to toggle)
rlvm 0.12-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 16,348 kB
  • sloc: cpp: 92,030; ansic: 39,532; perl: 768; python: 181; sh: 171; makefile: 7
file content (226 lines) | stat: -rw-r--r-- 8,213 bytes parent folder | download
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
// -*- 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 <boost/assign.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/tuple/tuple.hpp>

#include <string>
#include <vector>

#include "MachineBase/RLMachine.hpp"
#include "Modules/Module_Grp.hpp"
#include "Systems/Base/GraphicsObject.hpp"
#include "Systems/Base/GraphicsTextObject.hpp"
#include "TestSystem/TestMachine.hpp"
#include "TestSystem/TestSystem.hpp"
#include "libReallive/archive.h"

#include "testUtils.hpp"

using namespace boost;
using namespace boost::assign;

// 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 boost::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(data.get<0>(), data.get<1>(), data.get<2>());

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

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

    ("grpCopy", 0, TestMachine::Arg(1, 0),
     NONE)
    ("grpCopy", 1, TestMachine::Arg(1, 0, 255),
     NONE)
    ("grpCopy", 2, TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0),
     NONE)
    ("grpCopy", 3, TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0, 255),
     NONE)
    ("recCopy", 0, TestMachine::Arg(1, 0),
     NONE)
    ("recCopy", 1, TestMachine::Arg(1, 0, 255),
     NONE)
    ("recCopy", 2, TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0),
     NONE)
    ("recCopy", 3, TestMachine::Arg(0, 0, 200, 200, 1, 0, 0, 0, 255),
     NONE)

    // These commands should promote:
    ("grpDisplay", 0, TestMachine::Arg(0, 5),
     SHOULD_PROMOTE_BG)
    ("grpDisplay", 1, TestMachine::Arg(0, 5, 255),
     SHOULD_PROMOTE_BG)
    ("grpDisplay", 2, TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("grpDisplay", 3, TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0, 255),
     SHOULD_PROMOTE_BG)
    ("recDisplay", 0, TestMachine::Arg(0, 5),
     SHOULD_PROMOTE_BG)
    ("recDisplay", 1, TestMachine::Arg(0, 5, 255),
     SHOULD_PROMOTE_BG)
    ("recDisplay", 2, TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("recDisplay", 3, TestMachine::Arg(0, 5, 0, 0, 200, 200, 0, 0, 255),
     SHOULD_PROMOTE_BG)

    ("grpOpenBg", 0, TestMachine::Arg("file", 0),
     SHOULD_PROMOTE_BG)
    ("grpOpenBg", 1, TestMachine::Arg("file", 0, 255),
     SHOULD_PROMOTE_BG)
    ("grpOpenBg", 2, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("grpOpenBg", 3, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
     SHOULD_PROMOTE_BG)
    ("recOpenBg", 0, TestMachine::Arg("file", 0),
     SHOULD_PROMOTE_BG)
    ("recOpenBg", 1, TestMachine::Arg("file", 0, 255),
     SHOULD_PROMOTE_BG)
    ("recOpenBg", 2, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("recOpenBg", 3, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
     SHOULD_PROMOTE_BG)

    ("grpMaskOpen", 0, TestMachine::Arg("file", 0),
     SHOULD_PROMOTE_BG)
    ("grpMaskOpen", 1, TestMachine::Arg("file", 0, 255),
     SHOULD_PROMOTE_BG)
    ("grpMaskOpen", 2, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("grpMaskOpen", 3, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
     SHOULD_PROMOTE_BG)
    ("recMaskOpen", 0, TestMachine::Arg("file", 0),
     SHOULD_PROMOTE_BG)
    ("recMaskOpen", 1, TestMachine::Arg("file", 0, 255),
     SHOULD_PROMOTE_BG)
    ("recMaskOpen", 2, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("recMaskOpen", 3, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
     SHOULD_PROMOTE_BG)

    ("recMulti", 0, TestMachine::Arg("file", 0),
     SHOULD_PROMOTE_BG)
    ("recMulti", 1, TestMachine::Arg("file", 0, 255),
     SHOULD_PROMOTE_BG)

    ("grpOpen", 0, TestMachine::Arg("file", 0),
     SHOULD_PROMOTE_BG)
    ("grpOpen", 1, TestMachine::Arg("file", 0, 255),
     SHOULD_PROMOTE_BG)
    ("grpOpen", 2, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("grpOpen", 3, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0, 255),
     SHOULD_PROMOTE_BG)
    ("recOpen", 0, TestMachine::Arg("file", 0),
     SHOULD_PROMOTE_BG)
    ("recOpen", 1, TestMachine::Arg("file", 0, 255),
     SHOULD_PROMOTE_BG)
    ("recOpen", 2, TestMachine::Arg("file", 0, 0, 0, 200, 200, 0, 0),
     SHOULD_PROMOTE_BG)
    ("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));