1#!/usr/bin/perl
2# Test "cksum -a sm3".
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
19use strict;
20
21(my $program_name = $0) =~ s|.*/||;
22
23# Turn off localization of executable's output.
24@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
25
26my $sha_degenerate =
27  "1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b";
28
29my @Tests =
30    (
31     ['s1', {IN=> {f=> ''}},
32{OUT=>"$sha_degenerate  f\n"}],
33     ['s2', {IN=> {f=> 'a'}},
34{OUT=>"623476ac18f65a2909e43c7fec61b49c7e764a91a18ccb82f1917a29c86c5e88  f\n"}],
35     ['s3', {IN=> {f=> 'abc'}},
36{OUT=>"66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0  f\n"}],
37     ['s4',
38      {IN=> {f=> 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'}},
39{OUT=>"639b6cc5e64d9e37a390b192df4fa1ea0720ab747ff692b9f38c4e66ad7b8c05  f\n"}],
40     ['s8', {IN=> {f=> 'a' x 1000000}},
41{OUT=>"c8aaf89429554029e231941a2acc0ad61ff2a5acd8fadd25847a3a732b3b02c3  f\n"}],
42    );
43
44# Insert the arguments for each test.
45my $t;
46foreach $t (@Tests)
47  {
48    splice @$t, 1, 0, '--untagged --text -a sm3'
49  }
50
51my $save_temps = $ENV{DEBUG};
52my $verbose = $ENV{VERBOSE};
53
54my $prog = 'cksum';
55my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
56exit $fail;
57