From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3624 invoked by alias); 22 Feb 2007 16:39:28 -0000 Received: (qmail 3579 invoked by uid 22791); 22 Feb 2007 16:39:24 -0000 X-Spam-Check-By: sourceware.org Received: from gbenson.demon.co.uk (HELO gbenson.demon.co.uk) (80.177.220.214) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 22 Feb 2007 16:39:16 +0000 Date: Thu, 22 Feb 2007 16:39:00 -0000 From: Gary Benson To: mauve-patches@sources.redhat.com Subject: FYI: TimeZone tests Message-ID: <20070222163910.GD3932@redhat.com> Mail-Followup-To: mauve-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="kORqDWCi7qDJ0mEj" Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2007/txt/msg00013.txt.bz2 --kORqDWCi7qDJ0mEj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 125 Hi again, This commit adds the TimeZone tests that Jakub Jelinek wrote while writing his new time zone stuff. Cheers, Gary --kORqDWCi7qDJ0mEj Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=patch Content-length: 5145 Index: ChangeLog =================================================================== RCS file: /cvs/mauve/mauve/ChangeLog,v retrieving revision 1.2041 diff -u -r1.2041 ChangeLog --- ChangeLog 22 Feb 2007 13:13:32 -0000 1.2041 +++ ChangeLog 22 Feb 2007 16:31:55 -0000 @@ -1,3 +1,7 @@ +2007-02-22 Gary Benson + + * gnu/testlet/java/util/TimeZone/zdump.java: New test. + 2007-02-22 Gary Benson * gnu/testlet/java/util/SimpleTimeZone/equals.java: New tests. Index: gnu/testlet/java/util/TimeZone/zdump.java =================================================================== RCS file: gnu/testlet/java/util/TimeZone/zdump.java diff -N gnu/testlet/java/util/TimeZone/zdump.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/TimeZone/zdump.java 22 Feb 2007 16:31:55 -0000 @@ -0,0 +1,153 @@ +// Copyright (C) 2007 Red Hat, Inc. +// Written by Gary Benson +// Based on code by Jakub Jelinek + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.4 + +package gnu.testlet.java.util.TimeZone; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Calendar; +import java.util.Date; +import java.util.SimpleTimeZone; +import java.util.TimeZone; + +import gnu.testlet.Testlet; +import gnu.testlet.TestHarness; + +public class zdump implements Testlet +{ + public static final String zdump = "/usr/sbin/zdump"; + + public void test(TestHarness harness) + { + String zoneinfodir = System.getProperty("gnu.java.util.zoneinfo.dir"); + if (zoneinfodir == null) + return; + + if (!new File(zdump).exists() || !new File(zoneinfodir).isDirectory()) + return; + + TimeZone utc = (TimeZone) new SimpleTimeZone(0, "GMT"); + TimeZone.setDefault(utc); + + String[] zones = TimeZone.getAvailableIDs(); + for (int i = 0; i < zones.length; i++) + { + if (!new File(zoneinfodir, zones[i]).exists()) + continue; + + // These two timezones have different definitions between + // tzdata and JDK. In JDK EST is EST5EDT, while in tzdata + // just EST5, similarly for MST. + if (zones[i].equals("EST") || zones[i].equals("MST")) + continue; + + checkZone(harness, zones[i]); + } + } + + public static void checkZone(TestHarness harness, String zone) + { + harness.checkPoint(zone); + + TimeZone tz = TimeZone.getTimeZone(zone); + if (tz == null) + { + harness.check(false); + return; + } + + Calendar cal = Calendar.getInstance(tz); + + BufferedReader br = null; + Process process = null; + try + { + process = Runtime.getRuntime().exec(zdump + " -v " + zone); + br = new BufferedReader(new InputStreamReader( + process.getInputStream())); + + for (String line = br.readLine(); line != null; line = br.readLine()) + { + int end1 = line.indexOf(" UTC = "); + if (end1 < 0) + continue; + int start1 = line.indexOf(" "); + if (start1 < 0 || start1 >= end1) + continue; + int start2 = line.indexOf(" isdst="); + int start3 = line.indexOf(" gmtoff="); + if (start2 <= end1 || start3 <= start2) + continue; + + Date d = new Date(line.substring(start1 + 2, end1 + 4)); + cal.setTime(d); + + int isdst = Integer.parseInt(line.substring(start2 + 7, start3)); + int gmtoff = Integer.parseInt( + line.substring(start3 + 8, line.length())); + + harness.debug("Zone " + zone + " " + d + + " isdst=" + isdst + + " inDaylightTime=" + tz.inDaylightTime(d)); + harness.check(tz.inDaylightTime(d) == (isdst != 0)); + + harness.debug("Zone " + zone + " " + d + + " gmtoff=" + gmtoff + + " getOffset=" + tz.getOffset(d.getTime())); + harness.check(tz.getOffset(d.getTime()) == gmtoff * 1000); + + int offset = cal.get(Calendar.DST_OFFSET) + + cal.get(Calendar.ZONE_OFFSET); + + harness.debug("Zone " + zone + " " + d + + " gmtoff=" + gmtoff + + " DST_OFFSET+ZONE_OFFSET=" + offset); + harness.check(offset == gmtoff * 1000); + } + } + catch (IOException ioe) + { + } + finally + { + try + { + if (br != null) + br.close(); + if (process != null) + { + process.waitFor(); + process.exitValue(); + } + } + catch (IOException ioe) + { + } + catch (InterruptedException ine) + { + } + } + } +} --kORqDWCi7qDJ0mEj--