tzservices/tzloc/test/rtest/T_MultiThreadTimeZoneChange.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2008-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 <e32base.h>
       
    17 #include <e32std.h>
       
    18 #include <e32des16.h>
       
    19 #include <e32test.h>
       
    20 #include <tzlocalizer.h> 
       
    21 
       
    22 
       
    23 _LIT(KFormatErrorCode, " the error code is %d \n");
       
    24 
       
    25 
       
    26 _LIT(KThread1,"thread1");
       
    27 _LIT(KThread2,"thread2");
       
    28 _LIT(KThread3,"thread3");
       
    29 _LIT(KThread4,"thread4");
       
    30 _LIT(KThread5,"thread5");
       
    31 _LIT(KThread6,"thread6");
       
    32 _LIT(KThread7,"thread7");
       
    33 _LIT(KThread8,"thread8");
       
    34 _LIT(KThread9,"thread9");
       
    35 _LIT(KThread10,"thread10");
       
    36 
       
    37 _LIT(KTxtEPOC32EX,"EPOC32EX");
       
    38 
       
    39 
       
    40 const TUint32 KLondon = 2592;
       
    41 const TInt KHeapSize = 0x2000;
       
    42 
       
    43 
       
    44 RTest test (_L("T_MultiThreadTimeZoneChange"));
       
    45 
       
    46 
       
    47 LOCAL_C void TestConvertByUsingCTzConverterL()
       
    48 	{
       
    49 	//create a CTzLocalizer object for setting the timezone
       
    50 	CTzLocalizer* localizer = CTzLocalizer::NewLC();  
       
    51 	
       
    52 	//Set timezone to be London
       
    53 	localizer->SetTimeZoneL(KLondon);
       
    54 	
       
    55 	CleanupStack::PopAndDestroy(localizer);
       
    56 	}
       
    57 
       
    58 
       
    59 /**
       
    60  * Start converting function.
       
    61  */
       
    62 LOCAL_C void StartConvertL()
       
    63     {
       
    64 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler();
       
    65 	CleanupStack::PushL(scheduler);
       
    66 	CActiveScheduler::Install(scheduler);
       
    67 	
       
    68     TestConvertByUsingCTzConverterL();
       
    69     
       
    70 	CleanupStack::PopAndDestroy(scheduler);
       
    71 	}
       
    72 
       
    73 /**
       
    74  * Run single thread. 
       
    75  */
       
    76 LOCAL_C TInt RunThread()
       
    77     {
       
    78 	__UHEAP_MARK;
       
    79     CTrapCleanup* cleanup = CTrapCleanup::New();    // get clean-up stack
       
    80 
       
    81     TRAPD(error, StartConvertL());    // more initialization
       
    82     __ASSERT_ALWAYS( !error, User::Panic(KTxtEPOC32EX, error));
       
    83 	
       
    84 	delete cleanup;             // destroy clean-up stack
       
    85     __UHEAP_MARKEND;
       
    86     
       
    87 	return error;
       
    88     }	
       
    89 
       
    90 /**
       
    91  * Thread function entry  point 
       
    92  */
       
    93 LOCAL_C TInt ThreadFunc(TAny* /*aAny*/)  
       
    94     {
       
    95 	return RunThread();
       
    96 	}
       
    97 
       
    98 /**
       
    99  * Thread function entry  point 
       
   100  */
       
   101 LOCAL_C void PrintStatus(TRequestStatus& aThreadResult, TInt aThreadNumber)
       
   102 	{
       
   103 	if(aThreadResult.Int() != KErrNone)
       
   104 		{
       
   105 		test.Printf(KFormatErrorCode, aThreadResult.Int());
       
   106 		}
       
   107 	else
       
   108 		{
       
   109 		test.Printf(_L("Thread %d was successfull\n"), aThreadNumber);
       
   110 		}	
       
   111 	}
       
   112 
       
   113 /**
       
   114  * Run Multi threads for testing the converting performance
       
   115  * 
       
   116  */
       
   117 LOCAL_C void RunMultiThreadsL()
       
   118     {
       
   119 	RThread thread1;
       
   120 	RThread thread2;
       
   121 	RThread thread3;	
       
   122 	RThread thread4;
       
   123 	RThread thread5;
       
   124 	RThread thread6;
       
   125 	RThread thread7;
       
   126 	RThread thread8;	
       
   127 	RThread thread9;
       
   128 	RThread thread10;
       
   129 	
       
   130 	TInt tResult = KErrNone;
       
   131 	
       
   132 	tResult = thread1.Create(KThread1, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   133 	User::LeaveIfError(tResult);
       
   134 	
       
   135 	tResult = thread2.Create(KThread2, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   136 	User::LeaveIfError(tResult);
       
   137 	
       
   138 	tResult = thread3.Create(KThread3, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   139 	User::LeaveIfError(tResult);
       
   140 	
       
   141 	tResult = thread4.Create(KThread4, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   142 	User::LeaveIfError(tResult);
       
   143 	
       
   144 	tResult = thread5.Create(KThread5, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   145 	User::LeaveIfError(tResult);
       
   146 	
       
   147 	tResult = thread6.Create(KThread6, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   148 	User::LeaveIfError(tResult);
       
   149 	
       
   150 	tResult = thread7.Create(KThread7, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   151 	User::LeaveIfError(tResult);
       
   152 	
       
   153 	tResult = thread8.Create(KThread8, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   154 	User::LeaveIfError(tResult);
       
   155 	
       
   156 	tResult = thread9.Create(KThread9, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   157 	User::LeaveIfError(tResult);
       
   158 	
       
   159 	tResult = thread10.Create(KThread10, ThreadFunc, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
       
   160 	User::LeaveIfError(tResult);
       
   161 	
       
   162 	// Request notification when these threads die using Logon
       
   163 	// function.
       
   164 	TRequestStatus status1;
       
   165 	TRequestStatus status2;
       
   166 	TRequestStatus status3;
       
   167 	TRequestStatus status4;
       
   168 	TRequestStatus status5;
       
   169 	TRequestStatus status6;
       
   170 	TRequestStatus status7;
       
   171 	TRequestStatus status8; 
       
   172 	TRequestStatus status9;
       
   173 	TRequestStatus status10;
       
   174 	
       
   175 	thread1.Logon(status1);
       
   176 	thread2.Logon(status2);
       
   177 	thread3.Logon(status3);
       
   178 	thread4.Logon(status4);
       
   179 	thread5.Logon(status5);
       
   180 	thread6.Logon(status6);
       
   181 	thread7.Logon(status7);
       
   182 	thread8.Logon(status8);
       
   183 	thread9.Logon(status9);
       
   184 	thread10.Logon(status10);
       
   185 		
       
   186 	CTzLocalizer* localizer = CTzLocalizer::NewLC();
       
   187 	//set timezone to be London
       
   188 	localizer->SetTimeZoneL(KLondon);		
       
   189 	CleanupStack::PopAndDestroy(localizer);
       
   190 	
       
   191 	// Make all threads eligible for execution using Resume
       
   192 	// function.
       
   193 	thread1.Resume();
       
   194 	thread2.Resume();
       
   195 	thread3.Resume();
       
   196 	thread4.Resume();
       
   197 	thread5.Resume();
       
   198 	thread6.Resume();
       
   199 	thread7.Resume();
       
   200 	thread8.Resume();
       
   201 	thread9.Resume();
       
   202 	thread10.Resume();
       
   203 
       
   204 	// Wait for the above requests to complete. Use 
       
   205 	// WaitForRequest of the User class. 
       
   206 	
       
   207 	User::WaitForRequest(status1);
       
   208 	PrintStatus(status1, 1);
       
   209 	
       
   210 	User::WaitForRequest(status2);
       
   211 	PrintStatus(status2, 2);
       
   212 	
       
   213 	User::WaitForRequest(status3);
       
   214 	PrintStatus(status3, 3);
       
   215 	
       
   216 	User::WaitForRequest(status4);
       
   217 	PrintStatus(status4, 4);
       
   218 
       
   219 	User::WaitForRequest(status5);
       
   220 	PrintStatus(status5, 5);
       
   221 		
       
   222 	User::WaitForRequest(status6);
       
   223 	PrintStatus(status6, 6);
       
   224 	
       
   225 	User::WaitForRequest(status7);
       
   226 	PrintStatus(status7, 7);
       
   227 	
       
   228 	User::WaitForRequest(status8);
       
   229 	PrintStatus(status8, 8);
       
   230 	
       
   231 	User::WaitForRequest(status9);
       
   232 	PrintStatus(status9, 9);
       
   233 
       
   234 	User::WaitForRequest(status10);
       
   235 	PrintStatus(status10, 10);
       
   236 
       
   237 	
       
   238 	// End threads. Use Kill function.
       
   239 	thread1.Kill(KErrNone);
       
   240 	thread2.Kill(KErrNone);
       
   241 	thread3.Kill(KErrNone);
       
   242 	thread4.Kill(KErrNone);
       
   243 	thread5.Kill(KErrNone);
       
   244 	thread6.Kill(KErrNone);
       
   245 	thread7.Kill(KErrNone);
       
   246 	thread8.Kill(KErrNone);
       
   247 	thread9.Kill(KErrNone);
       
   248 	thread10.Kill(KErrNone);
       
   249 	
       
   250 	// Close the handle to threads
       
   251 	thread1.Close();
       
   252 	thread2.Close();
       
   253 	thread3.Close();
       
   254 	thread4.Close();
       
   255 	thread5.Close();
       
   256 	thread6.Close();
       
   257 	thread7.Close();
       
   258 	thread8.Close();
       
   259 	thread9.Close();
       
   260 	thread10.Close();	
       
   261 	}
       
   262 
       
   263 
       
   264 LOCAL_C void DoStartL()
       
   265 	{
       
   266 	// Create active scheduler (to run active objects)
       
   267 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
       
   268 	CleanupStack::PushL(scheduler);
       
   269 	CActiveScheduler::Install(scheduler);
       
   270 
       
   271 	RunMultiThreadsL();
       
   272 
       
   273 	// Delete active scheduler
       
   274 	CleanupStack::PopAndDestroy(scheduler);
       
   275 	}
       
   276 
       
   277 //  Global Functions
       
   278 
       
   279 /**
       
   280 @SYMTestCaseID PIM-TMULTITHREADTIMEZONECHANGE-0001
       
   281 */	
       
   282 GLDEF_C TInt E32Main()
       
   283 	{
       
   284 	// Create cleanup stack
       
   285 	__UHEAP_MARK;
       
   286 	test.Start(_L("@SYMTestCaseID PIM-TMULTITHREADTIMEZONECHANGE-0001 Starting Test T_MultiThreadTimeZoneChange"));
       
   287 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   288 
       
   289 	// Run application code inside TRAP harness.
       
   290 	TRAPD(mainError, DoStartL());
       
   291 	
       
   292 	test(mainError == KErrNone);
       
   293 	
       
   294 	delete cleanup;
       
   295 	test.End();
       
   296 	test.Close();
       
   297 	__UHEAP_MARKEND;
       
   298 	return KErrNone;
       
   299 	}
       
   300 
       
   301 
       
   302