sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\locale\t_names.cpp sl@0: // Overview: sl@0: // Test Date, Time and Currency Symbol locale settings. sl@0: // API Information: sl@0: // TDayName,TDayNameAbb,TMonthName, TMonthNameAbb, TDateSuffix, TAmPmName, sl@0: // TCurrencySymbol. sl@0: // Details: sl@0: // - Construct and set the full, abbreviated text name for a day of the week, sl@0: // month and check it is as specified. sl@0: // - Construct and set date suffix text for a specific day in the month and sl@0: // test that constructor, TDateSuffix::Set panics when invalid parameters sl@0: // are passed. sl@0: // - Construct and assign current locale's text identifying time before noon, sl@0: // after noon and check it is as expected. sl@0: // - Assign the current locale's currency symbol with different text and check sl@0: // it is as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: #ifdef __VC32__ sl@0: // Solve compilation problem caused by non-English locale sl@0: #pragma setlocale("english") sl@0: #endif sl@0: sl@0: LOCAL_D RTest test(_L("T_NAMES")); sl@0: sl@0: void TestDayName() sl@0: { sl@0: test.Start(_L("TDayName")); sl@0: TDayName name1; sl@0: test(name1.Compare(_L("Monday"))==KErrNone); sl@0: TDayName name2(ESunday); sl@0: test(name2.Compare(_L("Sunday"))==KErrNone); sl@0: name1.Set(EWednesday); sl@0: test(name1.Compare(_L("Wednesday"))==KErrNone); sl@0: } sl@0: sl@0: void TestDayNameAbb() sl@0: { sl@0: test.Next(_L("TDayNameAbb")); sl@0: TDayNameAbb name1; sl@0: test(name1.Compare(_L("Mon"))==KErrNone); sl@0: TDayNameAbb name2(ETuesday); sl@0: test(name2.Compare(_L("Tue"))==KErrNone); sl@0: name1.Set(ESaturday); sl@0: test(name1.Compare(_L("Sat"))==KErrNone); sl@0: } sl@0: sl@0: void TestMonthName() sl@0: { sl@0: test.Next(_L("TMonthName")); sl@0: TMonthName name1; sl@0: test(name1.Compare(_L("January"))==KErrNone); sl@0: TMonthName name2(EDecember); sl@0: test(name2.Compare(_L("December"))==KErrNone); sl@0: name1.Set(EMarch); sl@0: test(name1.Compare(_L("March"))==KErrNone); sl@0: } sl@0: sl@0: void TestMonthNameAbb() sl@0: { sl@0: test.Next(_L("TMonthNameAbb")); sl@0: TMonthNameAbb name1; sl@0: test(name1.Compare(_L("Jan"))==KErrNone); sl@0: TMonthNameAbb name2(EFebruary); sl@0: test(name2.Compare(_L("Feb"))==KErrNone); sl@0: name1.Set(ENovember); sl@0: test(name1.Compare(_L("Nov"))==KErrNone); sl@0: } sl@0: sl@0: TInt TestThread1(TAny* Ptr) sl@0: // sl@0: // Used in TestDateSuffix() to test the constructor panics when silly parameters are passed sl@0: // sl@0: { sl@0: TDateSuffix ds((TInt) Ptr); sl@0: (void)ds; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: TInt TestThread2(TAny* Ptr) sl@0: // sl@0: // Used in TestDateSuffix() to test TDateSuffix::Set panics when silly parameters are passed sl@0: // sl@0: { sl@0: TDateSuffix suff(0); sl@0: suff.Set((TInt) Ptr); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: void TestDateSuffix() sl@0: { sl@0: test.Next(_L("TDateSuffix")); sl@0: sl@0: test.Start(_L("Simple creation and assignment")); sl@0: TDateSuffix suff1; sl@0: test(suff1.Compare(_L("st"))==KErrNone); sl@0: TDateSuffix suff2(1); sl@0: test(suff2.Compare(_L("nd"))==KErrNone); sl@0: suff1.Set(2); sl@0: test(suff1.Compare(_L("rd"))==KErrNone); sl@0: sl@0: test.Next(_L("Constructor in a thread")); sl@0: RThread thread; sl@0: TRequestStatus stat; sl@0: thread.Create(_L("Test Thread"),TestThread1,KDefaultStackSize,0x100,0x200,(TAny*)0); sl@0: thread.Logon(stat); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(thread.ExitType()==EExitKill); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Constructor panics for -1")); sl@0: thread.Create(_L("Test Thread"),TestThread1,KDefaultStackSize,0x100,0x200,(TAny*)-1); sl@0: thread.Logon(stat); sl@0: // don't want just in time debugging as we trap panics sl@0: TBool justInTime=User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: User::SetJustInTime(justInTime); sl@0: test(thread.ExitType()==EExitPanic); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Constructor panics for KMaxSuffices")); sl@0: thread.Create(_L("Test Thread"),TestThread1,KDefaultStackSize,0x100,0x200,(TAny*)KMaxSuffixes); sl@0: thread.Logon(stat); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: User::SetJustInTime(justInTime); sl@0: test(thread.ExitType()==EExitPanic); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Set in a thread")); sl@0: thread.Create(_L("Test Thread"),TestThread2,KDefaultStackSize,0x100,0x200,(TAny*)0); sl@0: thread.Logon(stat); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(thread.ExitType()==EExitKill); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Set panics for -1")); sl@0: thread.Create(_L("Test Thread"),TestThread2,KDefaultStackSize,0x100,0x200,(TAny*)-1); sl@0: thread.Logon(stat); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: User::SetJustInTime(justInTime); sl@0: test(thread.ExitType()==EExitPanic); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Set panics for KMaxSuffices")); sl@0: thread.Create(_L("Test Thread"),TestThread2,KDefaultStackSize,0x100,0x200,(TAny*)KMaxSuffixes); sl@0: thread.Logon(stat); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: User::SetJustInTime(justInTime); sl@0: test(thread.ExitType()==EExitPanic); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void TestAmPmName() sl@0: { sl@0: test.Next(_L("TAmPmName")); sl@0: TAmPmName name1; sl@0: test(name1.Compare(_L("am"))==KErrNone); sl@0: TAmPmName name2(EPm); sl@0: test(name2.Compare(_L("pm"))==KErrNone); sl@0: name1.Set(EPm); sl@0: test(name1.Compare(_L("pm"))==KErrNone); sl@0: } sl@0: sl@0: void TestCurrencySymbol() sl@0: { sl@0: test.Next(_L("TCurrencySymbol")); sl@0: TCurrencySymbol name; sl@0: test(name.Compare(_L("\xA3"))==KErrNone); sl@0: name[0]=0; sl@0: name.SetLength(0); sl@0: test(name.Compare(_L("\xA3"))!=KErrNone); sl@0: name.Set(); sl@0: test(name.Compare(_L("\xA3"))==KErrNone); sl@0: name.Copy(_L("Syphilis")); sl@0: test(name.Compare(_L("\xA3"))!=KErrNone); sl@0: test(name.Compare(_L("Syphilis"))==KErrNone); sl@0: User::SetCurrencySymbol(name); sl@0: TCurrencySymbol name2; sl@0: test(name2.Compare(_L("Syphilis"))==KErrNone); sl@0: name2.Copy(_L("\xA3")); sl@0: User::SetCurrencySymbol(name2); sl@0: name.Set(); sl@0: test(name.Compare(_L("\xA3"))==KErrNone); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: test.Title(); sl@0: TestDayName(); sl@0: TestDayNameAbb(); sl@0: TestMonthName(); sl@0: TestMonthNameAbb(); sl@0: TestDateSuffix(); sl@0: TestAmPmName(); sl@0: TestCurrencySymbol(); sl@0: test.End(); sl@0: sl@0: return(KErrNone); sl@0: }