47
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Unit test for MpMediaWallViewPlugin
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QSignalSpy>
|
|
19 |
#include <qnamespace.h>
|
|
20 |
|
|
21 |
#include "stub/inc/mpmediawallview.h"
|
|
22 |
#include "stub/inc/xqplugin.h"
|
|
23 |
#include "unittest_mpmediawallviewplugin.h"
|
|
24 |
|
|
25 |
|
|
26 |
// Do this so we can access all member variables.
|
|
27 |
#define private public
|
|
28 |
#include "mpmediawallviewplugin.h"
|
|
29 |
#undef private
|
|
30 |
|
|
31 |
//This so MpMediaWallViewPlugin.cpp can load qt stub items
|
|
32 |
#include "../../src/mpmediawallviewplugin.cpp"
|
|
33 |
|
|
34 |
/*!
|
|
35 |
Make our test case a stand-alone executable that runs all the test functions.
|
|
36 |
*/
|
|
37 |
int main(int argc, char *argv[])
|
|
38 |
{
|
|
39 |
QApplication app(argc, argv);
|
|
40 |
TestMpMediaWallViewPlugin tv;
|
|
41 |
|
|
42 |
if ( argc > 1 ) {
|
|
43 |
return QTest::qExec( &tv, argc, argv);
|
|
44 |
}
|
|
45 |
else {
|
|
46 |
char *pass[3];
|
|
47 |
pass[0] = argv[0];
|
|
48 |
pass[1] = "-o";
|
|
49 |
pass[2] = "c:\\data\\unittest_mpmediawallviewplugin.txt";
|
|
50 |
|
|
51 |
return QTest::qExec(&tv, 3, pass);
|
|
52 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
TestMpMediaWallViewPlugin::TestMpMediaWallViewPlugin()
|
|
56 |
: mTest(0)
|
|
57 |
{
|
|
58 |
}
|
|
59 |
|
|
60 |
TestMpMediaWallViewPlugin::~TestMpMediaWallViewPlugin()
|
|
61 |
{
|
|
62 |
delete mTest;
|
|
63 |
}
|
|
64 |
|
|
65 |
/*!
|
|
66 |
Called before the first testfunction is executed.
|
|
67 |
*/
|
|
68 |
void TestMpMediaWallViewPlugin::initTestCase()
|
|
69 |
{
|
|
70 |
}
|
|
71 |
|
|
72 |
/*!
|
|
73 |
Called after the last testfunction was executed.
|
|
74 |
*/
|
|
75 |
void TestMpMediaWallViewPlugin::cleanupTestCase()
|
|
76 |
{
|
|
77 |
}
|
|
78 |
|
|
79 |
/*!
|
|
80 |
Called before each testfunction is executed.
|
|
81 |
*/
|
|
82 |
void TestMpMediaWallViewPlugin::init()
|
|
83 |
{
|
|
84 |
mTest = new MpMediaWallViewPlugin();
|
|
85 |
}
|
|
86 |
|
|
87 |
/*!
|
|
88 |
Called after every testfunction.
|
|
89 |
*/
|
|
90 |
void TestMpMediaWallViewPlugin::cleanup()
|
|
91 |
{
|
|
92 |
delete mTest;
|
|
93 |
mTest = 0;
|
|
94 |
}
|
|
95 |
|
|
96 |
/*!
|
|
97 |
testConstructor
|
|
98 |
*/
|
|
99 |
void TestMpMediaWallViewPlugin::testConstructor()
|
|
100 |
{
|
|
101 |
QVERIFY(!mTest->mView);
|
|
102 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::NullView);
|
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
|
106 |
testCreateView
|
|
107 |
*/
|
|
108 |
void TestMpMediaWallViewPlugin::testCreateView()
|
|
109 |
{
|
|
110 |
|
|
111 |
mTest->createView();
|
|
112 |
QVERIFY(mTest->mView);
|
|
113 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::Created);
|
|
114 |
/*
|
|
115 |
QSignalSpy spy( mTest, SIGNAL(command(int)) );
|
|
116 |
mTest->mView->emitCommand(123);
|
|
117 |
QCOMPARE(spy.count(), 1);
|
|
118 |
QCOMPARE(spy.at(0).at(0), QVariant(123));
|
|
119 |
*/
|
|
120 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
121 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
122 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
123 |
|
|
124 |
delete mTest->mView;
|
|
125 |
//mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete.
|
|
126 |
|
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
/*!
|
|
131 |
testdestroyView
|
|
132 |
*/
|
|
133 |
void TestMpMediaWallViewPlugin::testdestroyView()
|
|
134 |
{
|
|
135 |
|
|
136 |
mTest->mView = new MpMediaWallView();
|
|
137 |
mTest->mState = MpMediaWallViewPlugin::Created;
|
|
138 |
mTest->destroyView();
|
|
139 |
QVERIFY(!mTest->mView);
|
|
140 |
mTest->mView = new MpMediaWallView();
|
|
141 |
mTest->mState = MpMediaWallViewPlugin::NullView;
|
|
142 |
mTest->destroyView();
|
|
143 |
QVERIFY(mTest->mView);
|
|
144 |
|
|
145 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
146 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
147 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
148 |
|
|
149 |
delete mTest->mView;
|
|
150 |
//mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete.
|
|
151 |
|
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
/*!
|
|
156 |
testActivateView
|
|
157 |
*/
|
|
158 |
void TestMpMediaWallViewPlugin::testActivateView()
|
|
159 |
{
|
|
160 |
|
|
161 |
mTest->mState = MpMediaWallViewPlugin::NullView;
|
|
162 |
mTest->activateView(); // we should be able to call activate without a view and not crash.
|
|
163 |
|
|
164 |
|
|
165 |
mTest->mView = new MpMediaWallView();
|
|
166 |
mTest->mState = MpMediaWallViewPlugin::NullView;
|
|
167 |
mTest->activateView();
|
|
168 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::NullView);
|
|
169 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
170 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
171 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
172 |
|
|
173 |
mTest->mView->resetCounters();
|
|
174 |
mTest->mState = MpMediaWallViewPlugin::Activated;
|
|
175 |
mTest->activateView();
|
|
176 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::Activated);
|
|
177 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
178 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
179 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
180 |
|
|
181 |
mTest->mView->resetCounters();
|
|
182 |
mTest->mState = MpMediaWallViewPlugin::Created;
|
|
183 |
mTest->activateView();
|
|
184 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::Activated);
|
|
185 |
QCOMPARE(mTest->mView->mInitializeViewCount,1);
|
|
186 |
QCOMPARE(mTest->mView->mActivateViewCount,1);
|
|
187 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
188 |
|
|
189 |
mTest->mView->resetCounters();
|
|
190 |
mTest->mState = MpMediaWallViewPlugin::Initialized;
|
|
191 |
mTest->activateView();
|
|
192 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::Activated);
|
|
193 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
194 |
QCOMPARE(mTest->mView->mActivateViewCount,1);
|
|
195 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
196 |
|
|
197 |
|
|
198 |
delete mTest->mView;
|
|
199 |
//mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete.
|
|
200 |
|
|
201 |
}
|
|
202 |
|
|
203 |
|
|
204 |
/*!
|
|
205 |
testDeactivateView
|
|
206 |
*/
|
|
207 |
void TestMpMediaWallViewPlugin::testDeactivateView()
|
|
208 |
{
|
|
209 |
|
|
210 |
mTest->mState = MpMediaWallViewPlugin::NullView;
|
|
211 |
mTest->deactivateView(); // we should be able to call deactivate without a view and not crash.
|
|
212 |
|
|
213 |
mTest->mView = new MpMediaWallView();
|
|
214 |
mTest->mState = MpMediaWallViewPlugin::NullView;
|
|
215 |
mTest->deactivateView();
|
|
216 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::NullView);
|
|
217 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
218 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
219 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
220 |
|
|
221 |
mTest->mView->resetCounters();
|
|
222 |
mTest->mState = MpMediaWallViewPlugin::Activated;
|
|
223 |
mTest->deactivateView();
|
|
224 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::Initialized);
|
|
225 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
226 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
227 |
QCOMPARE(mTest->mView->mDeactivateViewCount,1);
|
|
228 |
|
|
229 |
mTest->mView->resetCounters();
|
|
230 |
mTest->mState = MpMediaWallViewPlugin::Created;
|
|
231 |
mTest->deactivateView();
|
|
232 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::Created);
|
|
233 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
234 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
235 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
236 |
|
|
237 |
mTest->mView->resetCounters();
|
|
238 |
mTest->mState = MpMediaWallViewPlugin::Initialized;
|
|
239 |
mTest->deactivateView();
|
|
240 |
QCOMPARE(mTest->mState, MpMediaWallViewPlugin::Initialized);
|
|
241 |
QCOMPARE(mTest->mView->mInitializeViewCount,0);
|
|
242 |
QCOMPARE(mTest->mView->mActivateViewCount,0);
|
|
243 |
QCOMPARE(mTest->mView->mDeactivateViewCount,0);
|
|
244 |
|
|
245 |
delete mTest->mView;
|
|
246 |
//mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete.
|
|
247 |
|
|
248 |
}
|
|
249 |
|
|
250 |
void TestMpMediaWallViewPlugin::testGetView()
|
|
251 |
{
|
|
252 |
MpMediaWallView* tmpView;
|
|
253 |
mTest->mView = new MpMediaWallView();
|
|
254 |
tmpView = mTest->mView;
|
|
255 |
mTest->getView();
|
|
256 |
QCOMPARE(int(tmpView),int(mTest->getView()));
|
|
257 |
delete mTest->mView;
|
|
258 |
//mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete.
|
|
259 |
|
|
260 |
}
|
|
261 |
|
|
262 |
// End of file
|