Skip to content

Commit

Permalink
test: update testcase for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rtgiskard committed Oct 6, 2024
1 parent 426247d commit 0b46c06
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/test_utils.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#include "doctest.h"

#include <cstddef>
#include <cstdint>
#include <array>
#include <string>
Expand All @@ -10,14 +11,14 @@

auto utils = mtrx::utils::KeyUtils(mtrx::utils::HashParams());

TEST_CASE("gen rand bytes") {
TEST_CASE("genRandBytes") {
std::array<uint8_t, 28> hash;

utils.seed();
utils.genRandBytes(hash.data(), hash.size());
}

TEST_CASE("key hash and verify") {
TEST_CASE("KeyUtils: hash and verify") {
// provide hash buffer and a sample key
std::array<uint8_t, 32> hash;
std::string key = "key to hash and verify";
Expand All @@ -43,6 +44,9 @@ TEST_CASE("hexFromBytes") {
CHECK(mtrx::utils::hexFromBytes(buf, 1) == "00");
CHECK(mtrx::utils::hexFromBytes(buf, 2) == "0002");
CHECK(mtrx::utils::hexFromBytes(buf, 4) == "0002c2ef");

auto buf2 = mtrx::utils::make_bytes(0x00, 0x02, 0xc2, 0xef);
CHECK(mtrx::utils::hexFromBytes(buf2.data(), buf2.size()) == "0002c2ef");
}

TEST_CASE("hexToBytes") {
Expand Down Expand Up @@ -84,4 +88,10 @@ TEST_CASE("rand hex convert") {

CHECK(mtrx::utils::hexToBytes(str, buf, sizeof(buf)));
CHECK(mtrx::utils::hexFromBytes(buf, sizeof(buf)) == str);

CHECK(mtrx::utils::hexToBytes(str, (char *)buf, sizeof(buf)));
CHECK(mtrx::utils::hexFromBytes((char *)buf, sizeof(buf)) == str);

CHECK(mtrx::utils::hexToBytes(str, (std::byte *)buf, sizeof(buf)));
CHECK(mtrx::utils::hexFromBytes((std::byte *)buf, sizeof(buf)) == str);
}

0 comments on commit 0b46c06

Please sign in to comment.