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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/***************************************************************************
*
* Copyright 2010,2011 BMW Car IT GmbH
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************/
#include <gtest/gtest.h>
#include "Surface.h"
#include "Layer.h"
class SurfaceTest : public ::testing::Test
{
public:
void SetUp()
{
m_pSurface = new Surface(0);
ASSERT_TRUE(m_pSurface);
}
void TearDown()
{
if (m_pSurface)
{
delete m_pSurface;
m_pSurface = 0;
}
}
Surface* m_pSurface;
};
TEST_F(SurfaceTest, defaultConstructor)
{
Surface surface(0);
/// make sure, surface was not added to any layer
EXPECT_EQ(GraphicalObject::INVALID_ID, surface.getContainingLayerId());
/// make sure, surface has default size
EXPECT_EQ(0, surface.OriginalSourceHeight);
EXPECT_EQ(0, surface.OriginalSourceWidth);
/// make sure, surface has default visibility
EXPECT_FALSE(surface.getVisibility());
/// make sure, surface has default opacity
EXPECT_DOUBLE_EQ(1.0, surface.getOpacity());
/// make sure, surface has default orientation
EXPECT_EQ(Zero, surface.getOrientation());
/// make sure, surface has default pixel format
EXPECT_EQ(PIXELFORMAT_UNKNOWN, surface.getPixelFormat());
/// make sure, surface has default source rectangle
const Rectangle& srcRect = surface.getSourceRegion();
EXPECT_EQ(0u, srcRect.height);
EXPECT_EQ(0u, srcRect.width);
EXPECT_EQ(0u, srcRect.x);
EXPECT_EQ(0u, srcRect.y);
/// make sure, surface has default destination rectangle
const Rectangle& destRect = surface.getDestinationRegion();
EXPECT_EQ(0u, destRect.height);
EXPECT_EQ(0u, destRect.width);
EXPECT_EQ(0u, destRect.x);
EXPECT_EQ(0u, destRect.y);
/// make sure, surface has no native content associated
EXPECT_FALSE(m_pSurface->hasNativeContent());
}
TEST_F(SurfaceTest, specialConstructor)
{
unsigned int expectedId = 144;
Surface surface(expectedId, getpid());
/// make sure surface has specified id
EXPECT_EQ(expectedId, surface.getID());
/// make sure, surface was not added to any layer
EXPECT_EQ(GraphicalObject::INVALID_ID, surface.getContainingLayerId());
/// make sure, surface has default size
EXPECT_EQ(0, surface.OriginalSourceHeight);
EXPECT_EQ(0, surface.OriginalSourceWidth);
/// make sure, surface has default visibility
EXPECT_FALSE(surface.getVisibility());
/// make sure, surface has default opacity
EXPECT_DOUBLE_EQ(1.0, surface.getOpacity());
/// make sure, surface has default orientation
EXPECT_EQ(Zero, surface.getOrientation());
/// make sure, surface has default pixel format
EXPECT_EQ(PIXELFORMAT_UNKNOWN, surface.getPixelFormat());
/// make sure, surface has default source rectangle
const Rectangle& srcRect = surface.getSourceRegion();
EXPECT_EQ(0u, srcRect.height);
EXPECT_EQ(0u, srcRect.width);
EXPECT_EQ(0u, srcRect.x);
EXPECT_EQ(0u, srcRect.y);
/// make sure, surface has default destination rectangle
const Rectangle& destRect = surface.getDestinationRegion();
EXPECT_EQ(0u, destRect.height);
EXPECT_EQ(0u, destRect.width);
EXPECT_EQ(0u, destRect.x);
EXPECT_EQ(0u, destRect.y);
/// make sure, surface has no native content associated
EXPECT_FALSE(m_pSurface->hasNativeContent());
}
TEST_F(SurfaceTest, getPixelFormat)
{
PixelFormat expected1 = PIXELFORMAT_RGBA5551;
PixelFormat expected2 = PIXELFORMAT_RGB565;
/// set pixel format of surface to expected value
m_pSurface->setPixelFormat(expected1);
/// make sure, surface has expected pixel format
EXPECT_EQ(expected1, m_pSurface->getPixelFormat());
/// set pixel format of surface to other expected value
m_pSurface->setPixelFormat(expected2);
/// make sure, surface has other expected pixel format
EXPECT_EQ(expected2, m_pSurface->getPixelFormat());
}
TEST_F(SurfaceTest, setPixelFormat)
{
PixelFormat expected1 = PIXELFORMAT_R8;
PixelFormat expected2 = PIXELFORMAT_RGBA8888;
/// set pixel format of surface to expected value
m_pSurface->setPixelFormat(expected1);
/// make sure, surface has expected pixel format
EXPECT_EQ(expected1, m_pSurface->getPixelFormat());
/// set pixel format of surface to other expected value
m_pSurface->setPixelFormat(expected2);
/// make sure, surface has other expected pixel format
EXPECT_EQ(expected2, m_pSurface->getPixelFormat());
}
TEST_F(SurfaceTest, getContainingLayerId)
{
unsigned int expectedLayerId = 202;
Layer layer(expectedLayerId, getpid());
/// make sure, surface has no containg layer
EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId());
/// add surface to layer
layer.addSurface(m_pSurface);
/// make sure, surface is contained by layer
EXPECT_EQ(expectedLayerId, m_pSurface->getContainingLayerId());
/// remove surface from layer
layer.removeSurface(m_pSurface);
/// make sure, surface is no longer contained by layer
EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId());
}
TEST_F(SurfaceTest, setContainingLayerId)
{
unsigned int expectedLayerId = 207;
/// make sure, surface has no containing layer
EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId());
/// set surface to be contained by expected layer
m_pSurface->setContainingLayerId(expectedLayerId);
/// make sure, surface is contained by layer
EXPECT_EQ(expectedLayerId, m_pSurface->getContainingLayerId());
/// set surface to be contained by no layer
m_pSurface->setContainingLayerId(GraphicalObject::INVALID_ID);
/// make sure, surface is no longer contained by layer
EXPECT_EQ(GraphicalObject::INVALID_ID, m_pSurface->getContainingLayerId());
}
TEST_F(SurfaceTest, hasNativeContent)
{
unsigned int expectedNativeHandle = 211;
/// make sure, surface has no native content associated
EXPECT_FALSE(m_pSurface->hasNativeContent());
/// set expected native content of surface
m_pSurface->setNativeContent(expectedNativeHandle);
/// make sure, surface has native content associated
EXPECT_TRUE(m_pSurface->hasNativeContent());
/// remove native content of surface
m_pSurface->removeNativeContent();
/// make sure, surface has no native content associated
EXPECT_FALSE(m_pSurface->hasNativeContent());
}
TEST_F(SurfaceTest, removeNativeContent)
{
unsigned int expectedNativeHandle = 213;
/// set expected native content of surface
m_pSurface->setNativeContent(expectedNativeHandle);
/// make sure, surface has native content associated
EXPECT_TRUE(m_pSurface->hasNativeContent());
/// remove native content of surface
m_pSurface->removeNativeContent();
/// make sure, surface has no native content associated
EXPECT_FALSE(m_pSurface->hasNativeContent());
}
TEST_F(SurfaceTest, setNativeContent)
{
unsigned int expectedNativeHandle1 = 217;
unsigned int expectedNativeHandle2 = 218;
/// make sure, surface has no native content associated
EXPECT_FALSE(m_pSurface->hasNativeContent());
/// set 1st expected native content of surface
m_pSurface->setNativeContent(expectedNativeHandle1);
/// make sure, surface has 1st expected native content associated
EXPECT_TRUE(m_pSurface->hasNativeContent());
EXPECT_EQ((long)expectedNativeHandle1, m_pSurface->getNativeContent());
/// set 2nd expected native content of surface
m_pSurface->setNativeContent(expectedNativeHandle2);
/// make sure, surface still has 1st expected native content associated
EXPECT_TRUE(m_pSurface->hasNativeContent());
EXPECT_EQ((long)expectedNativeHandle1, m_pSurface->getNativeContent());
/// remove native content of surface
m_pSurface->removeNativeContent();
/// set 2nd expected native content of surface again
m_pSurface->setNativeContent(expectedNativeHandle2);
/// make sure, surface has 2nd expected native content associated
EXPECT_TRUE(m_pSurface->hasNativeContent());
EXPECT_EQ((long)expectedNativeHandle2, m_pSurface->getNativeContent());
}
TEST_F(SurfaceTest, getNativeContent)
{
unsigned int expectedNativeHandle1 = 217;
unsigned int expectedNativeHandle2 = 218;
/// make sure, surface has no native content associated
EXPECT_FALSE(m_pSurface->hasNativeContent());
/// set 1st expected native content of surface
m_pSurface->setNativeContent(expectedNativeHandle1);
/// make sure, surface has 1st expected native content associated
EXPECT_TRUE(m_pSurface->hasNativeContent());
EXPECT_EQ((long)expectedNativeHandle1, m_pSurface->getNativeContent());
/// remove native content of surface
m_pSurface->removeNativeContent();
/// set 2nd expected native content of surface again
m_pSurface->setNativeContent(expectedNativeHandle2);
/// make sure, surface has 2nd expected native content associated
EXPECT_TRUE(m_pSurface->hasNativeContent());
EXPECT_EQ((long)expectedNativeHandle2, m_pSurface->getNativeContent());
}
|