|
1 /* |
|
2 * Copyright (c) 2006-2006 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: TGlxFromFocusOutwardIterator unit tests |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <digia/eunit/eunitmacros.h> |
|
22 |
|
23 #include "ut_tglxselectioniterator.h" |
|
24 |
|
25 // ---------------------------------------------------------------------------- |
|
26 // NewL |
|
27 // ---------------------------------------------------------------------------- |
|
28 // |
|
29 T_CGlxSelectionIterator* T_CGlxSelectionIterator::NewL() |
|
30 { |
|
31 T_CGlxSelectionIterator* self = T_CGlxSelectionIterator::NewLC(); |
|
32 CleanupStack::Pop(); |
|
33 return self; |
|
34 } |
|
35 |
|
36 // ---------------------------------------------------------------------------- |
|
37 // NewLC |
|
38 // ---------------------------------------------------------------------------- |
|
39 // |
|
40 T_CGlxSelectionIterator* T_CGlxSelectionIterator::NewLC() |
|
41 { |
|
42 T_CGlxSelectionIterator* self = new( ELeave ) T_CGlxSelectionIterator(); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ---------------------------------------------------------------------------- |
|
49 // Destructor |
|
50 // ---------------------------------------------------------------------------- |
|
51 // |
|
52 T_CGlxSelectionIterator::~T_CGlxSelectionIterator() |
|
53 { |
|
54 // Don't do anything |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // Constructor |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 T_CGlxSelectionIterator::T_CGlxSelectionIterator() |
|
62 : iList(NULL) |
|
63 { |
|
64 // Don't do anything |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // Constructor |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 void T_CGlxSelectionIterator::ConstructL() |
|
72 { |
|
73 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
74 // It generates the test case table. |
|
75 CEUnitTestSuiteClass::ConstructL(); |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // T_CGlxSelectionIterator::SetupL() |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 void T_CGlxSelectionIterator::SetupL() |
|
83 { |
|
84 iVirtualIterator = &iConcreateIterator; |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------------------------------- |
|
88 // T_CGlxSelectionIterator::Teardown() |
|
89 // ---------------------------------------------------------------------------- |
|
90 // |
|
91 void T_CGlxSelectionIterator::Teardown() |
|
92 { |
|
93 // Don't do anything |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // T_CGlxSelectionIterator::UT_TestOperatorPlusPlusL() |
|
98 // ---------------------------------------------------------------------------- |
|
99 // |
|
100 void T_CGlxSelectionIterator::UT_TestOperatorPlusPlusL() |
|
101 { |
|
102 |
|
103 RArray<TInt> selection; |
|
104 CleanupClosePushL(selection); |
|
105 |
|
106 selection.AppendL(0); |
|
107 selection.AppendL(1); |
|
108 selection.AppendL(2); |
|
109 |
|
110 Test(3, EFalse, 3, 0, selection, "012e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
111 Test(3, ETrue, 3, 0, selection, "012e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
112 |
|
113 Test(2, EFalse, 3, 0, selection, "01e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
114 Test(2, ETrue, 3, 0, selection, "e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
115 |
|
116 selection.Reset(); |
|
117 |
|
118 selection.AppendL(0); |
|
119 selection.AppendL(3); |
|
120 selection.AppendL(4); |
|
121 selection.AppendL(7); |
|
122 selection.AppendL(9); |
|
123 |
|
124 Test(13, EFalse, 14, 0, selection, "03479e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
125 Test(13, ETrue, 14, 0, selection, "03479e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
126 |
|
127 selection.Reset(); |
|
128 |
|
129 selection.AppendL(5); |
|
130 selection.AppendL(9); |
|
131 |
|
132 Test(13, EFalse, 11, 0, selection, "59e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
133 Test(1, EFalse, 11, 0, selection, "5e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
134 Test(1, ETrue, 11, 0, selection, "e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
135 |
|
136 selection.Reset(); |
|
137 |
|
138 // Focus no selection |
|
139 Test(13, EFalse, 10, 4, selection, "4e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
140 |
|
141 Test(13, ETrue, 10, 4, selection, "4e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
142 Test(1, ETrue, 10, 4, selection, "4e"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
143 |
|
144 CleanupStack::PopAndDestroy(&selection); |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // T_CGlxSelectionIterator::UT_TestInRangeL() |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 void T_CGlxSelectionIterator::UT_TestInRangeL() |
|
152 { |
|
153 RArray<TInt> selection; |
|
154 CleanupClosePushL(selection); |
|
155 |
|
156 selection.AppendL(0); |
|
157 selection.AppendL(1); |
|
158 selection.AppendL(2); |
|
159 |
|
160 TestSingleInRange(3, EFalse, 3, 0, selection, "xxx"); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
161 TestSingleInRange(4, EFalse, 4, 0, selection, "xxx "); |
|
162 TestSingleInRange(4, EFalse, 3, 0, selection, "xxx"); |
|
163 TestSingleInRange(4, ETrue, 3, 0, selection, "xxx"); |
|
164 TestSingleInRange(2, EFalse, 4, 0, selection, "xx "); |
|
165 TestSingleInRange(2, ETrue, 4, 0, selection, " "); |
|
166 |
|
167 selection.Reset(); |
|
168 |
|
169 selection.AppendL(2); |
|
170 selection.AppendL(4); |
|
171 |
|
172 TestSingleInRange(3, EFalse, 6, 0, selection, " x x "); // range, disable_if_more_than_range_selected, list count, focus index, selection, result |
|
173 TestSingleInRange(4, EFalse, 5, 0, selection, " x x"); |
|
174 TestSingleInRange(4, ETrue, 6, 0, selection, " x x "); |
|
175 TestSingleInRange(2, EFalse, 6, 0, selection, " x x "); |
|
176 TestSingleInRange(2, ETrue, 6, 0, selection, " x x "); |
|
177 TestSingleInRange(1, EFalse, 6, 0, selection, " x "); |
|
178 TestSingleInRange(1, ETrue, 6, 0, selection, " "); |
|
179 |
|
180 CleanupStack::PopAndDestroy(&selection); |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // T_CGlxSelectionIterator::Test |
|
185 // ---------------------------------------------------------------------------- |
|
186 // |
|
187 void T_CGlxSelectionIterator::Test(TInt aRange, TBool aDisabledIfMoreThanRangeSelected, |
|
188 TInt aListCount, TInt aFocusIndex, RArray<TInt>& aSelection, const char* aResults) |
|
189 { |
|
190 |
|
191 __ASSERT_DEBUG(aFocusIndex >= 0 && aFocusIndex < aListCount && aListCount >= 0, Panic(EGlxPanicIllegalArgument)); // Make sure is testing all cases, also failed case |
|
192 |
|
193 iConcreateIterator.SetRange(aRange); |
|
194 iConcreateIterator.SetDisabledIfMoreThanRangeSelected(aDisabledIfMoreThanRangeSelected); |
|
195 iVirtualIterator->SetToFirst(&iList); |
|
196 iList.iCount = aListCount; |
|
197 iList.iFocus = aFocusIndex; |
|
198 iList.iSelection = aSelection; |
|
199 TInt resultCount = User::StringLength(reinterpret_cast<const TUint8*>(aResults)); |
|
200 |
|
201 for (TInt i = 0; i < resultCount; i++) |
|
202 { |
|
203 TInt result = (*iVirtualIterator)++; |
|
204 char c = aResults[i]; |
|
205 TInt expectedResult = c - '0'; |
|
206 if (c == 'e') |
|
207 { |
|
208 expectedResult = KErrNotFound; |
|
209 } |
|
210 EUNIT_ASSERT(result == expectedResult); |
|
211 } |
|
212 } |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // T_CGlxSelectionIterator::TestSingleInRange |
|
216 // ---------------------------------------------------------------------------- |
|
217 // |
|
218 void T_CGlxSelectionIterator::TestSingleInRange( |
|
219 TInt aRange, TBool aDisabledIfMoreThanRangeSelected, TInt aListCount, |
|
220 TInt aFocusIndex, RArray<TInt>& aSelection, const char* aResult) |
|
221 { |
|
222 __ASSERT_DEBUG(aFocusIndex >= 0 && aFocusIndex < aListCount && aListCount >= 0, Panic(EGlxPanicIllegalArgument)); // Make sure is testing all cases, also failed case |
|
223 iConcreateIterator.SetRange(aRange); |
|
224 iConcreateIterator.SetDisabledIfMoreThanRangeSelected(aDisabledIfMoreThanRangeSelected); |
|
225 iVirtualIterator->SetToFirst(&iList); |
|
226 iList.iCount = aListCount; |
|
227 iList.iFocus = aFocusIndex; |
|
228 iList.iSelection = aSelection; |
|
229 |
|
230 |
|
231 for (TInt i = 0; i < aListCount; i++) |
|
232 { |
|
233 char c = aResult[i]; |
|
234 __ASSERT_DEBUG(c != 0, Panic(EGlxPanicIllegalArgument)); // Not enough results |
|
235 |
|
236 TBool inRange = iVirtualIterator->InRange(i); |
|
237 EUNIT_ASSERT((inRange && c == 'x') || (!inRange && c == ' ')); |
|
238 } |
|
239 |
|
240 } |
|
241 |
|
242 |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // Test table |
|
246 // ---------------------------------------------------------------------------- |
|
247 // |
|
248 |
|
249 EUNIT_BEGIN_TEST_TABLE( |
|
250 T_CGlxSelectionIterator, |
|
251 "Unit tests for T_CGlxSelectionIterator", |
|
252 "UNIT" ) |
|
253 |
|
254 EUNIT_TEST( |
|
255 "Test operator++", |
|
256 "TGlxSelectionIterator", |
|
257 "++", |
|
258 "FUNCTIONALITY", |
|
259 SetupL, UT_TestOperatorPlusPlusL, Teardown) |
|
260 |
|
261 EUNIT_TEST( |
|
262 "Test InRange", |
|
263 "TGlxSelectionIterator", |
|
264 "++", |
|
265 "FUNCTIONALITY", |
|
266 SetupL, UT_TestInRangeL, Teardown) |
|
267 |
|
268 EUNIT_END_TEST_TABLE |
|
269 // END OF FILE |