|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // __ACTION_INFO_BEGIN__ |
|
15 // [Action Name] |
|
16 // ReceiveSmsMessages |
|
17 // [Action Parameters] |
|
18 // CMsvSession Session <input>: Reference to the session. |
|
19 // TInt Counter <input>: Value of expected number of messages |
|
20 // [Action Description] |
|
21 // Receives a specified number of sms messages. It waits for a new |
|
22 // message to appear in the inbox and decrements a count. It completes |
|
23 // once the required number of messages has been received. |
|
24 // [APIs Used] |
|
25 // CMsvEntry::SetEntryL |
|
26 // CMsvEntry::AddObserverL |
|
27 // __ACTION_INFO_END__ |
|
28 // |
|
29 // |
|
30 |
|
31 /** |
|
32 @file |
|
33 */ |
|
34 |
|
35 |
|
36 #include <smut.h> |
|
37 #include <msvapi.h> |
|
38 |
|
39 #include "CMtfTestActionReceiveSmsMessages.h" |
|
40 #include "CMtfTestCase.h" |
|
41 #include "CMtfTestActionParameters.h" |
|
42 |
|
43 CMtfTestAction* CMtfTestActionReceiveSmsMessages::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
44 { |
|
45 CMtfTestActionReceiveSmsMessages* self = new (ELeave) CMtfTestActionReceiveSmsMessages(aTestCase); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aActionParameters); |
|
48 CleanupStack::Pop(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CMtfTestActionReceiveSmsMessages::CMtfTestActionReceiveSmsMessages(CMtfTestCase& aTestCase) |
|
53 : CMtfTestAction(aTestCase) |
|
54 { |
|
55 } |
|
56 |
|
57 CMtfTestActionReceiveSmsMessages::~CMtfTestActionReceiveSmsMessages() |
|
58 { |
|
59 Cancel(); |
|
60 iMsventry->RemoveObserver(*this); |
|
61 delete iMsventry; |
|
62 } |
|
63 |
|
64 void CMtfTestActionReceiveSmsMessages::ExecuteActionL() |
|
65 { |
|
66 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionReceiveSmsMessages); |
|
67 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
68 iNumberOfMessages = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(1)); |
|
69 iMsventry = CMsvEntry::NewL(*paramSession,KMsvGlobalInBoxIndexEntryId,TMsvSelectionOrdering()); |
|
70 iMsventry->AddObserverL(*this); |
|
71 iStatus = KRequestPending; |
|
72 CActiveScheduler::Add(this); |
|
73 SetActive(); |
|
74 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionReceiveSmsMessages); |
|
75 } |
|
76 |
|
77 void CMtfTestActionReceiveSmsMessages::DoCancel() |
|
78 { |
|
79 TRequestStatus *status=&iStatus; |
|
80 User::RequestComplete(status,KErrCancel); |
|
81 } |
|
82 |
|
83 void CMtfTestActionReceiveSmsMessages::RunL() |
|
84 { |
|
85 TestCase().ActionCompletedL(*this); |
|
86 } |
|
87 |
|
88 void CMtfTestActionReceiveSmsMessages::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* aArg1, TAny* /* aArg2*/, TAny* /*aArg3*/) |
|
89 /** |
|
90 * Called by CMsvEntry when a messaging event has occurred. It is used here to find out if any new messages have been created. |
|
91 */ |
|
92 { |
|
93 CMsvEntrySelection* entries = NULL; |
|
94 switch (aEvent) |
|
95 { |
|
96 case EMsvNewChildren: |
|
97 if(aArg1 == NULL) |
|
98 { |
|
99 User::Leave(KErrGeneral); |
|
100 } |
|
101 else{ |
|
102 entries = static_cast<CMsvEntrySelection*>(aArg1); |
|
103 } |
|
104 break; |
|
105 |
|
106 default: |
|
107 User::Leave(KErrGeneral); |
|
108 } |
|
109 |
|
110 iNumberOfMessages-=entries->Count(); |
|
111 if(iNumberOfMessages>0) |
|
112 { |
|
113 return; |
|
114 } |
|
115 else if(iNumberOfMessages == 0) |
|
116 { |
|
117 TRequestStatus *status=&iStatus; |
|
118 User::RequestComplete(status,KErrNone); |
|
119 } |
|
120 else if(iNumberOfMessages<0) |
|
121 { |
|
122 User::Leave(KErrGeneral); |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 |