lowlevellibsandfws/apputils/tsrc/T_CNTF.CPP
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 // Started by BLB, November 1996
       
    15 // test code for CEnvironmentChangeNotifier
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <bacntf.h>
       
    20 #include <e32test.h>
       
    21 
       
    22 LOCAL_D RTest test(_L("T_CNTF"));
       
    23 
       
    24 TInt TheStatus=0;
       
    25 TBool WasCalled=EFalse;
       
    26 CEnvironmentChangeNotifier* TheNotifier=NULL;
       
    27 
       
    28 GLDEF_C TInt MyCallback(TAny*)
       
    29 	{
       
    30 	TInt stat=TheNotifier->Change()&~(EChangesPowerStatus|EChangesThreadDeath);
       
    31 	if (stat)
       
    32 		{	// ignore just changes in power status etc
       
    33 		WasCalled=ETrue;
       
    34 		TheStatus=stat;
       
    35 		CActiveScheduler::Stop();
       
    36 		}
       
    37 	return(KErrNone);
       
    38 	}
       
    39 
       
    40 /**
       
    41 @SYMTestCaseID          SYSLIB-BAFL-CT-0406
       
    42 @SYMTestCaseDesc        TLocale class functionality test
       
    43 @SYMTestPriority        Medium
       
    44 @SYMTestActions         Tests for environment setting changes.
       
    45 @SYMTestExpectedResults Tests must not fail
       
    46 @SYMREQ                 REQ0000
       
    47 */
       
    48 LOCAL_C void testLocale()
       
    49 	{
       
    50 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0406 Changing locale "));
       
    51 	TLocale locale;
       
    52 	test(!WasCalled);
       
    53 	locale.SetCountryCode(locale.CountryCode()+1);
       
    54 	locale.Set();
       
    55 	CActiveScheduler::Start();
       
    56 	test(WasCalled);
       
    57 	test(TheStatus&EChangesLocale);
       
    58 	test((TheStatus&EChangesMidnightCrossover)==0);
       
    59 	WasCalled=EFalse;
       
    60 	TheStatus=0;
       
    61 	}
       
    62 
       
    63 /**
       
    64 @SYMTestCaseID          SYSLIB-BAFL-CT-0407
       
    65 @SYMTestCaseDesc        Tests for Locale changes
       
    66 @SYMTestPriority        Medium
       
    67 @SYMTestActions         Tests for change in systems time.
       
    68 @SYMTestExpectedResults Tests must not fail
       
    69 @SYMREQ                 REQ0000
       
    70 */
       
    71 LOCAL_C void testMidnight()
       
    72 	{
       
    73 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0407 Midnight crossover "));
       
    74 	TTime timeNow;
       
    75 	timeNow.HomeTime();
       
    76 	TDateTime dateTime=timeNow.DateTime();
       
    77 	dateTime.SetHour(23);
       
    78 	dateTime.SetSecond(58);
       
    79 	dateTime.SetMinute(59);
       
    80 	timeNow=dateTime;
       
    81 	User::SetHomeTime(timeNow);
       
    82 	test(!WasCalled);
       
    83 	CActiveScheduler::Start();
       
    84 	test(WasCalled);
       
    85 	test(TheStatus&EChangesSystemTime);
       
    86 	test((TheStatus&EChangesLocale)==0);
       
    87 	if ((TheStatus&EChangesMidnightCrossover)==0)
       
    88 		{
       
    89 		WasCalled=EFalse;
       
    90 		TheStatus=0;
       
    91 		CActiveScheduler::Start();
       
    92 		test(WasCalled);
       
    93 		test(TheStatus&EChangesMidnightCrossover);
       
    94 		test((TheStatus&EChangesLocale)==0);
       
    95 		}
       
    96 	WasCalled=EFalse;
       
    97 	TheStatus=0;
       
    98 	}
       
    99 
       
   100 // Following testLocale re-set the country code value back to the default
       
   101 // so that any more tests added in future will be starting from the OS default state
       
   102 LOCAL_C void resetLocale()
       
   103 	{
       
   104 	test.Next(_L("Resetting locale before next test"));
       
   105 	TLocale locale;
       
   106 	test(!WasCalled);
       
   107 	locale.SetCountryCode(locale.CountryCode()-1);
       
   108 	locale.Set();
       
   109 	CActiveScheduler::Start();
       
   110 	test(WasCalled);
       
   111 	test(TheStatus&EChangesLocale);
       
   112 	WasCalled=EFalse;
       
   113 	TheStatus=0;
       
   114 	}
       
   115 
       
   116 GLDEF_C TInt E32Main()
       
   117 	{
       
   118 	__UHEAP_MARK;
       
   119 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   120 	CActiveScheduler* shed=new(ELeave) CActiveScheduler;
       
   121 	CActiveScheduler::Install(shed);
       
   122 	test.Title();
       
   123 	test.Start(_L("Testing change notifier "));
       
   124 	TCallBack callback(MyCallback);
       
   125 	TheNotifier=CEnvironmentChangeNotifier::NewL(0,callback);
       
   126 	TheNotifier->Start();
       
   127 
       
   128 	// Check notifier is working
       
   129 	CActiveScheduler::Start();
       
   130 	test(WasCalled);
       
   131 	test(TheStatus!=0);
       
   132 	WasCalled=EFalse;
       
   133 	TheStatus=0;
       
   134 
       
   135 	// Test - change country code
       
   136 	testLocale();
       
   137 
       
   138 	// Test - check midnight rollover
       
   139 	testMidnight();
       
   140 
       
   141 	// Reset country code to default state
       
   142 	resetLocale();
       
   143 
       
   144 	TheNotifier->Cancel();
       
   145 	delete(CActiveScheduler::Current());
       
   146 	delete(TheNotifier);
       
   147 	test.End();
       
   148 	test.Close();
       
   149 	delete cleanup;
       
   150 	__UHEAP_MARKEND;
       
   151 	return(KErrNone);
       
   152     }