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->addNewCameraLayer();
37  object->addNewVectorLayer();
38  object->addNewBitmapLayer();
39  REQUIRE(layerMgr->count() == 3);
40  REQUIRE(layerMgr->currentLayerIndex() == 0);
41  REQUIRE(layerMgr->getLayer(0)->type() == Layer::CAMERA);
42  REQUIRE(layerMgr->getLayer(1)->type() == Layer::VECTOR);
43  REQUIRE(layerMgr->getLayer(2)->type() == Layer::BITMAP);
44  }
45  delete editor;
46 }
47 
48 TEST_CASE("LayerManager::deleteLayer()")
49 {
50  Object* object = new Object;
51  Editor* editor = new Editor;
52  editor->setObject(object);
53 
54  SECTION("delete layers")
55  {
56  LayerManager* layerMgr = new LayerManager(editor);
57  layerMgr->init();
58 
59  object->init();
60 
61  REQUIRE(layerMgr->count() == 0);
62  layerMgr->createCameraLayer("Camera1");
63  REQUIRE(layerMgr->count() == 1);
64  layerMgr->createVectorLayer("Vector2");
65  REQUIRE(layerMgr->count() == 2);
66  layerMgr->createBitmapLayer("Bitmap3");
67  REQUIRE(layerMgr->count() == 3);
68  layerMgr->deleteLayer(2);
69  REQUIRE(layerMgr->count() == 2);
70  layerMgr->deleteLayer(1);
71  REQUIRE(layerMgr->count() == 1);
72  }
73 
74  SECTION("delete camera layers")
75  {
76  LayerManager* layerMgr = new LayerManager(editor);
77  layerMgr->init();
78 
79  // create 2 camera layers
80  REQUIRE(layerMgr->count() == 0);
81  layerMgr->createCameraLayer("Camera1");
82  REQUIRE(layerMgr->count() == 1);
83  layerMgr->createCameraLayer("Camera2");
84  REQUIRE(layerMgr->count() == 2);
85 
86  // delete one of them, ok.
87  layerMgr->deleteLayer(1);
88  REQUIRE(layerMgr->count() == 1);
89 
90  // delete the second, no, cant do it.
91  Status st = layerMgr->deleteLayer(0);
92  REQUIRE(layerMgr->count() == 1);
93  REQUIRE((st == Status::ERROR_NEED_AT_LEAST_ONE_CAMERA_LAYER));
94  }
95  delete editor;
96 }
97 
98 TEST_CASE("Layer::setCurrentLayer(index)") {
99  Object* object = new Object;
100  Editor* editor = new Editor;
101  editor->setObject(object);
102 
103  SECTION("Deselect previous layer") {
104  LayerManager* layerMgr = new LayerManager(editor);
105  layerMgr->init();
106 
107  layerMgr->createBitmapLayer("Bitmap1");
108  layerMgr->createBitmapLayer("Bitmap2");
109  layerMgr->setCurrentLayer(0);
110 
111  Layer* currentLayer = layerMgr->currentLayer();
112  currentLayer->addNewKeyFrameAt(1);
113  currentLayer->addNewKeyFrameAt(2);
114 
115  currentLayer->setFrameSelected(1, true);
116  currentLayer->setFrameSelected(2, true);
117 
118  REQUIRE(currentLayer->selectedKeyFrameCount() == 2);
119 
120  layerMgr->setCurrentLayer(1);
121 
122  // Make sure that previous layer has deselected all frames
123  REQUIRE(layerMgr->getLayer(0)->selectedKeyFrameCount() == 0);
124  REQUIRE(layerMgr->getLayer(1)->selectedKeyFrameCount() == 0);
125 
126  }
127  delete editor;
128 }
Definition: layer.h:38
Definition: object.h:41
Definition: editor.h:55