56
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDES
|
|
19 |
#include "testmsginit.h"
|
|
20 |
#include "debugtraces.h"
|
|
21 |
#include "msgsimnumberdetector.h"
|
|
22 |
#include "coutboxobserver.h"
|
|
23 |
#include "startupmonitor.h"
|
|
24 |
#include "coutboxsendoperation.h"
|
|
25 |
#include "cmobilesignalstrengthhandler.h"
|
|
26 |
#include "testoutboxobserver_stub.h"
|
|
27 |
#include "testoutboxsender_stub.h"
|
|
28 |
#include "testsimnumdetector_stub.h"
|
|
29 |
|
|
30 |
#include <csmsaccount.h>
|
|
31 |
#include <e32property.h>
|
|
32 |
#include <startupdomainpskeys.h>
|
|
33 |
|
|
34 |
|
|
35 |
void TestMsgInit::initTestCase()
|
|
36 |
{
|
|
37 |
|
|
38 |
}
|
|
39 |
|
|
40 |
void TestMsgInit::init()
|
|
41 |
{
|
|
42 |
qDebug("TestMsgInit::init enter");
|
|
43 |
|
|
44 |
iTestMsgSimOperation = CTestMsgSimOperation::NewL();
|
|
45 |
QVERIFY2(iTestMsgSimOperation != NULL, "CTestMsgSimOperation init failed.");
|
|
46 |
|
|
47 |
qDebug("TestMsgInit::init exit");
|
|
48 |
}
|
|
49 |
|
|
50 |
void TestMsgInit::validateMobileSignalStrength()
|
|
51 |
{
|
|
52 |
qDebug("TestMsgInit::validateMobileSignalStrength enter");
|
|
53 |
|
|
54 |
CTestOutboxObserver* mOutBoxObserver = CTestOutboxObserver::NewL();
|
|
55 |
QVERIFY2(mOutBoxObserver != NULL, "CTestOutboxObserver init failed.");
|
|
56 |
CleanupStack::PushL(mOutBoxObserver);
|
|
57 |
|
|
58 |
iSignalStrengthHandler = CMobileSignalStrengthHandler::NewL();
|
|
59 |
QVERIFY2(iSignalStrengthHandler != NULL, "CMobileSignalStrengthHandler init failed.");
|
|
60 |
|
|
61 |
if (iSignalStrengthHandler->ObservingSupported())
|
|
62 |
{
|
|
63 |
iSignalStrengthHandler->SetSignalStrengthObserverL(mOutBoxObserver);
|
|
64 |
iSignalStrengthHandler->StartObservingL();
|
|
65 |
}
|
|
66 |
|
|
67 |
CleanupStack::PopAndDestroy(mOutBoxObserver);
|
|
68 |
//QTest::qWait(1000);
|
|
69 |
if(NULL !=iSignalStrengthHandler)
|
|
70 |
{
|
|
71 |
delete iSignalStrengthHandler;
|
|
72 |
iSignalStrengthHandler = NULL;
|
|
73 |
}
|
|
74 |
qDebug("TestMsgInit::validateMobileSignalStrength exit");
|
|
75 |
}
|
|
76 |
|
|
77 |
void TestMsgInit::validateOutboxSenderOperation()
|
|
78 |
{
|
|
79 |
qDebug("TestMsgInit::validateOutboxSenderOperation enter");
|
|
80 |
|
|
81 |
CTestOutboxSender* mTestOutboxSender = CTestOutboxSender::NewL(*(iTestMsgSimOperation->iMsvSession));
|
|
82 |
QVERIFY2(mTestOutboxSender != NULL, "CTestOutboxSender init failed.");
|
|
83 |
CleanupStack::PushL(mTestOutboxSender);
|
|
84 |
|
|
85 |
CMsvSingleOpWatcher* msingleOpWatcher = CMsvSingleOpWatcher::NewL(*mTestOutboxSender);
|
|
86 |
QVERIFY2(msingleOpWatcher != NULL, "CMsvSingleOpWatcher init failed.");
|
|
87 |
CleanupStack::PushL(msingleOpWatcher);
|
|
88 |
|
|
89 |
iMsvOperation = COutboxSendOperation::NewL(*(iTestMsgSimOperation->iMsvSession), msingleOpWatcher->iStatus);
|
|
90 |
QVERIFY2(iMsvOperation != NULL, "COutboxSendOperation init failed.");
|
|
91 |
|
|
92 |
//QTest::qWait(1000);
|
|
93 |
if(NULL !=iMsvOperation)
|
|
94 |
{
|
|
95 |
delete iMsvOperation;
|
|
96 |
iMsvOperation = NULL;
|
|
97 |
}
|
|
98 |
CleanupStack::PopAndDestroy(2); //mTestOutboxSender, msingleOpWatcher
|
|
99 |
|
|
100 |
qDebug("TestMsgInit::validateOutboxSenderOperation exit");
|
|
101 |
}
|
|
102 |
|
|
103 |
void TestMsgInit::validateOutboxObserver()
|
|
104 |
{
|
|
105 |
qDebug("TestMsgInit::validateOutboxObserver enter");
|
|
106 |
|
|
107 |
// Observes the OUTBOX for any offline messages...
|
|
108 |
iOutBoxObserver = COutboxObserver::NewL();
|
|
109 |
QVERIFY2(iOutBoxObserver != NULL, "COutboxObserver init failed.");
|
|
110 |
|
|
111 |
// Start the Auto-send AO, to handle offline SMS messages
|
|
112 |
iOutBoxObserver->HandleMsvSessionReadyL(*(iTestMsgSimOperation->iMsvSession));
|
|
113 |
//QTest::qWait(1000);
|
|
114 |
|
|
115 |
if(NULL !=iOutBoxObserver)
|
|
116 |
{
|
|
117 |
delete iOutBoxObserver;
|
|
118 |
iOutBoxObserver = NULL;
|
|
119 |
}
|
|
120 |
qDebug("TestMsgInit::validateOutboxObserver exit");
|
|
121 |
}
|
|
122 |
|
|
123 |
void TestMsgInit::validateSimNumDetector()
|
|
124 |
{
|
|
125 |
qDebug("TestMsgInit::validateSimNumDetector enter");
|
|
126 |
|
|
127 |
TInt startupState = 0;
|
|
128 |
TInt modifiedState = ESwStateNormalRfOn;
|
|
129 |
TInt status = 0;
|
|
130 |
|
|
131 |
//Load current settings
|
|
132 |
CSmsSettings* smsSettings = CSmsSettings::NewLC();
|
|
133 |
CSmsAccount* smsAccount = CSmsAccount::NewLC();
|
|
134 |
smsAccount->LoadSettingsL(*smsSettings);
|
|
135 |
|
|
136 |
// Remove all old SMSC's configured
|
|
137 |
TInt numSCAddresses = smsSettings->ServiceCenterCount();
|
|
138 |
|
|
139 |
qDebug() << "numSCAddresses:" << numSCAddresses;
|
|
140 |
|
|
141 |
for (TInt j = numSCAddresses; j > 0; j--)
|
|
142 |
{
|
|
143 |
smsSettings->RemoveServiceCenter(j - 1);
|
|
144 |
}
|
|
145 |
|
|
146 |
// Save settings
|
|
147 |
TInt maxTries(5);
|
|
148 |
TBool done(EFalse);
|
|
149 |
while (maxTries && !done)
|
|
150 |
{
|
|
151 |
TRAPD( err, smsAccount->SaveSettingsL( *smsSettings ) );
|
|
152 |
if (err == KErrNone)
|
|
153 |
{
|
|
154 |
qDebug("CMsgSimOperation::CreateDefaultSettingsL settings saved");
|
|
155 |
|
|
156 |
done = ETrue;
|
|
157 |
}
|
|
158 |
else if (err == KErrLocked)
|
|
159 |
{
|
|
160 |
qDebug("CMsgSimOperation::CreateDefaultSettingsL KErrLocked");
|
|
161 |
|
|
162 |
// Wait a while and retry.
|
|
163 |
User::After(100000); // 0.1 seconds
|
|
164 |
maxTries--;
|
|
165 |
}
|
|
166 |
else
|
|
167 |
{
|
|
168 |
User::Leave(err);
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
QVERIFY2((iSimHandler = new MsgSimNumDetector()) != NULL, "Message settings engine init failed.");
|
|
173 |
status = RProperty::Get( KPSUidStartup, KPSGlobalSystemState, startupState );
|
|
174 |
if(ESwStateNormalRfOn != startupState)
|
|
175 |
{
|
|
176 |
RProperty::Set( KPSUidStartup, KPSGlobalSystemState, modifiedState );
|
|
177 |
}
|
|
178 |
qDebug() << "startupState:" << startupState;
|
|
179 |
qDebug() << "modifiedState:" << modifiedState;
|
|
180 |
RProperty::Set(KPSUidStartup, KPSGlobalSystemState, startupState);
|
|
181 |
|
|
182 |
qDebug() << "startupState:" << startupState;
|
|
183 |
qDebug() << "modifiedState:" << modifiedState;
|
|
184 |
CleanupStack::PopAndDestroy(2); // smsAccount, smsSettings
|
|
185 |
//QTest::qWait(1000);
|
|
186 |
if(NULL !=iSimHandler)
|
|
187 |
{
|
|
188 |
delete iSimHandler;
|
|
189 |
iSimHandler = NULL;
|
|
190 |
}
|
|
191 |
|
|
192 |
qDebug("TestMsgInit::validateSimNumDetector Exit");
|
|
193 |
}
|
|
194 |
|
|
195 |
void TestMsgInit::cleanup()
|
|
196 |
{
|
|
197 |
if(NULL !=iTestMsgSimOperation)
|
|
198 |
{
|
|
199 |
delete iTestMsgSimOperation;
|
|
200 |
iTestMsgSimOperation = NULL;
|
|
201 |
}
|
|
202 |
}
|
|
203 |
|
|
204 |
void TestMsgInit::cleanupTestCase()
|
|
205 |
{
|
|
206 |
|
|
207 |
}
|
|
208 |
|
|
209 |
//main entry point
|
|
210 |
int main(int argc, char *argv[])
|
|
211 |
{
|
|
212 |
int ret = -1;
|
|
213 |
QCoreApplication app(argc, argv);
|
|
214 |
QObject* tc = new TestMsgInit();
|
|
215 |
|
|
216 |
#ifdef __WINSCW__
|
|
217 |
char *new_argv[3];
|
|
218 |
QString str = "C:\\data\\" + QFileInfo(QCoreApplication::applicationFilePath()).baseName() + ".log";
|
|
219 |
QByteArray bytes = str.toAscii();
|
|
220 |
char arg1[] = "-o";
|
|
221 |
new_argv[0] = argv[0];
|
|
222 |
new_argv[1] = arg1;
|
|
223 |
new_argv[2] = bytes.data();
|
|
224 |
ret = QTest::qExec(tc, 3, new_argv);
|
|
225 |
#else
|
|
226 |
ret = QTest::qExec(tc, argc, argv);
|
|
227 |
#endif
|
|
228 |
delete tc;
|
|
229 |
return ret;
|
|
230 |
}
|
|
231 |
|