|
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: TestAccessPointEntry class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <QtTest/QtTest> |
|
20 #include <qdebug.h> |
|
21 #include <hbapplication.h> |
|
22 |
|
23 |
|
24 #include "stub/inc/cpitemdatahelper.h" |
|
25 #include "stub/inc/cpsettingformentryitemdata.h" |
|
26 #include "stub/inc/cmapplsettingsui.h" |
|
27 #include "stub/inc/cmconnectionmethod_shim.h" |
|
28 #include "stub/inc/cmmanager_shim.h" |
|
29 #include "stub/inc/videosettingsgroup.h" |
|
30 |
|
31 #include "testaccesspointentry.h" |
|
32 #include "videosettingsgroup.h" |
|
33 #include "cmmanager_shim.h" |
|
34 #include "cmconnectionmethod_shim.h" |
|
35 |
|
36 // trick to get access to protected/private members. |
|
37 #define private public |
|
38 #include "videosettingsaccesspointentry.h" |
|
39 #undef private |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // initTestCase |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void TestAccessPointEntry::initTestCase() |
|
46 { |
|
47 mItemHelper = new CpItemDataHelper; |
|
48 mGroup = new VideoSettingsGroup(*mItemHelper); |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // cleanupTestCase |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 void TestAccessPointEntry::cleanupTestCase() |
|
56 { |
|
57 delete mGroup; |
|
58 mGroup = 0; |
|
59 delete mItemHelper; |
|
60 mItemHelper = 0; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // init |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void TestAccessPointEntry::init() |
|
68 { |
|
69 mTestObject = new VideoSettingsAccessPointEntry(*mItemHelper, QString("test"), mGroup); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // cleanup |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void TestAccessPointEntry::cleanup() |
|
77 { |
|
78 delete mTestObject; |
|
79 mTestObject = 0; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // testConstructor |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void TestAccessPointEntry::testConstructor() |
|
87 { |
|
88 // verify clicked signal connection. |
|
89 ConnectionHolder connection = mItemHelper->mConnections[mTestObject]; |
|
90 QCOMPARE( connection.signal, SIGNAL(clicked()) ); |
|
91 QVERIFY( connection.receiver == mTestObject ); |
|
92 QCOMPARE( connection.method, SLOT(openSelectionDialogSlot()) ); |
|
93 |
|
94 // verify mApplSettings construction |
|
95 QVERIFY( mTestObject->mApplSettings ); |
|
96 QVERIFY( disconnect(mTestObject->mApplSettings, SIGNAL(finished(uint)), mTestObject, SLOT(accessPointDialogFinished(uint))) ); |
|
97 connect(mTestObject->mApplSettings, SIGNAL(finished(uint)), mTestObject, SLOT(accessPointDialogFinished(uint))); |
|
98 |
|
99 // verify mSelection initial values |
|
100 QVERIFY( mTestObject->mSelection.result == CmApplSettingsUi::SelectionTypeConnectionMethod ); |
|
101 QVERIFY( mTestObject->mSelection.id == 0 ); |
|
102 |
|
103 // verify CmManagerShim construction |
|
104 QVERIFY( mTestObject->mCmManager ); |
|
105 |
|
106 // verify base class 'construction' |
|
107 QCOMPARE( mTestObject->mText, QString("test") ); |
|
108 QVERIFY( mTestObject->mDescription.isNull() ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // testConstructor |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void TestAccessPointEntry::testDestructor() |
|
116 { |
|
117 CmManagerShim::mDestructorCount = 0; |
|
118 cleanup(); |
|
119 QCOMPARE( CmManagerShim::mDestructorCount, 1 ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // testSetIapId |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void TestAccessPointEntry::testSetIapId() |
|
127 { |
|
128 // with empty cmArray |
|
129 mTestObject->setIapId(5); |
|
130 QCOMPARE( mTestObject->mDescription, hbTrId("txt_videos_dblist_none") ); |
|
131 |
|
132 // with non-empty cmArray, but id is not found. |
|
133 mTestObject->mCmManager->mConnectionMethods[0] = new CmConnectionMethodShim(0, 4, QString("0")); |
|
134 mTestObject->mCmManager->mConnectionMethods[2] = new CmConnectionMethodShim(2, 6, QString("2")); |
|
135 mTestObject->setIapId(5); |
|
136 QCOMPARE( mTestObject->mDescription, hbTrId("txt_videos_dblist_none") ); |
|
137 |
|
138 // with non-empty cmArray, and id is found, but CmManagerShim throws at that id. |
|
139 mTestObject->mCmManager->mConnectionMethods[1] = new CmConnectionMethodShim(1, 5, QString("1")); |
|
140 CmManagerShim::mConnectionMethodThrowsAtId = 1; |
|
141 mTestObject->setIapId(5); |
|
142 QCOMPARE( mTestObject->mDescription, hbTrId("txt_videos_dblist_none") ); |
|
143 |
|
144 // with non-empty cmArray, and id is found. |
|
145 CmManagerShim::mConnectionMethodThrowsAtId = -1; |
|
146 mTestObject->setIapId(5); |
|
147 QCOMPARE( mTestObject->mDescription, QString("1") ); |
|
148 |
|
149 // with non-empty cmArray, and id is found, but CmManagerShim throws at id before. |
|
150 CmManagerShim::mConnectionMethodThrowsAtId = 0; |
|
151 mTestObject->mDescription = QString(); |
|
152 mTestObject->setIapId(5); |
|
153 QCOMPARE( mTestObject->mDescription, QString("1") ); |
|
154 |
|
155 // with non-empty cmArray, and id is found, but CmManagerShim throws at id after. |
|
156 CmManagerShim::mConnectionMethodThrowsAtId = 2; |
|
157 mTestObject->mDescription = QString(); |
|
158 mTestObject->setIapId(5); |
|
159 QCOMPARE( mTestObject->mDescription, QString("1") ); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // testCreateSettingView |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void TestAccessPointEntry::testCreateSettingView() |
|
167 { |
|
168 QVERIFY(mTestObject->callCreateSettingView() == 0 ); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // testOpenSelectionDialogSlot |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void TestAccessPointEntry::testOpenSelectionDialogSlot() |
|
176 { |
|
177 connect(this, SIGNAL(testSignal()), mTestObject, SLOT(openSelectionDialogSlot())); |
|
178 QSet<CmApplSettingsUi::BearerTypeFilter> filter; |
|
179 filter.insert(1); |
|
180 mTestObject->mApplSettings->mListItems = QFlags<CmApplSettingsUi::SelectionDialogItems>(); |
|
181 mTestObject->mApplSettings->mBearerTypeFilter = filter; |
|
182 mTestObject->mApplSettings->mOpenCallAmount = 0; |
|
183 |
|
184 emit testSignal(); |
|
185 |
|
186 QVERIFY( mTestObject->mApplSettings->mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods) ); |
|
187 QVERIFY( mTestObject->mApplSettings->mListItems.testFlag(CmApplSettingsUi::ShowDestinations) == false); |
|
188 QCOMPARE( mTestObject->mApplSettings->mBearerTypeFilter.count(), 0); |
|
189 QVERIFY( mTestObject->mApplSettings->mSelection.result == CmApplSettingsUi::SelectionTypeConnectionMethod ); |
|
190 QCOMPARE( mTestObject->mApplSettings->mOpenCallAmount, 1 ); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // testAccessPointDialogFinished |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void TestAccessPointEntry::testAccessPointDialogFinished() |
|
198 { |
|
199 // error |
|
200 mTestObject->mApplSettings->mSelection.id = 5; |
|
201 mTestObject->mSelection.id = 0; |
|
202 mTestObject->mDescription = QString(); |
|
203 mGroup->mApId = 0; |
|
204 |
|
205 mTestObject->mApplSettings->emitFinished(CmApplSettingsUi::ApplSettingsErrorCancel); |
|
206 |
|
207 QCOMPARE( mTestObject->mSelection.id, (uint)0 ); |
|
208 |
|
209 // no error |
|
210 mTestObject->mDescription = QString(); |
|
211 mTestObject->mCmManager->mConnectionMethods[5] = new CmConnectionMethodShim(5, 4, QString("5")); |
|
212 |
|
213 mTestObject->mApplSettings->emitFinished(CmApplSettingsUi::ApplSettingsErrorNone); |
|
214 |
|
215 QCOMPARE( mTestObject->mSelection.id, mTestObject->mApplSettings->mSelection.id ); |
|
216 QCOMPARE( mGroup->mApId, (uint)4 ); |
|
217 QCOMPARE( mTestObject->mDescription, QString("5") ); |
|
218 |
|
219 // no error, but CmManagerShim throws at that id. |
|
220 mTestObject->mSelection.id = 0; |
|
221 mTestObject->mDescription = QString(); |
|
222 mGroup->mApId = 0; |
|
223 CmManagerShim::mConnectionMethodThrowsAtId = 5; |
|
224 |
|
225 mTestObject->mApplSettings->emitFinished(CmApplSettingsUi::ApplSettingsErrorNone); |
|
226 |
|
227 QCOMPARE( mTestObject->mSelection.id, (uint)0 ); |
|
228 QCOMPARE( mGroup->mApId, (uint)0 ); |
|
229 QVERIFY( mTestObject->mDescription.isNull() ); |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // main |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 int main(int argc, char *argv[]) |
|
237 { |
|
238 HbApplication app(argc, argv); |
|
239 |
|
240 TestAccessPointEntry tc; |
|
241 |
|
242 char *pass[3]; |
|
243 pass[0] = argv[0]; |
|
244 pass[1] = "-o"; |
|
245 pass[2] = "c:\\data\\TestAccessPointEntry.txt"; |
|
246 |
|
247 return QTest::qExec(&tc, 3, pass); |
|
248 } |
|
249 |
|
250 // end of file |