blob: 33ab5ec7aad73cf7178d0acd770d6f04ceb1bdee [file] [log] [blame]
James Kuszmaul56802ab2023-08-23 15:18:34 -07001#include "aos/sha256.h"
2
3#include "gtest/gtest.h"
4
5#include "aos/testing/tmpdir.h"
6#include "aos/util/file.h"
7
8namespace aos::testing {
9
10constexpr const char *kTestString = "Test String";
11constexpr const char *kTestStringSha =
12 "30c6ff7a44f7035af933babaea771bf177fc38f06482ad06434cbcc04de7ac14";
13
14TEST(Sha256Test, ChecksumString) {
15 EXPECT_EQ(kTestStringSha, Sha256(kTestString));
16 EXPECT_EQ("2b4da12a4bfe66a061c24440521a9e5b994e4f0bcc47a17436275f5283bb6852",
17 Sha256("Test String 2"));
18}
19
20TEST(Sha256Test, ChecksumFile) {
21 const std::filesystem::path test_file =
22 aos::testing::TestTmpDir() + "/test.txt";
23 util::WriteStringToFileOrDie(test_file.string(), kTestString);
24 EXPECT_EQ(kTestStringSha, Sha256OfFile(test_file));
25}
26
27} // namespace aos::testing