1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 /* |
2 // All rights reserved. |
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 // This component and the accompanying materials are made available |
3 * All rights reserved. |
4 // under the terms of "Eclipse Public License v1.0" |
4 * This component and the accompanying materials are made available |
5 // which accompanies this distribution, and is available |
5 * under the terms of "Eclipse Public License v1.0" |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 * which accompanies this distribution, and is available |
7 // |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 // Initial Contributors: |
8 * |
9 // Nokia Corporation - initial contribution. |
9 * Initial Contributors: |
10 // |
10 * Nokia Corporation - initial contribution. |
11 // Contributors: |
11 * |
12 // |
12 * Contributors: |
13 // Description: |
13 * |
14 // |
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
15 |
18 |
16 #include <e32std.h> |
19 #include <e32std.h> |
17 #include <e32test.h> |
20 #include <e32test.h> |
18 #include <e32const.h> |
21 #include <e32const.h> |
19 #include <collate.h> |
22 #include <collate.h> |
20 #include <cntdb.h> |
23 #include <cntdb.h> |
21 #include <cntitem.h> |
24 #include <cntitem.h> |
22 #include <cntfldst.h> |
25 #include <cntfldst.h> |
23 #include "t_utils2.h" |
26 #include "t_utils2.h" |
24 #include "T_UTILS.H" |
27 #include "t_utils.h" |
25 #include <badesca.h> |
28 #include <badesca.h> |
26 |
29 |
27 LOCAL_D TInt ThreadFunction(TAny*); |
30 LOCAL_D TInt ThreadFunction(TAny*); |
28 |
31 |
29 _LIT(KDatabaseFileName, "C:T_OwnCardDelete"); |
32 _LIT(KDatabaseFileName, "C:T_OwnCardDelete"); |
246 CContactDatabase* dbAnother = CContactDatabase::OpenL(KDatabaseFileName); |
249 CContactDatabase* dbAnother = CContactDatabase::OpenL(KDatabaseFileName); |
247 CleanupStack::PushL(dbAnother); |
250 CleanupStack::PushL(dbAnother); |
248 |
251 |
249 SwitchToMainThread(mutex); // 1) Back to MT-a |
252 SwitchToMainThread(mutex); // 1) Back to MT-a |
250 |
253 |
251 // |
254 /////////////////////////////////////////////// |
252 // Main thread has now opened the database |
255 // Main thread has now opened the database |
253 // |
256 /////////////////////////////////////////////// |
254 |
257 |
255 aTest.Printf(_L("Populating the database \n")); |
258 aTest.Printf(_L("Populating the database \n")); |
256 PopulateDatabaseL(db, KTotalContacts); |
259 PopulateDatabaseL(db, KTotalContacts); |
257 WaitForNotificationsL(db); |
260 WaitForNotificationsL(db); |
258 |
261 |
272 aTest.Printf(_L("Id: %d \n"), id); |
275 aTest.Printf(_L("Id: %d \n"), id); |
273 aTest(id != KNullContactId && idCopy != KNullContactId, __LINE__); |
276 aTest(id != KNullContactId && idCopy != KNullContactId, __LINE__); |
274 |
277 |
275 SwitchToMainThread(mutex); // 2) Back to MT-b |
278 SwitchToMainThread(mutex); // 2) Back to MT-b |
276 |
279 |
277 // |
280 /////////////////////////////////////////////// |
278 // Main thread has now checked the added values |
281 // Main thread has now checked the added values |
279 // |
282 /////////////////////////////////////////////// |
280 |
283 |
281 DeleteMultipleContactsL(db); |
284 DeleteMultipleContactsL(db); |
282 WaitForNotificationsL(db); |
285 WaitForNotificationsL(db); |
283 |
286 |
284 aTest.Printf(_L("Checking deleted count value \n")); |
287 aTest.Printf(_L("Checking deleted count value \n")); |
293 aTest.Printf(_L("Id: %d \n"), id); |
296 aTest.Printf(_L("Id: %d \n"), id); |
294 aTest(id == KNullContactId && idCopy == KNullContactId, __LINE__); |
297 aTest(id == KNullContactId && idCopy == KNullContactId, __LINE__); |
295 |
298 |
296 SwitchToMainThread(mutex); // 3) Back to MT-c |
299 SwitchToMainThread(mutex); // 3) Back to MT-c |
297 |
300 |
298 // |
301 /////////////////////////////////////////////// |
299 // Main thread has now checked the deleted values |
302 // Main thread has now checked the deleted values |
300 // |
303 /////////////////////////////////////////////// |
301 |
304 |
302 CleanupStack::PopAndDestroy(dbAnother); |
305 CleanupStack::PopAndDestroy(dbAnother); |
303 CleanupStack::PopAndDestroy(db); |
306 CleanupStack::PopAndDestroy(db); |
304 CleanupStack::PopAndDestroy(); // close mutex handle |
307 CleanupStack::PopAndDestroy(); // close mutex handle |
305 |
308 |
323 CleanupClosePushL(thd); |
326 CleanupClosePushL(thd); |
324 thd.Resume(); |
327 thd.Resume(); |
325 |
328 |
326 SwitchToWorkerThread(mtx, thd, EFalse, ETrue); // a) Run: WT-start to WT-1 |
329 SwitchToWorkerThread(mtx, thd, EFalse, ETrue); // a) Run: WT-start to WT-1 |
327 |
330 |
328 // |
331 /////////////////////////////////////////////// |
329 // Worker thread has now replaced the database |
332 // Worker thread has now replaced the database |
330 // |
333 /////////////////////////////////////////////// |
331 |
334 |
332 aTest.Printf(_L("Open existing database \n")); |
335 aTest.Printf(_L("Open existing database \n")); |
333 CContactDatabase* db = CContactDatabase::OpenL(KDatabaseFileName); |
336 CContactDatabase* db = CContactDatabase::OpenL(KDatabaseFileName); |
334 CleanupStack::PushL(db); |
337 CleanupStack::PushL(db); |
335 |
338 |
336 SwitchToWorkerThread(mtx, thd, ETrue, ETrue); // b) Run: WT-1 to WT-2 |
339 SwitchToWorkerThread(mtx, thd, ETrue, ETrue); // b) Run: WT-1 to WT-2 |
337 |
340 |
338 // |
341 /////////////////////////////////////////////// |
339 // Worker thread has now added the contacts |
342 // Worker thread has now added the contacts |
340 // |
343 /////////////////////////////////////////////// |
341 |
344 |
342 WaitForNotificationsL(db); |
345 WaitForNotificationsL(db); |
343 |
346 |
344 aTest.Printf(_L("Checking db count \n")); |
347 aTest.Printf(_L("Checking db count \n")); |
345 TInt count = db->CountL(); |
348 TInt count = db->CountL(); |
351 aTest.Printf(_L("id: %d \n"), id); |
354 aTest.Printf(_L("id: %d \n"), id); |
352 aTest(id != KNullContactId, __LINE__); |
355 aTest(id != KNullContactId, __LINE__); |
353 |
356 |
354 SwitchToWorkerThread(mtx, thd, ETrue, ETrue); // c) Run: WT-2 to WT-3 |
357 SwitchToWorkerThread(mtx, thd, ETrue, ETrue); // c) Run: WT-2 to WT-3 |
355 |
358 |
356 // |
359 /////////////////////////////////////////////// |
357 // Worker thread has now deleted the contacts |
360 // Worker thread has now deleted the contacts |
358 // |
361 /////////////////////////////////////////////// |
359 |
362 |
360 aTest.Printf(_L("Checking deleted db count \n")); |
363 aTest.Printf(_L("Checking deleted db count \n")); |
361 |
364 |
362 WaitForNotificationsL(db); |
365 WaitForNotificationsL(db); |
363 |
366 |