sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "../sfields/FLDNUMS.H"
|
sl@0
|
20 |
#include "T_ROMAN.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
#define test(cond) \
|
sl@0
|
23 |
{ \
|
sl@0
|
24 |
TBool __bb = (cond); \
|
sl@0
|
25 |
TEST(__bb); \
|
sl@0
|
26 |
if (!__bb) \
|
sl@0
|
27 |
{ \
|
sl@0
|
28 |
ERR_PRINTF1(_L("ERROR: Test Failed")); \
|
sl@0
|
29 |
User::Leave(1); \
|
sl@0
|
30 |
} \
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
#define UNUSED_VAR(a) a = a
|
sl@0
|
34 |
|
sl@0
|
35 |
const TInt KTestCleanupStack=0x40;
|
sl@0
|
36 |
|
sl@0
|
37 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
38 |
|
sl@0
|
39 |
//
|
sl@0
|
40 |
|
sl@0
|
41 |
void CT_ROMAN::GetValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
TPtr ptr=aBuf->Des();
|
sl@0
|
44 |
TInt size=aNumeral.DeneryToChar(ptr,aDenery);
|
sl@0
|
45 |
if (size>0)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
aBuf->ReAlloc(size);
|
sl@0
|
48 |
ptr=aBuf->Des();
|
sl@0
|
49 |
size = aNumeral.DeneryToChar(ptr,aDenery);
|
sl@0
|
50 |
test(size==KErrNone);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
|
sl@0
|
55 |
void CT_ROMAN::DisplayValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
GetValue(aBuf,aDenery,aNumeral);
|
sl@0
|
58 |
INFO_PRINTF2(_L("%D: "),aDenery);
|
sl@0
|
59 |
INFO_PRINTF1(*aBuf);
|
sl@0
|
60 |
INFO_PRINTF1(_L("\n"));
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
void CT_ROMAN::test1()
|
sl@0
|
65 |
{
|
sl@0
|
66 |
INFO_PRINTF1(_L("Testing with buffer of adequate size"));
|
sl@0
|
67 |
INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-T_ROMAN-0001 "));
|
sl@0
|
68 |
HBufC* hbuf = HBufC::NewL(10);
|
sl@0
|
69 |
CleanupStack::PushL(hbuf);
|
sl@0
|
70 |
TRomanNumeral roman;
|
sl@0
|
71 |
GetValue(hbuf,4,roman);
|
sl@0
|
72 |
TPtr buf = hbuf->Des();
|
sl@0
|
73 |
test(buf==_L("IV"));
|
sl@0
|
74 |
CleanupStack::PopAndDestroy();
|
sl@0
|
75 |
//
|
sl@0
|
76 |
INFO_PRINTF1(_L("Testing with inadequate buffer"));
|
sl@0
|
77 |
HBufC* minibuf = HBufC::NewL(1);
|
sl@0
|
78 |
CleanupStack::PushL(minibuf);
|
sl@0
|
79 |
GetValue(minibuf,4,roman);
|
sl@0
|
80 |
TPtr buf2 = minibuf->Des();
|
sl@0
|
81 |
test(buf2==_L("IV"));
|
sl@0
|
82 |
CleanupStack::PopAndDestroy();
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
|
sl@0
|
86 |
void CT_ROMAN::test2()
|
sl@0
|
87 |
{
|
sl@0
|
88 |
INFO_PRINTF1(_L("Testing Roman numerals for a range of denery values"));
|
sl@0
|
89 |
HBufC* hbuf = HBufC::NewL(10);
|
sl@0
|
90 |
CleanupStack::PushL(hbuf);
|
sl@0
|
91 |
TRomanNumeral roman;
|
sl@0
|
92 |
|
sl@0
|
93 |
DisplayValue(hbuf,1,roman);
|
sl@0
|
94 |
test(0 == hbuf->CompareC(_L("i"), 1, 0));
|
sl@0
|
95 |
DisplayValue(hbuf,4,roman);
|
sl@0
|
96 |
test(0 == hbuf->CompareC(_L("iv"), 1, 0));
|
sl@0
|
97 |
DisplayValue(hbuf,9,roman);
|
sl@0
|
98 |
test(0 == hbuf->CompareC(_L("ix"), 1, 0));
|
sl@0
|
99 |
DisplayValue(hbuf,17,roman);
|
sl@0
|
100 |
test(0 == hbuf->CompareC(_L("xvii"), 1, 0));
|
sl@0
|
101 |
DisplayValue(hbuf,34,roman);
|
sl@0
|
102 |
test(0 == hbuf->CompareC(_L("xxxiv"), 1, 0));
|
sl@0
|
103 |
DisplayValue(hbuf,99,roman);
|
sl@0
|
104 |
test(0 == hbuf->CompareC(_L("xcix"), 1, 0));
|
sl@0
|
105 |
DisplayValue(hbuf,143,roman);
|
sl@0
|
106 |
test(0 == hbuf->CompareC(_L("cxliii"), 1, 0));
|
sl@0
|
107 |
DisplayValue(hbuf,1982,roman);
|
sl@0
|
108 |
test(0 == hbuf->CompareC(_L("mcmlxxxii"), 1, 0));
|
sl@0
|
109 |
|
sl@0
|
110 |
CleanupStack::PopAndDestroy();
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
|
sl@0
|
114 |
void CT_ROMAN::test3()
|
sl@0
|
115 |
{
|
sl@0
|
116 |
INFO_PRINTF1(_L("Testing alphabetic numerals for a range of denery values"));
|
sl@0
|
117 |
HBufC* hbuf = HBufC::NewL(10);
|
sl@0
|
118 |
CleanupStack::PushL(hbuf);
|
sl@0
|
119 |
TAlphabeticNumeral alpha;
|
sl@0
|
120 |
|
sl@0
|
121 |
DisplayValue(hbuf,1,alpha);
|
sl@0
|
122 |
test(0 == hbuf->CompareC(_L("a"), 1, 0));
|
sl@0
|
123 |
DisplayValue(hbuf,4,alpha);
|
sl@0
|
124 |
test(0 == hbuf->CompareC(_L("d"), 1, 0));
|
sl@0
|
125 |
DisplayValue(hbuf,9,alpha);
|
sl@0
|
126 |
test(0 == hbuf->CompareC(_L("i"), 1, 0));
|
sl@0
|
127 |
DisplayValue(hbuf,17,alpha);
|
sl@0
|
128 |
test(0 == hbuf->CompareC(_L("q"), 1, 0));
|
sl@0
|
129 |
DisplayValue(hbuf,34,alpha);
|
sl@0
|
130 |
test(0 == hbuf->CompareC(_L("ah"), 1, 0));
|
sl@0
|
131 |
DisplayValue(hbuf,99,alpha);
|
sl@0
|
132 |
test(0 == hbuf->CompareC(_L("cu"), 1, 0));
|
sl@0
|
133 |
DisplayValue(hbuf,143,alpha);
|
sl@0
|
134 |
test(0 == hbuf->CompareC(_L("em"), 1, 0));
|
sl@0
|
135 |
DisplayValue(hbuf,1982,alpha);
|
sl@0
|
136 |
test(0 == hbuf->CompareC(_L("bxf"), 1, 0));
|
sl@0
|
137 |
|
sl@0
|
138 |
CleanupStack::PopAndDestroy();
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
|
sl@0
|
142 |
void CT_ROMAN::runTests()
|
sl@0
|
143 |
// Test the fields dll.
|
sl@0
|
144 |
//
|
sl@0
|
145 |
{
|
sl@0
|
146 |
// test with HBufs both large enough and too small
|
sl@0
|
147 |
test1();
|
sl@0
|
148 |
|
sl@0
|
149 |
// test for a range of denery values
|
sl@0
|
150 |
test2();
|
sl@0
|
151 |
|
sl@0
|
152 |
// Test alphabetics
|
sl@0
|
153 |
test3();
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
|
sl@0
|
157 |
void CT_ROMAN::setupCleanup()
|
sl@0
|
158 |
//
|
sl@0
|
159 |
// Initialise the cleanup stack.
|
sl@0
|
160 |
//
|
sl@0
|
161 |
{
|
sl@0
|
162 |
|
sl@0
|
163 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
164 |
TRAPD(r,\
|
sl@0
|
165 |
{\
|
sl@0
|
166 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
167 |
CleanupStack::PushL((TAny*)1);\
|
sl@0
|
168 |
test(r==KErrNone);\
|
sl@0
|
169 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
170 |
});
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
CT_ROMAN::CT_ROMAN()
|
sl@0
|
174 |
{
|
sl@0
|
175 |
SetTestStepName(KTestStep_T_ROMAN);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
TVerdict CT_ROMAN::doTestStepL()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
INFO_PRINTF1(_L("Testing denery to Roman numeral converter"));
|
sl@0
|
181 |
SetTestStepResult(EFail);
|
sl@0
|
182 |
|
sl@0
|
183 |
__UHEAP_MARK;
|
sl@0
|
184 |
|
sl@0
|
185 |
setupCleanup();
|
sl@0
|
186 |
|
sl@0
|
187 |
TRAPD(error1, runTests());
|
sl@0
|
188 |
|
sl@0
|
189 |
delete TheTrapCleanup;
|
sl@0
|
190 |
|
sl@0
|
191 |
__UHEAP_MARKEND;
|
sl@0
|
192 |
|
sl@0
|
193 |
if(error1 == KErrNone)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
SetTestStepResult(EPass);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
return TestStepResult();
|
sl@0
|
199 |
}
|