diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ca38a569..6d05ed1e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,6 +20,7 @@ luna_test(libluna/TestFormat.cpp TestFormat) luna_test(libluna/TestHashTable.cpp TestHashTable) luna_test(libluna/TestCPath.cpp TestCPath) luna_test(libluna/TestSharedPtr.cpp TestSharedPtr) +luna_test(libluna/TestSHA.cpp TestSHA) luna_test(libc/TestScanf.cpp TestScanf) luna_test(libc/TestString.cpp TestString) luna_test(libc/TestEnv.cpp TestEnv) diff --git a/tests/libluna/TestSHA.cpp b/tests/libluna/TestSHA.cpp new file mode 100644 index 00000000..bf9178e4 --- /dev/null +++ b/tests/libluna/TestSHA.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +TestResult test_empty_string_hash() +{ + SHA256 sha; + auto digest = TRY(sha.digest()); + auto string = TRY(digest.to_string()); + + validate(string.view() == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); + + test_success; +} + +TestResult test_known_string_hash() +{ + const char* text = "Hello, world!"; + + SHA256 sha; + TRY(sha.append((const u8*)text, strlen(text))); + auto digest = TRY(sha.digest()); + auto string = TRY(digest.to_string()); + + validate(string.view() == "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"); + + test_success; +} + +Result test_main() +{ + test_prelude; + + run_test(test_empty_string_hash); + run_test(test_known_string_hash); + + return {}; +}