|
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 // ResetMessageStore |
|
17 // [Action Parameters] |
|
18 // Session <input>: Reference to the session. |
|
19 // [Action Description] |
|
20 // Deletes all entries in the message folder. If an entry cannot be deleted ignores the entry. |
|
21 // After deleting all entries that can be deleted reads msgs.rsc and checks that the structure |
|
22 // provided in msgs.rsc is the same as the message store. |
|
23 // [APIs Used] |
|
24 // none. |
|
25 // __ACTION_INFO_END__ |
|
26 // |
|
27 // |
|
28 |
|
29 /** |
|
30 @file |
|
31 */ |
|
32 |
|
33 |
|
34 |
|
35 #include <msvapi.h> |
|
36 #include <miutset.h> |
|
37 #include <barsc.h> |
|
38 #include <bautils.h> |
|
39 #include <msgs.rsg> |
|
40 |
|
41 #include "CMtfAsyncWaiter.h" |
|
42 |
|
43 #include <mmsvattachmentmanager.h> |
|
44 #include "messagingtestutility.h" |
|
45 #include <cemailaccounts.h> |
|
46 |
|
47 #include "CMtfTestActionResetMessageStore.h" |
|
48 #include "CMtfTestCase.h" |
|
49 #include "CMtfTestActionParameters.h" |
|
50 |
|
51 _LIT(KServerResourceFile,"z:\\resource\\messaging\\msgs.rsc"); |
|
52 |
|
53 _LIT(KStoreInitFileName, "c:\\private\\1000484b\\StoreInit.tmp"); |
|
54 |
|
55 CMtfTestAction* CMtfTestActionResetMessageStore::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
56 { |
|
57 CMtfTestActionResetMessageStore* self = new (ELeave) CMtfTestActionResetMessageStore(aTestCase); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(aActionParameters); |
|
60 CleanupStack::Pop(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 CMtfTestActionResetMessageStore::CMtfTestActionResetMessageStore(CMtfTestCase& aTestCase) |
|
66 : CMtfTestAction(aTestCase) |
|
67 { |
|
68 } |
|
69 |
|
70 |
|
71 CMtfTestActionResetMessageStore::~CMtfTestActionResetMessageStore() |
|
72 { |
|
73 } |
|
74 |
|
75 |
|
76 void CMtfTestActionResetMessageStore::ExecuteActionL() |
|
77 { |
|
78 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionResetMessageStore); |
|
79 iSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
80 |
|
81 iDeleteAllChildren = new (ELeave) CMtfTestActionUtilsDeleteAllChildren(iSession,KMsvRootIndexEntryId); |
|
82 iDeleteAllChildren->StartL(iStatus); |
|
83 CActiveScheduler::Add(this); |
|
84 SetActive(); |
|
85 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionResetMessageStore); |
|
86 } |
|
87 |
|
88 |
|
89 void CMtfTestActionResetMessageStore::DoCancel() |
|
90 { |
|
91 iDeleteAllChildren->Cancel(); |
|
92 } |
|
93 |
|
94 void CMtfTestActionResetMessageStore::RunL() |
|
95 { |
|
96 TInt undeleted = iDeleteAllChildren->Undeleted(); |
|
97 delete iDeleteAllChildren; |
|
98 |
|
99 User::LeaveIfError(iStatus.Int()); |
|
100 |
|
101 RFs fs; |
|
102 User::LeaveIfError(fs.Connect()); |
|
103 |
|
104 TFileName fileName; |
|
105 TParse parse; |
|
106 parse.Set(KServerResourceFile,&fileName,NULL); |
|
107 fileName = parse.FullName(); |
|
108 BaflUtils::NearestLanguageFile(fs, fileName); |
|
109 |
|
110 RResourceFile resource; |
|
111 resource.OpenL(fs,fileName); |
|
112 CleanupClosePushL(resource); |
|
113 |
|
114 TResourceReader reader; |
|
115 HBufC8* buf = resource.AllocReadLC(R_SERVER_INDEX_STARTUP); |
|
116 reader.SetBuffer(buf); |
|
117 |
|
118 const TInt numberOfEntries = reader.ReadInt16(); |
|
119 if (undeleted != numberOfEntries) |
|
120 User::Leave(KErrGeneral); |
|
121 |
|
122 RMessagingTestUtilityServer ts; |
|
123 User::LeaveIfError(ts.Connect()); |
|
124 CleanupClosePushL(ts); |
|
125 // delete "StoreInit.tmp" |
|
126 ts.DeleteFile(KStoreInitFileName); |
|
127 CleanupStack::PopAndDestroy(&ts); |
|
128 |
|
129 // central repository cleanup |
|
130 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
131 |
|
132 // delete pop3 accounts |
|
133 RArray<TPopAccount> pop3Accounts; |
|
134 CleanupClosePushL(pop3Accounts); |
|
135 accounts->GetPopAccountsL(pop3Accounts); |
|
136 for (TInt i=0; i<pop3Accounts.Count(); ++i) |
|
137 { |
|
138 accounts->DeletePopAccountL(pop3Accounts[i]); |
|
139 } |
|
140 |
|
141 // delete imap4 accounts |
|
142 RArray<TImapAccount> imap4Accounts; |
|
143 CleanupClosePushL(imap4Accounts); |
|
144 accounts->GetImapAccountsL(imap4Accounts); |
|
145 for (TInt j=0; j<imap4Accounts.Count(); ++j) |
|
146 { |
|
147 accounts->DeleteImapAccountL(imap4Accounts[j]); |
|
148 } |
|
149 |
|
150 // delete smtp accounts |
|
151 RArray<TSmtpAccount> smtpAccounts; |
|
152 CleanupClosePushL(smtpAccounts); |
|
153 accounts->GetSmtpAccountsL(smtpAccounts); |
|
154 for (TInt k=0; k<smtpAccounts.Count(); ++k) |
|
155 { |
|
156 accounts->DeleteSmtpAccountL(smtpAccounts[k]); |
|
157 } |
|
158 |
|
159 CleanupStack::PopAndDestroy(4, accounts); |
|
160 |
|
161 for (TInt i=0; i<numberOfEntries; i++) |
|
162 { |
|
163 TMsvId id = reader.ReadInt32(); |
|
164 CMsvEntry* clientEntry = iSession->GetEntryL(id); |
|
165 CleanupStack::PushL(clientEntry); |
|
166 |
|
167 |
|
168 if (clientEntry->HasStoreL()) |
|
169 { |
|
170 CMsvStore* store = clientEntry->EditStoreL(); |
|
171 CleanupStack::PushL(store); |
|
172 |
|
173 MMsvAttachmentManager& attManager = store->AttachmentManagerL(); |
|
174 TInt count = attManager.AttachmentCount(); |
|
175 CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); |
|
176 CleanupStack::PushL(waiter); |
|
177 for( TInt i=0; i<count; ++i ) |
|
178 { |
|
179 // remember as we remove an attachment the next attachment becomes index 0 |
|
180 attManager.RemoveAttachmentL( 0, waiter->iStatus ); |
|
181 waiter->StartAndWait(); |
|
182 User::LeaveIfError(waiter->Result()); |
|
183 } |
|
184 store->CommitL(); |
|
185 CleanupStack::PopAndDestroy(waiter); |
|
186 |
|
187 store->DeleteL(); |
|
188 CleanupStack::PopAndDestroy(store); |
|
189 } |
|
190 |
|
191 TMsvEntry indexEntry = clientEntry->Entry(); |
|
192 |
|
193 if (!((indexEntry.Parent() == reader.ReadInt32()) && |
|
194 (indexEntry.iServiceId == reader.ReadInt32()) && |
|
195 (indexEntry.iType.iUid == reader.ReadInt32()) && |
|
196 (indexEntry.iMtm.iUid == reader.ReadInt32()) && |
|
197 // (indexEntry.iData == reader.ReadInt32()) && |
|
198 ((reader.ReadInt32()) | 1) && |
|
199 (!indexEntry.iDescription.Compare(reader.ReadTPtrC())) && |
|
200 (!indexEntry.iDetails.Compare(reader.ReadTPtrC())))) |
|
201 User::Leave(KErrGeneral); |
|
202 |
|
203 CleanupStack::PopAndDestroy(clientEntry); |
|
204 } |
|
205 |
|
206 CleanupStack::PopAndDestroy(buf); |
|
207 CleanupStack::PopAndDestroy(); // resource |
|
208 |
|
209 fs.Close(); |
|
210 TestCase().INFO_PRINTF1(_L("CMtfTestActionResetMessageStore completed")); |
|
211 TestCase().ActionCompletedL(*this); |
|
212 } |
|
213 |