1 /*! |
|
2 * Copyright (c) 2009 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: Unit tests for StringLoader. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QtGui> |
|
20 #include <hbapplication.h> |
|
21 #include <QSignalSpy> |
|
22 //#include <hbglobal_p.h> |
|
23 #include <stringloader.h> |
|
24 #include "phoneaction.h" |
|
25 #include "phoneresourceadapter.h" |
|
26 |
|
27 class TestPhoneStringLoader : public QObject |
|
28 { |
|
29 Q_OBJECT |
|
30 public: |
|
31 TestPhoneStringLoader(); |
|
32 virtual ~TestPhoneStringLoader(); |
|
33 |
|
34 public slots: |
|
35 void initTestCase (); |
|
36 void cleanupTestCase (); |
|
37 void init (); |
|
38 void cleanup (); |
|
39 |
|
40 private slots: |
|
41 void testLoad (); |
|
42 void testLoadL1 (); |
|
43 void testLoadL2 (); |
|
44 void testLoadL3 (); |
|
45 void testLoadL4 (); |
|
46 void testLoadL5 (); |
|
47 void testLoadL6 (); |
|
48 void testLoadL7 (); |
|
49 void testLoadLC1 (); |
|
50 void testLoadLC2 (); |
|
51 void testLoadLC3 (); |
|
52 void testLoadLC4 (); |
|
53 void testLoadLC5 (); |
|
54 void testLoadLC6 (); |
|
55 void testLoadLC7 (); |
|
56 }; |
|
57 |
|
58 int m_resourceId; |
|
59 bool m_convertCalled; |
|
60 bool m_set_text_map; |
|
61 PhoneResourceAdapter* m_resource_adapter; |
|
62 |
|
63 PhoneResourceAdapter* PhoneResourceAdapter::Instance (QObject *parent) |
|
64 { |
|
65 |
|
66 Q_UNUSED (parent); |
|
67 if ( 0 == m_resource_adapter ) |
|
68 m_resource_adapter = new PhoneResourceAdapter; |
|
69 |
|
70 return m_resource_adapter; |
|
71 } |
|
72 |
|
73 QMap<PhoneAction::ActionType, PhoneAction *> PhoneResourceAdapter::convert (int symbianResourceId, ...) |
|
74 { |
|
75 m_resourceId = symbianResourceId; |
|
76 m_convertCalled = true; |
|
77 QMap<PhoneAction::ActionType, PhoneAction *> map; |
|
78 if (m_set_text_map) { |
|
79 PhoneAction *text = new PhoneAction; |
|
80 text->setText(tr("Test")); |
|
81 map[PhoneAction::Text] = text; |
|
82 } |
|
83 |
|
84 return map; |
|
85 } |
|
86 |
|
87 TestPhoneStringLoader::TestPhoneStringLoader () |
|
88 { |
|
89 } |
|
90 |
|
91 TestPhoneStringLoader::~TestPhoneStringLoader () |
|
92 { |
|
93 } |
|
94 |
|
95 void TestPhoneStringLoader::initTestCase () |
|
96 { |
|
97 } |
|
98 |
|
99 void TestPhoneStringLoader::cleanupTestCase () |
|
100 { |
|
101 } |
|
102 |
|
103 void TestPhoneStringLoader::init () |
|
104 { |
|
105 m_resourceId = -1; |
|
106 m_convertCalled = false; |
|
107 m_set_text_map = false; |
|
108 } |
|
109 |
|
110 void TestPhoneStringLoader::cleanup () |
|
111 { |
|
112 delete m_resource_adapter; |
|
113 m_resource_adapter = 0; |
|
114 } |
|
115 |
|
116 void TestPhoneStringLoader::testLoad () |
|
117 { |
|
118 TBuf<255> string(KNullDesC); |
|
119 StringLoader::Load(string, 1000); |
|
120 QCOMPARE (m_resourceId, 1000); |
|
121 QCOMPARE (m_convertCalled, true); |
|
122 |
|
123 m_set_text_map = true; |
|
124 StringLoader::Load(string, 1000); |
|
125 QCOMPARE (m_resourceId, 1000); |
|
126 QCOMPARE (m_convertCalled, true); |
|
127 |
|
128 } |
|
129 |
|
130 void TestPhoneStringLoader::testLoadL1 () |
|
131 { |
|
132 HBufC *buf = StringLoader::LoadL(1000); |
|
133 QCOMPARE (m_resourceId, 1000); |
|
134 QCOMPARE (m_convertCalled, true); |
|
135 delete buf; |
|
136 |
|
137 m_set_text_map = true; |
|
138 buf = StringLoader::LoadL(1000); |
|
139 QCOMPARE (m_resourceId, 1000); |
|
140 QCOMPARE (m_convertCalled, true); |
|
141 delete buf; |
|
142 } |
|
143 |
|
144 void TestPhoneStringLoader::testLoadL2 () |
|
145 { |
|
146 HBufC *buf = StringLoader::LoadL(1234, 3); |
|
147 QCOMPARE (m_resourceId, 1234); |
|
148 QCOMPARE (m_convertCalled, true); |
|
149 delete buf; |
|
150 |
|
151 m_set_text_map = true; |
|
152 buf = StringLoader::LoadL(1234, 3); |
|
153 QCOMPARE (m_resourceId, 1234); |
|
154 QCOMPARE (m_convertCalled, true); |
|
155 delete buf; |
|
156 } |
|
157 |
|
158 void TestPhoneStringLoader::testLoadL3 () |
|
159 { |
|
160 TBuf<255> string(KNullDesC); |
|
161 HBufC *buf = StringLoader::LoadL(1234, string); |
|
162 QCOMPARE (m_resourceId, 1234); |
|
163 QCOMPARE (m_convertCalled, true); |
|
164 delete buf; |
|
165 |
|
166 m_set_text_map = true; |
|
167 buf = StringLoader::LoadL(1234, string); |
|
168 QCOMPARE (m_resourceId, 1234); |
|
169 QCOMPARE (m_convertCalled, true); |
|
170 delete buf; |
|
171 } |
|
172 |
|
173 void TestPhoneStringLoader::testLoadL4 () |
|
174 { |
|
175 TBuf<255> string(KNullDesC); |
|
176 HBufC *buf = StringLoader::LoadL(666, string, 5); |
|
177 QCOMPARE (m_resourceId, 666); |
|
178 QCOMPARE (m_convertCalled, true); |
|
179 delete buf; |
|
180 |
|
181 m_set_text_map = true; |
|
182 buf = StringLoader::LoadL(666, string, 5); |
|
183 QCOMPARE (m_resourceId, 666); |
|
184 QCOMPARE (m_convertCalled, true); |
|
185 delete buf; |
|
186 } |
|
187 |
|
188 void TestPhoneStringLoader::testLoadL5 () |
|
189 { |
|
190 CArrayFixFlat<TInt>* list = new(ELeave)CArrayFixFlat<TInt>(2); |
|
191 HBufC *buf = StringLoader::LoadL(4321, *list); |
|
192 QCOMPARE (m_resourceId, 4321); |
|
193 QCOMPARE (m_convertCalled, true); |
|
194 delete buf; |
|
195 |
|
196 m_set_text_map = true; |
|
197 buf = StringLoader::LoadL(4321, *list); |
|
198 QCOMPARE (m_resourceId, 4321); |
|
199 QCOMPARE (m_convertCalled, true); |
|
200 delete list; |
|
201 delete buf; |
|
202 } |
|
203 |
|
204 void TestPhoneStringLoader::testLoadL6 () |
|
205 { |
|
206 CDesCArray *list = new ( ELeave )CDesCArrayFlat(2); |
|
207 HBufC *buf = StringLoader::LoadL(555, *list); |
|
208 QCOMPARE (m_resourceId, 555); |
|
209 QCOMPARE (m_convertCalled, true); |
|
210 delete buf; |
|
211 |
|
212 m_set_text_map = true; |
|
213 buf = StringLoader::LoadL(555, *list); |
|
214 QCOMPARE (m_resourceId, 555); |
|
215 QCOMPARE (m_convertCalled, true); |
|
216 delete list; |
|
217 delete buf; |
|
218 } |
|
219 |
|
220 void TestPhoneStringLoader::testLoadL7 () |
|
221 { |
|
222 CDesCArray *list = new ( ELeave )CDesCArrayFlat(2); |
|
223 CArrayFixFlat<TInt>* list2 = new(ELeave)CArrayFixFlat<TInt>(2); |
|
224 HBufC *buf = StringLoader::LoadL(5678, *list, *list2); |
|
225 QCOMPARE (m_resourceId, 5678); |
|
226 QCOMPARE (m_convertCalled, true); |
|
227 delete buf; |
|
228 |
|
229 m_set_text_map = true; |
|
230 buf = StringLoader::LoadL(5678, *list, *list2); |
|
231 QCOMPARE (m_resourceId, 5678); |
|
232 QCOMPARE (m_convertCalled, true); |
|
233 delete list; |
|
234 delete list2; |
|
235 delete buf; |
|
236 } |
|
237 |
|
238 void TestPhoneStringLoader::testLoadLC1 () |
|
239 { |
|
240 HBufC *buf = 0; |
|
241 TRAP_IGNORE( |
|
242 buf = StringLoader::LoadLC(1001); |
|
243 QCOMPARE (m_resourceId, 1001); |
|
244 QCOMPARE (m_convertCalled, true); |
|
245 CleanupStack::PopAndDestroy( buf ); |
|
246 ); |
|
247 |
|
248 m_set_text_map = true; |
|
249 TRAP_IGNORE( |
|
250 buf = StringLoader::LoadLC(1001); |
|
251 QCOMPARE (m_resourceId, 1001); |
|
252 QCOMPARE (m_convertCalled, true); |
|
253 CleanupStack::PopAndDestroy( buf ); |
|
254 ); |
|
255 } |
|
256 |
|
257 void TestPhoneStringLoader::testLoadLC2 () |
|
258 { |
|
259 HBufC *buf = 0; |
|
260 TRAP_IGNORE( |
|
261 buf = StringLoader::LoadLC(1235, 2); |
|
262 QCOMPARE (m_resourceId, 1235); |
|
263 QCOMPARE (m_convertCalled, true); |
|
264 CleanupStack::PopAndDestroy( buf ); |
|
265 ); |
|
266 |
|
267 m_set_text_map = true; |
|
268 |
|
269 TRAP_IGNORE( |
|
270 buf = StringLoader::LoadLC(1235, 2); |
|
271 QCOMPARE (m_resourceId, 1235); |
|
272 QCOMPARE (m_convertCalled, true); |
|
273 CleanupStack::PopAndDestroy( buf ); |
|
274 ); |
|
275 } |
|
276 |
|
277 void TestPhoneStringLoader::testLoadLC3 () |
|
278 { |
|
279 HBufC *buf = 0; |
|
280 TBuf<255> string(KNullDesC); |
|
281 TRAP_IGNORE( |
|
282 buf = StringLoader::LoadLC(1234, string); |
|
283 QCOMPARE (m_resourceId, 1234); |
|
284 QCOMPARE (m_convertCalled, true); |
|
285 CleanupStack::PopAndDestroy( buf ); |
|
286 ); |
|
287 |
|
288 m_set_text_map = true; |
|
289 TRAP_IGNORE( |
|
290 buf = StringLoader::LoadLC(1234, string); |
|
291 QCOMPARE (m_resourceId, 1234); |
|
292 QCOMPARE (m_convertCalled, true); |
|
293 CleanupStack::PopAndDestroy( buf ); |
|
294 ); |
|
295 } |
|
296 |
|
297 void TestPhoneStringLoader::testLoadLC4 () |
|
298 { |
|
299 HBufC *buf = 0; |
|
300 TBuf<255> string(KNullDesC); |
|
301 |
|
302 TRAP_IGNORE( |
|
303 buf = StringLoader::LoadLC(667, string, 9); |
|
304 QCOMPARE (m_resourceId, 667); |
|
305 QCOMPARE (m_convertCalled, true); |
|
306 CleanupStack::PopAndDestroy( buf ); |
|
307 ); |
|
308 |
|
309 m_set_text_map = true; |
|
310 |
|
311 TRAP_IGNORE( |
|
312 buf = StringLoader::LoadLC(667, string, 9); |
|
313 QCOMPARE (m_resourceId, 667); |
|
314 QCOMPARE (m_convertCalled, true); |
|
315 CleanupStack::PopAndDestroy( buf ); |
|
316 ); |
|
317 } |
|
318 |
|
319 void TestPhoneStringLoader::testLoadLC5 () |
|
320 { |
|
321 HBufC *buf = 0; |
|
322 CArrayFixFlat<TInt>* list = new(ELeave)CArrayFixFlat<TInt>(2); |
|
323 |
|
324 TRAP_IGNORE( |
|
325 buf = StringLoader::LoadLC(4322, *list); |
|
326 QCOMPARE (m_resourceId, 4322); |
|
327 QCOMPARE (m_convertCalled, true); |
|
328 CleanupStack::PopAndDestroy( buf ); |
|
329 ); |
|
330 |
|
331 m_set_text_map = true; |
|
332 |
|
333 TRAP_IGNORE( |
|
334 buf = StringLoader::LoadLC(4322, *list); |
|
335 QCOMPARE (m_resourceId, 4322); |
|
336 QCOMPARE (m_convertCalled, true); |
|
337 CleanupStack::PopAndDestroy( buf ); |
|
338 ); |
|
339 delete list; |
|
340 } |
|
341 |
|
342 void TestPhoneStringLoader::testLoadLC6 () |
|
343 { |
|
344 HBufC *buf = 0; |
|
345 CDesCArray *list = new ( ELeave )CDesCArrayFlat(5); |
|
346 |
|
347 TRAP_IGNORE( |
|
348 buf = StringLoader::LoadLC(556, *list); |
|
349 QCOMPARE (m_resourceId, 556); |
|
350 QCOMPARE (m_convertCalled, true); |
|
351 CleanupStack::PopAndDestroy( buf ); |
|
352 ); |
|
353 |
|
354 m_set_text_map = true; |
|
355 |
|
356 TRAP_IGNORE( |
|
357 buf = StringLoader::LoadLC(556, *list); |
|
358 QCOMPARE (m_resourceId, 556); |
|
359 QCOMPARE (m_convertCalled, true); |
|
360 CleanupStack::PopAndDestroy( buf ); |
|
361 ); |
|
362 delete list; |
|
363 } |
|
364 |
|
365 void TestPhoneStringLoader::testLoadLC7 () |
|
366 { |
|
367 HBufC *buf = 0; |
|
368 CDesCArray *list = new ( ELeave )CDesCArrayFlat(3); |
|
369 CArrayFixFlat<TInt>* list2 = new(ELeave)CArrayFixFlat<TInt>(2); |
|
370 |
|
371 TRAP_IGNORE( |
|
372 buf = StringLoader::LoadLC(5679, *list, *list2); |
|
373 QCOMPARE (m_resourceId, 5679); |
|
374 QCOMPARE (m_convertCalled, true); |
|
375 CleanupStack::PopAndDestroy( buf ); |
|
376 ); |
|
377 |
|
378 m_set_text_map = true; |
|
379 |
|
380 TRAP_IGNORE( |
|
381 buf = StringLoader::LoadLC(5679, *list, *list2); |
|
382 QCOMPARE (m_resourceId, 5679); |
|
383 QCOMPARE (m_convertCalled, true); |
|
384 CleanupStack::PopAndDestroy( buf ); |
|
385 ); |
|
386 |
|
387 delete list; |
|
388 delete list2; |
|
389 } |
|
390 |
|
391 QTEST_MAIN(TestPhoneStringLoader) |
|
392 #include "unit_tests.moc" |
|