phonebookengines/contactsmodel/tsrc/t_serverstart.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 1997-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 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <e32test.h>
       
    18 #include <cntdb.h>
       
    19 #include "T_UTILS.H"
       
    20 
       
    21 _LIT(KTestName,"T_ServerStart");
       
    22 _LIT(KTest1,"@SYMTESTCaseID:PIM-T-SERVERSTART-0001 Simultaneous startup");
       
    23 
       
    24 LOCAL_D RTest test(KTestName);
       
    25 
       
    26 
       
    27 static void CheckOnlyOneServerLaunched()
       
    28 	{
       
    29 	TInt count=0;
       
    30 	TFullName fullName;
       
    31 	TFindProcess find(_L("cntsrv*"));
       
    32 	while(find.Next(fullName)==KErrNone)
       
    33 		{
       
    34 		count++;
       
    35 		}
       
    36 	__ASSERT_DEBUG(count==1,User::Invariant());
       
    37 	}
       
    38 
       
    39 
       
    40 /** Thread function */
       
    41 static TInt LaunchThread(TAny* /*aAny*/)
       
    42 	{
       
    43 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
       
    44 	CActiveScheduler::Install(scheduler);
       
    45 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    46 
       
    47 	User::After(1000000);
       
    48 	CContactDatabase* db =NULL;
       
    49 
       
    50 	TRAPD(err, db = CContactDatabase::OpenL());
       
    51 	__ASSERT_ALWAYS(err==KErrNone,User::Invariant());
       
    52 	CheckOnlyOneServerLaunched();
       
    53 	delete db;
       
    54 
       
    55 	delete cleanup;	
       
    56 	delete CActiveScheduler::Current();
       
    57 	return KErrNone;
       
    58 	}
       
    59 
       
    60 
       
    61 /** Create two threads which simultaneously attempt to open the database */
       
    62 LOCAL_C void simultaneousStartupL()
       
    63 	{
       
    64 	RThread thread1;
       
    65 	RThread thread2;
       
    66 	// Create the threads
       
    67 	User::LeaveIfError(thread1.Create(_L("Thread1"), LaunchThread, KDefaultStackSize, 0x2000, 0x20000, NULL));
       
    68 	User::LeaveIfError(thread2.Create(_L("Thread2"), LaunchThread, KDefaultStackSize, 0x2000, 0x20000, NULL));
       
    69 	// Let them run
       
    70 	thread1.Resume();
       
    71 	thread2.Resume();
       
    72 	User::After(5000000);
       
    73 
       
    74 	thread1.Close();
       
    75 	thread2.Close();
       
    76 	}
       
    77 
       
    78 
       
    79 /** 
       
    80  * Create default contacts file ready for test
       
    81  * Run simultaneous startup test
       
    82  */
       
    83 
       
    84 /**
       
    85 
       
    86 @SYMTestCaseID     PIM-T-SERVERSTART-0001
       
    87 
       
    88 */
       
    89 
       
    90 void doMainL()
       
    91 	{
       
    92 	test.Start(KTest1);
       
    93 
       
    94 
       
    95 	TRAP_IGNORE(CContactDatabase::DeleteDefaultFileL());
       
    96 	CContactDatabase* db = CContactDatabase::CreateL();
       
    97 	delete db;
       
    98 	simultaneousStartupL();
       
    99 	test.End();
       
   100 	test.Close();
       
   101 	}
       
   102 
       
   103 
       
   104 /** Standard E32 entry point */
       
   105 GLDEF_C TInt E32Main()
       
   106 	{	
       
   107 	__UHEAP_MARK;
       
   108 	CActiveScheduler::Install(new(ELeave) CActiveScheduler);
       
   109 	CTrapCleanup* theCleanup=CTrapCleanup::New();
       
   110 
       
   111 	TRAPD(ret,doMainL());	
       
   112 	
       
   113 	test(ret==KErrNone);
       
   114 	delete theCleanup;	
       
   115 	delete CActiveScheduler::Current();
       
   116 	__UHEAP_MARKEND;
       
   117 	return(KErrNone);
       
   118 	}
       
   119