tests/libjava-mauve/src/gnu/testlet/java/lang/Boolean/BooleanTest.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 /* Copyright (C) 1999  Hewlett-Packard Company
       
     2 
       
     3    This file is part of Mauve.
       
     4 
       
     5    Mauve is free software; you can redistribute it and/or modify
       
     6    it under the terms of the GNU General Public License as published by
       
     7    the Free Software Foundation; either version 2, or (at your option)
       
     8    any later version.
       
     9 
       
    10    Mauve is distributed in the hope that it will be useful,
       
    11    but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13    GNU General Public License for more details.
       
    14 
       
    15    You should have received a copy of the GNU General Public License
       
    16    along with Mauve; see the file COPYING.  If not, write to
       
    17    the Free Software Foundation, 59 Temple Place - Suite 330,
       
    18    Boston, MA 02111-1307, USA.
       
    19 */
       
    20 
       
    21 // Tags: JDK1.0
       
    22 
       
    23 package gnu.testlet.java.lang.Boolean;
       
    24 import gnu.testlet.Testlet;
       
    25 import gnu.testlet.TestHarness;
       
    26 
       
    27 public class BooleanTest implements Testlet
       
    28 {
       
    29   public void test_Basics(TestHarness harness)
       
    30   {
       
    31     harness.checkPoint ("Basics");
       
    32 
       
    33     harness.check (Boolean.TRUE.equals(new Boolean(true)) 
       
    34 		   && Boolean.FALSE.equals(new Boolean(false)));
       
    35       
       
    36     Boolean b1 = new Boolean( true );
       
    37     Boolean b2 = new Boolean( false );
       
    38     
       
    39     harness.check (b1.booleanValue() == true && b2.booleanValue() == false);
       
    40       
       
    41     Boolean bs1 = new Boolean ("True");
       
    42     Boolean bs2 = new Boolean ("False");
       
    43     Boolean bs3 = new Boolean ("true");
       
    44     Boolean bs4 = new Boolean ("hi");
       
    45     Boolean bs5 = new Boolean ("");
       
    46 
       
    47     harness.check (bs1.booleanValue() == true 
       
    48 		   && bs2.booleanValue() == false
       
    49 		   && bs3.booleanValue() == true
       
    50 		   && bs4.booleanValue() == false
       
    51 		   && bs5.booleanValue() == false );
       
    52       
       
    53     harness.check (bs1.toString().equals("true")
       
    54 		   && bs2.toString().equals("false"));
       
    55   }
       
    56   
       
    57   public void test_equals (TestHarness harness)
       
    58     {
       
    59       harness.checkPoint ("equals");
       
    60 
       
    61       Boolean b1 = new Boolean(true);
       
    62       Boolean b2 = new Boolean(false);
       
    63       
       
    64       harness.check (! b1.equals(new Integer(4)));
       
    65 
       
    66       harness.check (! b1.equals(null));
       
    67       
       
    68       harness.check (! b1.equals( b2 ));
       
    69       
       
    70       harness.check (b1.equals( new Boolean(true) ));
       
    71     }
       
    72   
       
    73   public void test_hashCode(TestHarness harness)
       
    74     {
       
    75       harness.checkPoint ("hashCode");
       
    76 
       
    77       Boolean b1 = new Boolean(true);
       
    78       Boolean b2 = new Boolean(false);
       
    79       
       
    80       harness.check ( b1.hashCode() == 1231 
       
    81 		      && b2.hashCode() == 1237 );
       
    82     }
       
    83   
       
    84   public void test_booleanValue(TestHarness harness)
       
    85     {
       
    86       harness.checkPoint ("booleanValue");
       
    87 
       
    88       Boolean b1 = new Boolean(true);
       
    89       Boolean b2 = new Boolean(false);
       
    90       
       
    91       harness.check ( b1.booleanValue() == true 
       
    92 		      && b2.booleanValue() == false );
       
    93     }
       
    94   
       
    95   public void test_valueOf(TestHarness harness)
       
    96     {
       
    97       harness.checkPoint ("valueOf");
       
    98 
       
    99       harness.check (Boolean.valueOf("True").booleanValue() 
       
   100 		     && Boolean.valueOf("true").booleanValue()
       
   101 		     && !Boolean.valueOf("anc").booleanValue());
       
   102     }
       
   103   
       
   104   public void test_getBoolean(TestHarness harness)
       
   105     {
       
   106       harness.checkPoint ("getBoolean");
       
   107 
       
   108       java.util.Properties prop = System.getProperties();
       
   109       prop.put("booleankey1" , "true" );
       
   110       prop.put("booleankey2" , "false" );
       
   111       prop.put("booleankey3" , "hi" );
       
   112       
       
   113       System.setProperties(prop);
       
   114 
       
   115       harness.check ( Boolean.getBoolean("booleankey1") == true 
       
   116 		      && Boolean.getBoolean("booleankey2") == false 
       
   117 		      && Boolean.getBoolean("booleankey3") == false );
       
   118     }
       
   119 
       
   120   public void test (TestHarness harness)
       
   121     {
       
   122       test_Basics (harness);
       
   123       test_equals (harness);
       
   124       test_hashCode (harness);
       
   125       test_booleanValue (harness);
       
   126       test_valueOf (harness);
       
   127       test_getBoolean (harness);
       
   128     }
       
   129 }