|
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: Test title resolver. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef ONLY_MENU_TESTCASES |
|
19 |
|
20 #include "t_hsutils.h" |
|
21 #include "hsdeviceinfolistener.h" |
|
22 |
|
23 |
|
24 const QString KTestingOperatorName = QString("Testing"); |
|
25 const QString KTestingOperatorName2 = QString("Testing2"); |
|
26 |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 void t_hsUtils::testDeviceInfoListener() |
|
33 { |
|
34 HsDeviceInfoListener *infoListener = new HsDeviceInfoListener(); |
|
35 QCOMPARE(infoListener->operatorName(), KTestingOperatorName); |
|
36 QCOMPARE(infoListener->status(), HsDeviceInfoListener::NoService); |
|
37 QCOMPARE(infoListener->networkStatus(), QSystemNetworkInfo::UndefinedStatus); |
|
38 infoListener->mNetworkInfo->setProperty("testNetworkMode", QVariant((int)QSystemNetworkInfo::GsmMode)); |
|
39 infoListener->mNetworkInfo->setProperty("testNetworkStatus", QVariant(QSystemNetworkInfo::Roaming)); |
|
40 infoListener->updateCurrentNetworkMode(); |
|
41 QCOMPARE(infoListener->networkStatus(), QSystemNetworkInfo::Roaming); |
|
42 |
|
43 delete infoListener; |
|
44 } |
|
45 |
|
46 void t_hsUtils::testDeviceInfoListenerNetworkMode_data() |
|
47 { |
|
48 QTest::addColumn<int>("Mode"); |
|
49 QTest::addColumn<int>("Status"); |
|
50 QTest::addColumn<int>("Expected"); |
|
51 QTest::newRow("Gsm1") |
|
52 << (int)QSystemNetworkInfo::GsmMode |
|
53 << (int)QSystemNetworkInfo::NoNetworkAvailable |
|
54 << (int)HsDeviceInfoListener::NoService; |
|
55 QTest::newRow("Gsm2") |
|
56 << (int)QSystemNetworkInfo::GsmMode |
|
57 << (int)QSystemNetworkInfo::Connected |
|
58 << (int)HsDeviceInfoListener::ServiceAvailable; |
|
59 QTest::newRow("Gsm3") |
|
60 << (int)QSystemNetworkInfo::GsmMode |
|
61 << (int)QSystemNetworkInfo::HomeNetwork |
|
62 << (int)HsDeviceInfoListener::ServiceAvailable; |
|
63 QTest::newRow("Gsm4") |
|
64 << (int)QSystemNetworkInfo::GsmMode |
|
65 << (int)QSystemNetworkInfo::Roaming |
|
66 << (int)HsDeviceInfoListener::ServiceAvailable; |
|
67 QTest::newRow("Wcdma1") |
|
68 << (int)QSystemNetworkInfo::WcdmaMode |
|
69 << (int)QSystemNetworkInfo::NoNetworkAvailable |
|
70 << (int)HsDeviceInfoListener::NoService; |
|
71 QTest::newRow("Wcdma2") |
|
72 << (int)QSystemNetworkInfo::WcdmaMode |
|
73 << (int)QSystemNetworkInfo::Connected |
|
74 << (int)HsDeviceInfoListener::ServiceAvailable; |
|
75 QTest::newRow("Wcdma3") |
|
76 << (int)QSystemNetworkInfo::WcdmaMode |
|
77 << (int)QSystemNetworkInfo::HomeNetwork |
|
78 << (int)HsDeviceInfoListener::ServiceAvailable; |
|
79 QTest::newRow("Wcdma4") |
|
80 << (int)QSystemNetworkInfo::WcdmaMode |
|
81 << (int)QSystemNetworkInfo::Roaming |
|
82 << (int)HsDeviceInfoListener::ServiceAvailable; |
|
83 |
|
84 } |
|
85 void t_hsUtils::testDeviceInfoListenerNetworkMode() |
|
86 { |
|
87 QFETCH(int, Mode); |
|
88 QFETCH(int, Status); |
|
89 QFETCH(int, Expected); |
|
90 |
|
91 HsDeviceInfoListener *infoListener = new HsDeviceInfoListener(); |
|
92 infoListener->mNetworkInfo->setProperty("testNetworkMode", QVariant(Mode)); |
|
93 infoListener->mNetworkInfo->setProperty("testNetworkStatus", QVariant(Status)); |
|
94 infoListener->updateCurrentNetworkMode(); |
|
95 infoListener->updateStatus(); |
|
96 QCOMPARE(infoListener->operatorName(), KTestingOperatorName); |
|
97 QCOMPARE((int)infoListener->status(), Expected); |
|
98 delete infoListener; |
|
99 } |
|
100 |
|
101 void t_hsUtils::testDeviceInfoListenerOfflineProfile() |
|
102 { |
|
103 HsDeviceInfoListener *infoListener = new HsDeviceInfoListener(); |
|
104 infoListener->mDeviceInfo->setProperty("offlineMode", QVariant(true)); |
|
105 infoListener->updateCurrentNetworkMode(); |
|
106 infoListener->updateStatus(); |
|
107 |
|
108 if (infoListener->simStatus() == QSystemDeviceInfo::SimNotAvailable) { |
|
109 QCOMPARE(infoListener->status(), HsDeviceInfoListener::NoService); |
|
110 } |
|
111 else { |
|
112 QCOMPARE(infoListener->status(), HsDeviceInfoListener::OfflineProfile); |
|
113 } |
|
114 delete infoListener; |
|
115 } |
|
116 |
|
117 void t_hsUtils::testDeviceInfoListenerNetworkStatusChanged() |
|
118 { |
|
119 qRegisterMetaType<HsDeviceInfoListener::HsDeviceInfoStatus>( |
|
120 "HsDeviceInfoListener::HsDeviceInfoStatus"); |
|
121 |
|
122 HsDeviceInfoListener *infoListener = new HsDeviceInfoListener(); |
|
123 QSignalSpy spy(infoListener, SIGNAL(statusChanged(HsDeviceInfoListener::HsDeviceInfoStatus))); |
|
124 |
|
125 infoListener->onNetworkStatusChanged(QSystemNetworkInfo::GsmMode, QSystemNetworkInfo::Roaming); |
|
126 QCOMPARE(spy.count(), 0); |
|
127 |
|
128 infoListener->mNetworkInfo->setProperty("testNetworkMode", QVariant((int)QSystemNetworkInfo::GsmMode)); |
|
129 infoListener->mNetworkInfo->setProperty("testNetworkStatus", QVariant(QSystemNetworkInfo::Roaming)); |
|
130 infoListener->onNetworkStatusChanged(QSystemNetworkInfo::GsmMode, QSystemNetworkInfo::Roaming); |
|
131 QCOMPARE(spy.count(), 1); |
|
132 |
|
133 delete infoListener; |
|
134 } |
|
135 |
|
136 void t_hsUtils::testDeviceInfoListenerNetworkNameChanged() |
|
137 { |
|
138 HsDeviceInfoListener *infoListener = new HsDeviceInfoListener(); |
|
139 QSignalSpy spy(infoListener, SIGNAL(networkNameChanged(const QString &))); |
|
140 |
|
141 infoListener->onNetworkNameChanged(QSystemNetworkInfo::GsmMode, KTestingOperatorName2); |
|
142 // this should not emit anything because UnknownMode |
|
143 QCOMPARE(spy.count(), 0); |
|
144 |
|
145 infoListener->mNetworkInfo->setProperty("testNetworkMode", QVariant((int)QSystemNetworkInfo::GsmMode)); |
|
146 infoListener->mNetworkInfo->setProperty("testNetworkStatus", QVariant(QSystemNetworkInfo::Roaming)); |
|
147 infoListener->onNetworkNameChanged(QSystemNetworkInfo::GsmMode, KTestingOperatorName); |
|
148 QCOMPARE(spy.count(), 1); |
|
149 QList<QVariant> arguments = spy.takeFirst(); |
|
150 QCOMPARE(arguments.at(0).toString(), KTestingOperatorName); |
|
151 |
|
152 delete infoListener; |
|
153 } |
|
154 |
|
155 void t_hsUtils::testDeviceInfoListenerNetworkCurrentProfileChanged() |
|
156 { |
|
157 HsDeviceInfoListener *infoListener = new HsDeviceInfoListener(); |
|
158 infoListener->mDeviceInfo->setProperty("offlineMode", QVariant(true)); |
|
159 infoListener->updateCurrentNetworkMode(); |
|
160 qRegisterMetaType<HsDeviceInfoListener::HsDeviceInfoStatus>( |
|
161 "HsDeviceInfoListener::HsDeviceInfoStatus"); |
|
162 QSignalSpy spy(infoListener, SIGNAL(statusChanged(HsDeviceInfoListener::HsDeviceInfoStatus))); |
|
163 |
|
164 infoListener->mDeviceInfo->setProperty("simAvailable", QVariant(true)); |
|
165 if (infoListener->simStatus() != QSystemDeviceInfo::SimNotAvailable) { |
|
166 infoListener->onCurrentProfileChanged(QSystemDeviceInfo::OfflineProfile); |
|
167 QCOMPARE(spy.count(), 1); |
|
168 } |
|
169 delete infoListener; |
|
170 } |
|
171 |
|
172 #endif // ONLY_MENU_TESTCASES |