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