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