67
|
1 |
/*
|
|
2 |
* Copyright (c) 2008-2010 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
package com.nokia.mj.impl.utils;
|
|
20 |
|
|
21 |
import java.util.Date;
|
|
22 |
|
|
23 |
import com.nokia.mj.impl.utils.ResourceLoader;
|
|
24 |
import com.nokia.mj.impl.utils.Formatter;
|
|
25 |
|
|
26 |
import com.nokia.mj.impl.utils.Logger;
|
|
27 |
|
|
28 |
import com.nokia.mj.impl.installer.utils.InstallerMain;
|
|
29 |
|
|
30 |
import j2meunit.framework.Test;
|
|
31 |
import j2meunit.framework.TestCase;
|
|
32 |
import j2meunit.framework.TestMethod;
|
|
33 |
import j2meunit.framework.TestSuite;
|
|
34 |
|
|
35 |
public class LocalisationTest extends TestCase implements InstallerMain
|
|
36 |
{
|
|
37 |
// Must have no-argument constructor for Class.forname()
|
|
38 |
public LocalisationTest()
|
|
39 |
{
|
|
40 |
}
|
|
41 |
|
|
42 |
public LocalisationTest(String sTestName, TestMethod rTestMethod)
|
|
43 |
{
|
|
44 |
super(sTestName, rTestMethod);
|
|
45 |
}
|
|
46 |
|
|
47 |
// Begin j2meunit test framework setup
|
|
48 |
public void installerMain(String[] args)
|
|
49 |
{
|
|
50 |
com.nokia.mj.impl.utils.OmjTestRunner.run(suite());
|
|
51 |
}
|
|
52 |
|
|
53 |
public Test suite()
|
|
54 |
{
|
|
55 |
// TestSuite aSuite = new TestSuite();
|
|
56 |
TestSuite aSuite = new TestSuite(this.getClass().getName());
|
|
57 |
|
80
|
58 |
aSuite.addTest(new LocalisationTest("testFormatDigits", new TestMethod()
|
|
59 |
{
|
|
60 |
public void run(TestCase tc)
|
|
61 |
{
|
|
62 |
((LocalisationTest) tc).testFormatDigits();
|
|
63 |
}
|
|
64 |
}));
|
|
65 |
|
|
66 |
aSuite.addTest(new LocalisationTest("testFormatterAvkon", new TestMethod()
|
|
67 |
{
|
|
68 |
public void run(TestCase tc)
|
|
69 |
{
|
|
70 |
((LocalisationTest) tc).testFormatterAvkon();
|
|
71 |
}
|
|
72 |
}));
|
|
73 |
|
|
74 |
aSuite.addTest(new LocalisationTest("testResourceLoaderAvkon", new TestMethod()
|
67
|
75 |
{
|
|
76 |
public void run(TestCase tc)
|
|
77 |
{
|
80
|
78 |
((LocalisationTest) tc).testResourceLoaderAvkon();
|
67
|
79 |
}
|
|
80 |
}));
|
|
81 |
|
80
|
82 |
if (ResourceLoader.getLocaleIdQt() != null)
|
|
83 |
{
|
|
84 |
aSuite.addTest(new LocalisationTest("testFormatterQt", new TestMethod()
|
|
85 |
{
|
|
86 |
public void run(TestCase tc)
|
|
87 |
{
|
|
88 |
((LocalisationTest) tc).testFormatterQt();
|
|
89 |
}
|
|
90 |
}));
|
|
91 |
|
|
92 |
aSuite.addTest(new LocalisationTest("testResourceLoaderQt", new TestMethod()
|
|
93 |
{
|
|
94 |
public void run(TestCase tc)
|
|
95 |
{
|
|
96 |
((LocalisationTest) tc).testResourceLoaderQt();
|
|
97 |
}
|
|
98 |
}));
|
|
99 |
|
|
100 |
aSuite.addTest(new LocalisationTest("testNumerusQt", new TestMethod()
|
|
101 |
{
|
|
102 |
public void run(TestCase tc)
|
|
103 |
{
|
|
104 |
((LocalisationTest) tc).testNumerusQt();
|
|
105 |
}
|
|
106 |
}));
|
|
107 |
}
|
|
108 |
|
|
109 |
aSuite.addTest(new LocalisationTest("testResourceLoaderCreate", new TestMethod()
|
67
|
110 |
{
|
|
111 |
public void run(TestCase tc)
|
|
112 |
{
|
80
|
113 |
((LocalisationTest) tc).testResourceLoaderCreate();
|
|
114 |
}
|
|
115 |
}));
|
|
116 |
|
|
117 |
aSuite.addTest(new LocalisationTest("testResourceLoaderDestroy", new TestMethod()
|
|
118 |
{
|
|
119 |
public void run(TestCase tc)
|
|
120 |
{
|
|
121 |
((LocalisationTest) tc).testResourceLoaderDestroy();
|
67
|
122 |
}
|
|
123 |
}));
|
|
124 |
|
|
125 |
return aSuite;
|
|
126 |
}
|
|
127 |
|
80
|
128 |
void testFormatDigits()
|
|
129 |
{
|
|
130 |
String str = "Message from number +358101234567 received.";
|
|
131 |
// Test are executed with english locale,
|
|
132 |
// numbers should not be changed.
|
|
133 |
assertEquals(str, FormatterAvkon.formatDigits(str));
|
|
134 |
assertEquals(str, FormatterQt.formatDigits(str));
|
|
135 |
}
|
|
136 |
|
|
137 |
void testFormatterAvkon()
|
67
|
138 |
{
|
|
139 |
// Zero argument
|
|
140 |
assertEquals(
|
|
141 |
"Test",
|
80
|
142 |
new FormatterAvkon("Test").toString());
|
67
|
143 |
|
|
144 |
// One argument tests
|
|
145 |
assertEquals(
|
|
146 |
"Test 100",
|
80
|
147 |
new FormatterAvkon("Test %0N").arg(100).toString());
|
67
|
148 |
|
|
149 |
assertEquals(
|
|
150 |
"Test 1",
|
80
|
151 |
new FormatterAvkon("Test %C").arg('1').toString());
|
67
|
152 |
|
|
153 |
assertEquals(
|
|
154 |
"Test A",
|
80
|
155 |
new FormatterAvkon("Test %0C").arg('A').toString());
|
67
|
156 |
|
|
157 |
// Two argument tests
|
|
158 |
assertEquals(
|
|
159 |
"Test test 100",
|
80
|
160 |
new FormatterAvkon("Test %1U %0N").arg(100).arg("test").toString());
|
67
|
161 |
|
|
162 |
assertEquals(
|
|
163 |
"100 test test",
|
80
|
164 |
new FormatterAvkon("%0 test %1").arg(100).arg("test").toString());
|
67
|
165 |
|
|
166 |
assertEquals(
|
|
167 |
"Test A B C",
|
80
|
168 |
new FormatterAvkon("Test %0C %1 %2C").arg('A').arg('B').arg('C').toString());
|
67
|
169 |
|
|
170 |
// Two argument tests with array
|
|
171 |
assertEquals(
|
|
172 |
"Test test 100",
|
80
|
173 |
new FormatterAvkon("Test %1U %0N").format(
|
|
174 |
new Object[]
|
|
175 |
{
|
|
176 |
new Integer(100), "test"
|
|
177 |
}));
|
67
|
178 |
|
|
179 |
assertEquals(
|
|
180 |
"100 test test",
|
80
|
181 |
new FormatterAvkon("%0 test %1").format(
|
|
182 |
new Object[]
|
|
183 |
{
|
|
184 |
new Integer(100), "test"
|
|
185 |
}));
|
67
|
186 |
|
|
187 |
// Missing argument, no failure, just unreplaced parameter
|
|
188 |
assertEquals(
|
|
189 |
"100 test %1",
|
80
|
190 |
new FormatterAvkon("%0 test %1").arg(100).toString());
|
67
|
191 |
|
|
192 |
// Extra argument, no failure
|
|
193 |
assertEquals(
|
|
194 |
"100 test",
|
80
|
195 |
new FormatterAvkon("%0 test").arg(100).arg("test").toString());
|
67
|
196 |
|
|
197 |
Date testDate = new Date(1234567890); // 15/01/1970
|
|
198 |
// Test case assumes emulator locale is default as EDateEuropean.
|
80
|
199 |
assertEquals("15/01/1970", new FormatterAvkon("%0").arg(testDate).toString());
|
67
|
200 |
|
|
201 |
Object obj = testDate;
|
80
|
202 |
assertEquals("15/01/1970", new FormatterAvkon("%0").arg(obj).toString());
|
67
|
203 |
|
|
204 |
obj = new Integer(1);
|
80
|
205 |
assertEquals("1", new FormatterAvkon("%0").arg(obj).toString());
|
67
|
206 |
|
|
207 |
obj = new String("me");
|
80
|
208 |
assertEquals("Test me", new FormatterAvkon("Test %0").arg(obj).toString());
|
67
|
209 |
|
|
210 |
// Test skip not supported type
|
|
211 |
obj = new Boolean(false);
|
80
|
212 |
assertEquals("Test %0", new FormatterAvkon("Test %0").arg(obj).toString());
|
67
|
213 |
|
|
214 |
// Test MAX %1U[08]
|
|
215 |
assertEquals(
|
|
216 |
"Test testMyTe 100",
|
80
|
217 |
new FormatterAvkon("Test %1U[08] %0N").arg(100).arg("testMyTest").toString());
|
67
|
218 |
|
|
219 |
// Test %U[]
|
|
220 |
assertEquals(
|
|
221 |
"Test testMyTest",
|
80
|
222 |
new FormatterAvkon("Test %U[]").arg("testMyTest").toString());
|
67
|
223 |
|
|
224 |
// Test %U[08]
|
|
225 |
assertEquals(
|
|
226 |
"Test testMyTe",
|
80
|
227 |
new FormatterAvkon("Test %U[08]").arg("testMyTest").toString());
|
67
|
228 |
|
|
229 |
// Test %0[]
|
|
230 |
assertEquals(
|
|
231 |
"Test testMyTest",
|
80
|
232 |
new FormatterAvkon("Test %0[]").arg("testMyTest").toString());
|
67
|
233 |
|
|
234 |
// Test %0[08]
|
|
235 |
assertEquals(
|
|
236 |
"Test testMyTe",
|
80
|
237 |
new FormatterAvkon("Test %0[08]").arg("testMyTest").toString());
|
67
|
238 |
|
|
239 |
// Test %U[20 Skip
|
|
240 |
assertEquals(
|
|
241 |
"Test %U[20",
|
80
|
242 |
new FormatterAvkon("Test %U[20").arg("testMyTest").toString());
|
67
|
243 |
|
|
244 |
// Test %U[300]
|
|
245 |
assertEquals(
|
|
246 |
"Test testMyTest",
|
80
|
247 |
new FormatterAvkon("Test %U[300]").arg("testMyTest").toString());
|
67
|
248 |
|
|
249 |
// Test %U[8]
|
|
250 |
assertEquals(
|
|
251 |
"Test testMyTe",
|
80
|
252 |
new FormatterAvkon("Test %U[8]").arg("testMyTest").toString());
|
67
|
253 |
|
|
254 |
// Test Max is higher than actual string. Expected output: whole string no padding.
|
|
255 |
assertEquals(
|
|
256 |
"Test testMyTest",
|
80
|
257 |
new FormatterAvkon("Test %U[80]").arg("testMyTest").toString());
|
67
|
258 |
|
|
259 |
// Test Max is higher than pattern and string is shorter than pattern.
|
|
260 |
assertEquals(
|
|
261 |
"t to",
|
80
|
262 |
new FormatterAvkon("t %U[09]").arg("to").toString());
|
67
|
263 |
|
|
264 |
// Test 0 len Max
|
|
265 |
assertEquals(
|
|
266 |
"t ",
|
80
|
267 |
new FormatterAvkon("t %U[00]").arg("to").toString());
|
67
|
268 |
|
|
269 |
// Test 1 len Max
|
|
270 |
assertEquals(
|
|
271 |
"t 1",
|
80
|
272 |
new FormatterAvkon("t %U[01]").arg("12").toString());
|
67
|
273 |
|
|
274 |
// Test 0 len Max with 0 len replacement
|
|
275 |
assertEquals(
|
|
276 |
"t ",
|
80
|
277 |
new FormatterAvkon("t %U[00]").arg("").toString());
|
67
|
278 |
|
|
279 |
// Test 1 len Max with 1 len replacement
|
|
280 |
assertEquals(
|
|
281 |
"t 1",
|
80
|
282 |
new FormatterAvkon("t %U[01]").arg("1").toString());
|
|
283 |
}
|
|
284 |
|
|
285 |
void testFormatterQt()
|
|
286 |
{
|
|
287 |
try
|
|
288 |
{
|
|
289 |
ResourceLoaderQt res =
|
|
290 |
(ResourceLoaderQt)ResourceLoaderQt.getInstance(
|
|
291 |
"common", "txt_common_");
|
|
292 |
|
|
293 |
// Zero argument
|
|
294 |
assertEquals(
|
|
295 |
"Test",
|
|
296 |
new FormatterQt(res, "Test").toString());
|
|
297 |
|
|
298 |
// One argument tests
|
|
299 |
assertEquals(
|
|
300 |
"Test 100",
|
|
301 |
new FormatterQt(res, "Test %1").arg(100).toString());
|
|
302 |
|
|
303 |
assertEquals(
|
|
304 |
"Test 100",
|
|
305 |
new FormatterQt(res, "Test %L1").arg(100).toString());
|
|
306 |
|
|
307 |
assertEquals(
|
|
308 |
"Test AAA",
|
|
309 |
new FormatterQt(res, "Test %1").arg("AAA").toString());
|
|
310 |
|
|
311 |
assertEquals(
|
|
312 |
"Test A",
|
|
313 |
new FormatterQt(res, "Test %1").arg('A').toString());
|
|
314 |
|
|
315 |
// Two argument tests
|
|
316 |
assertEquals(
|
|
317 |
"Test test 100",
|
|
318 |
new FormatterQt(res, "Test %2 %L1").arg(100).arg("test").toString());
|
|
319 |
|
|
320 |
assertEquals(
|
|
321 |
"100 test test",
|
|
322 |
new FormatterQt(res, "%1 test %2").arg(100).arg("test").toString());
|
|
323 |
|
|
324 |
assertEquals(
|
|
325 |
"Test A B C",
|
|
326 |
new FormatterQt(res, "Test %1 %2 %3").arg('A').arg('B').arg('C').toString());
|
|
327 |
|
|
328 |
// Two argument tests with array
|
|
329 |
assertEquals(
|
|
330 |
"Test test 100",
|
|
331 |
new FormatterQt(res, "Test %2 %L1").format(new Object[]
|
|
332 |
{
|
|
333 |
new Integer(100), "test"
|
|
334 |
}));
|
|
335 |
|
|
336 |
assertEquals(
|
|
337 |
"100 test test",
|
|
338 |
new FormatterQt(res, "%1 test %2").format(new Object[]
|
|
339 |
{
|
|
340 |
new Integer(100), "test"
|
|
341 |
}));
|
|
342 |
|
|
343 |
// Missing argument, no failure, just unreplaced parameter
|
|
344 |
assertEquals(
|
|
345 |
"100 test %2",
|
|
346 |
new FormatterQt(res, "%1 test %2").arg(100).toString());
|
|
347 |
|
|
348 |
// Extra argument, no failure
|
|
349 |
assertEquals(
|
|
350 |
"100 test",
|
|
351 |
new FormatterQt(res, "%1 test").arg(100).arg("test").toString());
|
|
352 |
|
|
353 |
Date testDate = new Date(1234567890); // 15/01/1970
|
|
354 |
assertEquals("date1 15/01/1970",
|
|
355 |
new FormatterQt(res, "date1 %1").arg(testDate).toString());
|
|
356 |
|
|
357 |
Object obj = testDate;
|
|
358 |
assertEquals("date2 15/01/1970",
|
|
359 |
new FormatterQt(res, "date2 %1").arg(obj).toString());
|
|
360 |
|
|
361 |
assertEquals("date3 15/01/1970",
|
|
362 |
new FormatterQt(res, "date3 %1").format(
|
|
363 |
new Object[] { obj }));
|
|
364 |
|
|
365 |
obj = new Integer(1);
|
|
366 |
assertEquals("1", new FormatterQt(res, "%1").arg(obj).toString());
|
|
367 |
|
|
368 |
obj = new String("me");
|
|
369 |
assertEquals(
|
|
370 |
"Test me",
|
|
371 |
new FormatterQt(res, "Test %1").arg(obj).toString());
|
|
372 |
|
|
373 |
// Test skip not supported type
|
|
374 |
obj = new Boolean(false);
|
|
375 |
assertEquals(
|
|
376 |
"Test %1",
|
|
377 |
new FormatterQt(res, "Test %1").arg(obj).toString());
|
|
378 |
|
|
379 |
// Test MAX %[8]2
|
|
380 |
//assertEquals(
|
|
381 |
// "Test testMyTe 100",
|
|
382 |
// new FormatterQt(res, "Test %[8]2 %1").arg(100).arg("testMyTest").toString());
|
|
383 |
|
|
384 |
// Test %[] Skip
|
|
385 |
assertEquals(
|
|
386 |
"Test %[]",
|
|
387 |
new FormatterQt(res, "Test %[]").arg("testMyTest").toString());
|
|
388 |
|
|
389 |
// Test %[]1 Skip
|
|
390 |
assertEquals(
|
|
391 |
"Test %[]1",
|
|
392 |
new FormatterQt(res, "Test %[]1").arg("testMyTest").toString());
|
|
393 |
|
|
394 |
// Test %[20 Skip
|
|
395 |
assertEquals(
|
|
396 |
"Test %[20",
|
|
397 |
new FormatterQt(res, "Test %[20").arg("testMyTest").toString());
|
|
398 |
|
|
399 |
// Test %[08]1
|
|
400 |
assertEquals(
|
|
401 |
"Test testMyTe\u2026",
|
|
402 |
new FormatterQt(res, "Test %[08]1").arg("testMyTest").toString());
|
|
403 |
|
|
404 |
// Test %[300]1
|
|
405 |
assertEquals(
|
|
406 |
"Test testMyTest",
|
|
407 |
new FormatterQt(res, "Test %[300]1").arg("testMyTest").toString());
|
|
408 |
|
|
409 |
// Test Max is higher than pattern and result is shorter than pattern.
|
|
410 |
assertEquals(
|
|
411 |
"t to",
|
|
412 |
new FormatterQt(res, "t %[09]1").arg("to").toString());
|
|
413 |
|
|
414 |
// Test 0 len Max
|
|
415 |
assertEquals(
|
|
416 |
"t \u2026",
|
|
417 |
new FormatterQt(res, "t %[00]1").arg("to").toString());
|
|
418 |
|
|
419 |
// Test 1 len Max
|
|
420 |
assertEquals(
|
|
421 |
"t 1\u2026",
|
|
422 |
new FormatterQt(res, "t %[01]1").arg("12").toString());
|
|
423 |
|
|
424 |
// Test 0 len Max with 0 len replacement
|
|
425 |
assertEquals(
|
|
426 |
"t ",
|
|
427 |
new FormatterQt(res, "t %[00]1").arg("").toString());
|
|
428 |
|
|
429 |
// Test 1 len Max with 1 len replacement
|
|
430 |
assertEquals(
|
|
431 |
"t 1",
|
|
432 |
new FormatterQt(res, "t %[01]1").arg("1").toString());
|
|
433 |
|
|
434 |
// Plurality form tests
|
|
435 |
}
|
|
436 |
catch (Throwable t)
|
|
437 |
{
|
|
438 |
t.printStackTrace();
|
|
439 |
assertTrue(t.toString(), false);
|
|
440 |
}
|
|
441 |
}
|
|
442 |
|
|
443 |
void testResourceLoaderAvkon()
|
|
444 |
{
|
|
445 |
doResourceLoaderAvkonTest("testresource", "test_", "", "");
|
|
446 |
doResourceLoaderAvkonTest("testresource,testresource2", "test_,test2_", "", "");
|
|
447 |
doResourceLoaderAvkonTest("testresource2,testresource", "unknown_prefix_,test_", "", "");
|
|
448 |
doResourceLoaderAvkonTest("testresource2,testresource", "unknown_prefix_,test_", "dummy,", "dummy,");
|
|
449 |
doResourceLoaderAvkonTest("testresource", "test_,unknown_prefix_", "", "");
|
67
|
450 |
}
|
|
451 |
|
80
|
452 |
private void doResourceLoaderAvkonTest(
|
|
453 |
String resourceFilename, String resourcePrefix,
|
|
454 |
String inPrefix, String outPrefix)
|
67
|
455 |
{
|
80
|
456 |
try
|
|
457 |
{
|
|
458 |
ResourceLoader res =
|
|
459 |
ResourceLoaderAvkon.getInstance(resourceFilename, resourcePrefix);
|
67
|
460 |
|
80
|
461 |
// Test existing
|
|
462 |
assertEquals(
|
|
463 |
"id1 test",
|
|
464 |
res.format(inPrefix + "id_1").arg("test").toString());
|
|
465 |
assertEquals(
|
|
466 |
"id2 test2",
|
|
467 |
res.format(inPrefix + "id_2").arg("test2").toString());
|
|
468 |
assertEquals(
|
|
469 |
"id3 test3",
|
|
470 |
res.format(inPrefix + "id_3").arg("test3").toString());
|
67
|
471 |
|
80
|
472 |
// Test fetching the same text again
|
|
473 |
assertEquals(
|
|
474 |
"id1 test",
|
|
475 |
res.format(inPrefix + "id_1").arg("test").toString());
|
|
476 |
|
|
477 |
// Test full name
|
|
478 |
assertEquals(
|
|
479 |
"id1 test",
|
|
480 |
res.format(inPrefix + "id_1").arg("test").toString());
|
67
|
481 |
|
80
|
482 |
// Test non-existing, with prefix
|
|
483 |
assertTrue(
|
|
484 |
inPrefix + "id_notfound does not result " + outPrefix + "id_notfound",
|
|
485 |
res.format(inPrefix + "id_notfound").arg("test3").toString().endsWith(outPrefix + "id_notfound"));
|
67
|
486 |
|
80
|
487 |
// Test non-existing, without prefix
|
|
488 |
assertTrue(
|
|
489 |
inPrefix + "id_notfound does not result " + outPrefix + "id_notfound",
|
|
490 |
res.format(inPrefix + "id_notfound").arg("test3").toString().endsWith(outPrefix + "id_notfound"));
|
67
|
491 |
|
80
|
492 |
// Test array
|
|
493 |
assertEquals(
|
|
494 |
"id3 test3",
|
|
495 |
res.format(inPrefix + "id_3", new Object[] {"test3"}));
|
67
|
496 |
|
80
|
497 |
// Test enter decoding.
|
|
498 |
assertEquals(
|
|
499 |
"id4 \n test4 \n",
|
|
500 |
res.format(inPrefix + "id_4").arg("test4").toString());
|
67
|
501 |
|
80
|
502 |
// Test backlash decoding.
|
|
503 |
assertEquals(
|
|
504 |
"\\id5 \\ test5",
|
|
505 |
res.format(inPrefix + "id_5").arg("test5").toString());
|
67
|
506 |
|
80
|
507 |
// Test double-quote decoding.
|
|
508 |
assertEquals(
|
|
509 |
"id6 \"\" test6",
|
|
510 |
res.format(inPrefix + "id_6").arg("test6").toString());
|
67
|
511 |
|
80
|
512 |
// Test single-quote decoding.
|
|
513 |
assertEquals(
|
|
514 |
"id7 \' test7",
|
|
515 |
res.format(inPrefix + "id_7").arg("test7").toString());
|
|
516 |
|
|
517 |
// Test tabulator decoding.
|
|
518 |
assertEquals(
|
|
519 |
"id8\ttest8",
|
|
520 |
res.format(inPrefix + "id_8").arg("test8").toString());
|
67
|
521 |
|
80
|
522 |
// Test character code <0x20AC>
|
|
523 |
assertEquals(
|
|
524 |
"id9 It takes 800 \u20ac to win!",
|
|
525 |
res.format(inPrefix + "id_9").arg(800).toString());
|
67
|
526 |
|
80
|
527 |
// Test two character codes.
|
|
528 |
assertEquals(
|
|
529 |
"id10 It takes \u20ac 800 \u20ac to win!",
|
|
530 |
res.format(inPrefix + "id_10").arg(800).toString());
|
67
|
531 |
|
80
|
532 |
// Test two character codes in a row. Test <0x20ac><0x20ac>
|
|
533 |
assertEquals(
|
|
534 |
"id11 It takes \u20ac\u20ac to win!",
|
|
535 |
res.format(inPrefix + "id_11").toString());
|
67
|
536 |
|
80
|
537 |
// Test only character code.
|
|
538 |
assertEquals(
|
|
539 |
"\u20ac",
|
|
540 |
res.format(inPrefix + "id_12").toString());
|
67
|
541 |
|
80
|
542 |
// Test invalid character code.
|
|
543 |
assertEquals(
|
|
544 |
"id13 It <0x20A>to win!",
|
|
545 |
res.format(inPrefix + "id_13").toString());
|
67
|
546 |
|
|
547 |
|
80
|
548 |
// Test character code as first character.
|
|
549 |
assertEquals(
|
|
550 |
"\u20ac id14",
|
|
551 |
res.format(inPrefix + "id_14").toString());
|
|
552 |
|
|
553 |
// Test character code as last character.
|
|
554 |
assertEquals(
|
|
555 |
"id15 \u20ac",
|
|
556 |
res.format(inPrefix + "id_15").toString());
|
|
557 |
|
|
558 |
// Test invalid character.
|
|
559 |
assertEquals(
|
|
560 |
"id16 <0xG0AC>",
|
|
561 |
res.format(inPrefix + "id_16").toString());
|
|
562 |
}
|
|
563 |
catch (Throwable t)
|
|
564 |
{
|
|
565 |
t.printStackTrace();
|
|
566 |
assertTrue("'" + resourceFilename + "', '" + resourcePrefix + "', '" +
|
|
567 |
inPrefix + "', '" + outPrefix + "': " + t, false);
|
|
568 |
}
|
|
569 |
}
|
|
570 |
|
|
571 |
void testResourceLoaderQt()
|
|
572 |
{
|
|
573 |
try
|
|
574 |
{
|
|
575 |
ResourceLoader res =
|
|
576 |
ResourceLoaderQt.getInstance("common", "txt_common_");
|
|
577 |
assertEquals("OK", res.format("button_ok").toString());
|
|
578 |
// Test fetching the same text again
|
|
579 |
assertEquals("OK", res.format("button_ok").toString());
|
|
580 |
|
|
581 |
res = ResourceLoaderQt.getInstance("common_errors", "txt_");
|
|
582 |
assertEquals("Invalid installation package", res.format("error_info_installation_package_is_invalid").toString());
|
|
583 |
assertEquals("Unable to access server", res.format("error_info_no_server_access").toString());
|
|
584 |
|
|
585 |
res = ResourceLoaderQt.getInstance("common,javaapplicationinstaller", "txt_common_,txt_java_inst_");
|
|
586 |
assertEquals("Manufacturer", res.format("setlabel_cert_domain_val_manufacturer").toString());
|
|
587 |
// Test fetching the same text again
|
|
588 |
assertEquals("Manufacturer", res.format("setlabel_cert_domain_val_manufacturer").toString());
|
|
589 |
|
|
590 |
assertEquals(
|
|
591 |
"foo (bar)",
|
|
592 |
res.format("info_app_suite_name_version").arg("foo").arg("bar").toString());
|
|
593 |
// Test fetching the same text again
|
|
594 |
assertEquals(
|
|
595 |
"foo (bar)",
|
|
596 |
res.format("info_app_suite_name_version").arg("foo").arg("bar").toString());
|
|
597 |
|
|
598 |
|
|
599 |
assertEquals(
|
|
600 |
"text_not_found",
|
|
601 |
res.format("text_not_found").arg("foo").toString());
|
|
602 |
// Test fetching the same text again
|
|
603 |
assertEquals(
|
|
604 |
"text_not_found",
|
|
605 |
res.format("text_not_found").arg("foo").toString());
|
|
606 |
}
|
|
607 |
catch (Throwable t)
|
|
608 |
{
|
|
609 |
t.printStackTrace();
|
|
610 |
assertTrue(t.toString(), false);
|
|
611 |
}
|
|
612 |
}
|
67
|
613 |
|
80
|
614 |
void testNumerusQt()
|
|
615 |
{
|
|
616 |
try
|
|
617 |
{
|
|
618 |
ResourceLoader res =
|
|
619 |
ResourceLoaderQt.getInstance("clock", "txt_clock_");
|
|
620 |
assertEquals("1 hr", res.format("dblist_daily_val_ln_hr").argn(1).toString());
|
|
621 |
assertEquals("5 hrs", res.format("dblist_daily_val_ln_hr").argn(5).toString());
|
|
622 |
}
|
|
623 |
catch (Throwable t)
|
|
624 |
{
|
|
625 |
t.printStackTrace();
|
|
626 |
assertTrue(t.toString(), false);
|
|
627 |
}
|
|
628 |
}
|
|
629 |
|
|
630 |
void testResourceLoaderCreate()
|
|
631 |
{
|
|
632 |
try
|
|
633 |
{
|
|
634 |
// Create Avkon ResourceLoader with unknown resource.
|
|
635 |
ResourceLoader rl = ResourceLoader.getInstance(
|
|
636 |
"unknown_resource_1", "unknown_prefix", null, null);
|
|
637 |
ResourceLoader rl2 = ResourceLoader.getInstance(
|
|
638 |
"unknown_resource_1", "unknown_prefix", null, null);
|
|
639 |
assertTrue("1: null ResourceLoader", rl != null);
|
|
640 |
assertTrue("1: not Avkon ResourceLoader", rl instanceof ResourceLoaderAvkon);
|
|
641 |
assertTrue("1: not same ResourceLoader instance", rl == rl2);
|
|
642 |
|
|
643 |
// Create Qt ResourceLoader with known resource.
|
|
644 |
rl = ResourceLoader.getInstance(
|
|
645 |
null, null, "common", "txt_");
|
|
646 |
rl2 = ResourceLoader.getInstance(
|
|
647 |
null, null, "common", "txt_");
|
|
648 |
assertTrue("2: null ResourceLoader", rl != null);
|
|
649 |
if (ResourceLoader.getLocaleIdQt() == null)
|
|
650 |
{
|
|
651 |
assertTrue("2: not Avkon ResourceLoader", rl instanceof ResourceLoaderAvkon);
|
|
652 |
}
|
|
653 |
else
|
|
654 |
{
|
|
655 |
assertTrue("2: not Qt ResourceLoader", rl instanceof ResourceLoaderQt);
|
|
656 |
}
|
|
657 |
assertTrue("2: not same ResourceLoader instance", rl == rl2);
|
67
|
658 |
|
80
|
659 |
// When Qt resource is not found, Avkon ResourceLoader should
|
|
660 |
// be returned.
|
|
661 |
rl = ResourceLoader.getInstance(
|
|
662 |
null, null, "unknown_resource_2", "unknown_prefix");
|
|
663 |
rl2 = ResourceLoader.getInstance(
|
|
664 |
null, null, "unknown_resource_2", "unknown_prefix");
|
|
665 |
assertTrue("3: null ResourceLoader", rl != null);
|
|
666 |
assertTrue("3: not Avkon ResourceLoader", rl instanceof ResourceLoaderAvkon);
|
|
667 |
assertTrue("3: not same ResourceLoader instance", rl == rl2);
|
|
668 |
|
|
669 |
if (ResourceLoader.getLocaleIdQt() != null)
|
|
670 |
{
|
|
671 |
try
|
|
672 |
{
|
|
673 |
// Check that correct exception is thrown for
|
|
674 |
// unknown Qt resource.
|
|
675 |
rl = ResourceLoaderQt.getInstance(
|
|
676 |
"unknown_resource_3", "unknown_prefix");
|
|
677 |
assertTrue("no exception for unknown Qt resource", false);
|
|
678 |
}
|
|
679 |
catch (IllegalArgumentException iae)
|
|
680 |
{
|
|
681 |
// Expected exception
|
|
682 |
}
|
|
683 |
}
|
|
684 |
}
|
|
685 |
catch (Throwable t)
|
|
686 |
{
|
|
687 |
t.printStackTrace();
|
|
688 |
assertTrue(t.toString(), false);
|
|
689 |
}
|
|
690 |
}
|
|
691 |
|
|
692 |
void testResourceLoaderDestroy()
|
|
693 |
{
|
|
694 |
try
|
|
695 |
{
|
|
696 |
ResourceLoader.destroyAll();
|
|
697 |
}
|
|
698 |
catch (Throwable t)
|
|
699 |
{
|
|
700 |
t.printStackTrace();
|
|
701 |
assertTrue(t.toString(), false);
|
|
702 |
}
|
67
|
703 |
}
|
|
704 |
}
|