kerneltest/e32test/locale/t_names.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-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 the License "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 // e32test\locale\t_names.cpp
       
    15 // Overview:
       
    16 // Test Date, Time and Currency Symbol locale settings.
       
    17 // API Information:
       
    18 // TDayName,TDayNameAbb,TMonthName, TMonthNameAbb, TDateSuffix, TAmPmName,
       
    19 // TCurrencySymbol.
       
    20 // Details:
       
    21 // - Construct and set the full, abbreviated text name for a day of the week,
       
    22 // month and check it is as specified. 
       
    23 // - Construct and set date suffix text for a specific day in the month and 
       
    24 // test that constructor, TDateSuffix::Set panics when invalid parameters 
       
    25 // are passed.
       
    26 // - Construct and assign current locale's text identifying time before noon,
       
    27 // after noon and check it is as expected.
       
    28 // - Assign the current locale's currency symbol with different text and check 
       
    29 // it is as expected.
       
    30 // Platforms/Drives/Compatibility:
       
    31 // All.
       
    32 // Assumptions/Requirement/Pre-requisites:
       
    33 // Failures and causes:
       
    34 // Base Port information:
       
    35 // 
       
    36 //
       
    37 
       
    38 #include <e32test.h>
       
    39 
       
    40 #ifdef __VC32__
       
    41     // Solve compilation problem caused by non-English locale
       
    42     #pragma setlocale("english")
       
    43 #endif
       
    44 
       
    45 LOCAL_D RTest test(_L("T_NAMES"));
       
    46 
       
    47 void TestDayName()
       
    48 	{
       
    49 	test.Start(_L("TDayName"));
       
    50 	TDayName name1;
       
    51 	test(name1.Compare(_L("Monday"))==KErrNone);
       
    52 	TDayName name2(ESunday);
       
    53 	test(name2.Compare(_L("Sunday"))==KErrNone);
       
    54 	name1.Set(EWednesday);
       
    55 	test(name1.Compare(_L("Wednesday"))==KErrNone);
       
    56 	}
       
    57 
       
    58 void TestDayNameAbb()
       
    59 	{
       
    60 	test.Next(_L("TDayNameAbb"));
       
    61 	TDayNameAbb name1;
       
    62 	test(name1.Compare(_L("Mon"))==KErrNone);
       
    63 	TDayNameAbb name2(ETuesday);
       
    64 	test(name2.Compare(_L("Tue"))==KErrNone);
       
    65 	name1.Set(ESaturday);
       
    66 	test(name1.Compare(_L("Sat"))==KErrNone);
       
    67 	}
       
    68 
       
    69 void TestMonthName()
       
    70 	{
       
    71 	test.Next(_L("TMonthName"));
       
    72 	TMonthName name1;
       
    73 	test(name1.Compare(_L("January"))==KErrNone);
       
    74 	TMonthName name2(EDecember);
       
    75 	test(name2.Compare(_L("December"))==KErrNone);
       
    76 	name1.Set(EMarch);
       
    77 	test(name1.Compare(_L("March"))==KErrNone);
       
    78 	}
       
    79 
       
    80 void TestMonthNameAbb()
       
    81 	{
       
    82 	test.Next(_L("TMonthNameAbb"));
       
    83 	TMonthNameAbb name1;
       
    84 	test(name1.Compare(_L("Jan"))==KErrNone);
       
    85 	TMonthNameAbb name2(EFebruary);
       
    86 	test(name2.Compare(_L("Feb"))==KErrNone);
       
    87 	name1.Set(ENovember);
       
    88 	test(name1.Compare(_L("Nov"))==KErrNone);
       
    89 	}
       
    90 
       
    91 TInt TestThread1(TAny* Ptr)
       
    92 //
       
    93 // Used in TestDateSuffix() to test the constructor panics when silly parameters are passed
       
    94 //
       
    95 	{
       
    96 	TDateSuffix ds((TInt) Ptr);
       
    97 	(void)ds;
       
    98 	return(KErrNone);
       
    99 	}
       
   100 
       
   101 TInt TestThread2(TAny* Ptr)
       
   102 //
       
   103 // Used in TestDateSuffix() to test TDateSuffix::Set panics when silly parameters are passed
       
   104 //
       
   105 	{
       
   106 	TDateSuffix suff(0);
       
   107 	suff.Set((TInt) Ptr);
       
   108 	return(KErrNone);
       
   109 	}
       
   110 
       
   111 void TestDateSuffix()
       
   112 	{
       
   113 	test.Next(_L("TDateSuffix"));
       
   114 	
       
   115 	test.Start(_L("Simple creation and assignment"));
       
   116 	TDateSuffix suff1;
       
   117 	test(suff1.Compare(_L("st"))==KErrNone);
       
   118 	TDateSuffix suff2(1);
       
   119 	test(suff2.Compare(_L("nd"))==KErrNone);
       
   120 	suff1.Set(2);
       
   121 	test(suff1.Compare(_L("rd"))==KErrNone);
       
   122 	
       
   123 	test.Next(_L("Constructor in a thread"));
       
   124 	RThread thread;
       
   125 	TRequestStatus stat;
       
   126 	thread.Create(_L("Test Thread"),TestThread1,KDefaultStackSize,0x100,0x200,(TAny*)0);
       
   127 	thread.Logon(stat);
       
   128 	thread.Resume();
       
   129 	User::WaitForRequest(stat);
       
   130 	test(thread.ExitType()==EExitKill);
       
   131 	CLOSE_AND_WAIT(thread);
       
   132 	
       
   133 	test.Next(_L("Constructor panics for -1"));
       
   134 	thread.Create(_L("Test Thread"),TestThread1,KDefaultStackSize,0x100,0x200,(TAny*)-1);
       
   135 	thread.Logon(stat);
       
   136 	// don't want just in time debugging as we trap panics
       
   137 	TBool justInTime=User::JustInTime(); 
       
   138 	User::SetJustInTime(EFalse); 
       
   139 	thread.Resume();
       
   140 	User::WaitForRequest(stat);
       
   141 	User::SetJustInTime(justInTime); 
       
   142 	test(thread.ExitType()==EExitPanic);
       
   143 	CLOSE_AND_WAIT(thread);
       
   144 
       
   145 	test.Next(_L("Constructor panics for KMaxSuffices"));
       
   146 	thread.Create(_L("Test Thread"),TestThread1,KDefaultStackSize,0x100,0x200,(TAny*)KMaxSuffixes);
       
   147 	thread.Logon(stat);
       
   148 	User::SetJustInTime(EFalse); 
       
   149 	thread.Resume();
       
   150 	User::WaitForRequest(stat);
       
   151 	User::SetJustInTime(justInTime); 
       
   152 	test(thread.ExitType()==EExitPanic);
       
   153 	CLOSE_AND_WAIT(thread);
       
   154 	
       
   155 	test.Next(_L("Set in a thread"));
       
   156 	thread.Create(_L("Test Thread"),TestThread2,KDefaultStackSize,0x100,0x200,(TAny*)0);
       
   157 	thread.Logon(stat);
       
   158 	thread.Resume();
       
   159 	User::WaitForRequest(stat);
       
   160 	test(thread.ExitType()==EExitKill);
       
   161 	CLOSE_AND_WAIT(thread);
       
   162 	
       
   163 	test.Next(_L("Set panics for -1"));
       
   164 	thread.Create(_L("Test Thread"),TestThread2,KDefaultStackSize,0x100,0x200,(TAny*)-1);
       
   165 	thread.Logon(stat);
       
   166 	User::SetJustInTime(EFalse); 
       
   167 	thread.Resume();
       
   168 	User::WaitForRequest(stat);
       
   169 	User::SetJustInTime(justInTime); 
       
   170 	test(thread.ExitType()==EExitPanic);
       
   171 	CLOSE_AND_WAIT(thread);
       
   172 
       
   173 	test.Next(_L("Set panics for KMaxSuffices"));
       
   174 	thread.Create(_L("Test Thread"),TestThread2,KDefaultStackSize,0x100,0x200,(TAny*)KMaxSuffixes);
       
   175 	thread.Logon(stat);						  
       
   176 	User::SetJustInTime(EFalse); 
       
   177 	thread.Resume();
       
   178 	User::WaitForRequest(stat);
       
   179 	User::SetJustInTime(justInTime); 
       
   180 	test(thread.ExitType()==EExitPanic);
       
   181 	CLOSE_AND_WAIT(thread);
       
   182 
       
   183 	test.End();
       
   184 	}
       
   185 
       
   186 void TestAmPmName()
       
   187 	{
       
   188 	test.Next(_L("TAmPmName"));
       
   189 	TAmPmName name1;
       
   190 	test(name1.Compare(_L("am"))==KErrNone);
       
   191 	TAmPmName name2(EPm);
       
   192 	test(name2.Compare(_L("pm"))==KErrNone);
       
   193 	name1.Set(EPm);
       
   194 	test(name1.Compare(_L("pm"))==KErrNone);
       
   195 	}
       
   196 
       
   197 void TestCurrencySymbol()
       
   198 	{
       
   199 	test.Next(_L("TCurrencySymbol"));
       
   200 	TCurrencySymbol name;
       
   201 	test(name.Compare(_L("\xA3"))==KErrNone);
       
   202 	name[0]=0;
       
   203 	name.SetLength(0);
       
   204 	test(name.Compare(_L("\xA3"))!=KErrNone);
       
   205 	name.Set();
       
   206 	test(name.Compare(_L("\xA3"))==KErrNone);
       
   207 	name.Copy(_L("Syphilis"));
       
   208 	test(name.Compare(_L("\xA3"))!=KErrNone);
       
   209 	test(name.Compare(_L("Syphilis"))==KErrNone);
       
   210 	User::SetCurrencySymbol(name);
       
   211 	TCurrencySymbol name2;
       
   212 	test(name2.Compare(_L("Syphilis"))==KErrNone);
       
   213 	name2.Copy(_L("\xA3"));
       
   214 	User::SetCurrencySymbol(name2);
       
   215 	name.Set();
       
   216 	test(name.Compare(_L("\xA3"))==KErrNone);
       
   217 	}
       
   218 
       
   219 GLDEF_C TInt E32Main()
       
   220 	{
       
   221 
       
   222 	test.Title();
       
   223 	TestDayName();
       
   224 	TestDayNameAbb();
       
   225 	TestMonthName();
       
   226 	TestMonthNameAbb();
       
   227 	TestDateSuffix();
       
   228 	TestAmPmName();
       
   229 	TestCurrencySymbol();
       
   230 	test.End();
       
   231 
       
   232 	return(KErrNone);
       
   233 	}