|
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: |
|
21 * - Criteria object can be created |
|
22 * - Default values are correct |
|
23 * - Criteria parameters can be changed |
|
24 */ |
|
25 public class CriteriaTest extends ViperUnitTest |
|
26 { |
|
27 |
|
28 public CriteriaTest() |
|
29 { |
|
30 super("CriteriaTest"); |
|
31 } |
|
32 |
|
33 protected void runTest() throws java.lang.Throwable |
|
34 { |
|
35 testConstructor(); |
|
36 testSetters(); |
|
37 } |
|
38 |
|
39 // Test that Criteria constructor works and that default values are correct |
|
40 void testConstructor() |
|
41 { |
|
42 setCurrentTest("testConstructor()"); |
|
43 |
|
44 Criteria criteria = new Criteria(); |
|
45 |
|
46 // Default values |
|
47 int hacc = Criteria.NO_REQUIREMENT; |
|
48 int power = Criteria.NO_REQUIREMENT; |
|
49 boolean costAllowed = true; |
|
50 int vacc = Criteria.NO_REQUIREMENT; |
|
51 int maxresptime = Criteria.NO_REQUIREMENT; |
|
52 boolean speedRequired = false; |
|
53 boolean altitudeRequired = false; |
|
54 boolean addressInfoRequired = false; |
|
55 |
|
56 // Check the defaults |
|
57 assertTrue(criteria.getHorizontalAccuracy() == hacc |
|
58 && criteria.getVerticalAccuracy() == vacc |
|
59 && criteria.getPreferredPowerConsumption() == power |
|
60 && criteria.getPreferredResponseTime() == maxresptime |
|
61 && criteria.isAllowedToCost() == costAllowed |
|
62 && criteria.isSpeedAndCourseRequired() == speedRequired |
|
63 && criteria.isAltitudeRequired() == altitudeRequired |
|
64 && criteria.isAddressInfoRequired() == addressInfoRequired, |
|
65 "Default Criteria values incorrect"); |
|
66 |
|
67 } |
|
68 |
|
69 // Tests that all the setters work |
|
70 void testSetters() |
|
71 { |
|
72 setCurrentTest("testSetters()"); |
|
73 |
|
74 // Define a Criteria object with non-default parameters and check that |
|
75 // the values are unchanged when read. |
|
76 int hacc = 10; |
|
77 int power = Criteria.POWER_USAGE_LOW; |
|
78 boolean costAllowed = false; |
|
79 int vacc = 45; |
|
80 int maxresptime = 100; |
|
81 boolean speedRequired = true; |
|
82 boolean altitudeRequired = true; |
|
83 boolean addressInfoRequired = true; |
|
84 |
|
85 Criteria criteria = new Criteria(); |
|
86 criteria.setHorizontalAccuracy(hacc); |
|
87 criteria.setVerticalAccuracy(vacc); |
|
88 criteria.setPreferredPowerConsumption(power); |
|
89 criteria.setPreferredResponseTime(maxresptime); |
|
90 criteria.setCostAllowed(costAllowed); |
|
91 criteria.setSpeedAndCourseRequired(speedRequired); |
|
92 criteria.setAltitudeRequired(altitudeRequired); |
|
93 criteria.setAddressInfoRequired(addressInfoRequired); |
|
94 |
|
95 // Check that the values are correct |
|
96 assertTrue(criteria.getHorizontalAccuracy() == hacc |
|
97 && criteria.getVerticalAccuracy() == vacc |
|
98 && criteria.getPreferredPowerConsumption() == power |
|
99 && criteria.getPreferredResponseTime() == maxresptime |
|
100 && criteria.isAllowedToCost() == costAllowed |
|
101 && criteria.isSpeedAndCourseRequired() == speedRequired |
|
102 && criteria.isAltitudeRequired() == altitudeRequired |
|
103 && criteria.isAddressInfoRequired() == addressInfoRequired, |
|
104 "Retrieved Criteria values different from input"); |
|
105 } |
|
106 |
|
107 } |