All Classes Namespaces Functions Variables Enumerations Properties Pages
test_layermanager.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2012-2020 Matthew Chiawen Chang
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 */
16 #include "catch.hpp"
17 
18 #include "object.h"
19 #include "editor.h"
20 #include "layermanager.h"
21 #include "pencilerror.h"
22 
23 
24 TEST_CASE("LayerManager::init()")
25 {
26  Object* object = new Object;
27  Editor* editor = new Editor;
28  editor->setObject(object);
29 
30  SECTION("Test initial state")
31  {
32  LayerManager* layerMgr = new LayerManager(editor);
33  layerMgr->init();
34 
35  object->init();
36  object->createDefaultLayers(); // create default 3 layers
37  REQUIRE(layerMgr->count() == 3);
38  REQUIRE(layerMgr->currentLayerIndex() == 2);
39  REQUIRE(layerMgr->getLayer(0)->type() == Layer::CAMERA);
40  REQUIRE(layerMgr->getLayer(1)->type() == Layer::VECTOR);
41  REQUIRE(layerMgr->getLayer(2)->type() == Layer::BITMAP);
42  }
43  delete editor;
44 }
45 
46 TEST_CASE("LayerManager::deleteLayer()")
47 {
48  Object* object = new Object;
49  Editor* editor = new Editor;
50  editor->setObject(object);
51 
52  SECTION("delete layers")
53  {
54  LayerManager* layerMgr = new LayerManager(editor);
55  layerMgr->init();
56 
57  object->init();
58 
59  REQUIRE(layerMgr->count() == 0);
60  layerMgr->createCameraLayer("Camera1");
61  REQUIRE(layerMgr->count() == 1);
62  layerMgr->createVectorLayer("Vector2");
63  REQUIRE(layerMgr->count() == 2);
64  layerMgr->createBitmapLayer("Bitmap3");
65  REQUIRE(layerMgr->count() == 3);
66  layerMgr->deleteLayer(2);
67  REQUIRE(layerMgr->count() == 2);
68  layerMgr->deleteLayer(1);
69  REQUIRE(layerMgr->count() == 1);
70  }
71 
72  SECTION("delete camera layers")
73  {
74  LayerManager* layerMgr = new LayerManager(editor);
75  layerMgr->init();
76 
77  // create 2 camera layers
78  REQUIRE(layerMgr->count() == 0);
79  layerMgr->createCameraLayer("Camera1");
80  REQUIRE(layerMgr->count() == 1);
81  layerMgr->createCameraLayer("Camera2");
82  REQUIRE(layerMgr->count() == 2);
83 
84  // delete one of them, ok.
85  layerMgr->deleteLayer(1);
86  REQUIRE(layerMgr->count() == 1);
87 
88  // delete the second, no, cant do it.
89  Status st = layerMgr->deleteLayer(0);
90  REQUIRE(layerMgr->count() == 1);
91  REQUIRE((st == Status::ERROR_NEED_AT_LEAST_ONE_CAMERA_LAYER));
92  }
93  delete editor;
94 }
Definition: object.h:54
Definition: editor.h:51