Start/ | End/ | |||
True | False | - | Line | Source |
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 MpDetailsViewPlugin | |||
15 | * | |||
16 | */ | |||
17 | ||||
18 | #include <QSignalSpy> | |||
19 | #include <qnamespace.h> | |||
20 | #include <hbapplication.h> | |||
21 | #include <hbmainwindow.h> | |||
22 | #include <hbInstance.h> | |||
23 | ||||
24 | #include "unittest_mpdetailsviewplugin.h" | |||
25 | #include "stub/inc/mpdetailsview.h" | |||
26 | ||||
27 | // Do this so we can access all member variables. | |||
28 | #define private public | |||
29 | #include "mpdetailsviewplugin.h" | |||
30 | #undef private | |||
31 | ||||
32 | ||||
33 | /*! | |||
34 | Make our test case a stand-alone executable that runs all the test functions. | |||
35 | */ | |||
Top | ||||
1 | 0 | 36 | int main( int argc, char *argv[] ) | |
37 | { | |||
38 | HbApplication app( argc, argv ); | |||
39 | HbMainWindow window; | |||
40 | TestMpDetailsViewPlugin tv; | |||
41 | ||||
42 | char *pass[3]; | |||
43 | pass[0] = argv[0]; | |||
44 | pass[1] = "-o"; | |||
45 | pass[2] = "c:\\data\\unittest_mpdetailsviewplugin.txt"; | |||
46 | ||||
47 | int res = QTest::qExec( &tv, 3, pass ); | |||
48 | ||||
1 | 49 | return res; | ||
50 | } | |||
51 | ||||
Top | ||||
1 | 1 | 52 | TestMpDetailsViewPlugin::TestMpDetailsViewPlugin() | |
53 | : mTest( 0 ) | |||
54 | { | |||
55 | } | |||
56 | ||||
Top | ||||
1 | 1 | 57 | TestMpDetailsViewPlugin::~TestMpDetailsViewPlugin() | |
58 | { | |||
59 | delete mTest; | |||
60 | } | |||
61 | ||||
62 | /*! | |||
63 | Called before the first testfunction is executed. | |||
64 | */ | |||
Top | ||||
1 | 1 | 65 | void TestMpDetailsViewPlugin::initTestCase() | |
66 | { | |||
67 | } | |||
68 | ||||
69 | /*! | |||
70 | Called after the last testfunction was executed. | |||
71 | */ | |||
Top | ||||
1 | 1 | 72 | void TestMpDetailsViewPlugin::cleanupTestCase() | |
73 | { | |||
74 | } | |||
75 | ||||
76 | /*! | |||
77 | Called before each testfunction is executed. | |||
78 | */ | |||
Top | ||||
6 | 6 | 79 | void TestMpDetailsViewPlugin::init() | |
80 | { | |||
81 | mTest = new MpDetailsViewPlugin(); | |||
82 | } | |||
83 | ||||
84 | /*! | |||
85 | Called after every testfunction. | |||
86 | */ | |||
Top | ||||
6 | 6 | 87 | void TestMpDetailsViewPlugin::cleanup() | |
88 | { | |||
89 | delete mTest; | |||
90 | mTest = 0; | |||
91 | } | |||
92 | ||||
93 | /*! | |||
94 | testConstructor | |||
95 | */ | |||
Top | ||||
1 | 1 | 96 | void TestMpDetailsViewPlugin::testConstructor() | |
97 | { | |||
98 | QVERIFY( !mTest->mView ); | |||
0 | 1 | - | 98 | if (! QTest::qVerify ( ( ! mTest -> mView ) .. |
0 | - | 98 | return | |
98 | while ( 0 ) | |||
99 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::NullView ); | |||
0 | 1 | - | 99 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 99 | return | |
99 | while ( 0 ) | |||
100 | } | |||
101 | ||||
102 | /*! | |||
103 | testCreateView | |||
104 | */ | |||
Top | ||||
1 | 1 | 105 | void TestMpDetailsViewPlugin::testCreateView() | |
106 | { | |||
107 | mTest->createView(); | |||
108 | QVERIFY( mTest->mView ); | |||
0 | 1 | - | 108 | if (! QTest::qVerify ( ( mTest -> mView ) , .. |
0 | - | 108 | return | |
108 | while ( 0 ) | |||
109 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::Created ); | |||
0 | 1 | - | 109 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 109 | return | |
109 | while ( 0 ) | |||
110 | QSignalSpy spy( mTest, SIGNAL( command( int ) ) ); | |||
111 | mTest->mView->emitCommand( 123 ); | |||
112 | QCOMPARE( spy.count(), 1 ); | |||
0 | 1 | - | 112 | if (! QTest::qCompare ( spy . count ( ) , 1 .. |
0 | - | 112 | return | |
112 | while ( 0 ) | |||
113 | QCOMPARE( spy.at( 0 ).at( 0 ), QVariant( 123 ) ); | |||
0 | 1 | - | 113 | if (! QTest::qCompare ( spy . at ( 0 ) . at .. |
0 | - | 113 | return | |
113 | while ( 0 ) | |||
114 | ||||
115 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 115 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 115 | return | |
115 | while ( 0 ) | |||
116 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 116 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 116 | return | |
116 | while ( 0 ) | |||
117 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 117 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 117 | return | |
117 | while ( 0 ) | |||
118 | ||||
119 | delete mTest->mView; | |||
120 | //mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete. | |||
121 | } | |||
122 | ||||
123 | ||||
124 | /*! | |||
125 | testdestroyView | |||
126 | */ | |||
Top | ||||
1 | 1 | 127 | void TestMpDetailsViewPlugin::testdestroyView() | |
128 | { | |||
129 | mTest->mView = new MpDetailsView(); | |||
130 | mTest->mState = MpDetailsViewPlugin::Created; | |||
131 | mTest->destroyView(); | |||
132 | QVERIFY( !mTest->mView ); | |||
0 | 1 | - | 132 | if (! QTest::qVerify ( ( ! mTest -> mView ) .. |
0 | - | 132 | return | |
132 | while ( 0 ) | |||
133 | ||||
134 | mTest->mView = new MpDetailsView(); | |||
135 | mTest->mState = MpDetailsViewPlugin::Initialized; | |||
136 | mTest->destroyView(); | |||
137 | QVERIFY( !mTest->mView ); | |||
0 | 1 | - | 137 | if (! QTest::qVerify ( ( ! mTest -> mView ) .. |
0 | - | 137 | return | |
137 | while ( 0 ) | |||
138 | ||||
139 | mTest->mView = new MpDetailsView(); | |||
140 | mTest->mState = MpDetailsViewPlugin::Activated; | |||
141 | mTest->destroyView(); | |||
142 | QVERIFY( !mTest->mView ); | |||
0 | 1 | - | 142 | if (! QTest::qVerify ( ( ! mTest -> mView ) .. |
0 | - | 142 | return | |
142 | while ( 0 ) | |||
143 | ||||
144 | mTest->mView = new MpDetailsView(); | |||
145 | mTest->mState = MpDetailsViewPlugin::NullView; | |||
146 | mTest->destroyView(); | |||
147 | QVERIFY( mTest->mView ); | |||
0 | 1 | - | 147 | if (! QTest::qVerify ( ( mTest -> mView ) , .. |
0 | - | 147 | return | |
147 | while ( 0 ) | |||
148 | ||||
149 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 149 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 149 | return | |
149 | while ( 0 ) | |||
150 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 150 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 150 | return | |
150 | while ( 0 ) | |||
151 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 151 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 151 | return | |
151 | while ( 0 ) | |||
152 | ||||
153 | delete mTest->mView; | |||
154 | //mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete. | |||
155 | } | |||
156 | ||||
157 | /*! | |||
158 | testActivateView | |||
159 | */ | |||
Top | ||||
1 | 1 | 160 | void TestMpDetailsViewPlugin::testActivateView() | |
161 | { | |||
162 | mTest->mState = MpDetailsViewPlugin::NullView; | |||
163 | mTest->activateView(); // we should be able to call activate without a view and not crash. | |||
164 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::NullView ); | |||
0 | 1 | - | 164 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 164 | return | |
164 | while ( 0 ) | |||
165 | ||||
166 | mTest->mView = new MpDetailsView(); | |||
167 | mTest->mState = MpDetailsViewPlugin::NullView; | |||
168 | mTest->activateView(); | |||
169 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::NullView ); | |||
0 | 1 | - | 169 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 169 | return | |
169 | while ( 0 ) | |||
170 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 170 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 170 | return | |
170 | while ( 0 ) | |||
171 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 171 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 171 | return | |
171 | while ( 0 ) | |||
172 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 172 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 172 | return | |
172 | while ( 0 ) | |||
173 | ||||
174 | mTest->mView->resetCounters(); | |||
175 | mTest->mState = MpDetailsViewPlugin::Activated; | |||
176 | mTest->activateView(); | |||
177 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::Activated ); | |||
0 | 1 | - | 177 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 177 | return | |
177 | while ( 0 ) | |||
178 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 178 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 178 | return | |
178 | while ( 0 ) | |||
179 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 179 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 179 | return | |
179 | while ( 0 ) | |||
180 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 180 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 180 | return | |
180 | while ( 0 ) | |||
181 | ||||
182 | mTest->mView->resetCounters(); | |||
183 | mTest->mState = MpDetailsViewPlugin::Created; | |||
184 | mTest->activateView(); | |||
185 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::Activated ); | |||
0 | 1 | - | 185 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 185 | return | |
185 | while ( 0 ) | |||
186 | QCOMPARE( mTest->mView->mInitializeViewCount, 1 ); | |||
0 | 1 | - | 186 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 186 | return | |
186 | while ( 0 ) | |||
187 | QCOMPARE( mTest->mView->mActivateViewCount, 1 ); | |||
0 | 1 | - | 187 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 187 | return | |
187 | while ( 0 ) | |||
188 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 188 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 188 | return | |
188 | while ( 0 ) | |||
189 | ||||
190 | mTest->mView->resetCounters(); | |||
191 | mTest->mState = MpDetailsViewPlugin::Initialized; | |||
192 | mTest->activateView(); | |||
193 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::Activated ); | |||
0 | 1 | - | 193 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 193 | return | |
193 | while ( 0 ) | |||
194 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 194 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 194 | return | |
194 | while ( 0 ) | |||
195 | QCOMPARE( mTest->mView->mActivateViewCount, 1 ); | |||
0 | 1 | - | 195 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 195 | return | |
195 | while ( 0 ) | |||
196 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 196 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 196 | return | |
196 | while ( 0 ) | |||
197 | ||||
198 | delete mTest->mView; | |||
199 | //mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete. | |||
200 | } | |||
201 | ||||
202 | /*! | |||
203 | testDeactivateView | |||
204 | */ | |||
Top | ||||
1 | 1 | 205 | void TestMpDetailsViewPlugin::testDeactivateView() | |
206 | { | |||
207 | mTest->mState = MpDetailsViewPlugin::NullView; | |||
208 | mTest->deactivateView(); // we should be able to call deactivate without a view and not crash. | |||
209 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::NullView ); | |||
0 | 1 | - | 209 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 209 | return | |
209 | while ( 0 ) | |||
210 | ||||
211 | mTest->mView = new MpDetailsView(); | |||
212 | mTest->mState = MpDetailsViewPlugin::NullView; | |||
213 | mTest->deactivateView(); | |||
214 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::NullView ); | |||
0 | 1 | - | 214 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 214 | return | |
214 | while ( 0 ) | |||
215 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 215 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 215 | return | |
215 | while ( 0 ) | |||
216 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 216 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 216 | return | |
216 | while ( 0 ) | |||
217 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 217 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 217 | return | |
217 | while ( 0 ) | |||
218 | ||||
219 | mTest->mView->resetCounters(); | |||
220 | mTest->mState = MpDetailsViewPlugin::Created; | |||
221 | mTest->deactivateView(); | |||
222 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::Created ); | |||
0 | 1 | - | 222 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 222 | return | |
222 | while ( 0 ) | |||
223 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 223 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 223 | return | |
223 | while ( 0 ) | |||
224 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 224 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 224 | return | |
224 | while ( 0 ) | |||
225 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 225 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 225 | return | |
225 | while ( 0 ) | |||
226 | ||||
227 | mTest->mView->resetCounters(); | |||
228 | mTest->mState = MpDetailsViewPlugin::Initialized; | |||
229 | mTest->deactivateView(); | |||
230 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::Initialized ); | |||
0 | 1 | - | 230 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 230 | return | |
230 | while ( 0 ) | |||
231 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 231 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 231 | return | |
231 | while ( 0 ) | |||
232 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 232 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 232 | return | |
232 | while ( 0 ) | |||
233 | QCOMPARE( mTest->mView->mDeactivateViewCount, 0 ); | |||
0 | 1 | - | 233 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 233 | return | |
233 | while ( 0 ) | |||
234 | ||||
235 | mTest->mView->resetCounters(); | |||
236 | mTest->mState = MpDetailsViewPlugin::Activated; | |||
237 | mTest->deactivateView(); | |||
238 | QCOMPARE( mTest->mState, MpDetailsViewPlugin::Initialized ); | |||
0 | 1 | - | 238 | if (! QTest::qCompare ( mTest -> mState , Mp.. |
0 | - | 238 | return | |
238 | while ( 0 ) | |||
239 | QCOMPARE( mTest->mView->mInitializeViewCount, 0 ); | |||
0 | 1 | - | 239 | if (! QTest::qCompare ( mTest -> mView -> mI.. |
0 | - | 239 | return | |
239 | while ( 0 ) | |||
240 | QCOMPARE( mTest->mView->mActivateViewCount, 0 ); | |||
0 | 1 | - | 240 | if (! QTest::qCompare ( mTest -> mView -> mA.. |
0 | - | 240 | return | |
240 | while ( 0 ) | |||
241 | QCOMPARE( mTest->mView->mDeactivateViewCount, 1 ); | |||
0 | 1 | - | 241 | if (! QTest::qCompare ( mTest -> mView -> mD.. |
0 | - | 241 | return | |
241 | while ( 0 ) | |||
242 | ||||
243 | delete mTest->mView; | |||
244 | //mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete. | |||
245 | } | |||
246 | ||||
Top | ||||
1 | 1 | 247 | void TestMpDetailsViewPlugin::testGetView() | |
248 | { | |||
249 | MpDetailsView* tmpView; | |||
250 | mTest->mView = new MpDetailsView(); | |||
251 | tmpView = mTest->mView; | |||
252 | QCOMPARE( int( tmpView ),int( mTest->getView() ) ); | |||
0 | 1 | - | 252 | if (! QTest::qCompare ( int ( tmpView ) , in.. |
0 | - | 252 | return | |
252 | while ( 0 ) | |||
253 | delete mTest->mView; | |||
254 | //mTest->mView = 0; intentionally not = 0 to prevent unecesary double delete. | |||
255 | } | |||
256 | ||||
257 | // End of file | |||
***TER 39% (65/167) of SOURCE FILE unittest_mpdetailsviewplugin.cpp |