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_layer.cpp
1 #include "test_layer.h"
2 
3 #include "layer.h"
4 #include "layerbitmap.h"
5 #include "layervector.h"
6 #include "layercamera.h"
7 #include "layersound.h"
8 #include "object.h"
9 #include "util.h"
10 #include <memory>
11 
12 TestLayer::TestLayer()
13 {
14 }
15 
16 void TestLayer::initTestCase()
17 {
18  m_pObject = new Object();
19  m_pObject->init();
20 }
21 
22 void TestLayer::cleanupTestCase()
23 {
24  delete m_pObject;
25 }
26 
27 void TestLayer::testCase1()
28 {
29  QVERIFY2( true, "Failure" );
30 }
31 
32 void TestLayer::testLayerType()
33 {
34  std::unique_ptr< Layer > bitmapLayer( new LayerBitmap( m_pObject ) );
35  QVERIFY( bitmapLayer->type() == Layer::BITMAP );
36 
37  std::unique_ptr< Layer > vecLayer( new LayerVector( m_pObject ) );
38  QVERIFY( vecLayer->type() == Layer::VECTOR );
39 
40  std::unique_ptr< Layer > cameraLayer( new LayerCamera( m_pObject ) );
41  QVERIFY( cameraLayer->type() == Layer::CAMERA );
42 
43  std::unique_ptr< Layer > soundLayer( new LayerSound( m_pObject ) );
44  QVERIFY( soundLayer->type() == Layer::SOUND );
45 }
46 
47 void TestLayer::testAddNewKeyAtBitmap()
48 {
49  std::unique_ptr< Layer > spLayer( new LayerBitmap( m_pObject ) );
50 
51  bool bOK = false;
52 
53  bOK = spLayer->addNewEmptyKeyAt( 0 );
54  QVERIFY2( bOK == false, "Frame Number must > 0." );
55 
56  QVERIFY( spLayer->addNewEmptyKeyAt( 1 ) );
57 
58  QCOMPARE( spLayer->addNewEmptyKeyAt( 2 ), true );
59  QCOMPARE( spLayer->getMaxKeyFramePosition(), 2 );
60 }
61 
62 void TestLayer::testAddNewKeyAtVector()
63 {
64  Layer* layer = m_pObject->addNewVectorLayer();;
65  OnScopeExit( m_pObject->deleteLayer( layer ) );
66 
67  bool bOK = false;
68 
69  bOK = layer->addNewEmptyKeyAt( 0 );
70  QVERIFY2( bOK == false, "Frame Number must > 0." );
71 
72  QVERIFY( layer->addNewEmptyKeyAt( 1 ) == false );
73 
74  QCOMPARE( layer->addNewEmptyKeyAt( 2 ), true );
75  QCOMPARE( layer->getMaxKeyFramePosition(), 2 );
76 }
77 
78 void TestLayer::testHasKeyFrameAtPosition()
79 {
80  Layer* layer = m_pObject->addNewBitmapLayer();;
81  OnScopeExit( m_pObject->deleteLayer( layer ) );
82 
83  QCOMPARE( layer->keyExists( 1 ), true ); // there is a frame at 1 in default.
84 
85  QVERIFY( layer->addNewEmptyKeyAt( 15 ) );
86  QCOMPARE( layer->keyExists( 15 ), true );
87  QCOMPARE( layer->keyExists( 10 ), false );
88 
89  QVERIFY( layer->addNewEmptyKeyAt( 10 ) );
90  QCOMPARE( layer->keyExists( 10 ), true );
91 
92  // test false case
93  QCOMPARE( layer->keyExists( 0 ), false );
94  QCOMPARE( layer->keyExists( 1000 ), false );
95  QCOMPARE( layer->keyExists( -333 ), false );
96 }
97 
98 void TestLayer::testGetFirstFramePosition()
99 {
100  Layer* layer = m_pObject->addNewBitmapLayer();;
101  OnScopeExit( m_pObject->deleteLayer( layer ) );
102 
103  QCOMPARE( layer->firstKeyFramePosition(), 1 );
104  layer->addNewEmptyKeyAt( 99 );
105 
106  QCOMPARE( layer->firstKeyFramePosition(), 1 );
107 }
108 
109 void TestLayer::testGetMaxFramePosition()
110 {
111  Layer* layer = m_pObject->addNewBitmapLayer();;
112  OnScopeExit( m_pObject->deleteLayer( layer ) );
113 
114  // 1 at beginning.
115  QCOMPARE( layer->getMaxKeyFramePosition(), 1 );
116 
117  QVERIFY( layer->addNewEmptyKeyAt( 3 ) );
118  QCOMPARE( layer->getMaxKeyFramePosition(), 3 );
119 
120  QVERIFY( layer->addNewEmptyKeyAt( 8 ) );
121  QCOMPARE( layer->getMaxKeyFramePosition(), 8 );
122 
123  QVERIFY( layer->addNewEmptyKeyAt( 100 ) );
124  QCOMPARE( layer->getMaxKeyFramePosition(), 100 );
125 
126  QVERIFY( layer->addNewEmptyKeyAt( 80 ) );
127  QCOMPARE( layer->getMaxKeyFramePosition(), 100 );
128 }
129 
130 void TestLayer::testRemoveKeyFrame()
131 {
132  Layer* layer = m_pObject->addNewBitmapLayer();;
133  OnScopeExit( m_pObject->deleteLayer( layer ) );
134 
135  layer->removeKeyFrame( 1 );
136  QCOMPARE( layer->getMaxKeyFramePosition(), 0 );
137 
138  for ( int i = 2; i <= 20; ++i )
139  {
140  QVERIFY( layer->addNewEmptyKeyAt( i ) );
141  }
142 
143  QCOMPARE( layer->keyExists( 20 ), true );
144  layer->removeKeyFrame( 20 );
145  QCOMPARE( layer->keyExists( 20 ), false );
146 
147  QCOMPARE( layer->keyExists( 8 ), true );
148  layer->removeKeyFrame( 8 );
149  QCOMPARE( layer->keyExists( 8 ), false );
150 
151  QCOMPARE( layer->keyExists( 19 ), true );
152 
153  layer->removeKeyFrame( 19 );
154  QCOMPARE( layer->getMaxKeyFramePosition(), 18 );
155 
156  layer->removeKeyFrame( 18 );
157  QCOMPARE( layer->getMaxKeyFramePosition(), 17 );
158 }
159 
160 void TestLayer::testPreviousKeyFramePosition()
161 {
162  Layer* pLayer = m_pObject->addNewBitmapLayer();;
163  OnScopeExit( m_pObject->deleteLayer( pLayer ) );
164 
165  QCOMPARE( pLayer->getPreviousKeyFramePosition( 1 ), 1 );
166  QCOMPARE( pLayer->getPreviousKeyFramePosition( 10 ), 1 );
167  QCOMPARE( pLayer->getPreviousKeyFramePosition( 100 ), 1 );
168  QCOMPARE( pLayer->getPreviousKeyFramePosition( 1000 ), 1 );
169 
170  pLayer->addNewEmptyKeyAt( 2 );
171  pLayer->addNewEmptyKeyAt( 8 );
172  QCOMPARE( pLayer->getPreviousKeyFramePosition( 2 ), 1 );
173  QCOMPARE( pLayer->getPreviousKeyFramePosition( 8 ), 2 );
174 
175  QCOMPARE( pLayer->getPreviousKeyFramePosition( -5 ), 1 );
176 
177  pLayer->addNewEmptyKeyAt( 15 );
178  QCOMPARE( pLayer->getPreviousKeyFramePosition( 16 ), 15 );
179  QCOMPARE( pLayer->getPreviousKeyFramePosition( 17 ), 15 );
180 
181  pLayer->removeKeyFrame( 15 );
182  QCOMPARE( pLayer->getPreviousKeyFramePosition( 16 ), 8 );
183 }
184 
185 void TestLayer::testNextKeyFramePosition()
186 {
187  Layer* pLayer = m_pObject->addNewBitmapLayer();;
188  OnScopeExit( m_pObject->deleteLayer( pLayer ) );
189 
190  QCOMPARE( pLayer->getNextKeyFramePosition( 1 ), 1 );
191  QCOMPARE( pLayer->getNextKeyFramePosition( 10 ), 1 );
192  QCOMPARE( pLayer->getNextKeyFramePosition( 100 ), 1 );
193 
194  pLayer->addNewEmptyKeyAt( 5 );
195  QCOMPARE( pLayer->getNextKeyFramePosition( 1 ), 5 );
196  QCOMPARE( pLayer->getNextKeyFramePosition( 2 ), 5 );
197 }
Definition: layer.h:32
Definition: object.h:71