|
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 javax.microedition.location.*; |
|
18 |
|
19 /** |
|
20 * This suite of testcases tests that: - Coordinates object can be created and |
|
21 * changed - legal parameters are accepted - illegal parameters are not accepted |
|
22 */ |
|
23 public class QualifiedCoordinatesTest extends CoordinatesTest |
|
24 { |
|
25 private float iHacc; |
|
26 |
|
27 private float iVacc; |
|
28 |
|
29 private final static float[] LEGAL_ACC_VALUES = { 0, Float.NaN, |
|
30 Float.MAX_VALUE, Float.MIN_VALUE, Float.POSITIVE_INFINITY, |
|
31 }; |
|
32 |
|
33 public QualifiedCoordinatesTest() |
|
34 { |
|
35 super("QualifiedCoordinatesTest"); |
|
36 } |
|
37 |
|
38 protected void runTest() throws Throwable |
|
39 { |
|
40 testGoodArguments(); |
|
41 testBadArguments(); |
|
42 testArgumentsRange(); |
|
43 } |
|
44 |
|
45 void testGoodArguments() |
|
46 { |
|
47 setCurrentTest("testGoodArguments()"); |
|
48 |
|
49 float iHacc = 100.0f; |
|
50 float iVacc = 150.0f; |
|
51 |
|
52 super.testGoodArguments(); |
|
53 |
|
54 double lat = 57.111111d; |
|
55 double lon = 17.111111d; |
|
56 float alt = 31.111111f; |
|
57 |
|
58 // Test legal values for hacc |
|
59 for (int i = 0; i < LEGAL_ACC_VALUES.length; ++i) |
|
60 { |
|
61 assertGood(lat, lon, alt, LEGAL_ACC_VALUES[i], iVacc); |
|
62 } |
|
63 |
|
64 // Test legal values for vacc |
|
65 for (int i = 0; i < LEGAL_ACC_VALUES.length; ++i) |
|
66 { |
|
67 assertGood(lat, lon, alt, iHacc, LEGAL_ACC_VALUES[i]); |
|
68 } |
|
69 } |
|
70 |
|
71 void testBadArguments() |
|
72 { |
|
73 setCurrentTest("testBadArguments()"); |
|
74 |
|
75 super.testBadArguments(); |
|
76 } |
|
77 |
|
78 // Tests range of allowed values. |
|
79 void testArgumentsRange() |
|
80 { |
|
81 setCurrentTest("testArgumentsRange()"); |
|
82 |
|
83 super.testArgumentsRange(); |
|
84 |
|
85 // Test maximum allowed values |
|
86 double lat = 90.0d; |
|
87 double lon = 179.99999999999d; |
|
88 float alt = Float.POSITIVE_INFINITY; |
|
89 assertGood(lat, lon, alt); |
|
90 |
|
91 // Test minimum allowed values |
|
92 lat = -90.0d; |
|
93 lon = -180.0d; |
|
94 alt = Float.NEGATIVE_INFINITY; |
|
95 assertGood(lat, lon, alt); |
|
96 |
|
97 // Test out of range positive values |
|
98 lat = 0; |
|
99 lon = 0; |
|
100 double badLat = 90.0000000000001d; |
|
101 double badLon = 180.0d; |
|
102 |
|
103 assertBad(badLat, lon, alt); |
|
104 assertBad(lat, badLon, alt); |
|
105 assertBad(badLat, badLon, alt); |
|
106 |
|
107 // Test out of range negative values |
|
108 badLat = -90.000000000001d; |
|
109 badLon = -180.00000000001d; |
|
110 |
|
111 assertBad(badLat, lon, alt); |
|
112 assertBad(lat, badLon, alt); |
|
113 assertBad(badLat, badLon, alt); |
|
114 } |
|
115 |
|
116 // Inherited from CoordinatesTest |
|
117 protected Coordinates newCoordinates() |
|
118 { |
|
119 return new QualifiedCoordinates(iLat, iLon, iAlt, iHacc, iVacc); |
|
120 } |
|
121 |
|
122 // Inherited from CoordinatesTest |
|
123 protected Coordinates newZeroCoordinates() |
|
124 { |
|
125 return new QualifiedCoordinates(0, 0, 0, 0, 0); |
|
126 } |
|
127 |
|
128 // ------------------------ Helper methods ----------------------- |
|
129 |
|
130 private void assertGood(double aLat, double aLon, float aAlt, float aHacc, |
|
131 float aVacc) |
|
132 { |
|
133 iHacc = aHacc; |
|
134 iVacc = aVacc; |
|
135 assertGood(aLat, aLon, aAlt); |
|
136 |
|
137 QualifiedCoordinates coords = (QualifiedCoordinates) newCoordinates(); |
|
138 |
|
139 assertTrue( |
|
140 (Float.isNaN(aHacc) ^ coords.getHorizontalAccuracy() == aHacc) |
|
141 && (Float.isNaN(aVacc) ^ coords.getVerticalAccuracy() == aVacc), |
|
142 "Coordinates values not equal to constructor input"); |
|
143 |
|
144 // Test setters |
|
145 coords = (QualifiedCoordinates) newZeroCoordinates(); |
|
146 |
|
147 try |
|
148 { |
|
149 coords.setHorizontalAccuracy(aHacc); |
|
150 } |
|
151 catch (IllegalArgumentException iae) |
|
152 { |
|
153 assertTrue(false, "setHorizontalAccuracy(" + aHacc + ") failed"); |
|
154 } |
|
155 |
|
156 try |
|
157 { |
|
158 coords.setVerticalAccuracy(aVacc); |
|
159 } |
|
160 catch (IllegalArgumentException iae) |
|
161 { |
|
162 assertTrue(false, "setVerticalAccuracy(" + aVacc + ") failed"); |
|
163 } |
|
164 } |
|
165 } |