os/security/authorisation/userpromptservice/examples/integration/tmsgapp/tmsgapp.cpp
Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 // UPS client library is only included to allow the test application
25 // to reset its decision records.
26 #include <ups/upsclient.h>
28 _LIT(KTo, "+442071541000");
29 _LIT_SECURE_ID(KMySecureId, 0x01000003);
31 // CAlarm ********************************************************************
32 inline CAlarm::CAlarm() :CTimer(-1) {CActiveScheduler::Add(this);}
33 inline void CAlarm::ConstructL() {CTimer::ConstructL();}
40 void CAlarm::After(MAlarmObserver* aObserver, TTimeIntervalMicroSeconds32 aInterval)
42 iObserver = aObserver;
43 CTimer::After(aInterval);
46 // CSendMessages *************************************************************
47 CSendMessages::CSendMessages() : CActive(EPriorityStandard)
49 CActiveScheduler::Add(this);
52 CSendMessages::~CSendMessages()
58 CSendMessages* CSendMessages::NewLC()
60 CSendMessages* self = new(ELeave) CSendMessages();
61 CleanupStack::PushL(self);
66 void CSendMessages::ConstructL()
69 User::LeaveIfError(iMsgCon.Connect());
70 TRequestStatus* status = &iStatus;
71 *status = KRequestPending;
73 User::RequestComplete(status, KErrNone);
76 TInt CSendMessages::RunError(TInt /* aError */)
78 CActiveScheduler::Stop(); // Non-recoverable error
82 void CSendMessages::DoCancel()
84 iMsgCon.CancelSendMsg();
88 void CSendMessages::WakeupL()
90 * Timeout the pending message.
93 iMsgCon.CancelSendMsg();
96 void CSendMessages::RunL()
98 * Send a series of test messages and cancellations that should trigger
100 * All test cases timeout after KDefaultTimeout to enable automated tests
103 TInt err = iStatus.Int();
104 if (iStatus != KErrNone && iStatus != KErrCancel && iStatus != KErrPermissionDenied)
110 RDebug::Printf("Test %d completed with error %d", iTestNum, 0);
112 ++iTestNum; // move on to next test case
117 // Send message and wait for user prompt to complete
118 _LIT(KBody, "Hello");
119 iMsgCon.SendMsg(KTo, KBody, iStatus);
121 iAlarm.After(this, KDefaultTimeout);
126 // Send a message and cancel straight away, should be no user prompt
127 _LIT(KBody, "Hello - Cancel immediate");
128 iMsgCon.SendMsg(KTo, KBody, iStatus);
130 iAlarm.After(this, 1);
135 // Send a message and attempt to cancel whilst the user prompt is being displayed.
136 _LIT(KBody, "Hello - Cancel 5 secs");
137 iMsgCon.SendMsg(KTo, KBody, iStatus);
139 iAlarm.After(this, 5 * 1000 * 1000);
144 // Force the message server to exit
146 _LIT(KInfo, "Waiting for messageserver to exit");
147 User::InfoPrint(KInfo);
148 User::After(5 * 1000 * 1000);
149 User::LeaveIfError(iMsgCon.Connect()); // reconnect
151 // Send a message to the new server instance
152 _LIT(KBody, "Hello again");
153 iMsgCon.SendMsg(KTo, KBody, iStatus);
155 iAlarm.After(this, KDefaultTimeout);
160 CActiveScheduler::Stop();
165 void DeleteOldDecisionsL()
167 * Delete all decision records for this test application
170 UserPromptService::RUpsManagement m;
171 CleanupClosePushL(m);
172 User::LeaveIfError(m.Connect());
173 UserPromptService::CDecisionFilter* f = UserPromptService::CDecisionFilter::NewLC();
174 f->SetClientSid(KMySecureId, UserPromptService::EEqual);
175 m.RemoveDecisionsL(*f);
176 CleanupStack::PopAndDestroy(2, &m); // m, f
181 // Create active scheduler, reset UPS and start tests
182 CActiveScheduler* s=new(ELeave) CActiveScheduler;
183 CleanupStack::PushL(s);
184 CActiveScheduler::Install(s);
185 DeleteOldDecisionsL(); // reset decision database
186 CSendMessages* test = CSendMessages::NewLC();
188 CleanupStack::PopAndDestroy(2, s); // s, test
190 // Add log file for automated test environment
192 User::LeaveIfError(fs.Connect());
193 CleanupClosePushL(fs);
195 CleanupClosePushL(log);
196 User::LeaveIfError(log.Replace(fs, _L("c:\\tmsgapp.log"), EFileShareAny|EFileWrite));
197 User::LeaveIfError(log.Write(_L8("\n\n0 tests failed out of 1\n")));
198 CleanupStack::PopAndDestroy(2, &fs);
201 GLDEF_C TInt E32Main()
203 CTrapCleanup* cleanup = CTrapCleanup::New();
208 TRAP_IGNORE(MainL());