diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
commit | 619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch) | |
tree | 01868de723cb82c86842f33743fa7b14e24c1fa3 /test/buildtool/crypto | |
download | justbuild-619def44c1cca9f3cdf63544d5f24f2c7a7d9b77.tar.gz |
Initial self-hosting commit
This is the initial version of our tool that is able to
build itself. In can be bootstrapped by
./bin/bootstrap.py
Co-authored-by: Oliver Reiche <oliver.reiche@huawei.com>
Co-authored-by: Victor Moreno <victor.moreno1@huawei.com>
Diffstat (limited to 'test/buildtool/crypto')
-rw-r--r-- | test/buildtool/crypto/TARGETS | 13 | ||||
-rw-r--r-- | test/buildtool/crypto/crypto.test.cpp | 57 |
2 files changed, 70 insertions, 0 deletions
diff --git a/test/buildtool/crypto/TARGETS b/test/buildtool/crypto/TARGETS new file mode 100644 index 00000000..2f604833 --- /dev/null +++ b/test/buildtool/crypto/TARGETS @@ -0,0 +1,13 @@ +{ "crypto": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["crypto"] + , "srcs": ["crypto.test.cpp"] + , "deps": + [ ["@", "catch2", "", "catch2"] + , ["test", "catch-main"] + , ["src/buildtool/crypto", "hash_generator"] + ] + , "stage": ["test", "buildtool", "crypto"] + } +, "TESTS": {"type": "install", "tainted": ["test"], "deps": ["crypto"]} +}
\ No newline at end of file diff --git a/test/buildtool/crypto/crypto.test.cpp b/test/buildtool/crypto/crypto.test.cpp new file mode 100644 index 00000000..78bea66b --- /dev/null +++ b/test/buildtool/crypto/crypto.test.cpp @@ -0,0 +1,57 @@ +#include <algorithm> + +#include "catch2/catch.hpp" +#include "src/buildtool/crypto/hash_generator.hpp" + +template <HashGenerator::HashType type> +void test_single_hash(std::string const& bytes, std::string const& result) { + HashGenerator hash_gen{type}; + auto digest = hash_gen.Run(bytes); + CHECK(digest.HexString() == result); +} + +template <HashGenerator::HashType type> +void test_increment_hash(std::string const& bytes, std::string const& result) { + HashGenerator hash_gen{type}; + auto hasher = hash_gen.IncrementalHasher(); + hasher.Update(bytes); + auto digest = std::move(hasher).Finalize(); + CHECK(digest); + CHECK(digest->HexString() == result); +} + +TEST_CASE("Hash Generator", "[crypto]") { + std::string bytes{"test"}; + + SECTION("MD5") { + // same as: echo -n test | md5sum + test_single_hash<HashGenerator::HashType::MD5>( + bytes, "098f6bcd4621d373cade4e832627b4f6"); + test_increment_hash<HashGenerator::HashType::MD5>( + bytes, "098f6bcd4621d373cade4e832627b4f6"); + } + + SECTION("SHA-1") { + // same as: echo -n test | sha1sum + test_single_hash<HashGenerator::HashType::SHA1>( + bytes, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); + test_increment_hash<HashGenerator::HashType::SHA1>( + bytes, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); + } + + SECTION("SHA-256") { + // same as: echo -n test | sha256sum + test_single_hash<HashGenerator::HashType::SHA256>( + bytes, + "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); + test_increment_hash<HashGenerator::HashType::SHA256>( + bytes, + "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); + } + + SECTION("Git") { + // same as: echo -n test | git hash-object --stdin + test_single_hash<HashGenerator::HashType::GIT>( + bytes, "30d74d258442c7c65512eafab474568dd706c430"); + } +} |