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