New upstream version 1.9
[debian/gzip] / tests / timestamp
1 #!/bin/sh
2 # Exercise timestamps.
3
4 # Copyright 2016-2018 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 # limit so don't run it by default.
19
20 . "${srcdir=.}/init.sh"; path_prepend_ ..
21
22 TZ=UTC0
23 export TZ
24 oldIFS=$IFS
25
26 # On platforms supporting timestamps outside gzip's range,
27 # test that gzip warns when converting them to gzip format.
28 for time_date in \
29     '190101010000~Jan  1  1901' \
30     '196912312359.59~Dec 31  1969' \
31     '197001010000~Jan  1  1970' \
32     '210602070628.16~Feb  7  2106'
33 do
34   IFS='~'
35   set $time_date
36   time=$1
37   date=$2
38   IFS=$oldIFS
39   if touch -t $time in; then
40     ls_l=$(ls -l in)
41     case $ls_l in
42       *"$date"*) returns_ 2 gzip in || fail=1;;
43     esac
44   fi
45   rm -f in.gz in
46 done
47
48 # Test that timestamps in range for gzip do not generate warnings.
49 for time_date in \
50     '197001010000.01~Jan  1  1970' \
51     '203801190314.07~Jan 19  2038' \
52     '203801190314.08~Jan 19  2038' \
53     '210602070628.15~Feb  7  2106'
54 do
55   IFS='~'
56   set $time_date
57   time=$1
58   date=$2
59   IFS=$oldIFS
60   if touch -t $time in; then
61     ls_l=$(ls -l in)
62     case $ls_l in
63       *"$date"*) gzip in || fail=1;;
64     esac
65   fi
66   rm -f in.gz in
67 done
68
69 # Test that gzip succeeds when converting timestamps from gzip format,
70 # or warns that the timestamp is out of time_t range.
71 printf '\037\213\10\0\377\377\377\377\0\377\3\0\0\0\0\0\0\0\0\0' >y2106.gz ||
72   framework_failure_
73 gzip -Nlv <y2106.gz
74 status=$?
75 test $status -eq 0 || test $status -eq 2 || fail=1
76
77 # Ensure that --no-name does not provoke a timestamp warning.
78 : | gzip --no-name > k || fail=1
79
80 Exit $fail