All Classes Namespaces Functions Variables Enumerations Properties Pages
test_colormanager.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 "colormanager.h"
19 #include "object.h"
20 #include "editor.h"
21 #include "layer.h"
22 #include "layermanager.h"
23 
24 TEST_CASE("ColorManager Initial Test")
25 {
26  Object* object = new Object;
27  Editor* editor = new Editor;
28  editor->setObject(object);
29 
30  SECTION("init")
31  {
32  ColorManager* cm = new ColorManager(editor);
33  REQUIRE(cm != nullptr);
34  REQUIRE(cm->init() == true);
35  }
36 
37  delete editor;
38 }
39 
40 TEST_CASE("ColorManager set color tests")
41 {
42  Object* object = new Object;
43 
44  Editor* editor = new Editor;
45  editor->setObject(object);
46  ColorManager* cm = new ColorManager(editor);
47  cm->init();
48 
49  Object* layerObj = new Object;
50  Editor* layerEdit = new Editor;
51  editor->setObject(object);
52  LayerManager* layerMgr = new LayerManager(layerEdit);
53  layerMgr->init();
54 
55  layerObj->init();
56  // 0 = camera, 1 = vector, 2 = bitmap
57  layerObj->addNewCameraLayer();
58  layerObj->addNewVectorLayer();
59  layerObj->addNewBitmapLayer();
60 
61 
62  SECTION("setColor non vector layer")
63  {
64  cm->workingLayerChanged(layerObj->getLayer(2));
65  cm->setFrontColor(QColor(255,0,0));
66  REQUIRE(cm->frontColor() == QColor(255,0,0));
67  }
68 
69  SECTION("setColor vector layer")
70  {
71  object->addColorAtIndex(0, QColor(255,255,255));
72  cm->workingLayerChanged(layerObj->getLayer(1));
73  cm->setIndexedColor(QColor(255,255,255));
74  REQUIRE(cm->frontColor() == QColor(255,255,255));
75  }
76 
77 
78  delete layerEdit;
79  delete editor;
80 }
81 
82 TEST_CASE("Save and Load")
83 {
84  Object* object = new Object;
85  Editor* editor = new Editor;
86  editor->setObject(object);
87  ColorManager* cm2 = new ColorManager(editor);
88  cm2->init();
89 
90  Object* objToLoad = new Object;
91  objToLoad->data()->setCurrentColor(QColor(255,255,0));
92 
93  Object* objToSave = new Object;
94  objToSave->data()->setCurrentColor(QColor(45,45,255));
95 
96  SECTION("load")
97  {
98  cm2->setFrontColor(QColor(0,0,0));
99  REQUIRE(cm2->frontColor() == QColor(0,0,0));
100  REQUIRE(cm2->load(objToLoad) == Status::OK);
101  REQUIRE(cm2->frontColor() == QColor(255,255,0));
102  }
103 
104  SECTION("save")
105  {
106  cm2->setFrontColor(QColor(0,255,0));
107  REQUIRE(cm2->frontColor() == QColor(0,255,0));
108  REQUIRE(objToSave->data()->getCurrentColor() == QColor(45,45,255));
109  REQUIRE(cm2->save(objToSave) == Status::OK);
110  REQUIRE(objToSave->data()->getCurrentColor() == QColor(0,255,0));
111 
112  }
113 
114  delete objToSave;
115  delete objToLoad;
116  delete editor;
117 
118 }
119 
120 TEST_CASE("colorManager setColorNumber")
121 {
122  Object* object = new Object;
123  Editor* editor = new Editor;
124  editor->setObject(object);
125  ColorManager* cm3 = new ColorManager(editor);
126  cm3->init();
127 
128  SECTION("set number")
129  {
130  cm3->setColorNumber(0);
131  REQUIRE(cm3->frontColorNumber() == 0);
132  cm3->setColorNumber(4);
133  REQUIRE(cm3->frontColorNumber() == 4);
134  cm3->setColorNumber(10000);
135  REQUIRE(cm3->frontColorNumber() == 10000);
136  }
137  delete editor;
138 }
void setIndexedColor(const QColor &newColor)
Set color for current index.
QColor frontColor(bool useIndexedColor=true)
frontColor
Definition: object.h:41
Definition: editor.h:55