James Kuszmaul | 56802ab | 2023-08-23 15:18:34 -0700 | [diff] [blame^] | 1 | #include "aos/sha256.h" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | #include "aos/testing/tmpdir.h" |
| 6 | #include "aos/util/file.h" |
| 7 | |
| 8 | namespace aos::testing { |
| 9 | |
| 10 | constexpr const char *kTestString = "Test String"; |
| 11 | constexpr const char *kTestStringSha = |
| 12 | "30c6ff7a44f7035af933babaea771bf177fc38f06482ad06434cbcc04de7ac14"; |
| 13 | |
| 14 | TEST(Sha256Test, ChecksumString) { |
| 15 | EXPECT_EQ(kTestStringSha, Sha256(kTestString)); |
| 16 | EXPECT_EQ("2b4da12a4bfe66a061c24440521a9e5b994e4f0bcc47a17436275f5283bb6852", |
| 17 | Sha256("Test String 2")); |
| 18 | } |
| 19 | |
| 20 | TEST(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 |