1 // Tags: JDK1.4 |
|
2 |
|
3 // Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com) |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Mauve is free software; you can redistribute it and/or modify |
|
8 // it under the terms of the GNU General Public License as published by |
|
9 // the Free Software Foundation; either version 2, or (at your option) |
|
10 // any later version. |
|
11 |
|
12 // Mauve is distributed in the hope that it will be useful, |
|
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 // GNU General Public License for more details. |
|
16 |
|
17 // You should have received a copy of the GNU General Public License |
|
18 // along with Mauve; see the file COPYING. If not, write to |
|
19 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 // Boston, MA 02111-1307, USA. */ |
|
21 |
|
22 package gnu.testlet.java.util.SimpleTimeZone; |
|
23 |
|
24 import gnu.testlet.TestHarness; |
|
25 import gnu.testlet.Testlet; |
|
26 |
|
27 import java.util.Calendar; |
|
28 import java.util.SimpleTimeZone; |
|
29 import java.util.TimeZone; |
|
30 |
|
31 /** |
|
32 * Some checks for the hashCode() method in the SimpleTimeZone class. |
|
33 */ |
|
34 public class hashCode |
|
35 implements Testlet |
|
36 { |
|
37 /** |
|
38 * Runs the tests. |
|
39 * |
|
40 * @param harness the test harness. |
|
41 */ |
|
42 public void test(TestHarness harness) |
|
43 { |
|
44 test1(harness); |
|
45 test2(harness); |
|
46 } |
|
47 |
|
48 private void test1(TestHarness harness) |
|
49 { |
|
50 SimpleTimeZone z1 = new SimpleTimeZone(5 * 60 * 60 * 1000, "Z1"); |
|
51 SimpleTimeZone z2 = new SimpleTimeZone(5 * 60 * 60 * 1000, "Z1"); |
|
52 harness.check(z1.equals(z2)); |
|
53 harness.check(z1.hashCode(), z2.hashCode()); |
|
54 } |
|
55 |
|
56 // Tests converted from the SimpleTimeZoneTest.java attachment |
|
57 // of http://gcc.gnu.org/ml/java-patches/2007-q1/msg00587.html. |
|
58 private void test2(TestHarness harness) |
|
59 { |
|
60 TimeZone utc = (TimeZone) new SimpleTimeZone(0, "GMT"); |
|
61 TimeZone.setDefault(utc); |
|
62 Calendar cal = Calendar.getInstance(utc); |
|
63 |
|
64 TimeZone tz2 = new SimpleTimeZone( |
|
65 -12600000, "Test1", |
|
66 Calendar.MARCH, 8, -Calendar.SUNDAY, 60000, |
|
67 SimpleTimeZone.WALL_TIME, |
|
68 Calendar.NOVEMBER, 1, -Calendar.SUNDAY, 60000, |
|
69 SimpleTimeZone.STANDARD_TIME, |
|
70 3600000); |
|
71 |
|
72 TimeZone tz3 = new SimpleTimeZone( |
|
73 -12600000, "Test2", |
|
74 Calendar.MARCH, 8, -Calendar.SUNDAY, 60000, |
|
75 Calendar.NOVEMBER, 1, -Calendar.SUNDAY, 3660000, |
|
76 3600000); |
|
77 |
|
78 harness.check(tz2.hashCode() != tz3.hashCode()); |
|
79 |
|
80 ((SimpleTimeZone) tz2).setEndRule( |
|
81 Calendar.NOVEMBER, 1, -Calendar.SUNDAY, 3660000); |
|
82 |
|
83 harness.check(tz2.hashCode() == tz3.hashCode()); |
|
84 } |
|
85 |
|
86 } |
|