tests: Add tests for SHA256
All checks were successful
Build and test / build (push) Successful in 2m22s

This commit is contained in:
apio 2024-07-20 16:34:31 +02:00
parent 5fe0507ab1
commit 31c36b9b83
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 39 additions and 0 deletions

View File

@ -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)

38
tests/libluna/TestSHA.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <luna/SHA.h>
#include <string.h>
#include <test.h>
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<void> test_main()
{
test_prelude;
run_test(test_empty_string_hash);
run_test(test_known_string_hash);
return {};
}