48 public void installerMain(String[] args) |
48 public void installerMain(String[] args) |
49 { |
49 { |
50 com.nokia.mj.impl.utils.OmjTestRunner.run(suite()); |
50 com.nokia.mj.impl.utils.OmjTestRunner.run(suite()); |
51 } |
51 } |
52 |
52 |
53 |
|
54 public Test suite() |
53 public Test suite() |
55 { |
54 { |
56 // TestSuite aSuite = new TestSuite(); |
55 // TestSuite aSuite = new TestSuite(); |
57 TestSuite aSuite = new TestSuite(this.getClass().getName()); |
56 TestSuite aSuite = new TestSuite(this.getClass().getName()); |
58 |
57 |
59 aSuite.addTest(new LocalisationTest("formatterTest", new TestMethod() |
58 aSuite.addTest(new LocalisationTest("testFormatDigits", new TestMethod() |
60 { |
59 { |
61 public void run(TestCase tc) |
60 public void run(TestCase tc) |
62 { |
61 { |
63 ((LocalisationTest) tc).formatterTest(); |
62 ((LocalisationTest) tc).testFormatDigits(); |
64 } |
63 } |
65 })); |
64 })); |
66 |
65 |
67 aSuite.addTest(new LocalisationTest("resourceLoaderTest", new TestMethod() |
66 aSuite.addTest(new LocalisationTest("testFormatterAvkon", new TestMethod() |
68 { |
67 { |
69 public void run(TestCase tc) |
68 public void run(TestCase tc) |
70 { |
69 { |
71 ((LocalisationTest) tc).resourceLoaderTest(); |
70 ((LocalisationTest) tc).testFormatterAvkon(); |
72 } |
71 } |
73 })); |
72 })); |
74 |
73 |
|
74 aSuite.addTest(new LocalisationTest("testResourceLoaderAvkon", new TestMethod() |
|
75 { |
|
76 public void run(TestCase tc) |
|
77 { |
|
78 ((LocalisationTest) tc).testResourceLoaderAvkon(); |
|
79 } |
|
80 })); |
|
81 |
|
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() |
|
110 { |
|
111 public void run(TestCase tc) |
|
112 { |
|
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(); |
|
122 } |
|
123 })); |
|
124 |
75 return aSuite; |
125 return aSuite; |
76 } |
126 } |
77 |
127 |
78 void formatterTest() |
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() |
79 { |
138 { |
80 // Zero argument |
139 // Zero argument |
81 assertEquals( |
140 assertEquals( |
82 "Test", |
141 "Test", |
83 new Formatter("Test").toString()); |
142 new FormatterAvkon("Test").toString()); |
84 |
143 |
85 // One argument tests |
144 // One argument tests |
86 assertEquals( |
145 assertEquals( |
87 "Test 100", |
146 "Test 100", |
88 new Formatter("Test %0N").arg(100).toString()); |
147 new FormatterAvkon("Test %0N").arg(100).toString()); |
89 |
148 |
90 assertEquals( |
149 assertEquals( |
91 "Test 1", |
150 "Test 1", |
92 new Formatter("Test %C").arg('1').toString()); |
151 new FormatterAvkon("Test %C").arg('1').toString()); |
93 |
152 |
94 assertEquals( |
153 assertEquals( |
95 "Test A", |
154 "Test A", |
96 new Formatter("Test %0C").arg('A').toString()); |
155 new FormatterAvkon("Test %0C").arg('A').toString()); |
97 |
156 |
98 // Two argument tests |
157 // Two argument tests |
99 assertEquals( |
158 assertEquals( |
100 "Test test 100", |
159 "Test test 100", |
101 new Formatter("Test %1U %0N").arg(100).arg("test").toString()); |
160 new FormatterAvkon("Test %1U %0N").arg(100).arg("test").toString()); |
102 |
161 |
103 assertEquals( |
162 assertEquals( |
104 "100 test test", |
163 "100 test test", |
105 new Formatter("%0 test %1").arg(100).arg("test").toString()); |
164 new FormatterAvkon("%0 test %1").arg(100).arg("test").toString()); |
106 |
165 |
107 assertEquals( |
166 assertEquals( |
108 "Test A B C", |
167 "Test A B C", |
109 new Formatter("Test %0C %1 %2C").arg('A').arg('B').arg('C').toString()); |
168 new FormatterAvkon("Test %0C %1 %2C").arg('A').arg('B').arg('C').toString()); |
110 |
169 |
111 // Two argument tests with array |
170 // Two argument tests with array |
112 assertEquals( |
171 assertEquals( |
113 "Test test 100", |
172 "Test test 100", |
114 new Formatter("Test %1U %0N").format(new Object[] |
173 new FormatterAvkon("Test %1U %0N").format( |
115 { |
174 new Object[] |
116 new Integer(100), "test" |
175 { |
117 })); |
176 new Integer(100), "test" |
|
177 })); |
118 |
178 |
119 assertEquals( |
179 assertEquals( |
120 "100 test test", |
180 "100 test test", |
121 new Formatter("%0 test %1").format(new Object[] |
181 new FormatterAvkon("%0 test %1").format( |
122 { |
182 new Object[] |
123 new Integer(100), "test" |
183 { |
124 })); |
184 new Integer(100), "test" |
|
185 })); |
125 |
186 |
126 // Missing argument, no failure, just unreplaced parameter |
187 // Missing argument, no failure, just unreplaced parameter |
127 assertEquals( |
188 assertEquals( |
128 "100 test %1", |
189 "100 test %1", |
129 new Formatter("%0 test %1").arg(100).toString()); |
190 new FormatterAvkon("%0 test %1").arg(100).toString()); |
130 |
191 |
131 // Extra argument, no failure |
192 // Extra argument, no failure |
132 assertEquals( |
193 assertEquals( |
133 "100 test", |
194 "100 test", |
134 new Formatter("%0 test").arg(100).arg("test").toString()); |
195 new FormatterAvkon("%0 test").arg(100).arg("test").toString()); |
135 |
196 |
136 Date testDate = new Date(1234567890); // 15/01/1970 |
197 Date testDate = new Date(1234567890); // 15/01/1970 |
137 // Test case assumes emulator locale is default as EDateEuropean. |
198 // Test case assumes emulator locale is default as EDateEuropean. |
138 assertEquals("15/01/1970", new Formatter("%0").arg(testDate).toString()); |
199 assertEquals("15/01/1970", new FormatterAvkon("%0").arg(testDate).toString()); |
139 |
200 |
140 Object obj = testDate; |
201 Object obj = testDate; |
141 assertEquals("15/01/1970", new Formatter("%0").arg(obj).toString()); |
202 assertEquals("15/01/1970", new FormatterAvkon("%0").arg(obj).toString()); |
142 |
203 |
143 obj = new Integer(1); |
204 obj = new Integer(1); |
144 assertEquals("1", new Formatter("%0").arg(obj).toString()); |
205 assertEquals("1", new FormatterAvkon("%0").arg(obj).toString()); |
145 |
206 |
146 obj = new String("me"); |
207 obj = new String("me"); |
147 assertEquals("Test me", new Formatter("Test %0").arg(obj).toString()); |
208 assertEquals("Test me", new FormatterAvkon("Test %0").arg(obj).toString()); |
148 |
209 |
149 // Test skip not supported type |
210 // Test skip not supported type |
150 obj = new Boolean(false); |
211 obj = new Boolean(false); |
151 assertEquals("Test %0", new Formatter("Test %0").arg(obj).toString()); |
212 assertEquals("Test %0", new FormatterAvkon("Test %0").arg(obj).toString()); |
152 |
213 |
153 // Test MAX %1U[08] |
214 // Test MAX %1U[08] |
154 assertEquals( |
215 assertEquals( |
155 "Test testMyTe 100", |
216 "Test testMyTe 100", |
156 new Formatter("Test %1U[08] %0N").arg(100).arg("testMyTest").toString()); |
217 new FormatterAvkon("Test %1U[08] %0N").arg(100).arg("testMyTest").toString()); |
157 |
218 |
158 // Test %U[] |
219 // Test %U[] |
159 assertEquals( |
220 assertEquals( |
160 "Test testMyTest", |
221 "Test testMyTest", |
161 new Formatter("Test %U[]").arg("testMyTest").toString()); |
222 new FormatterAvkon("Test %U[]").arg("testMyTest").toString()); |
162 |
223 |
163 // Test %U[08] |
224 // Test %U[08] |
164 assertEquals( |
225 assertEquals( |
165 "Test testMyTe", |
226 "Test testMyTe", |
166 new Formatter("Test %U[08]").arg("testMyTest").toString()); |
227 new FormatterAvkon("Test %U[08]").arg("testMyTest").toString()); |
167 |
228 |
168 // Test %0[] |
229 // Test %0[] |
169 assertEquals( |
230 assertEquals( |
170 "Test testMyTest", |
231 "Test testMyTest", |
171 new Formatter("Test %0[]").arg("testMyTest").toString()); |
232 new FormatterAvkon("Test %0[]").arg("testMyTest").toString()); |
172 |
233 |
173 // Test %0[08] |
234 // Test %0[08] |
174 assertEquals( |
235 assertEquals( |
175 "Test testMyTe", |
236 "Test testMyTe", |
176 new Formatter("Test %0[08]").arg("testMyTest").toString()); |
237 new FormatterAvkon("Test %0[08]").arg("testMyTest").toString()); |
177 |
238 |
178 // Test %U[20 Skip |
239 // Test %U[20 Skip |
179 assertEquals( |
240 assertEquals( |
180 "Test %U[20", |
241 "Test %U[20", |
181 new Formatter("Test %U[20").arg("testMyTest").toString()); |
242 new FormatterAvkon("Test %U[20").arg("testMyTest").toString()); |
182 |
243 |
183 // Test %U[300] |
244 // Test %U[300] |
184 assertEquals( |
245 assertEquals( |
185 "Test testMyTest", |
246 "Test testMyTest", |
186 new Formatter("Test %U[300]").arg("testMyTest").toString()); |
247 new FormatterAvkon("Test %U[300]").arg("testMyTest").toString()); |
187 |
248 |
188 // Test %U[8] |
249 // Test %U[8] |
189 assertEquals( |
250 assertEquals( |
190 "Test testMyTe", |
251 "Test testMyTe", |
191 new Formatter("Test %U[8]").arg("testMyTest").toString()); |
252 new FormatterAvkon("Test %U[8]").arg("testMyTest").toString()); |
192 |
253 |
193 // Test Max is higher than actual string. Expected output: whole string no padding. |
254 // Test Max is higher than actual string. Expected output: whole string no padding. |
194 assertEquals( |
255 assertEquals( |
195 "Test testMyTest", |
256 "Test testMyTest", |
196 new Formatter("Test %U[80]").arg("testMyTest").toString()); |
257 new FormatterAvkon("Test %U[80]").arg("testMyTest").toString()); |
197 |
258 |
198 // Test Max is higher than pattern and string is shorter than pattern. |
259 // Test Max is higher than pattern and string is shorter than pattern. |
199 assertEquals( |
260 assertEquals( |
200 "t to", |
261 "t to", |
201 new Formatter("t %U[09]").arg("to").toString()); |
262 new FormatterAvkon("t %U[09]").arg("to").toString()); |
202 |
263 |
203 // Test 0 len Max |
264 // Test 0 len Max |
204 assertEquals( |
265 assertEquals( |
205 "t ", |
266 "t ", |
206 new Formatter("t %U[00]").arg("to").toString()); |
267 new FormatterAvkon("t %U[00]").arg("to").toString()); |
207 |
268 |
208 // Test 1 len Max |
269 // Test 1 len Max |
209 assertEquals( |
270 assertEquals( |
210 "t 1", |
271 "t 1", |
211 new Formatter("t %U[01]").arg("12").toString()); |
272 new FormatterAvkon("t %U[01]").arg("12").toString()); |
212 |
273 |
213 // Test 0 len Max with 0 len replacement |
274 // Test 0 len Max with 0 len replacement |
214 assertEquals( |
275 assertEquals( |
215 "t ", |
276 "t ", |
216 new Formatter("t %U[00]").arg("").toString()); |
277 new FormatterAvkon("t %U[00]").arg("").toString()); |
217 |
278 |
218 // Test 1 len Max with 1 len replacement |
279 // Test 1 len Max with 1 len replacement |
219 assertEquals( |
280 assertEquals( |
220 "t 1", |
281 "t 1", |
221 new Formatter("t %U[01]").arg("1").toString()); |
282 new FormatterAvkon("t %U[01]").arg("1").toString()); |
222 } |
283 } |
223 |
284 |
224 void resourceLoaderTest() |
285 void testFormatterQt() |
225 { |
286 { |
226 |
287 try |
227 ResourceLoader res = new ResourceLoader("testresource", "test_"); |
288 { |
228 |
289 ResourceLoaderQt res = |
229 // Test existing |
290 (ResourceLoaderQt)ResourceLoaderQt.getInstance( |
230 assertEquals( |
291 "common", "txt_common_"); |
231 "id1 test", |
292 |
232 res.format("id_1").arg("test").toString()); |
293 // Zero argument |
233 assertEquals( |
294 assertEquals( |
234 "id2 test2", |
295 "Test", |
235 res.format("id_2").arg("test2").toString()); |
296 new FormatterQt(res, "Test").toString()); |
236 assertEquals( |
297 |
237 "id3 test3", |
298 // One argument tests |
238 res.format("id_3").arg("test3").toString()); |
299 assertEquals( |
239 |
300 "Test 100", |
240 // Test full name |
301 new FormatterQt(res, "Test %1").arg(100).toString()); |
241 assertEquals( |
302 |
242 "id1 test", |
303 assertEquals( |
243 res.format("test_id_1").arg("test").toString()); |
304 "Test 100", |
244 // Test non-existing, with prefix |
305 new FormatterQt(res, "Test %L1").arg(100).toString()); |
245 assertEquals( |
306 |
246 "test_id_notfound", |
307 assertEquals( |
247 res.format("test_id_notfound").arg("test3").toString()); |
308 "Test AAA", |
248 |
309 new FormatterQt(res, "Test %1").arg("AAA").toString()); |
249 // Test non-existing, without prefix |
310 |
250 assertEquals( |
311 assertEquals( |
251 "test_id_notfound", |
312 "Test A", |
252 res.format("id_notfound").arg("test3").toString()); |
313 new FormatterQt(res, "Test %1").arg('A').toString()); |
253 |
314 |
254 // Test array |
315 // Two argument tests |
255 assertEquals( |
316 assertEquals( |
256 "id3 test3", |
317 "Test test 100", |
257 res.format("id_3", new Object[] {"test3"})); |
318 new FormatterQt(res, "Test %2 %L1").arg(100).arg("test").toString()); |
258 |
319 |
259 // Test enter decoding. |
320 assertEquals( |
260 assertEquals( |
321 "100 test test", |
261 "id4 \n test4 \n", |
322 new FormatterQt(res, "%1 test %2").arg(100).arg("test").toString()); |
262 res.format("id_4").arg("test4").toString()); |
323 |
263 |
324 assertEquals( |
264 // Test backlash decoding. |
325 "Test A B C", |
265 assertEquals( |
326 new FormatterQt(res, "Test %1 %2 %3").arg('A').arg('B').arg('C').toString()); |
266 "\\id5 \\ test5", |
327 |
267 res.format("id_5").arg("test5").toString()); |
328 // Two argument tests with array |
268 |
329 assertEquals( |
269 // Test double-quote decoding. |
330 "Test test 100", |
270 assertEquals( |
331 new FormatterQt(res, "Test %2 %L1").format(new Object[] |
271 "id6 \"\" test6", |
332 { |
272 res.format("id_6").arg("test6").toString()); |
333 new Integer(100), "test" |
273 |
334 })); |
274 // Test single-quote decoding. |
335 |
275 assertEquals( |
336 assertEquals( |
276 "id7 \' test7", |
337 "100 test test", |
277 res.format("id_7").arg("test7").toString()); |
338 new FormatterQt(res, "%1 test %2").format(new Object[] |
278 |
339 { |
279 // Test tabulator decoding. |
340 new Integer(100), "test" |
280 assertEquals( |
341 })); |
281 "id8\ttest8", |
342 |
282 res.format("id_8").arg("test8").toString()); |
343 // Missing argument, no failure, just unreplaced parameter |
283 |
344 assertEquals( |
284 // Test character code <0x20AC> |
345 "100 test %2", |
285 assertEquals( |
346 new FormatterQt(res, "%1 test %2").arg(100).toString()); |
286 "id9 It takes 800 \u20ac to win!", |
347 |
287 res.format("id_9").arg(800).toString()); |
348 // Extra argument, no failure |
288 |
349 assertEquals( |
289 // Test two character codes. |
350 "100 test", |
290 assertEquals( |
351 new FormatterQt(res, "%1 test").arg(100).arg("test").toString()); |
291 "id10 It takes \u20ac 800 \u20ac to win!", |
352 |
292 res.format("id_10").arg(800).toString()); |
353 Date testDate = new Date(1234567890); // 15/01/1970 |
293 |
354 assertEquals("date1 15/01/1970", |
294 // Test two character codes in a row. Test <0x20ac><0x20ac> |
355 new FormatterQt(res, "date1 %1").arg(testDate).toString()); |
295 assertEquals( |
356 |
296 "id11 It takes \u20ac\u20ac to win!", |
357 Object obj = testDate; |
297 res.format("id_11").toString()); |
358 assertEquals("date2 15/01/1970", |
298 |
359 new FormatterQt(res, "date2 %1").arg(obj).toString()); |
299 // Test only character code. |
360 |
300 assertEquals( |
361 assertEquals("date3 15/01/1970", |
301 "\u20ac", |
362 new FormatterQt(res, "date3 %1").format( |
302 res.format("id_12").toString()); |
363 new Object[] { obj })); |
303 |
364 |
304 // Test invalid character code. |
365 obj = new Integer(1); |
305 assertEquals( |
366 assertEquals("1", new FormatterQt(res, "%1").arg(obj).toString()); |
306 "id13 It <0x20A>to win!", |
367 |
307 res.format("id_13").toString()); |
368 obj = new String("me"); |
308 |
369 assertEquals( |
309 |
370 "Test me", |
310 // Test character code as first character. |
371 new FormatterQt(res, "Test %1").arg(obj).toString()); |
311 assertEquals( |
372 |
312 "\u20ac id14", |
373 // Test skip not supported type |
313 res.format("id_14").toString()); |
374 obj = new Boolean(false); |
314 |
375 assertEquals( |
315 // Test character code as last character. |
376 "Test %1", |
316 assertEquals( |
377 new FormatterQt(res, "Test %1").arg(obj).toString()); |
317 "id15 \u20ac", |
378 |
318 res.format("id_15").toString()); |
379 // Test MAX %[8]2 |
319 |
380 //assertEquals( |
320 // Test invalid character. |
381 // "Test testMyTe 100", |
321 assertEquals( |
382 // new FormatterQt(res, "Test %[8]2 %1").arg(100).arg("testMyTest").toString()); |
322 "id16 <0xG0AC>", |
383 |
323 res.format("id_16").toString()); |
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_", "", ""); |
|
450 } |
|
451 |
|
452 private void doResourceLoaderAvkonTest( |
|
453 String resourceFilename, String resourcePrefix, |
|
454 String inPrefix, String outPrefix) |
|
455 { |
|
456 try |
|
457 { |
|
458 ResourceLoader res = |
|
459 ResourceLoaderAvkon.getInstance(resourceFilename, resourcePrefix); |
|
460 |
|
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()); |
|
471 |
|
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()); |
|
481 |
|
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")); |
|
486 |
|
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")); |
|
491 |
|
492 // Test array |
|
493 assertEquals( |
|
494 "id3 test3", |
|
495 res.format(inPrefix + "id_3", new Object[] {"test3"})); |
|
496 |
|
497 // Test enter decoding. |
|
498 assertEquals( |
|
499 "id4 \n test4 \n", |
|
500 res.format(inPrefix + "id_4").arg("test4").toString()); |
|
501 |
|
502 // Test backlash decoding. |
|
503 assertEquals( |
|
504 "\\id5 \\ test5", |
|
505 res.format(inPrefix + "id_5").arg("test5").toString()); |
|
506 |
|
507 // Test double-quote decoding. |
|
508 assertEquals( |
|
509 "id6 \"\" test6", |
|
510 res.format(inPrefix + "id_6").arg("test6").toString()); |
|
511 |
|
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()); |
|
521 |
|
522 // Test character code <0x20AC> |
|
523 assertEquals( |
|
524 "id9 It takes 800 \u20ac to win!", |
|
525 res.format(inPrefix + "id_9").arg(800).toString()); |
|
526 |
|
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()); |
|
531 |
|
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()); |
|
536 |
|
537 // Test only character code. |
|
538 assertEquals( |
|
539 "\u20ac", |
|
540 res.format(inPrefix + "id_12").toString()); |
|
541 |
|
542 // Test invalid character code. |
|
543 assertEquals( |
|
544 "id13 It <0x20A>to win!", |
|
545 res.format(inPrefix + "id_13").toString()); |
|
546 |
|
547 |
|
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 } |
|
613 |
|
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); |
|
658 |
|
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 } |
324 } |
703 } |
325 } |
704 } |