Imported Upstream version 3.4
[platform/upstream/ccache.git] / unittest / test_hash.c
1 // Copyright (C) 2010-2018 Joel Rosdahl
2 //
3 // This program is free software; you can redistribute it and/or modify it
4 // under the terms of the GNU General Public License as published by the Free
5 // Software Foundation; either version 3 of the License, or (at your option)
6 // any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITHOUT
9 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 //
13 // You should have received a copy of the GNU General Public License along with
14 // this program; if not, write to the Free Software Foundation, Inc., 51
15 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 // This file contains tests for functions in hash.c.
18
19 #include "../src/ccache.h"
20 #include "framework.h"
21
22 TEST_SUITE(hash)
23
24 TEST(test_vectors_from_rfc_1320_should_be_correct)
25 {
26         struct mdfour h;
27
28         hash_start(&h);
29         hash_string(&h, "");
30         CHECK_STR_EQ_FREE2("31d6cfe0d16ae931b73c59d7e0c089c0-0", hash_result(&h));
31
32         hash_start(&h);
33         hash_string(&h, "a");
34         CHECK_STR_EQ_FREE2("bde52cb31de33e46245e05fbdbd6fb24-1", hash_result(&h));
35
36         hash_start(&h);
37         hash_string(&h, "message digest");
38         CHECK_STR_EQ_FREE2("d9130a8164549fe818874806e1c7014b-14", hash_result(&h));
39
40         hash_start(&h);
41         hash_string(
42           &h,
43           "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
44         CHECK_STR_EQ_FREE2("e33b4ddc9c38f2199c3e7b164fcc0536-80", hash_result(&h));
45 }
46
47 TEST(hash_result_should_be_idempotent)
48 {
49         struct mdfour h;
50
51         hash_start(&h);
52         hash_string(&h, "");
53         CHECK_STR_EQ_FREE2("31d6cfe0d16ae931b73c59d7e0c089c0-0", hash_result(&h));
54         CHECK_STR_EQ_FREE2("31d6cfe0d16ae931b73c59d7e0c089c0-0", hash_result(&h));
55 }
56
57 TEST_SUITE_END