Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
test_object.cpp
1 #include "test_object.h"
2 
3 #include <memory>
4 #include <QDomDocument>
5 #include <QDomElement>
6 #include "object.h"
7 #include "layerbitmap.h"
8 #include "layervector.h"
9 #include "layersound.h"
10 
11 
12 TestObject::TestObject()
13 {
14 }
15 
16 void TestObject::initTestCase()
17 {
18 }
19 
20 void TestObject::cleanupTestCase()
21 {
22 }
23 
24 void TestObject::testCase1()
25 {
26  std::unique_ptr< Object > obj( new Object );
27 
28  QCOMPARE( obj->getLayerCount(), 0 );
29  obj->init();
30  QCOMPARE( obj->getLayerCount(), 3 );
31 }
32 
33 void TestObject::testAddBitmapLayer()
34 {
35  std::unique_ptr< Object > obj( new Object );
36 
37  QCOMPARE( obj->getLayerCount(), 0 );
38  obj->addNewBitmapLayer();
39  QCOMPARE( obj->getLayerCount(), 1 );
40 
41  Layer* layer = obj->getLayer( 0 );
42  QCOMPARE( layer->type(), Layer::BITMAP );
43 }
44 
45 void TestObject::testAddVectorLayer()
46 {
47  std::unique_ptr< Object > obj( new Object );
48 
49  QCOMPARE( obj->getLayerCount(), 0 );
50  obj->addNewVectorLayer();
51  QCOMPARE( obj->getLayerCount(), 1 );
52 
53  Layer* layer = obj->getLayer( 0 );
54  QCOMPARE( layer->type(), Layer::VECTOR );
55 }
56 
57 void TestObject::testAddCameraLayer()
58 {
59  std::unique_ptr< Object > obj( new Object );
60 
61  QCOMPARE( obj->getLayerCount(), 0 );
62  obj->addNewCameraLayer();
63  QCOMPARE( obj->getLayerCount(), 1 );
64 
65  Layer* layer = obj->getLayer( 0 );
66  QCOMPARE( layer->type(), Layer::CAMERA );
67 }
68 
69 void TestObject::testAddSoundLayer()
70 {
71  std::unique_ptr< Object > obj( new Object );
72 
73  QCOMPARE( obj->getLayerCount(), 0 );
74  obj->addNewSoundLayer();
75  QCOMPARE( obj->getLayerCount(), 1 );
76 
77  Layer* layer = obj->getLayer( 0 );
78  QCOMPARE( layer->type(), Layer::SOUND );
79 }
80 
81 
82 void TestObject::testAddMoreLayers()
83 {
84  std::unique_ptr< Object > obj( new Object );
85  QCOMPARE( obj->getLayerCount(), 0 );
86 
87  obj->addNewSoundLayer();
88  QCOMPARE( obj->getLayerCount(), 1 );
89  QCOMPARE( obj->getLayer( 0 )->type(), Layer::SOUND );
90 
91  obj->addNewCameraLayer();
92  QCOMPARE( obj->getLayerCount(), 2 );
93  QCOMPARE( obj->getLayer( 1 )->type(), Layer::CAMERA );
94 
95  obj->addNewBitmapLayer();
96  QCOMPARE( obj->getLayerCount(), 3 );
97  QCOMPARE( obj->getLayer( 2 )->type(), Layer::BITMAP );
98 }
99 
100 void TestObject::testLayerID()
101 {
102  std::unique_ptr< Object > obj( new Object );
103 
104  Layer* bitmapLayer = obj->addNewBitmapLayer();
105  QCOMPARE( bitmapLayer->id(), 1 );
106  QCOMPARE( obj->getUniqueLayerID(), 2 );
107 
108  Layer* vectorLayer = obj->addNewVectorLayer();
109  QCOMPARE( vectorLayer->id(), 2 );
110  QCOMPARE( obj->getUniqueLayerID(), 3 );
111 }
112 
113 void TestObject::testMoveLayer()
114 {
115  std::unique_ptr< Object > obj( new Object );
116 
117  obj->addNewBitmapLayer();
118  obj->addNewVectorLayer();
119  QCOMPARE( obj->getLayer( 0 )->id(), 1 );
120  QCOMPARE( obj->getLayer( 1 )->id(), 2 );
121 
122  obj->moveLayer( 0, 1 );
123  QCOMPARE( obj->getLayer( 0 )->id(), 2 );
124  QCOMPARE( obj->getLayer( 1 )->id(), 1 );
125 
126 }
127 
128 void TestObject::testLoadXML()
129 {
130  std::unique_ptr< Object > obj( new Object );
131 
132  QString strXMLContent;
133  QTextStream sout( &strXMLContent );
134  sout << "<!DOCTYPE PencilDocument><object>";
135  sout << "</object>";
136  sout.flush();
137 
138  QDomDocument doc;
139  doc.setContent( strXMLContent );
140  QDomElement e = doc.firstChildElement( "object" );
141  QVERIFY( !e.isNull() );
142 
143  QVERIFY( obj->loadXML( e ) );
144 
145 }
Definition: layer.h:32
Definition: object.h:71