1#!/bin/sh
2# Validate cksum --algorithm operation
3
4# Copyright (C) 2021-2023 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
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ cksum
21
22cat > input_options <<\EOF || framework_failure_
23bsd     sum -r
24sysv    sum -s
25crc     cksum
26md5     md5sum MODE
27sha1    sha1sum MODE
28sha224  sha224sum MODE
29sha256  sha256sum MODE
30sha384  sha384sum MODE
31sha512  sha512sum MODE
32blake2b b2sum MODE
33EOF
34
35while read algo prog mode; do
36  for cmode in '-b' '-t'; do
37    pmode="$mode"
38    case $pmode in MODE) pmode=$cmode;; esac
39
40    $prog $pmode /dev/null >> out || continue
41    cksum --untagged $cmode --algorithm=$algo /dev/null > out-c || fail=1
42
43    case "$algo" in
44      bsd) ;;
45      sysv) ;;
46      crc) ;;
47      *) cksum --check --algorithm=$algo out-c || fail=1 ;;
48    esac
49
50    cat out-c >> out-a || framework_failure_
51  done
52done < input_options
53compare out out-a || fail=1
54
55# Ensure --check not allowed with older (non tagged) algorithms
56returns_ 1 cksum -a bsd --check </dev/null || fail=1
57
58# Ensure abbreviations not supported for algorithm selection
59returns_ 1 cksum -a sha22 </dev/null || fail=1
60
61Exit $fail
62