Lolly 1.4.28
Loading...
Searching...
No Matches
sha_test.cpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : sha_test.cpp
4 * DESCRIPTION: tests on sha
5 * COPYRIGHT : (C) 2023 Darcy Shen
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#include "a_lolly_test.hpp"
13#include "file.hpp"
14#include "lolly/hash/sha.hpp"
15
18
19TEST_CASE ("sha224_hexdigest") {
20 SUBCASE ("normal file") {
21 string_eq (sha224_hexdigest (url_pwd () * "LICENSE"),
22 "2f051189f6ddb2d2fd11faeb8cf3e3b38b4216f2798ce1d92421e129");
23 }
24 SUBCASE ("empty file") {
25 url temp= url_temp ();
26 string_save ("", temp);
27 CHECK_EQ (file_size (temp), 0);
28 string_eq (sha224_hexdigest (temp),
29 "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f");
30 }
31 SUBCASE ("invalid file") {
32 string_eq (sha224_hexdigest (url_system ("https://mogan.app")), "");
33 string_eq (sha224_hexdigest (url_system ("/path/to/not_exist")), "");
34 }
35}
36
37TEST_CASE ("sha256_hexdigest") {
38 SUBCASE ("normal file") {
39 string_eq (
40 sha256_hexdigest (url_pwd () * "LICENSE"),
41 "8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903");
42 }
43 SUBCASE ("empty file") {
44 url temp= url_temp ();
45 string_save ("", temp);
46 CHECK_EQ (file_size (temp), 0);
47 string_eq (
48 sha256_hexdigest (temp),
49 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
50 }
51 SUBCASE ("invalid file") {
52 string_eq (sha256_hexdigest (url_system ("https://mogan.app")), "");
53 string_eq (sha256_hexdigest (url_system ("/path/to/not_exist")), "");
54 }
55}
The list class represents a linked list.
Definition list.hpp:48
Definition url.hpp:37
void string_save(const string &s, url u)
Definition file.cpp:496
url url_temp(string suffix)
Definition file.cpp:274
int file_size(url u)
Definition file.cpp:155
void string_eq(string left, string right)
string sha224_hexdigest(url u)
Definition sha.cpp:86
string sha256_hexdigest(url u)
Definition sha.cpp:91
TEST_CASE("test for operator+= and advance()")
url url_system(string name)
Definition url.cpp:306
url url_pwd()
Definition url.cpp:326