179894
commit ebe899af0dc3215159a9c896ac6f35b72a18cb6e
179894
Author: Hans-Peter Nilsson <hp@axis.com>
179894
Date:   Fri Dec 17 21:45:54 2021 +0100
179894
179894
    timezone: test-case for BZ #28707
179894
179894
    This test-case is the tzfile for Asuncion generated by
179894
    tzlib-2021e as follows, using the tzlib-2021e zic: "zic -d
179894
    DEST -r @1546300800 -L /dev/null -b slim
179894
    SOURCE/southamerica".  Note that in its type 2 header, it
179894
    has two entries in its "time-types" array (types), but only
179894
    one entry in its "transition types" array (type_idxs).
179894
  
179894
            * timezone/Makefile, timezone/tst-pr28707.c,
179894
            timezone/testdata/gen-XT5.sh: New test.
179894
    
179894
    Co-authored-by: Christopher Wong <Christopher.Wong@axis.com>
179894
179894
    Reworked due to timezone/Makefile difference.
179894
179894
diff -Nrup a/timezone/Makefile b/timezone/Makefile
179894
--- a/timezone/Makefile	2021-07-06 15:04:00.000000000 -0400
179894
+++ b/timezone/Makefile	2022-01-05 15:03:57.433756574 -0500
179894
@@ -23,7 +23,7 @@ subdir	:= timezone
179894
 include ../Makeconfig
179894
 
179894
 others	:= zdump zic
179894
-tests	:= test-tz tst-timezone tst-tzset
179894
+tests	:= test-tz tst-timezone tst-tzset tst-bz28707
179894
 
179894
 generated-dirs += testdata
179894
 
179894
@@ -85,10 +85,12 @@ $(objpfx)tst-timezone.out: $(addprefix $
179894
 				       America/Sao_Paulo Asia/Tokyo \
179894
 				       Europe/London)
179894
 $(objpfx)tst-tzset.out: $(addprefix $(testdata)/XT, 1 2 3 4)
179894
+$(objpfx)tst-bz28707.out: $(testdata)/XT5
179894
 
179894
 test-tz-ENV = TZDIR=$(testdata)
179894
 tst-timezone-ENV = TZDIR=$(testdata)
179894
 tst-tzset-ENV = TZDIR=$(testdata)
179894
+tst-bz28707-ENV = TZDIR=$(testdata)
179894
 
179894
 # Note this must come second in the deps list for $(built-program-cmd) to work.
179894
 zic-deps = $(objpfx)zic $(leapseconds) yearistype
179894
@@ -122,6 +124,10 @@ $(testdata)/XT%: testdata/XT%
179894
 	$(make-target-directory)
179894
 	cp $< $@
179894
 
179894
+$(testdata)/XT%: testdata/gen-XT%.sh
179894
+	$(SHELL) $< > $@.tmp
179894
+	mv $@.tmp $@
179894
+
179894
 $(objpfx)tzselect: tzselect.ksh $(common-objpfx)config.make
179894
 	sed -e 's|/bin/bash|$(BASH)|' \
179894
 	    -e 's|TZDIR=[^}]*|TZDIR=$(zonedir)|' \
179894
diff -Nrup a/timezone/testdata/gen-XT5.sh b/timezone/testdata/gen-XT5.sh
179894
--- a/timezone/testdata/gen-XT5.sh	1969-12-31 19:00:00.000000000 -0500
179894
+++ b/timezone/testdata/gen-XT5.sh	2022-01-05 12:50:01.666972313 -0500
179894
@@ -0,0 +1,16 @@
179894
+#! /bin/sh
179894
+
179894
+# This test-case is the tzfile for America/Asuncion
179894
+# generated by tzlib-2021e as follows, using the tzlib-2021e
179894
+# zic: "zic -d DEST -r @1546300800 -L /dev/null -b slim
179894
+# SOURCE/southamerica".  Note that in its type 2 header, it
179894
+# has two entries in its "time-types" array (types), but
179894
+# only one entry in its "transition types" array
179894
+# (type_idxs).
179894
+
179894
+printf \
179894
+'TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'\
179894
+'\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0\0\0\0TZif2\0\0\0\0\0\0\0\0'\
179894
+'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\2\0\0\0\b\0'\
179894
+'\0\0\0\*\255\200\1\0\0\0\0\0\0\377\377\325\320\1\4-00\0-03\0\n'\
179894
+'<-04>4<-03>,M10.1.0/0,M3.4.0/0\n'
179894
diff -Nrup a/timezone/tst-bz28707.c b/timezone/tst-bz28707.c
179894
--- a/timezone/tst-bz28707.c	1969-12-31 19:00:00.000000000 -0500
179894
+++ b/timezone/tst-bz28707.c	2022-01-05 12:50:01.666972313 -0500
179894
@@ -0,0 +1,46 @@
179894
+/* Copyright (C) 2021 Free Software Foundation, Inc.
179894
+   This file is part of the GNU C Library.
179894
+
179894
+   The GNU C Library is free software; you can redistribute it and/or
179894
+   modify it under the terms of the GNU Lesser General Public
179894
+   License as published by the Free Software Foundation; either
179894
+   version 2.1 of the License, or (at your option) any later version.
179894
+
179894
+   The GNU C Library is distributed in the hope that it will be useful,
179894
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
179894
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
179894
+   Lesser General Public License for more details.
179894
+
179894
+   You should have received a copy of the GNU Lesser General Public
179894
+   License along with the GNU C Library; if not, see
179894
+   <https://www.gnu.org/licenses/>.  */
179894
+
179894
+#include <time.h>
179894
+#include <stdio.h>
179894
+#include <stdlib.h>
179894
+#include <string.h>
179894
+
179894
+/* Test that we can use a truncated timezone-file, where the time-type
179894
+   at index 0 is not indexed by the transition-types array (and the
179894
+   transition-types array does not contain at least both one DST and one
179894
+   normal time members).  */
179894
+
179894
+static int
179894
+do_test (void)
179894
+{
179894
+  if (setenv ("TZ", "XT5", 1))
179894
+    {
179894
+      puts ("setenv failed.");
179894
+      return 1;
179894
+    }
179894
+
179894
+  tzset ();
179894
+
179894
+  return
179894
+    /* Sanity-check that we got the right timezone-name for DST.  For
179894
+       normal time, we're likely to get "-00" (the "unspecified" marker),
179894
+       even though the POSIX timezone string says "-04".  Let's not test
179894
+       that.  */
179894
+    !(strcmp (tzname[1], "-03") == 0);
179894
+}
179894
+#include <support/test-driver.c>