javaextensions/location/tsrc/junit/src/automatic/CriteriaTest.java
branchRCL_3
changeset 18 9ac0a0a7da70
parent 17 0fd27995241b
child 19 71c436fe3ce0
equal deleted inserted replaced
17:0fd27995241b 18:9ac0a0a7da70
     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 package com.nokia.mj.test.lapi;
       
    18 
       
    19 import j2meunit.framework.*;
       
    20 import javax.microedition.location.*;
       
    21 
       
    22 /**
       
    23  * <b>TEST CASE SPECIFICATION</b>
       
    24  *
       
    25  * This suite of testcases tests that: - Criteria object can be created -
       
    26  * Default values are correct - Criteria parameters can be changed
       
    27  *
       
    28  */
       
    29 
       
    30 public class CriteriaTest extends TestCase
       
    31 {
       
    32 
       
    33     public CriteriaTest()
       
    34     {
       
    35     }
       
    36 
       
    37     public CriteriaTest(String sTestName, TestMethod rTestMethod)
       
    38     {
       
    39         super(sTestName, rTestMethod);
       
    40     }
       
    41 
       
    42     /***************************************************************************
       
    43      * Creates the test suite. You need to add a new aSuite.addTest antry for
       
    44      * any new test methods, otherwise they won't be run.
       
    45      */
       
    46     public Test suite()
       
    47     {
       
    48         TestSuite aSuite = new TestSuite();
       
    49 
       
    50         aSuite.addTest(new CriteriaTest("testConstructor", new TestMethod()
       
    51         {
       
    52             public void run(TestCase tc)
       
    53             {
       
    54                 ((CriteriaTest) tc).testConstructor();
       
    55             }
       
    56         }));
       
    57 
       
    58         aSuite.addTest(new CriteriaTest("testSetters", new TestMethod()
       
    59         {
       
    60             public void run(TestCase tc)
       
    61             {
       
    62                 ((CriteriaTest) tc).testSetters();
       
    63             }
       
    64         }));
       
    65 
       
    66         return aSuite;
       
    67 
       
    68     }
       
    69 
       
    70     // Test that Criteria constructor works and that default values are correct
       
    71     public void testConstructor()
       
    72     {
       
    73 
       
    74         Criteria criteria = new Criteria();
       
    75 
       
    76         // Default values
       
    77         int hacc = Criteria.NO_REQUIREMENT;
       
    78         int power = Criteria.NO_REQUIREMENT;
       
    79         boolean costAllowed = true;
       
    80         int vacc = Criteria.NO_REQUIREMENT;
       
    81         int maxresptime = Criteria.NO_REQUIREMENT;
       
    82         boolean speedRequired = false;
       
    83         boolean altitudeRequired = false;
       
    84         boolean addressInfoRequired = false;
       
    85 
       
    86         // Check the defaults
       
    87         assertTrue("Default Criteria values incorrect", criteria
       
    88                    .getHorizontalAccuracy() == hacc
       
    89                    && criteria.getVerticalAccuracy() == vacc
       
    90                    && criteria.getPreferredPowerConsumption() == power
       
    91                    && criteria.getPreferredResponseTime() == maxresptime
       
    92                    && criteria.isAllowedToCost() == costAllowed
       
    93                    && criteria.isSpeedAndCourseRequired() == speedRequired
       
    94                    && criteria.isAltitudeRequired() == altitudeRequired
       
    95                    && criteria.isAddressInfoRequired() == addressInfoRequired);
       
    96 
       
    97     }
       
    98 
       
    99     // Tests that all the setters work
       
   100     public void testSetters()
       
   101     {
       
   102 
       
   103         // Define a Criteria object with non-default parameters and check that
       
   104         // the values are unchanged when read.
       
   105         int hacc = 10;
       
   106         int power = Criteria.POWER_USAGE_LOW;
       
   107         boolean costAllowed = false;
       
   108         int vacc = 45;
       
   109         int maxresptime = 100;
       
   110         boolean speedRequired = true;
       
   111         boolean altitudeRequired = true;
       
   112         boolean addressInfoRequired = true;
       
   113 
       
   114         Criteria criteria = new Criteria();
       
   115         criteria.setHorizontalAccuracy(hacc);
       
   116         criteria.setVerticalAccuracy(vacc);
       
   117         criteria.setPreferredPowerConsumption(power);
       
   118         criteria.setPreferredResponseTime(maxresptime);
       
   119         criteria.setCostAllowed(costAllowed);
       
   120         criteria.setSpeedAndCourseRequired(speedRequired);
       
   121         criteria.setAltitudeRequired(altitudeRequired);
       
   122         criteria.setAddressInfoRequired(addressInfoRequired);
       
   123 
       
   124         // Check that the values are correct
       
   125         assertTrue("Retrieved Criteria values different from input", criteria
       
   126                    .getHorizontalAccuracy() == hacc
       
   127                    && criteria.getVerticalAccuracy() == vacc
       
   128                    && criteria.getPreferredPowerConsumption() == power
       
   129                    && criteria.getPreferredResponseTime() == maxresptime
       
   130                    && criteria.isAllowedToCost() == costAllowed
       
   131                    && criteria.isSpeedAndCourseRequired() == speedRequired
       
   132                    && criteria.isAltitudeRequired() == altitudeRequired
       
   133                    && criteria.isAddressInfoRequired() == addressInfoRequired);
       
   134     }
       
   135 
       
   136 }