tests: Add tests for SHA256
All checks were successful
Build and test / build (push) Successful in 2m22s
All checks were successful
Build and test / build (push) Successful in 2m22s
This commit is contained in:
parent
5fe0507ab1
commit
31c36b9b83
@ -20,6 +20,7 @@ luna_test(libluna/TestFormat.cpp TestFormat)
|
|||||||
luna_test(libluna/TestHashTable.cpp TestHashTable)
|
luna_test(libluna/TestHashTable.cpp TestHashTable)
|
||||||
luna_test(libluna/TestCPath.cpp TestCPath)
|
luna_test(libluna/TestCPath.cpp TestCPath)
|
||||||
luna_test(libluna/TestSharedPtr.cpp TestSharedPtr)
|
luna_test(libluna/TestSharedPtr.cpp TestSharedPtr)
|
||||||
|
luna_test(libluna/TestSHA.cpp TestSHA)
|
||||||
luna_test(libc/TestScanf.cpp TestScanf)
|
luna_test(libc/TestScanf.cpp TestScanf)
|
||||||
luna_test(libc/TestString.cpp TestString)
|
luna_test(libc/TestString.cpp TestString)
|
||||||
luna_test(libc/TestEnv.cpp TestEnv)
|
luna_test(libc/TestEnv.cpp TestEnv)
|
||||||
|
38
tests/libluna/TestSHA.cpp
Normal file
38
tests/libluna/TestSHA.cpp
Normal 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 {};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user