|
1 /* |
|
2 * Copyright (c) 2002 - 2007 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: Base class for all test cases class member functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <BAUTILS.H> |
|
20 #include <S32FILE.H> |
|
21 #include <D32DBMS.H> |
|
22 #include "DbCorruptTests.h" |
|
23 #include <EmailStoreUids.hrh> |
|
24 |
|
25 //these must match those defined in ContainerStoreDefs. |
|
26 _LIT( KDbFilename, "message_store.db" ); |
|
27 _LIT( KGeneralTableName, "G001" ); |
|
28 _LIT( KGeneralTableDbSchemaVersionCol, "G002" ); |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 CDbCorruptTests* CDbCorruptTests::NewL( CStifLogger* aLog ) |
|
33 { |
|
34 CDbCorruptTests* self = new(ELeave) CDbCorruptTests( aLog ); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // Constructor |
|
43 // ----------------------------------------------------------------------------- |
|
44 CDbCorruptTests::CDbCorruptTests( CStifLogger* aLog ) : CAsyncTestCaseBase( aLog ) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // Destructor |
|
50 // ----------------------------------------------------------------------------- |
|
51 CDbCorruptTests::~CDbCorruptTests() |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // 2nd phase constructor |
|
57 // ----------------------------------------------------------------------------- |
|
58 void CDbCorruptTests::ConstructL() |
|
59 { |
|
60 CAsyncTestCaseBase::ConstructL(); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // ExecuteL : start executing the test case |
|
65 // ----------------------------------------------------------------------------- |
|
66 TBool CDbCorruptTests::ExecuteL() |
|
67 { |
|
68 LogHeader( _L("Database Corruption") ); |
|
69 |
|
70 RFs fs; |
|
71 RFile file; |
|
72 CPermanentFileStore* fileStore; |
|
73 CMsgStorePropertyContainer* properties; |
|
74 RDbStoreDatabase database; |
|
75 RDbTable table; |
|
76 CDbColSet* colSet; |
|
77 TUint unreadCount; |
|
78 TUint totalCount; |
|
79 TInt result; |
|
80 TFileName dbFileName; |
|
81 |
|
82 User::LeaveIfError( fs.Connect() ); |
|
83 |
|
84 properties = CMsgStorePropertyContainer::NewL(); |
|
85 |
|
86 iLog->Log( _L("Case %d: Database file exists but is empty"), iCaseId++ ); |
|
87 |
|
88 iLog->Log( _L(" Shutdown the server") ); |
|
89 //shutdown the server |
|
90 ShutdownServerL(); |
|
91 |
|
92 // The file cannot be opened until the server has shut down, so keep trying until it is possible. |
|
93 result = KErrInUse; |
|
94 while( result == KErrInUse ) |
|
95 { |
|
96 Yield( 100000 ); |
|
97 dbFileName.Format( _L("C:\\private\\%x\\%S"), KUidMessageStoreExe, &KDbFilename ); |
|
98 result = file.Replace( fs, dbFileName, EFileWrite ); |
|
99 } |
|
100 |
|
101 file.Close(); |
|
102 |
|
103 CMsgStore* session = CMsgStore::NewL( ETrue ); |
|
104 CleanupStack::PushL( session ); //+1 |
|
105 |
|
106 iLog->Log( _L("Case %d: Create Mailbox"), iCaseId++ ); |
|
107 CMsgStoreAccount* account1 = CMsgStoreAccount::NewLC( 1234, KNullDesC ); //+2 |
|
108 CMsgStoreMailBox* mailbox1 = session->CreateAccountL( *account1 ); |
|
109 CleanupStack::PushL( mailbox1 ); //+3 |
|
110 |
|
111 iLog->Log( _L("Case %d: Message counts are 0"), iCaseId++ ); |
|
112 mailbox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
113 CheckCondition( _L("no crash, counts are zero"), totalCount == 0 && unreadCount == 0 ); |
|
114 |
|
115 iLog->Log( _L("Case %d: Create Folder"), iCaseId++ ); |
|
116 TMsgStoreId inbox1Id = mailbox1->CreateFolderL( mailbox1->Id(), *properties ); |
|
117 CMsgStoreFolder* inbox1 = mailbox1->FolderL( inbox1Id ); |
|
118 CleanupStack::PushL( inbox1 ); //+4 |
|
119 |
|
120 iLog->Log( _L("Case %d: Create Message"), iCaseId++ ); |
|
121 CMsgStoreMessage* msg = mailbox1->CreateMessageL( inbox1Id, *properties ); |
|
122 delete msg; |
|
123 |
|
124 CleanupStack::PopAndDestroy(4); |
|
125 |
|
126 //shutdown the server again |
|
127 iLog->Log( _L(" Shutdown the server again") ); |
|
128 ShutdownServerL(); |
|
129 |
|
130 iLog->Log( _L("Case %d: Database file exists but contains bad content"), iCaseId++ ); |
|
131 result = KErrInUse; |
|
132 while( result == KErrInUse ) |
|
133 { |
|
134 Yield( 100000 ); |
|
135 result = file.Replace( fs, dbFileName, EFileWrite ); |
|
136 } |
|
137 |
|
138 file.Write( _L8("RANDOM CONTENT") ); |
|
139 file.Close(); |
|
140 |
|
141 session = CMsgStore::NewL( ETrue ); |
|
142 CleanupStack::PushL( session ); //+1 |
|
143 |
|
144 iLog->Log( _L("Case %d: Create Mailbox"), iCaseId++ ); |
|
145 account1 = CMsgStoreAccount::NewLC( 1234, KNullDesC ); //+2 |
|
146 mailbox1 = session->CreateAccountL( *account1 ); |
|
147 CleanupStack::PushL( mailbox1 ); //+3 |
|
148 |
|
149 iLog->Log( _L("Case %d: Message counts are 0"), iCaseId++ ); |
|
150 mailbox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
151 CheckCondition( _L("no crash, counts are zero"), totalCount == 0 && unreadCount == 0 ); |
|
152 |
|
153 iLog->Log( _L("Case %d: Create Folder"), iCaseId++ ); |
|
154 inbox1Id = mailbox1->CreateFolderL( mailbox1->Id(), *properties ); |
|
155 inbox1 = mailbox1->FolderL( inbox1Id ); |
|
156 CleanupStack::PushL( inbox1 ); //+4 |
|
157 |
|
158 iLog->Log( _L("Case %d: Create Message"), iCaseId++ ); |
|
159 msg = mailbox1->CreateMessageL( inbox1Id, *properties ); |
|
160 |
|
161 delete msg; |
|
162 CleanupStack::PopAndDestroy(4); |
|
163 |
|
164 //shutdown the server again |
|
165 iLog->Log( _L(" Shutdown the server again") ); |
|
166 ShutdownServerL(); |
|
167 |
|
168 iLog->Log( _L("Case %d: Database file exists and contains an empty database"), iCaseId++ ); |
|
169 |
|
170 result = KErrInUse; |
|
171 while( result == KErrInUse ) |
|
172 { |
|
173 Yield( 100000 ); |
|
174 TRAP( result, fileStore = CPermanentFileStore::ReplaceL( fs, dbFileName, EFileRead|EFileWrite ) ); |
|
175 } |
|
176 |
|
177 fileStore->SetTypeL( fileStore->Layout() ); |
|
178 TStreamId id = database.CreateL( fileStore ); |
|
179 fileStore->SetRootL( id ); |
|
180 fileStore->CommitL(); |
|
181 database.Close(); |
|
182 delete fileStore; |
|
183 |
|
184 session = CMsgStore::NewL( ETrue ); |
|
185 CleanupStack::PushL( session ); //+1 |
|
186 |
|
187 iLog->Log( _L("Case %d: Create Mailbox"), iCaseId++ ); |
|
188 |
|
189 account1 = CMsgStoreAccount::NewLC( 1234, KNullDesC ); //+2 |
|
190 mailbox1 = session->CreateAccountL( *account1 ); |
|
191 CleanupStack::PushL( mailbox1 ); //+3 |
|
192 |
|
193 iLog->Log( _L("Case %d: Message counts are 0"), iCaseId++ ); |
|
194 mailbox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
195 CheckCondition( _L("no crash, counts are zero"), totalCount == 0 && unreadCount == 0 ); |
|
196 |
|
197 iLog->Log( _L("Case %d: Create Folder"), iCaseId++ ); |
|
198 inbox1Id = mailbox1->CreateFolderL( mailbox1->Id(), *properties ); |
|
199 inbox1 = mailbox1->FolderL( inbox1Id ); |
|
200 CleanupStack::PushL( inbox1 ); //+4 |
|
201 |
|
202 iLog->Log( _L("Case %d: Create Message"), iCaseId++ ); |
|
203 msg = mailbox1->CreateMessageL( inbox1Id, *properties ); |
|
204 delete msg; |
|
205 |
|
206 CleanupStack::PopAndDestroy(4); |
|
207 |
|
208 //shutdown the server again |
|
209 iLog->Log( _L(" Shutdown the server again") ); |
|
210 ShutdownServerL(); |
|
211 |
|
212 iLog->Log( _L("Case %d: Database schema mismatch"), iCaseId++ ); |
|
213 |
|
214 result = KErrInUse; |
|
215 while( result == KErrInUse ) |
|
216 { |
|
217 Yield( 100000 ); |
|
218 TRAP( result, fileStore = CPermanentFileStore::OpenL( fs, dbFileName, EFileRead|EFileWrite ) ); |
|
219 } |
|
220 |
|
221 database.OpenL( fileStore, fileStore->Root() ); |
|
222 User::LeaveIfError( table.Open( database, KGeneralTableName ) ); |
|
223 colSet = table.ColSetL(); |
|
224 TUint schemaVersionColNum = colSet->ColNo( KGeneralTableDbSchemaVersionCol ); |
|
225 delete colSet; |
|
226 table.FirstL(); |
|
227 table.UpdateL(); |
|
228 table.SetColL( schemaVersionColNum, 0 ); |
|
229 table.PutL(); |
|
230 table.Close(); |
|
231 database.Close(); |
|
232 delete fileStore; |
|
233 |
|
234 session = CMsgStore::NewL( ETrue ); |
|
235 CleanupStack::PushL( session ); //+1 |
|
236 |
|
237 iLog->Log( _L("Case %d: Create Mailbox"), iCaseId++ ); |
|
238 account1 = CMsgStoreAccount::NewLC( 1234, KNullDesC ); //+2 |
|
239 mailbox1 = session->CreateAccountL( *account1 ); |
|
240 CleanupStack::PushL( mailbox1 ); //+3 |
|
241 |
|
242 iLog->Log( _L("Case %d: Message counts are 0"), iCaseId++ ); |
|
243 mailbox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
244 CheckCondition( _L("no crash, counts are zero"), totalCount == 0 && unreadCount == 0 ); |
|
245 |
|
246 iLog->Log( _L("Case %d: Create Folder"), iCaseId++ ); |
|
247 inbox1Id = mailbox1->CreateFolderL( mailbox1->Id(), *properties ); |
|
248 inbox1 = mailbox1->FolderL( inbox1Id ); |
|
249 CleanupStack::PushL( inbox1 ); //+4 |
|
250 |
|
251 iLog->Log( _L("Case %d: Create Message"), iCaseId++ ); |
|
252 msg = mailbox1->CreateMessageL( inbox1Id, *properties ); |
|
253 |
|
254 delete msg; |
|
255 CleanupStack::PopAndDestroy(4); |
|
256 |
|
257 delete properties; |
|
258 fs.Close(); |
|
259 |
|
260 //we are done |
|
261 return ETrue; |
|
262 } |
|
263 |
|
264 |
|
265 // End of File |