|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: test sortutil.h |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // [INCLUDE FILES] |
|
23 #include <e32svr.h> |
|
24 #include <stifparser.h> |
|
25 #include <stiftestinterface.h> |
|
26 #include <sortutil.h> |
|
27 |
|
28 #include "testdomsortutil.h" |
|
29 #include "csortkeyarray.h" |
|
30 |
|
31 enum TReturnType |
|
32 { |
|
33 EErrExtraParamaters = KErrGeneral, |
|
34 EErrBadParamaters = KErrGeneral, |
|
35 EErrFailed = KErrGeneral |
|
36 }; |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CTestDOMSortUtil::RunMethodL |
|
42 // Run specified method. Contains also table of test mothods and their names. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 TInt CTestDOMSortUtil::RunMethodL( CStifItemParser& aItem ) |
|
46 { |
|
47 |
|
48 static TStifFunctionInfo const KFunctions[] = |
|
49 { |
|
50 // First string is the function name used in TestScripter script file. |
|
51 // Second is the actual implementation member function. |
|
52 |
|
53 // test functions of TSortKey class |
|
54 ENTRY( "TestSortKeyConstruct", CTestDOMSortUtil::TestSortKeyConstruct ), |
|
55 ENTRY( "TestSortKeyText", CTestDOMSortUtil::TestSortKeyText ), |
|
56 ENTRY( "TestSortKeyType", CTestDOMSortUtil::TestSortKeyType ), |
|
57 |
|
58 // test functions of CSortUtil class |
|
59 ENTRY( "TestSortUtilNewL", CTestDOMSortUtil::TestSortUtilNewL ), |
|
60 |
|
61 // test functions of MSortUtil class |
|
62 ENTRY( "TestSortUtilCompareItems", |
|
63 CTestDOMSortUtil::TestSortUtilCompareItemsL ), |
|
64 |
|
65 // [test cases entries] |
|
66 |
|
67 }; |
|
68 |
|
69 const TInt count = sizeof( KFunctions ) / sizeof( TStifFunctionInfo ); |
|
70 |
|
71 return RunInternalL( KFunctions, count, aItem ); |
|
72 |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CTestDOMSortUtil::TestSortKeyConstruct |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 TInt CTestDOMSortUtil::TestSortKeyConstruct( CStifItemParser& /*aItem*/ ) |
|
80 { |
|
81 |
|
82 // Print to UI |
|
83 _LIT( KTestDOMSortUtil, "testdomsortutil" ); |
|
84 _LIT( KTestSortKeyConstruct, "In SortKey Construct" ); |
|
85 TestModuleIf().Printf( 0, KTestDOMSortUtil, KTestSortKeyConstruct ); |
|
86 // Print to log file |
|
87 iLog->Log( KTestSortKeyConstruct ); |
|
88 |
|
89 _LIT( KText, "SoftKey" ); |
|
90 TSortKey sortKey( KText, ESortKeyBasic ); |
|
91 |
|
92 return KErrNone; |
|
93 |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CTestDOMSortUtil::TestSortKeyText |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TInt CTestDOMSortUtil::TestSortKeyText( CStifItemParser& /*aItem*/ ) |
|
101 { |
|
102 |
|
103 // Print to UI |
|
104 _LIT( KTestDOMSortUtil, "testdomsortutil" ); |
|
105 _LIT( KTestSortKeyText, "In SortKey Text" ); |
|
106 TestModuleIf().Printf( 0, KTestDOMSortUtil, KTestSortKeyText ); |
|
107 // Print to log file |
|
108 iLog->Log( KTestSortKeyText ); |
|
109 |
|
110 _LIT( KText, "text" ); |
|
111 TSortKey sortKey( KText, ESortKeyBasic ); |
|
112 |
|
113 TDesC text = sortKey.Text(); |
|
114 STIF_ASSERT_NOT_EQUALS( 0, text.Length() ); |
|
115 return KErrNone; |
|
116 |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CTestDOMSortUtil::TestSortKeyType |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 TInt CTestDOMSortUtil::TestSortKeyType( CStifItemParser& /*aItem*/ ) |
|
124 { |
|
125 |
|
126 // Print to UI |
|
127 _LIT( KTestDOMSortUtil, "testdomsortutil" ); |
|
128 _LIT( KTestSortKeyType, "In SortKey Type" ); |
|
129 TestModuleIf().Printf( 0, KTestDOMSortUtil, KTestSortKeyType ); |
|
130 // Print to log file |
|
131 iLog->Log( KTestSortKeyType ); |
|
132 |
|
133 _LIT( KText, "text" ); |
|
134 TSortKey sortKey( KText, ESortKeyBasic ); |
|
135 |
|
136 TSortKeyType type = sortKey.Type(); |
|
137 STIF_ASSERT_EQUALS( ESortKeyBasic, type ); |
|
138 return KErrNone; |
|
139 |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CTestDOMSortUtil::TestSortUtilNewL |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CTestDOMSortUtil::TestSortUtilNewL( CStifItemParser& /*aItem*/ ) |
|
147 { |
|
148 |
|
149 // Print to UI |
|
150 _LIT( KTestDOMSortUtil, "testdomsortutil" ); |
|
151 _LIT( KTestSortUtilNewL, "In SortUtil NewL" ); |
|
152 TestModuleIf().Printf( 0, KTestDOMSortUtil, KTestSortUtilNewL ); |
|
153 // Print to log file |
|
154 iLog->Log( KTestSortUtilNewL ); |
|
155 |
|
156 CSortUtil* sortUtil = CSortUtil::NewL(); |
|
157 CleanupStack::PushL( sortUtil ); |
|
158 STIF_ASSERT_NOT_NULL( sortUtil ); |
|
159 |
|
160 CleanupStack::PopAndDestroy( sortUtil ); |
|
161 return KErrNone; |
|
162 |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CTestDOMSortUtil::TestSortUtilCompareItemsL |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 TInt CTestDOMSortUtil::TestSortUtilCompareItemsL( CStifItemParser& aItem ) |
|
170 { |
|
171 |
|
172 // Print to UI |
|
173 _LIT( KSortUtilsTestClass, "testdomsortutil" ); |
|
174 _LIT( KTestSortUtilCompareItems, "In MSortUtil CompareItems" ); |
|
175 TestModuleIf().Printf( 0, KSortUtilsTestClass, KTestSortUtilCompareItems ); |
|
176 // Print to log file |
|
177 iLog->Log( KTestSortUtilCompareItems ); |
|
178 |
|
179 TInt numLhs = 0; |
|
180 TInt numRhs = 0; |
|
181 User::LeaveIfError(aItem.GetNextInt (numLhs)); |
|
182 __ASSERT_ALWAYS(numLhs > 0, User::Leave(EErrBadParamaters)); |
|
183 |
|
184 User::LeaveIfError(aItem.GetNextInt (numRhs)); |
|
185 __ASSERT_ALWAYS(numRhs > 0, User::Leave(EErrBadParamaters)); |
|
186 |
|
187 TPtrC lhs, rhs, extra; |
|
188 |
|
189 CSortUtil* sortUtil = CSortUtil::NewL(); |
|
190 CleanupStack::PushL( sortUtil ); |
|
191 CSortKeyArray* leftSortKeyArray = CSortKeyArray::NewL(); |
|
192 CleanupStack::PushL( leftSortKeyArray ); |
|
193 CSortKeyArray* rightSortKeyArray = CSortKeyArray::NewL(); |
|
194 CleanupStack::PushL( rightSortKeyArray ); |
|
195 |
|
196 leftSortKeyArray->Reset(); |
|
197 rightSortKeyArray->Reset(); |
|
198 |
|
199 aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing ); |
|
200 TInt i = 0; |
|
201 while( i != numLhs ) |
|
202 { |
|
203 User::LeaveIfError( aItem.GetNextString( lhs ) ); |
|
204 leftSortKeyArray->AppendL( TSortKey( KNullDesC, ESortKeyBasic ) ); |
|
205 leftSortKeyArray->SetText( lhs, i ); |
|
206 i++; |
|
207 } |
|
208 |
|
209 i = 0; |
|
210 while( i != numRhs ) |
|
211 { |
|
212 User::LeaveIfError( aItem.GetNextString( rhs ) ); |
|
213 rightSortKeyArray->AppendL( TSortKey( KNullDesC, ESortKeyBasic ) ); |
|
214 rightSortKeyArray->SetText( rhs, i ); |
|
215 i++; |
|
216 } |
|
217 |
|
218 TInt expectedResult; |
|
219 User::LeaveIfError( aItem.GetNextInt( expectedResult ) ); |
|
220 |
|
221 __ASSERT_ALWAYS( aItem.GetNextString( extra ) != KErrNone, User::Leave( EErrExtraParamaters ) ); |
|
222 |
|
223 TInt actualResult; |
|
224 actualResult = sortUtil->Interface()->CompareItems( *leftSortKeyArray, *rightSortKeyArray ); |
|
225 |
|
226 leftSortKeyArray->Reset(); |
|
227 rightSortKeyArray->Reset(); |
|
228 |
|
229 CleanupStack::PopAndDestroy( rightSortKeyArray ); |
|
230 CleanupStack::PopAndDestroy( leftSortKeyArray ); |
|
231 CleanupStack::PopAndDestroy( sortUtil ); |
|
232 |
|
233 if( ( expectedResult > 0 && actualResult > 0 ) || |
|
234 ( expectedResult < 0 && actualResult < 0 ) || |
|
235 ( expectedResult == 0 && actualResult == 0 ) ) |
|
236 return KErrNone; |
|
237 else |
|
238 return EErrFailed; |
|
239 } |
|
240 |
|
241 |
|
242 // [End of File] |