summaryrefslogtreecommitdiff
path: root/LayerManagerBase/tests/SceneTest.cpp
blob: 152a99e495a38e9a706d1937ad300899ab9dfca8 (plain)
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
/***************************************************************************
 *
 * Copyright 2010,2011 BMW Car IT GmbH
 * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia 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 "IScene.h"
#include "Scene.h"
#include "SurfaceMap.h"
#include "LmScreenList.h"
#include <vector>

class SceneTest : public ::testing::Test
{
public:
    void SetUp()
    {
        m_pScene = new Scene();
        ASSERT_TRUE(m_pScene);

        LmScreenList& screenList = m_pScene->getScreenList();
        LmScreen* pScreen = new LmScreen();
        ASSERT_TRUE(pScreen);
        screenList.push_back(pScreen);
    }

    void TearDown()
    {
        if (m_pScene)
        {
            LmScreenList& screenList = m_pScene->getScreenList();
            LmScreenListIterator iter = screenList.begin();
            LmScreenListIterator iterEnd = screenList.end();
            for (; iter != iterEnd; ++iter)
            {
                delete (*iter);
            }
            delete m_pScene;
            m_pScene = 0;
        }
    }

    IScene* m_pScene;
};

TEST_F(SceneTest, createLayer)
{
    uint size;
    uint* array;
    Layer* pLayer;
    uint expected = 91;

    /// make sure, scene contains no layers
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)0, size) << "Scene should contain 0 layers";

    /// create layer with expected id
    pLayer = m_pScene->createLayer(expected, 0);
    ASSERT_TRUE(pLayer) << "Layer was not created.";

    /// make sure layer has expected id
    EXPECT_EQ(expected, pLayer->getID());

    /// make sure, scene contains one layer
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 layer";

    /// make sure, layer contains no surfaces
    SurfaceList& slist = pLayer->getAllSurfaces();
    EXPECT_EQ((uint)0, slist.size());
}

TEST_F(SceneTest, createLayer_invalidId)
{
    uint size;
    uint* array;
    Layer* pLayer;

    /// make sure, scene contains no layers
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)0, size) << "Scene should contain 0 layers";

    /// create layer with invalid id
    pLayer = m_pScene->createLayer(GraphicalObject::INVALID_ID, 0);
    ASSERT_TRUE(pLayer) << "Layer was not created.";

    /// make sure new layer has valid id
    EXPECT_NE(GraphicalObject::INVALID_ID, pLayer->getID());

    /// make sure, scene contains one layer
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 layer";
}

TEST_F(SceneTest, createLayer_twice)
{
    uint size;
    uint* array;
    uint expected = 55;
    double expectedOpacity = 0.322;
    Layer* pLayer1;
    Layer* pLayer2;

    /// create Layer with id 55
    pLayer1 = m_pScene->createLayer(expected, 0);
    ASSERT_EQ(expected, pLayer1->getID());

    /// make sure, scene contains one layer
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 layer";

    /// try to create existing layer 55, handle to existing layer should be returned
    pLayer2 = m_pScene->createLayer(expected, 0);
    ASSERT_EQ(expected, pLayer2->getID());

    /// make sure, scene still contains one layer
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 layer";

    /// change opacity using first layer handle
    pLayer1->setOpacity(expectedOpacity);

    /// check opacity of layer using second handle
    EXPECT_DOUBLE_EQ(expectedOpacity, pLayer2->getOpacity());
}

TEST_F(SceneTest, createSurface)
{
    uint size;
    uint* array;
    Surface* pSurface;
    uint expected = 131;

    /// make sure, scene contains no surfaces
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)0, size) << "Scene should contain 0 surfaces";

    /// create surface with expected id
    pSurface = m_pScene->createSurface(expected, 0);
    ASSERT_TRUE(pSurface) << "Surface was not created.";

    /// make sure surface has expected id
    EXPECT_EQ(expected, pSurface->getID());

    /// make sure, scene contains one surface
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 surface";

    /// make sure, surface was not added to any layer
    EXPECT_EQ(GraphicalObject::INVALID_ID, pSurface->getContainingLayerId());
}

TEST_F(SceneTest, createSurface_invalidId)
{
    uint size;
    uint* array;
    Surface* pSurface;

    /// make sure, scene contains no surfaces
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)0, size) << "Scene should contain 0 surfaces";

    /// create surface with invalid id
    pSurface = m_pScene->createSurface(GraphicalObject::INVALID_ID, 0);
    ASSERT_TRUE(pSurface) << "Surface was not created.";

    /// make sure new surface has valid id
    EXPECT_NE(GraphicalObject::INVALID_ID, pSurface->getID());

    /// make sure, scene contains one surface
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 surface";
}

TEST_F(SceneTest, createSurface_twice)
{
    uint size;
    uint* array;
    Surface* pSurface1;
    Surface* pSurface2;
    uint expected = 135;
    double expectedOpacity = 0.718;

    /// make sure, scene contains no surfaces
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)0, size) << "Scene should contain 0 surfaces";

    /// create surface with expected id
    pSurface1 = m_pScene->createSurface(expected, 0);
    ASSERT_TRUE(pSurface1) << "Surface was not created.";

    /// make sure surface has expected id
    EXPECT_EQ(expected, pSurface1->getID());

    /// make sure, scene contains one surface
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 surface";

    /// create surface with expected id again
    pSurface2 = m_pScene->createSurface(expected, 0);
    ASSERT_TRUE(pSurface2) << "Surface was not created.";

    /// make sure surface has expected id again
    EXPECT_EQ(expected, pSurface2->getID());

    /// make sure, scene still contains one surface
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)1, size) << "Scene should contain 1 surface";

    /// change opacity using first surface handle
    pSurface1->setOpacity(expectedOpacity);

    /// check opacity of surface using second surface handle
    EXPECT_DOUBLE_EQ(expectedOpacity, pSurface2->getOpacity());
}

TEST_F(SceneTest, removeLayer)
{
    uint expectedLayerId = 188;
    Layer* pLayer;

    /// create layer
    pLayer = m_pScene->createLayer(expectedLayerId, 0);
    ASSERT_TRUE(pLayer);

    /// make sure, layer exists
    ASSERT_EQ(pLayer, m_pScene->getLayer(expectedLayerId));

    /// remove layer
    m_pScene->removeLayer(pLayer);

    /// make sure, layer does not exist
    ASSERT_FALSE(m_pScene->getLayer(expectedLayerId));
}

TEST_F(SceneTest, removeSurface)
{
    uint expectedSurfaceId = 189;
    Surface* pSurface;

    /// create Surface
    pSurface = m_pScene->createSurface(expectedSurfaceId, 0);
    ASSERT_TRUE(pSurface);

    /// make sure, Surface exists
    ASSERT_EQ(pSurface, m_pScene->getSurface(expectedSurfaceId));

    /// remove Surface
    m_pScene->removeSurface(pSurface);

    /// make sure, Surface does not exist
    ASSERT_FALSE(m_pScene->getSurface(expectedSurfaceId));
}

TEST_F(SceneTest, getLayer)
{
    uint expectedLayerId = 198;
    Layer* pLayer;

    /// try to get non existing layer
    EXPECT_FALSE(m_pScene->getLayer(expectedLayerId));

    /// create layer
    pLayer = m_pScene->createLayer(expectedLayerId, 0);
    ASSERT_TRUE(pLayer);

    /// get layer
    ASSERT_EQ(pLayer, m_pScene->getLayer(expectedLayerId));

    /// remove layer
    m_pScene->removeLayer(pLayer);

    /// try to get removed layer
    ASSERT_FALSE(m_pScene->getLayer(expectedLayerId));
}

TEST_F(SceneTest, getSurface)
{
    uint expectedSurfaceId = 198;
    Surface* pSurface;

    /// try to get non existing Surface
    EXPECT_FALSE(m_pScene->getSurface(expectedSurfaceId));

    /// create Surface
    pSurface = m_pScene->createSurface(expectedSurfaceId, 0);
    ASSERT_TRUE(pSurface);

    /// get Surface
    ASSERT_EQ(pSurface, m_pScene->getSurface(expectedSurfaceId));

    /// remove Surface
    m_pScene->removeSurface(pSurface);

    /// try to get removed Surface
    ASSERT_FALSE(m_pScene->getSurface(expectedSurfaceId));
}

TEST_F(SceneTest, getLayerIDs)
{
    unsigned int layerId1 = 101;
    unsigned int layerId2 = 102;
    unsigned int layerId3 = 103;
    unsigned int layerId4 = 104;
    unsigned int size;
    unsigned int* array;

    /// make sure, scene contains no layers
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)0, size);

    /// create 4 layers in scene
    m_pScene->createLayer(layerId1, 0);
    m_pScene->createLayer(layerId2, 0);
    m_pScene->createLayer(layerId3, 0);
    m_pScene->createLayer(layerId4, 0);

    /// make sure, scene contains these 4 layers
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)4, size);
    EXPECT_EQ(layerId1, array[0]);
    EXPECT_EQ(layerId2, array[1]);
    EXPECT_EQ(layerId3, array[2]);
    EXPECT_EQ(layerId4, array[3]);
}

TEST_F(SceneTest, getLayerIDsOfScreen)
{
    unsigned int screenId = 0;
    unsigned int layerId1 = 121;
    unsigned int layerId2 = 122;
    unsigned int layerId3 = 123;
    unsigned int layerId4 = 124;
    unsigned int size;
    unsigned int* array;
    Layer* l1;
    Layer* l2;
    Layer* l3;
    Layer* l4;

    /// make sure, scene contains no layers
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)0, size);

    /// create 4 layers in scene, but dont add them to render order
    l1 = m_pScene->createLayer(layerId1, 0);
    l2 = m_pScene->createLayer(layerId2, 0);
    l3 = m_pScene->createLayer(layerId3, 0);
    l4 = m_pScene->createLayer(layerId4, 0);

    /// make sure, scene contains these 4 layers
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)4, size);
    EXPECT_EQ(layerId1, array[0]);
    EXPECT_EQ(layerId2, array[1]);
    EXPECT_EQ(layerId3, array[2]);
    EXPECT_EQ(layerId4, array[3]);

    /// make sure, screen still has no layers applied
    m_pScene->getLayerIDsOfScreen(screenId, &size, &array);
    ASSERT_EQ((uint)0, size);

    /// add 3 layers to screen
    LayerList& llist = m_pScene->getCurrentRenderOrder(screenId);
    llist.push_back(l1);
    llist.push_back(l3);
    llist.push_back(l4);

    /// make sure, screen now has 3 layers
    m_pScene->getLayerIDsOfScreen(screenId, &size, &array);
    ASSERT_EQ((uint)3, size);
    EXPECT_EQ(l1->getID(), array[0]);
    EXPECT_EQ(l3->getID(), array[1]);
    EXPECT_EQ(l4->getID(), array[2]);

    /// add 4th layer to screen
    llist.push_back(l2);

    /// make sure, screen now has 4 layers
    m_pScene->getLayerIDsOfScreen(screenId, &size, &array);
    ASSERT_EQ((uint)4, size);
    EXPECT_EQ(l1->getID(), array[0]);
    EXPECT_EQ(l3->getID(), array[1]);
    EXPECT_EQ(l4->getID(), array[2]);
    EXPECT_EQ(l2->getID(), array[3]);
}

TEST_F(SceneTest, getSurfaceIDs)
{
    unsigned int surfaceId1 = 141;
    unsigned int surfaceId2 = 142;
    unsigned int surfaceId3 = 143;
    unsigned int surfaceId4 = 144;
    unsigned int size;
    unsigned int* array;

    /// make sure, scene contains no surfaces
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)0, size);

    /// create 4 surfaces in scene
    m_pScene->createSurface(surfaceId1, 0);
    m_pScene->createSurface(surfaceId2, 0);
    m_pScene->createSurface(surfaceId3, 0);
    m_pScene->createSurface(surfaceId4, 0);

    /// make sure, scene contains these 4 surfaces
    m_pScene->getSurfaceIDs(&size, &array);
    ASSERT_EQ((uint)4, size);
    EXPECT_EQ(surfaceId1, array[0]);
    EXPECT_EQ(surfaceId2, array[1]);
    EXPECT_EQ(surfaceId3, array[2]);
    EXPECT_EQ(surfaceId4, array[3]);
}

TEST_F(SceneTest, DISABLED_lockScene)
{
}

TEST_F(SceneTest, DISABLED_unlockScene)
{
}

TEST_F(SceneTest, getCurrentRenderOrder)
{
    // TODO: how to test? return by typically reference can't be invalid.

    /// get render order
    LayerList& llist = m_pScene->getCurrentRenderOrder(0);

    /// make sure, list of layers is returned
    ASSERT_TRUE(&llist);
}

TEST_F(SceneTest, getAllSurfaces)
{
    uint expectedId1 = 241;
    uint expectedId2 = 242;
    uint expectedId3 = 243;
    Surface* s1;
    Surface* s2;
    Surface* s3;

    /// try to get surfaces, when no surfaces exist in scene
    ASSERT_EQ((uint)0, m_pScene->getAllSurfaces().size());

    /// add 3 surfaces to scene
    s1 = m_pScene->createSurface(expectedId1, 0);
    s2 = m_pScene->createSurface(expectedId2, 0);
    s3 = m_pScene->createSurface(expectedId3, 0);

    /// get all surfaces
    const SurfaceMap& smap1 = m_pScene->getAllSurfaces();
    ASSERT_EQ((uint)3, smap1.size());
    // order is undefined here, but each surface must be contained once
    EXPECT_EQ((uint)1, smap1.count(expectedId1));
    EXPECT_EQ((uint)1, smap1.count(expectedId2));
    EXPECT_EQ((uint)1, smap1.count(expectedId3));

    /// remove 2 surfaces again
    m_pScene->removeSurface(s1);
    m_pScene->removeSurface(s3);

    /// check, if the remaining surface is the expected one
    const SurfaceMap& smap2 = m_pScene->getAllSurfaces();
    ASSERT_EQ((uint)1, smap2.size());
    EXPECT_EQ((uint)1, smap2.count(expectedId2));
    EXPECT_EQ(s2, smap2.at(expectedId2));
}


TEST_F(SceneTest, isLayerInCurrentRenderOrder)
{
    unsigned int layerId1 = 121;
    unsigned int size;
    unsigned int* array;
    Layer* l1;

    /// create layer in scene, but dont add it to render order
    l1 = m_pScene->createLayer(layerId1, 0);

    /// make sure, scene contains the new layers
    m_pScene->getLayerIDs(&size, &array);
    ASSERT_EQ((uint)1, size);
    EXPECT_EQ(layerId1, array[0]);

    /// make sure, layer is not in render order
    ASSERT_FALSE(m_pScene->isLayerInCurrentRenderOrder(layerId1));

    /// add layer to render order
    LayerList& llist = m_pScene->getCurrentRenderOrder(0);
    llist.push_back(l1);

    /// make sure, layer is in render order
    ASSERT_TRUE(m_pScene->isLayerInCurrentRenderOrder(layerId1));

    /// remove layer from render order
    llist.remove(l1);

    /// make sure, layer is not in render order
    ASSERT_FALSE(m_pScene->isLayerInCurrentRenderOrder(layerId1));
}