javaextensions/location/tsrc/vipertest/src/LandmarkTest.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 import javax.microedition.location.*;
       
    18 
       
    19 public class LandmarkTest extends ViperUnitTest
       
    20 {
       
    21 
       
    22     public LandmarkTest()
       
    23     {
       
    24         super("LandmarkTest");
       
    25     }
       
    26 
       
    27     protected void runTest() throws java.lang.Throwable
       
    28     {
       
    29         testBadConstructor();
       
    30         testConstructor();
       
    31         testBadSetter();
       
    32         testSetters();
       
    33     }
       
    34 
       
    35     void testBadConstructor()
       
    36     {
       
    37         setCurrentTest("testBadConstructor()");
       
    38 
       
    39         try
       
    40         {
       
    41             // Trying to create a landmark where name is null
       
    42             Landmark lm = new Landmark(null, null, null, null);
       
    43             assertTrue(false, "No exception thrown for constructor values");
       
    44         }
       
    45         catch (NullPointerException npe)
       
    46         {
       
    47             // Exception thrown correctly
       
    48         }
       
    49     }
       
    50 
       
    51     void testConstructor()
       
    52     {
       
    53         setCurrentTest("testConstructor()");
       
    54 
       
    55         // Create a Landmark object with correct parameters and check that
       
    56         // the values are unchanged when read.
       
    57         String name = "Office";
       
    58         Landmark lm1 = new Landmark(name, null, null, null);
       
    59 
       
    60         String description = "Where I work";
       
    61         Landmark lm2 = new Landmark(name, description, null, null);
       
    62 
       
    63         float hacc = 50.0f;
       
    64         float vacc = 80.0f;
       
    65         QualifiedCoordinates coords = new QualifiedCoordinates(57.0f, 17.0f,
       
    66                 34.0f, hacc, vacc);
       
    67 
       
    68         Landmark lm3 = new Landmark(name, null, coords, null);
       
    69         Landmark lm4 = new Landmark(name, description, coords, null);
       
    70 
       
    71         AddressInfo address = new AddressInfo();
       
    72 
       
    73         Landmark lm5 = new Landmark(name, null, null, address);
       
    74         Landmark lm6 = new Landmark(name, description, null, address);
       
    75         Landmark lm7 = new Landmark(name, null, coords, address);
       
    76 
       
    77         Landmark lm = new Landmark(name, description, coords, address);
       
    78 
       
    79         // Check the Landmark's values
       
    80         assertTrue(lm.getName() == name && lm.getDescription() == description
       
    81                    && lm.getQualifiedCoordinates() == coords
       
    82                    && lm.getAddressInfo() == address,
       
    83                    "Retrieved Landmark values incorrect");
       
    84 
       
    85     }
       
    86 
       
    87     void testBadSetter()
       
    88     {
       
    89         setCurrentTest("testBadSetter()");
       
    90         String name = "Office";
       
    91 
       
    92         // Create a new unmodified Landmark object
       
    93         Landmark lm = new Landmark(name, null, null, null);
       
    94 
       
    95         try
       
    96         {
       
    97             lm.setName(null);
       
    98             assertTrue(false, "No exception thrown for bad argument");
       
    99         }
       
   100         catch (NullPointerException npe)
       
   101         {
       
   102             // Exception thrown correctly
       
   103         }
       
   104 
       
   105     }
       
   106 
       
   107     void testSetters()
       
   108     {
       
   109         setCurrentTest("testSetters()");
       
   110 
       
   111         String name = "Office";
       
   112 
       
   113         // Create a new unmodified Landmark object
       
   114         Landmark lm = new Landmark(name, null, null, null);
       
   115 
       
   116         String newName = "Home";
       
   117         String description = "Where I live";
       
   118         QualifiedCoordinates coords = new QualifiedCoordinates(57.0f, 17.0f,
       
   119                 34.0f, 20.0f, 20.0f);
       
   120         AddressInfo address = new AddressInfo();
       
   121 
       
   122         lm.setName(newName);
       
   123         lm.setDescription(description);
       
   124         lm.setQualifiedCoordinates(coords);
       
   125         lm.setAddressInfo(address);
       
   126 
       
   127         // Check the Landmark's values
       
   128         assertTrue(lm.getName() == newName
       
   129                    && lm.getDescription() == description
       
   130                    && lm.getQualifiedCoordinates() == coords
       
   131                    && lm.getAddressInfo() == address,
       
   132                    "Retrieved Landmark values incorrect");
       
   133     }
       
   134 }