summaryrefslogtreecommitdiff
path: root/libjava/classpath/testsuite/java.lang/BooleanTest.java
blob: caee011bf44c10ef97597f49569a5fe25dc8de4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
 * Test the Boolean object wrapper class.
 *
 * @author Brian Jones (brian.jones@oryxsoft.com)
 */
public class BooleanTest 
{
  Boolean j;
  String x;

  public static void main (String[] argv)
    {
      BooleanTest test = new BooleanTest();
      
      test.constructorsTest();
      test.booleanValueTest();
      test.equalsTest();
      test.getBooleanTest();
      test.hashCodeTest();
      test.toStringTest();
      test.valueOfTest();
      test.variablesTest();
    }

  public void constructorsTest()
    {
      j = new Boolean(true);    // is true
      if (j.booleanValue() != true)
	failed("Boolean(true)");
      else
	passed("Boolean(true)");

      j = new Boolean(false);   // is false
      if (j.booleanValue() != false)
	failed("Boolean(false)");
      else
	passed("Boolean(false)");

      j = new Boolean("tRuE");  // is true
      if (j.booleanValue() != true)
	failed("Boolean(\"tRuE\")");
      else
	passed("Boolean(String)");

      j = new Boolean("brian"); // is false
      if (j.booleanValue() != false)
	failed("Boolean(\"brian\")");
      else
	passed("Boolean(String)");

      j = new Boolean(null);    // is false
      if (j.booleanValue() != false)
	failed("Boolean(null)");
      else
	passed("Boolean(String)");
    }

  public void booleanValueTest()
    {
      if (Boolean.TRUE.booleanValue() != true)
	failed("Boolean.booleanValue()");
      else
	passed("Boolean.booleanValue()");
    }

  public void equalsTest()
    {
      j = new Boolean("false");
      if (j.equals(Boolean.FALSE) != true)
	failed("Boolean.equals(Object)");
      else
	passed("Boolean.equals(Object)");
    }

  public void getBooleanTest()
    {
      if (Boolean.getBoolean("BIG_DAWG_TEST"))
	failed("Boolean.getBoolean(String)");
      else
	passed("Boolean.getBoolean(String)");
    }

  public void hashCodeTest()
    {
      j = new Boolean(null);    // is false
      boolean caught = false;
      try 
	{
	  int i = j.hashCode();
	}
      catch (Exception e)
	{
	  caught = true;
	  failed("Boolean.hashCode()");
	}
      if (!caught)
	passed("Boolean.hashCode()");
    }

  public void toStringTest()
    {
      j = Boolean.TRUE;
      String x = j.toString();
      if (x.equals("true") != true)
	failed("j.toString() where j is Boolean.TRUE");
      else
	passed("Boolean.toString()");

      j = Boolean.FALSE;
      x = j.toString();
      if (x.equals("false") != true)
	failed("j.toString() where j is Boolean.FALSE");
      else
	passed("Boolean.toString()");
    }

  public void valueOfTest()
    {
      j = Boolean.valueOf("tRUe"); // true
      if (j.booleanValue() != true)
	failed("Boolean.valueOf(String)");
      else
	passed("Boolean.valueOf(String)");

      j = Boolean.valueOf(null);   // false
      if (j.booleanValue() != false)
	failed("Boolean.valueOf(null)");
      else
	passed("Boolean.valueOf(null)");

      j = Boolean.valueOf("lc");   // false
      if (j.booleanValue() != false)
	failed("Boolean.valueOf(String)");
      else
	passed("Boolean.valueOf(String)");
    }

  public void variablesTest()
    {
      if (Boolean.TRUE.booleanValue() != true)
	failed("Boolean.TRUE");
      else
	passed("Boolean.TRUE");

      if (Boolean.FALSE.booleanValue() != false)
	failed("Boolean.FALSE");
      else
	passed("Boolean.FALSE");

      x = Boolean.TYPE.getName();
      if (x.equals("boolean") != true)
	failed("Boolean.TYPE.getName() is " + x + " != boolean");
      else
	passed("Boolean.TYPE.getName() is boolean");
    }

  public void failed(String s)
    {
      if (s != null)
	System.out.println("FAILED: " + s);
      else
	System.out.println("FAILED: ");
    }

  public void passed(String s)
    {
      if (s != null)
	System.out.println("PASSED: " + s);
      else
	System.out.println("PASSED: ");
    }
}