Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "../sfields/FLDNUMS.H"
24 TBool __bb = (cond); \
28 ERR_PRINTF1(_L("ERROR: Test Failed")); \
33 #define UNUSED_VAR(a) a = a
35 const TInt KTestCleanupStack=0x40;
37 LOCAL_D CTrapCleanup* TheTrapCleanup;
41 void CT_ROMAN::GetValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
44 TInt size=aNumeral.DeneryToChar(ptr,aDenery);
49 size = aNumeral.DeneryToChar(ptr,aDenery);
55 void CT_ROMAN::DisplayValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
57 GetValue(aBuf,aDenery,aNumeral);
58 INFO_PRINTF2(_L("%D: "),aDenery);
60 INFO_PRINTF1(_L("\n"));
64 void CT_ROMAN::test1()
66 INFO_PRINTF1(_L("Testing with buffer of adequate size"));
67 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-T_ROMAN-0001 "));
68 HBufC* hbuf = HBufC::NewL(10);
69 CleanupStack::PushL(hbuf);
71 GetValue(hbuf,4,roman);
72 TPtr buf = hbuf->Des();
74 CleanupStack::PopAndDestroy();
76 INFO_PRINTF1(_L("Testing with inadequate buffer"));
77 HBufC* minibuf = HBufC::NewL(1);
78 CleanupStack::PushL(minibuf);
79 GetValue(minibuf,4,roman);
80 TPtr buf2 = minibuf->Des();
82 CleanupStack::PopAndDestroy();
86 void CT_ROMAN::test2()
88 INFO_PRINTF1(_L("Testing Roman numerals for a range of denery values"));
89 HBufC* hbuf = HBufC::NewL(10);
90 CleanupStack::PushL(hbuf);
93 DisplayValue(hbuf,1,roman);
94 test(0 == hbuf->CompareC(_L("i"), 1, 0));
95 DisplayValue(hbuf,4,roman);
96 test(0 == hbuf->CompareC(_L("iv"), 1, 0));
97 DisplayValue(hbuf,9,roman);
98 test(0 == hbuf->CompareC(_L("ix"), 1, 0));
99 DisplayValue(hbuf,17,roman);
100 test(0 == hbuf->CompareC(_L("xvii"), 1, 0));
101 DisplayValue(hbuf,34,roman);
102 test(0 == hbuf->CompareC(_L("xxxiv"), 1, 0));
103 DisplayValue(hbuf,99,roman);
104 test(0 == hbuf->CompareC(_L("xcix"), 1, 0));
105 DisplayValue(hbuf,143,roman);
106 test(0 == hbuf->CompareC(_L("cxliii"), 1, 0));
107 DisplayValue(hbuf,1982,roman);
108 test(0 == hbuf->CompareC(_L("mcmlxxxii"), 1, 0));
110 CleanupStack::PopAndDestroy();
114 void CT_ROMAN::test3()
116 INFO_PRINTF1(_L("Testing alphabetic numerals for a range of denery values"));
117 HBufC* hbuf = HBufC::NewL(10);
118 CleanupStack::PushL(hbuf);
119 TAlphabeticNumeral alpha;
121 DisplayValue(hbuf,1,alpha);
122 test(0 == hbuf->CompareC(_L("a"), 1, 0));
123 DisplayValue(hbuf,4,alpha);
124 test(0 == hbuf->CompareC(_L("d"), 1, 0));
125 DisplayValue(hbuf,9,alpha);
126 test(0 == hbuf->CompareC(_L("i"), 1, 0));
127 DisplayValue(hbuf,17,alpha);
128 test(0 == hbuf->CompareC(_L("q"), 1, 0));
129 DisplayValue(hbuf,34,alpha);
130 test(0 == hbuf->CompareC(_L("ah"), 1, 0));
131 DisplayValue(hbuf,99,alpha);
132 test(0 == hbuf->CompareC(_L("cu"), 1, 0));
133 DisplayValue(hbuf,143,alpha);
134 test(0 == hbuf->CompareC(_L("em"), 1, 0));
135 DisplayValue(hbuf,1982,alpha);
136 test(0 == hbuf->CompareC(_L("bxf"), 1, 0));
138 CleanupStack::PopAndDestroy();
142 void CT_ROMAN::runTests()
143 // Test the fields dll.
146 // test with HBufs both large enough and too small
149 // test for a range of denery values
157 void CT_ROMAN::setupCleanup()
159 // Initialise the cleanup stack.
163 TheTrapCleanup=CTrapCleanup::New();
166 for (TInt i=KTestCleanupStack;i>0;i--)\
167 CleanupStack::PushL((TAny*)1);\
169 CleanupStack::Pop(KTestCleanupStack);\
175 SetTestStepName(KTestStep_T_ROMAN);
178 TVerdict CT_ROMAN::doTestStepL()
180 INFO_PRINTF1(_L("Testing denery to Roman numeral converter"));
181 SetTestStepResult(EFail);
187 TRAPD(error1, runTests());
189 delete TheTrapCleanup;
193 if(error1 == KErrNone)
195 SetTestStepResult(EPass);
198 return TestStepResult();