|
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: |
|
15 * |
|
16 */ |
|
17 import java.util.Enumeration; |
|
18 import java.util.Vector; |
|
19 |
|
20 import javax.microedition.location.*; |
|
21 |
|
22 /* |
|
23 * These test are for testing error reports, so that we can avoid regressions |
|
24 * Used for complicated tests that don't fit in the other test suites |
|
25 */ |
|
26 public class ErrorsTest extends ViperUnitTest |
|
27 { |
|
28 private static final String STORE_1_NAME = "store1"; |
|
29 |
|
30 private static final String STORE_2_NAME = "store2"; |
|
31 |
|
32 private static final String LONG_CATEGORY_NAME = "Relatively long category name..."; |
|
33 |
|
34 private static final String SHORT_CATEGORY_NAME = "a"; |
|
35 |
|
36 private static final String LANDMARKSTORE_NAME = "store1"; |
|
37 |
|
38 private static final String SEQUENTIAL_CATEGORY = "sequential_category_tck_jsr179"; |
|
39 |
|
40 private static final QualifiedCoordinates VALID_QUALIFIED_COORDINATES = new QualifiedCoordinates( |
|
41 45.0d, 120.0d, 274f, 7.2f, 10.5f); |
|
42 |
|
43 public ErrorsTest() |
|
44 { |
|
45 super("ErrorsTest"); |
|
46 } |
|
47 |
|
48 protected void runTest() throws java.lang.Throwable |
|
49 { |
|
50 // testGc1(); - Doesn't work, need to change test |
|
51 testGc2(); |
|
52 |
|
53 tp17(); |
|
54 tp19_p1(); |
|
55 tp19_p2(); |
|
56 tp19_p3(); |
|
57 tp19_p4(); |
|
58 tp19_p5(); |
|
59 |
|
60 // Some TCK tests failed, trying to repeat with equivalent tests. |
|
61 landmarkStore0412(); |
|
62 landmarkStore0608(); |
|
63 landmarkStore0701(); |
|
64 landmarkStore0702(); |
|
65 landmarkStore0703(); |
|
66 landmarkStore0801(); |
|
67 landmarkStore0802(); |
|
68 landmarkStore0803(); |
|
69 landmarkStore1201(); |
|
70 landmarkStore1202(); |
|
71 landmarkStore1303(); |
|
72 landmarkStore1701(); |
|
73 } |
|
74 |
|
75 void testGc1() throws Exception |
|
76 { |
|
77 setCurrentTest("testGc1()"); |
|
78 LandmarkStore store = LandmarkStore.getInstance(null); |
|
79 String id = store.toString(); |
|
80 assertTrue(store == LandmarkStore.getInstance(null), |
|
81 "Not the same instance"); |
|
82 |
|
83 store = null; |
|
84 echo("Calling System.gc()"); |
|
85 System.gc(); |
|
86 try |
|
87 { |
|
88 Thread.sleep(1000); |
|
89 } |
|
90 catch (Exception e) |
|
91 { |
|
92 } |
|
93 System.gc(); |
|
94 try |
|
95 { |
|
96 Thread.sleep(1000); |
|
97 } |
|
98 catch (Exception e) |
|
99 { |
|
100 } |
|
101 |
|
102 store = LandmarkStore.getInstance(null); |
|
103 assertFalse(id.equals(store.toString()), "The same instance"); |
|
104 |
|
105 Landmark lm = new Landmark("test", null, null, null); |
|
106 store.addLandmark(lm, null); |
|
107 store.deleteLandmark(lm); |
|
108 } |
|
109 |
|
110 private void testGc_helper1() throws Exception |
|
111 { |
|
112 LandmarkStore store = LandmarkStore.getInstance(null); |
|
113 } |
|
114 |
|
115 private void testGc_helper2() throws Exception |
|
116 { |
|
117 System.gc(); |
|
118 LandmarkStore store = LandmarkStore.getInstance(null); |
|
119 |
|
120 Landmark lm = new Landmark("test", null, null, null); |
|
121 store.addLandmark(lm, null); |
|
122 store.deleteLandmark(lm); |
|
123 } |
|
124 |
|
125 void testGc2() throws Exception |
|
126 { |
|
127 setCurrentTest("testGc2()"); |
|
128 testGc_helper1(); |
|
129 testGc_helper2(); |
|
130 |
|
131 deleteAllLandmarksAndCategories(); |
|
132 } |
|
133 |
|
134 void tp17() throws Throwable |
|
135 { |
|
136 setCurrentTest("tp17()"); |
|
137 |
|
138 // 1. ------------------------------------------------------------------ |
|
139 String lm1_name1 = "lm1_name"; |
|
140 String lm1_description1 = "lm1_description"; |
|
141 String lm1_street1 = "lm1_street"; |
|
142 double lm1_latitude1 = 12.3; |
|
143 double lm1_longitude1 = 32.1; |
|
144 float lm1_altitude1 = 3.9f; |
|
145 float lm1_horAccuracy1 = 5.5f; |
|
146 float lm1_verAccuracy1 = 6.6f; |
|
147 |
|
148 QualifiedCoordinates lm1_coords1 = new QualifiedCoordinates( |
|
149 lm1_latitude1, lm1_longitude1, lm1_altitude1, lm1_horAccuracy1, |
|
150 lm1_verAccuracy1); |
|
151 |
|
152 AddressInfo lm1_addressInfo1 = new AddressInfo(); |
|
153 lm1_addressInfo1.setField(AddressInfo.STREET, lm1_street1); |
|
154 |
|
155 Landmark lm1 = new Landmark(lm1_name1, lm1_description1, lm1_coords1, |
|
156 lm1_addressInfo1); |
|
157 |
|
158 QualifiedCoordinates lm1_coords_returned1 = lm1 |
|
159 .getQualifiedCoordinates(); |
|
160 |
|
161 AddressInfo lm1_addressInfo_returned1 = lm1.getAddressInfo(); |
|
162 |
|
163 // 2. ------------------------------------------------------------------ |
|
164 String lm1_name2 = "lm1_name2"; |
|
165 String lm1_description2 = "lm1_description2"; |
|
166 String lm1_street2 = "lm1_street2"; |
|
167 double lm1_latitude2 = 16.8; |
|
168 double lm1_longitude2 = 26.7; |
|
169 float lm1_altitude2 = 7.1f; |
|
170 float lm1_horAccuracy2 = 2.7f; |
|
171 float lm1_verAccuracy2 = 8.1f; |
|
172 |
|
173 QualifiedCoordinates lm1_coords2 = new QualifiedCoordinates( |
|
174 lm1_latitude2, lm1_longitude2, lm1_altitude2, lm1_horAccuracy2, |
|
175 lm1_verAccuracy2); |
|
176 |
|
177 AddressInfo lm1_addressInfo2 = new AddressInfo(); |
|
178 lm1_addressInfo2.setField(AddressInfo.STREET, lm1_street2); |
|
179 |
|
180 lm1.setName(lm1_name2); |
|
181 lm1.setDescription(lm1_description2); |
|
182 lm1.setQualifiedCoordinates(lm1_coords2); |
|
183 lm1.setAddressInfo(lm1_addressInfo2); |
|
184 |
|
185 QualifiedCoordinates lm1_coords_returned2 = lm1 |
|
186 .getQualifiedCoordinates(); |
|
187 |
|
188 AddressInfo lm1_addressInfo_returned2 = lm1.getAddressInfo(); |
|
189 |
|
190 // 3. ------------------------------------------------------------------ |
|
191 boolean check3 = false; |
|
192 |
|
193 try |
|
194 { |
|
195 lm1.setName(null); |
|
196 assertTrue(false, |
|
197 "TP17-ERR stage3, NullPointerException was not thrown as expected."); |
|
198 } |
|
199 catch (java.lang.NullPointerException e) |
|
200 { |
|
201 check3 = true; |
|
202 } |
|
203 |
|
204 // 4. ------------------------------------------------------------------ |
|
205 String lm2_name1 = "lm2_name1"; |
|
206 |
|
207 Landmark lm2 = new Landmark(lm2_name1, null, null, null); |
|
208 |
|
209 // 5. ------------------------------------------------------------------ |
|
210 boolean check5 = false; |
|
211 |
|
212 try |
|
213 { |
|
214 Landmark lm3 = new Landmark(null, null, null, null); |
|
215 assertTrue(false, |
|
216 "TP17-ERR stage5, NullPointerException was not thrown as expected."); |
|
217 } |
|
218 catch (java.lang.NullPointerException e) |
|
219 { |
|
220 check5 = true; |
|
221 } |
|
222 } |
|
223 |
|
224 void tp19_p1() throws Throwable |
|
225 { |
|
226 setCurrentTest("tp19_p1()"); |
|
227 |
|
228 System.gc(); |
|
229 // waitForEposShutdown(10000); |
|
230 // waitForLandmarksShutdown(10000); |
|
231 // delete_EPOSLM_LDB(); |
|
232 try |
|
233 { |
|
234 Thread.sleep(1000); |
|
235 } |
|
236 catch (Exception e) |
|
237 { |
|
238 } |
|
239 deleteAllLandmarksAndCategories(); |
|
240 |
|
241 LandmarkStore store = LandmarkStore.getInstance(null); |
|
242 |
|
243 // 1. ------------------------------------------------------------------ |
|
244 |
|
245 final String tc80Category = "TC80CategoryISINDEED32CHARACTERS"; |
|
246 |
|
247 store.addCategory(tc80Category); |
|
248 |
|
249 // 2. ------------------------------------------------------------------ |
|
250 |
|
251 boolean check = false; |
|
252 |
|
253 try |
|
254 { |
|
255 store.addCategory(tc80Category); |
|
256 assertTrue(false, |
|
257 "TP19-ERR TC80 stage2, IllegalArgumentException was not thrown as expected."); |
|
258 } |
|
259 catch (java.lang.IllegalArgumentException e) |
|
260 { |
|
261 check = true; |
|
262 } |
|
263 |
|
264 // 3. ------------------------------------------------------------------ |
|
265 |
|
266 check = false; |
|
267 |
|
268 try |
|
269 { |
|
270 store.addCategory(null); |
|
271 assertTrue(false, |
|
272 "TP19-ERR TC80 stage3, NullPointerException was not thrown as expected."); |
|
273 } |
|
274 catch (java.lang.NullPointerException e) |
|
275 { |
|
276 check = true; |
|
277 } |
|
278 store = null; |
|
279 } |
|
280 |
|
281 void tp19_p2() throws Throwable |
|
282 { |
|
283 setCurrentTest("tp19_p2()"); |
|
284 System.gc(); |
|
285 // waitForEposShutdown(10000); |
|
286 // waitForLandmarksShutdown(10000); |
|
287 // delete_EPOSLM_LDB(); |
|
288 try |
|
289 { |
|
290 Thread.sleep(1000); |
|
291 } |
|
292 catch (Exception e) |
|
293 { |
|
294 } |
|
295 deleteAllLandmarksAndCategories(); |
|
296 |
|
297 LandmarkStore store = LandmarkStore.getInstance(null); |
|
298 |
|
299 // 1. ------------------------------------------------------------------ |
|
300 |
|
301 Enumeration emptyEnum = store.getCategories(); |
|
302 assertTrue(!emptyEnum.hasMoreElements(), |
|
303 "TP19-ERR TC90 stage1, Enumeration was not empty."); |
|
304 |
|
305 // 2. ------------------------------------------------------------------ |
|
306 |
|
307 final String tc90cat1 = "TC90cat1"; |
|
308 final String tc90cat2 = "TC90cat2"; |
|
309 |
|
310 store.addCategory(tc90cat1); |
|
311 store.addCategory(tc90cat2); |
|
312 |
|
313 // 3. ------------------------------------------------------------------ |
|
314 |
|
315 Enumeration categories = store.getCategories(); |
|
316 assertTrue(categories.hasMoreElements(), |
|
317 "TP19-ERR stage3, Enumeration was empty."); |
|
318 |
|
319 boolean tc90cat1_found = false; |
|
320 boolean tc90cat2_found = false; |
|
321 |
|
322 int count = 0; |
|
323 |
|
324 while (categories.hasMoreElements()) |
|
325 { |
|
326 |
|
327 String cat_temporary = (String) categories.nextElement(); |
|
328 |
|
329 assertTrue(tc90cat1.equals(cat_temporary) |
|
330 || tc90cat2.equals(cat_temporary), |
|
331 "TP19-ERR stage3, An unexpected Category was found in the LandmarkStore."); |
|
332 |
|
333 if (tc90cat1.equals(cat_temporary)) |
|
334 { |
|
335 tc90cat1_found = true; |
|
336 } |
|
337 if (tc90cat2.equals(cat_temporary)) |
|
338 { |
|
339 tc90cat2_found = true; |
|
340 } |
|
341 |
|
342 count++; |
|
343 } |
|
344 |
|
345 assertTrue(count == 2, |
|
346 "TP19-ERR stage3, There were not 2 elements in the Enumeration."); |
|
347 assertTrue( |
|
348 tc90cat1_found, |
|
349 "TP19-ERR stage3, Category nr 1 - tc90cat1 - was not found in the Landmark store."); |
|
350 assertTrue( |
|
351 tc90cat2_found, |
|
352 "TP19-ERR stage3, Category nr 2 - tc90cat2 - was not found in the Landmark store."); |
|
353 } |
|
354 |
|
355 void tp19_p3() throws Throwable |
|
356 { |
|
357 setCurrentTest("tp19_p3()"); |
|
358 System.gc(); |
|
359 // waitForEposShutdown(10000); |
|
360 // waitForLandmarksShutdown(10000); |
|
361 // delete_EPOSLM_LDB(); |
|
362 try |
|
363 { |
|
364 Thread.sleep(1000); |
|
365 } |
|
366 catch (Exception e) |
|
367 { |
|
368 } |
|
369 deleteAllLandmarksAndCategories(); |
|
370 |
|
371 LandmarkStore store = LandmarkStore.getInstance(null); |
|
372 |
|
373 final String tc91cat1 = "TC91cat1"; |
|
374 store.addCategory(tc91cat1); |
|
375 |
|
376 // 1. ------------------------------------------------------------------ |
|
377 |
|
378 store.deleteCategory(tc91cat1); |
|
379 |
|
380 // 2. ------------------------------------------------------------------ |
|
381 |
|
382 boolean check = false; |
|
383 |
|
384 try |
|
385 { |
|
386 store.deleteCategory(null); |
|
387 assertTrue(false, |
|
388 "TP19-ERR stage4, NullPointerException was not thrown as expected."); |
|
389 } |
|
390 catch (java.lang.NullPointerException e) |
|
391 { |
|
392 check = true; |
|
393 } |
|
394 assertTrue(check, "TP19-ERR TC91 stage2, Wrong Throwable was thrown."); |
|
395 |
|
396 // 3. ------------------------------------------------------------------ |
|
397 |
|
398 store.deleteCategory("TC91_ShouldReturnSilently"); |
|
399 } |
|
400 |
|
401 void tp19_p4() throws Throwable |
|
402 { |
|
403 setCurrentTest("tp19_p4()"); |
|
404 System.gc(); |
|
405 // waitForEposShutdown(10000); |
|
406 // waitForLandmarksShutdown(10000); |
|
407 // delete_EPOSLM_LDB(); |
|
408 try |
|
409 { |
|
410 Thread.sleep(1000); |
|
411 } |
|
412 catch (Exception e) |
|
413 { |
|
414 } |
|
415 deleteAllLandmarksAndCategories(); |
|
416 |
|
417 LandmarkStore store = LandmarkStore.getInstance(null); |
|
418 |
|
419 final String tc92cat = "tc92cat"; |
|
420 final String tc92lmstring = "tc92lm"; |
|
421 |
|
422 Landmark tc92lm = new Landmark(tc92lmstring, null, null, null); |
|
423 store.addLandmark(tc92lm, null); |
|
424 |
|
425 // int err = iVTH.addLandmarksToCategory(tc92lmstring, tc92cat); |
|
426 // assert(err == 0, "TP19-ERR TC92 pre-condition error: (1) Landmark was |
|
427 // not sucessfully added to category."); |
|
428 // assert(iVTH.isLandmarkInCategory(tc92lmstring, tc92cat), "TP19-ERR |
|
429 // TC92 pre-condition error: (2) Landmark was not sucessfully added to |
|
430 // category."); |
|
431 store.addCategory(tc92cat); |
|
432 store.addLandmark(tc92lm, tc92cat); |
|
433 |
|
434 // Flow: --------------------------------------------------------------- |
|
435 store.deleteCategory(tc92cat); |
|
436 } |
|
437 |
|
438 void tp19_p5() throws Throwable |
|
439 { |
|
440 setCurrentTest("tp19_p5()"); |
|
441 System.gc(); |
|
442 // waitForEposShutdown(10000); |
|
443 // waitForLandmarksShutdown(10000); |
|
444 // delete_EPOSLM_LDB(); |
|
445 try |
|
446 { |
|
447 Thread.sleep(1000); |
|
448 } |
|
449 catch (Exception e) |
|
450 { |
|
451 } |
|
452 deleteAllLandmarksAndCategories(); |
|
453 |
|
454 LandmarkStore store = LandmarkStore.getInstance(null); |
|
455 |
|
456 final String tc93cat1 = "tc93cat1"; |
|
457 final String tc93cat2 = "tc93cat2"; |
|
458 final String tc93lmstring = "tc93lm"; |
|
459 |
|
460 // iVTH.addCategory(tc93cat1); |
|
461 // assert(iVTH.categoryExists(tc93cat1), "TP19-ERR TC93 pre-condition |
|
462 // error: category tc93cat1 was not added to LandmarkStore."); |
|
463 store.addCategory(tc93cat1); |
|
464 |
|
465 // iVTH.addCategory(tc93cat2); |
|
466 // assert(iVTH.categoryExists(tc93cat2), "TP19-ERR TC93 pre-condition |
|
467 // error: category tc93cat2 was not added to LandmarkStore."); |
|
468 store.addCategory(tc93cat2); |
|
469 |
|
470 Landmark tc93lm = new Landmark(tc93lmstring, null, null, null); |
|
471 store.addLandmark(tc93lm, null); // null because the landmark will be |
|
472 // added to the category via iVTH |
|
473 // native interface. |
|
474 // assert(iVTH.countLandmarksByName(tc93lmstring) == 1, "TP19-ERR TC93 |
|
475 // pre-condition error: Landmark was not added to LandmarkStore."); |
|
476 |
|
477 // int err = iVTH.addLandmarksToCategory(tc93lmstring, tc93cat1); |
|
478 // assert(err == 0, "TP19-ERR TC93 pre-condition error: (1) Landmark was |
|
479 // not sucessfully added to category."); |
|
480 // assert(iVTH.isLandmarkInCategory(tc93lmstring, tc93cat1), "TP19-ERR |
|
481 // TC93 pre-condition error: (2) Landmark was not sucessfully added to |
|
482 // category."); |
|
483 store.addLandmark(tc93lm, tc93cat1); |
|
484 |
|
485 // err = iVTH.addLandmarksToCategory(tc93lmstring, tc93cat2); |
|
486 // assert(err == 0, "TP19-ERR TC93 pre-condition error: (3) Landmark was |
|
487 // not sucessfully added to category."); |
|
488 // assert(iVTH.isLandmarkInCategory(tc93lmstring, tc93cat1), "TP19-ERR |
|
489 // TC93 pre-condition error: (4) Landmark was not sucessfully added to |
|
490 // category."); |
|
491 store.addLandmark(tc93lm, tc93cat2); |
|
492 |
|
493 // Flow: --------------------------------------------------------------- |
|
494 store.deleteCategory(tc93cat2); |
|
495 // assert(!iVTH.categoryExists(tc93cat2), "TP19-ERR TC93 category |
|
496 // tc93cat2 was not deleted."); |
|
497 // assert(iVTH.categoryExists(tc93cat1), "TP19-ERR TC93 both categories |
|
498 // were deleted from LandmarkStore."); |
|
499 // assert(iVTH.countLandmarksByName(tc93lmstring) == 1, "TP19-ERR TC93 |
|
500 // Landmark was DELETED when deleting category!"); |
|
501 // assert(iVTH.isLandmarkInCategory(tc93lmstring, tc93cat1), "TP19-ERR |
|
502 // TC93 Some strange error occurred!"); |
|
503 } |
|
504 |
|
505 // Equivalent to test LandmarkStore0412 in TCK (?) |
|
506 void landmarkStore0412() throws Exception |
|
507 { |
|
508 setCurrentTest("testLandmarkStore0412()"); |
|
509 |
|
510 removeExistingStores(); |
|
511 |
|
512 LandmarkStore.createLandmarkStore("store1"); |
|
513 LandmarkStore.createLandmarkStore("store2"); |
|
514 |
|
515 LandmarkStore store1 = LandmarkStore.getInstance("store1"); |
|
516 LandmarkStore store2 = LandmarkStore.getInstance("store2"); |
|
517 |
|
518 store1.addCategory("TEST_CATEGORY_1"); |
|
519 store1.addCategory("TEST_CATEGORY_2"); |
|
520 store2.addCategory("TEST_CATEGORY_1"); |
|
521 |
|
522 AddressInfo addressInfo = new AddressInfo(); |
|
523 for (int i = 1; i < 17; ++i) |
|
524 { |
|
525 addressInfo.setField(i, "Some text representing address stuff"); |
|
526 } |
|
527 |
|
528 QualifiedCoordinates q1 = new QualifiedCoordinates(-30.0d, -10.0d, |
|
529 Float.NaN, Float.NaN, Float.NaN); |
|
530 |
|
531 Landmark landmarkToAdd1 = new Landmark("landmark_1_name", |
|
532 "landmark_1_description", q1, addressInfo); |
|
533 |
|
534 QualifiedCoordinates q2 = new QualifiedCoordinates(30.0d, 165.0d, |
|
535 Float.NaN, Float.NaN, Float.NaN); |
|
536 |
|
537 Landmark landmarkToAdd2 = new Landmark("landmark_2_name", |
|
538 "landmark_2_description", q2, addressInfo); |
|
539 |
|
540 QualifiedCoordinates q3 = new QualifiedCoordinates(30.0d, -165.0d, |
|
541 Float.NaN, Float.NaN, Float.NaN); |
|
542 |
|
543 Landmark landmarkToAdd3 = new Landmark("landmark_3_name", |
|
544 "landmark_3_description", q3, addressInfo); |
|
545 |
|
546 addLandmarkToStore(store1, landmarkToAdd1, "TEST_CATEGORY_1"); |
|
547 addLandmarkToStore(store1, landmarkToAdd2, "TEST_CATEGORY_2"); |
|
548 addLandmarkToStore(store2, landmarkToAdd3, "TEST_CATEGORY_1"); |
|
549 |
|
550 // get Landmarks from store1 |
|
551 Enumeration e = store1 |
|
552 .getLandmarks(null, 10.0d, 50.0d, 150.0d, -150.0d); |
|
553 assertTrue(e != null, "No landmarks found"); |
|
554 Landmark received = (Landmark) e.nextElement(); |
|
555 assertTrue(!e.hasMoreElements(), "To many landmarks found"); |
|
556 |
|
557 String lmName = received.getName(); |
|
558 assertTrue(lmName.equals(landmarkToAdd2.getName()), |
|
559 "Wrong landmark found in store"); |
|
560 } |
|
561 |
|
562 // Equivalent to test LandmarkStore0608 in TCK (?) |
|
563 void landmarkStore0608() throws Exception |
|
564 { |
|
565 setCurrentTest("landmarkStore0608()"); |
|
566 removeExistingStores(); |
|
567 |
|
568 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
569 LandmarkStore.createLandmarkStore(STORE_2_NAME); |
|
570 |
|
571 LandmarkStore store1 = LandmarkStore.getInstance(STORE_1_NAME); |
|
572 LandmarkStore store2 = LandmarkStore.getInstance(STORE_2_NAME); |
|
573 |
|
574 Landmark LEGAL_LANDMARK_1 = new Landmark("landmark_1", |
|
575 "description_text", VALID_QUALIFIED_COORDINATES, null); |
|
576 |
|
577 // adds landmark to the stores: |
|
578 addLandmarkToStore(store2, LEGAL_LANDMARK_1, null); |
|
579 |
|
580 addLandmarkToStore(store1, LEGAL_LANDMARK_1, null); |
|
581 |
|
582 // deletes the Landmark landmarkFromStore1 from the store: |
|
583 store1.deleteLandmark(LEGAL_LANDMARK_1); |
|
584 |
|
585 // Queries the Landmarks from the store and checks that the |
|
586 // returned Enumeration isn't null: |
|
587 Vector landmarks = getAllLandmarksFromStore(store2); |
|
588 |
|
589 // there should be two Landmarks in the Vector: |
|
590 assertTrue( |
|
591 landmarks.size() == 1, |
|
592 "One Landmark was added to the newly created LandmarkStore. " |
|
593 + "deleteLandmark was called to another LandmarkStore with" |
|
594 + " same Landmark instance as parameter." |
|
595 + "The store containing the Landmark was expected to " |
|
596 + "remain as is. " |
|
597 + "Still, LandmarkStore.getLandmarks() returned " |
|
598 + "an Enumeration with " + landmarks.size() |
|
599 + " Landmarks."); |
|
600 |
|
601 // Check if landmarks are equal not implemented |
|
602 |
|
603 // if (!LandmarkStoreHelpers |
|
604 // .areLandmarksEqual( |
|
605 // (Landmark) landmarks.firstElement(), |
|
606 // LEGAL_LANDMARK_1, |
|
607 // true)) { |
|
608 // |
|
609 // return m_helper.failTestCase( testCaseID, |
|
610 // "One Landmark was added to newly created LandmarkStore, " |
|
611 // + "but getLandmarks returned a Landmark instance not identical" |
|
612 // + "to added one."); |
|
613 // } |
|
614 |
|
615 landmarks = getAllLandmarksFromStore(store1); |
|
616 assertTrue(landmarks.size() == 0, "One Landmark was stored to named " |
|
617 + "LandmarkStore and deleted, but the store still contains " |
|
618 + "Landmarks."); |
|
619 } |
|
620 |
|
621 // Equivalent to test landmarkStore0701 in TCK (?) |
|
622 void landmarkStore0701() throws Exception |
|
623 { |
|
624 setCurrentTest("landmarkStore0701()"); |
|
625 removeExistingStores(); |
|
626 |
|
627 LandmarkStore store = LandmarkStore.getInstance(null); |
|
628 assertFalse(store == null, |
|
629 " Getting default LandmarkStore with getInstance " |
|
630 + "returned null, but non-null value was expected."); |
|
631 } |
|
632 |
|
633 // Equivalent to test landmarkStore0702 in TCK (?) |
|
634 void landmarkStore0702() throws Exception |
|
635 { |
|
636 setCurrentTest("landmarkStore0702()"); |
|
637 removeExistingStores(); |
|
638 |
|
639 Landmark landmark = new Landmark("Landmark1", "Short description", |
|
640 VALID_QUALIFIED_COORDINATES, |
|
641 getAddressInfo_allFieldsLessThan30Chars()); |
|
642 LandmarkStore def = LandmarkStore.getInstance(null); |
|
643 def.addLandmark(landmark, null); |
|
644 |
|
645 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
646 LandmarkStore store = LandmarkStore.getInstance(STORE_1_NAME); |
|
647 assertFalse(store == null, " Getting LandmarkStore with getInstance " |
|
648 + "returned null, but non-null value was expected."); |
|
649 |
|
650 Vector landmarks = getAllLandmarksFromStore(store); |
|
651 assertFalse( |
|
652 landmarks.size() != 0, |
|
653 "Created new LandmarkStore instance and called." |
|
654 + " getLandmarks() was expected to return zero landmarks, " |
|
655 + " but enumeration containing " + landmarks.size() |
|
656 + " landmarks was returned."); |
|
657 } |
|
658 |
|
659 // Equivalent to test landmarkStore0703 in TCK (?) |
|
660 void landmarkStore0703() throws Exception |
|
661 { |
|
662 setCurrentTest("landmarkStore0703()"); |
|
663 removeExistingStores(); |
|
664 |
|
665 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
666 LandmarkStore store = LandmarkStore.getInstance(STORE_2_NAME); |
|
667 assertFalse(store != null, " Getting LandmarkStore with getInstance " |
|
668 + "returned non-null when null value was expected."); |
|
669 } |
|
670 |
|
671 // Equivalent to test landmarkStore0801 in TCK (?) |
|
672 void landmarkStore0801() throws Exception |
|
673 { |
|
674 setCurrentTest("landmarkStore0801()"); |
|
675 removeExistingStores(); |
|
676 |
|
677 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
678 LandmarkStore store = LandmarkStore.getInstance(STORE_1_NAME); |
|
679 assertTrue(store != null, |
|
680 "Getting created LandmarkStore with getInstance " |
|
681 + "returned null, when non-null value was expected."); |
|
682 |
|
683 // get Landmarks from store |
|
684 Enumeration e = store.getLandmarks(); |
|
685 assertTrue(e == null, "Created new LandmarkStore instance and called" |
|
686 + " getLandmarks(). The expected result was " |
|
687 + "that zero Landmarks are returned. "); |
|
688 } |
|
689 |
|
690 // Equivalent to test landmarkStore0802 in TCK (?) |
|
691 void landmarkStore0802() throws Exception |
|
692 { |
|
693 setCurrentTest("landmarkStore0802()"); |
|
694 |
|
695 removeExistingStores(); |
|
696 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
697 LandmarkStore.createLandmarkStore(STORE_2_NAME); |
|
698 LandmarkStore store = LandmarkStore.getInstance(STORE_2_NAME); |
|
699 assertTrue(store != null, |
|
700 " Getting created LandmarkStore with getInstance " |
|
701 + "returned null, but non-null value was expected."); |
|
702 // get Landmarks from store |
|
703 Enumeration e = store.getLandmarks(); |
|
704 assertTrue(e == null, "Created new LandmarkStore instance and called" |
|
705 + " getLandmarks(). The expected result was " |
|
706 + "that zero Landmarks are returned. "); |
|
707 } |
|
708 |
|
709 // Equivalent to test landmarkStore0803 in TCK (?) |
|
710 void landmarkStore0803() throws Exception |
|
711 { |
|
712 setCurrentTest("landmarkStore0803()"); |
|
713 |
|
714 try |
|
715 { |
|
716 removeExistingStores(); |
|
717 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
718 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
719 } |
|
720 catch (IllegalArgumentException ia) |
|
721 { |
|
722 return; |
|
723 } |
|
724 assertTrue(false, |
|
725 "Created new LandmarkStore with name already in use, " |
|
726 + "expected IllegalArgumentException to be thrown but " |
|
727 + "no exception was caught."); |
|
728 } |
|
729 |
|
730 // Equivalent to test landmarkStore1201 in TCK (?) |
|
731 void landmarkStore1201() throws Exception |
|
732 { |
|
733 setCurrentTest("landmarkStore1201()"); |
|
734 deleteAllLandmarksAndCategories(); |
|
735 |
|
736 LandmarkStore store = LandmarkStore.getInstance(null); |
|
737 store.addCategory(LONG_CATEGORY_NAME); |
|
738 |
|
739 // check that it was actually added |
|
740 Enumeration categories = store.getCategories(); |
|
741 assertTrue(categories != null, "store.getCategories() returned null!"); |
|
742 |
|
743 while (categories.hasMoreElements()) |
|
744 { |
|
745 String name = (String) categories.nextElement(); |
|
746 assertTrue(name != null, "Category name was null!"); |
|
747 if (LONG_CATEGORY_NAME.equals(name)) |
|
748 { |
|
749 return; |
|
750 } |
|
751 } |
|
752 assertTrue(false, "Added category with name \"" + LONG_CATEGORY_NAME |
|
753 + "\" to default LandmarkStore but Category was not" |
|
754 + "returned by getCategories method."); |
|
755 } |
|
756 |
|
757 // Equivalent to test landmarkStore1202 in TCK (?) |
|
758 void landmarkStore1202() throws Exception |
|
759 { |
|
760 setCurrentTest("landmarkStore1202()"); |
|
761 removeExistingStores(); |
|
762 |
|
763 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
764 LandmarkStore store1 = LandmarkStore.getInstance(STORE_1_NAME); |
|
765 |
|
766 LandmarkStore.createLandmarkStore(STORE_2_NAME); |
|
767 LandmarkStore store2 = LandmarkStore.getInstance(STORE_2_NAME); |
|
768 |
|
769 store1.addCategory(LONG_CATEGORY_NAME); |
|
770 |
|
771 // check that it was actually added to store1 only |
|
772 Enumeration categories = store2.getCategories(); |
|
773 |
|
774 while (categories.hasMoreElements()) |
|
775 { |
|
776 String name = (String) categories.nextElement(); |
|
777 assertFalse(LONG_CATEGORY_NAME.equals(name), |
|
778 "Two new LandmarkStores were created and new category " |
|
779 + "was added to " + STORE_1_NAME |
|
780 + ". Still same category was returned from \"" |
|
781 + STORE_2_NAME + "\"."); |
|
782 } |
|
783 |
|
784 categories = store1.getCategories(); |
|
785 |
|
786 while (categories.hasMoreElements()) |
|
787 { |
|
788 String name = (String) categories.nextElement(); |
|
789 if (LONG_CATEGORY_NAME.equals(name)) |
|
790 { |
|
791 return; |
|
792 } |
|
793 } |
|
794 assertTrue(false, "Added category with name \"" + SHORT_CATEGORY_NAME |
|
795 + "\" to default LandmarkStore but Category was not" |
|
796 + "returned by getCategories mehtod."); |
|
797 } |
|
798 |
|
799 // Equivalent to test landmarkStore1303 in TCK (?) |
|
800 void landmarkStore1303() throws Exception |
|
801 { |
|
802 setCurrentTest("landmarkStore1303()"); |
|
803 removeExistingStores(); |
|
804 |
|
805 LandmarkStore.createLandmarkStore(STORE_1_NAME); |
|
806 LandmarkStore store1 = LandmarkStore.getInstance(STORE_1_NAME); |
|
807 |
|
808 LandmarkStore.createLandmarkStore(STORE_2_NAME); |
|
809 LandmarkStore store2 = LandmarkStore.getInstance(STORE_2_NAME); |
|
810 |
|
811 String[] categories1 = getSupportedCategories(store1, 1); |
|
812 String[] categories2 = getSupportedCategories(store2, 1); |
|
813 |
|
814 assertFalse(categories1 == null || categories2 == null, |
|
815 "Required number of supported categories are" |
|
816 + "not available."); |
|
817 |
|
818 // Check that categories were actually added |
|
819 Vector returned = getCategoriesAsVector(store2); |
|
820 assertFalse(!returned.contains(categories2[0]), |
|
821 "One category was added to LandmarkStore" + STORE_2_NAME |
|
822 + " but it was not returned by method getCategories."); |
|
823 |
|
824 returned = getCategoriesAsVector(store1); |
|
825 |
|
826 assertFalse(!returned.contains(categories1[0]), |
|
827 "One category was added to default LandmarkStore" |
|
828 + STORE_1_NAME |
|
829 + " but it was not returned by method getCategories."); |
|
830 |
|
831 store1.deleteCategory(categories1[0]); |
|
832 |
|
833 returned = getCategoriesAsVector(store1); |
|
834 assertFalse(returned.contains(categories1[0]), |
|
835 "One category was added to LandmarkStore" + STORE_1_NAME |
|
836 + " and after that it was deleted. Still it was " |
|
837 + "returned by method getCategories."); |
|
838 |
|
839 returned = getCategoriesAsVector(store2); |
|
840 assertFalse(!returned.contains(categories2[0]), |
|
841 "One category was added to LandmarkStore" + STORE_2_NAME |
|
842 + " it was not deleted, but still it was not returned " |
|
843 + " by method getCategories."); |
|
844 } |
|
845 |
|
846 // Equivalent to test LandmarkStore1701 in TCK (?) |
|
847 void landmarkStore1701() throws Exception |
|
848 { |
|
849 setCurrentTest("landmarkStore1701()"); |
|
850 |
|
851 removeExistingStores(); |
|
852 |
|
853 LandmarkStore.createLandmarkStore(LANDMARKSTORE_NAME); |
|
854 |
|
855 // gets the LandmarkStore: |
|
856 LandmarkStore landmarkStore = LandmarkStore |
|
857 .getInstance(LANDMARKSTORE_NAME); |
|
858 |
|
859 // gets the Landmark that is put to the LandmarkStore: |
|
860 Landmark landmark = new Landmark("sequential_landmark_name", null, |
|
861 new QualifiedCoordinates(80d, 45d, 250f, 20f, 30f), null); |
|
862 |
|
863 landmarkStore.addCategory(SEQUENTIAL_CATEGORY); |
|
864 |
|
865 // adds one Landmark to the LandmarkStore: |
|
866 addLandmarkToStore(landmarkStore, landmark, null); |
|
867 |
|
868 // if we get here, no exceptions were thrown. After this test, |
|
869 // test LandmarkStoreSequentialTestPart4 is run. The order of the |
|
870 // tests is handled by the test script. |
|
871 // Notice: Now the LandmarkStore MUST NOT be emptied before exit! |
|
872 // This status will be ignored: |
|
873 } |
|
874 |
|
875 // ------------------------ Helper methods ----------------------- |
|
876 |
|
877 private String[] getSupportedCategories(LandmarkStore store, int count) |
|
878 throws Exception |
|
879 { |
|
880 |
|
881 assertTrue(store != null && count > 0, "internal error in " |
|
882 + "getSupportedCategories: " + "LandmarkStore=" |
|
883 + store.toString() + " and count=" + count); |
|
884 |
|
885 String[] supported = new String[count]; |
|
886 |
|
887 for (int i = 0; i < count; i++) |
|
888 { |
|
889 String categoryName = "Test_Category_" + i; |
|
890 |
|
891 store.addCategory(categoryName); |
|
892 supported[i] = categoryName; |
|
893 |
|
894 } |
|
895 |
|
896 // makes sure that the right number of categories or null |
|
897 // is always returned: |
|
898 assertFalse(supported != null && supported.length != count, |
|
899 "Internal error: " |
|
900 + "getSupportedCategories() method returned " |
|
901 + "wrong number of categories. " + count |
|
902 + " categories were requested, but " + supported.length |
|
903 + " categories were returned."); |
|
904 return supported; |
|
905 } |
|
906 |
|
907 private Vector getCategoriesAsVector(LandmarkStore store) |
|
908 { |
|
909 Vector v = new Vector(); |
|
910 Enumeration enum = store.getCategories(); |
|
911 while (enum.hasMoreElements()) |
|
912 { |
|
913 v.addElement(enum.nextElement()); |
|
914 } |
|
915 return v; |
|
916 } |
|
917 |
|
918 private Vector getAllLandmarksFromStore(LandmarkStore landmarkStore) |
|
919 throws Exception |
|
920 { |
|
921 Enumeration landmarks = null; |
|
922 landmarks = landmarkStore.getLandmarks(); |
|
923 |
|
924 assertFalse(landmarks != null && !landmarks.hasMoreElements(), |
|
925 "LandmarkStore.getLandmarks() returned an empty Enumeration. " |
|
926 + "If there are no Landmarks " |
|
927 + "in the LandmarkStore, it should return null."); |
|
928 |
|
929 // puts the Landmarks to a Vector: |
|
930 Vector result = new Vector(); |
|
931 while (landmarks != null && landmarks.hasMoreElements()) |
|
932 { |
|
933 Landmark current = (Landmark) landmarks.nextElement(); |
|
934 assertFalse(current == null, |
|
935 "LandmarkStore.getLandmarks() returned an " |
|
936 + "Enumeration that had a null Landmark in it."); |
|
937 result.addElement(current); |
|
938 } |
|
939 return result; |
|
940 } |
|
941 |
|
942 private static AddressInfo getAddressInfo_allFieldsLessThan30Chars() |
|
943 { |
|
944 |
|
945 // creates the AddressInfo object used in the tests |
|
946 // and sets its fields: |
|
947 AddressInfo addressInfo = new AddressInfo(); |
|
948 addressInfo.setField(AddressInfo.BUILDING_FLOOR, |
|
949 "value_building_floor 12"); |
|
950 addressInfo.setField(AddressInfo.BUILDING_NAME, "value_building_name "); |
|
951 addressInfo.setField(AddressInfo.BUILDING_ROOM, "value_building_room"); |
|
952 addressInfo.setField(AddressInfo.BUILDING_ZONE, |
|
953 "value_building_zone east"); |
|
954 addressInfo.setField(AddressInfo.CITY, "value_city Chicago"); |
|
955 addressInfo.setField(AddressInfo.COUNTRY, "value_country"); |
|
956 addressInfo.setField(AddressInfo.COUNTRY_CODE, |
|
957 "value_country_code * # "); |
|
958 addressInfo.setField(AddressInfo.COUNTY, "value_county Helsinki"); |
|
959 addressInfo.setField(AddressInfo.CROSSING1, "value_crossing1"); |
|
960 addressInfo.setField(AddressInfo.CROSSING2, "value_crossing2"); |
|
961 addressInfo.setField(AddressInfo.DISTRICT, "value_district"); |
|
962 addressInfo.setField(AddressInfo.EXTENSION, "value_extension"); |
|
963 addressInfo.setField(AddressInfo.PHONE_NUMBER, |
|
964 "value_phoneNumber +358 1234"); |
|
965 addressInfo |
|
966 .setField(AddressInfo.POSTAL_CODE, "value_postal_code 12345"); |
|
967 addressInfo.setField(AddressInfo.STATE, "value_state Florida"); |
|
968 addressInfo.setField(AddressInfo.STREET, "value_street Wall Street"); |
|
969 addressInfo.setField(AddressInfo.URL, "value_url @ //www.com/?id=8#d"); |
|
970 |
|
971 return addressInfo; |
|
972 } |
|
973 } |