Added tests for recoding single blocks to all formats
This commit is contained in:
parent
2fa67b6860
commit
cf22f8c569
@ -1,31 +1,54 @@
|
|||||||
#include <ModuleDataFormatter.h>
|
#include <ModuleDataFormatter.h>
|
||||||
#include <GCrypt/Key.h>
|
#include <GCrypt/Key.h>
|
||||||
|
#include <GCrypt/GPrng.h>
|
||||||
#include "Catch2.h"
|
#include "Catch2.h"
|
||||||
|
|
||||||
using namespace Leonetienne::GCrypt;
|
using namespace Leonetienne::GCrypt;
|
||||||
|
|
||||||
// Tests that recoding byte iobase works
|
// Tests that recoding iobase format works
|
||||||
TEST_CASE(__FILE__"RecodingSingleBlock-bytes", "[ModuleDataFormatter]") {
|
TEMPLATE_TEST_CASE_SIG(
|
||||||
|
__FILE__"Data formats can be converted, without changing in value",
|
||||||
|
"[ModuleDataFormatter]",
|
||||||
|
((Configuration::IOBASE_FORMAT formatUnderTest), formatUnderTest),
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_BYTES,
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_2,
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_8,
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_10,
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_16,
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_64,
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_UWU,
|
||||||
|
Configuration::IOBASE_FORMAT::BASE_UGH
|
||||||
|
) {
|
||||||
|
|
||||||
|
// Let's use a GPrng instead of Key::Random,
|
||||||
|
// because Key::Random is rather slow (because it's using hardware events).
|
||||||
|
// We just want randomized data for tests...
|
||||||
|
|
||||||
|
GPrng prng(Key::Random());
|
||||||
|
|
||||||
|
// Let's try 50 different random blocks per test
|
||||||
|
for (std::size_t i = 0; i < 50; i++) {
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
Block b_initial;
|
Block b_initial;
|
||||||
b_initial = Key::Random();
|
b_initial = prng.GetBlock();
|
||||||
|
|
||||||
// Exercise
|
// Exercise
|
||||||
// Convert to bytes
|
// Convert to a custom base
|
||||||
const std::string b_format = ModuleDataFormatter::FormatBlock(
|
const std::string b_format = ModuleDataFormatter::FormatBlock(
|
||||||
b_initial,
|
b_initial,
|
||||||
Configuration::IOBASE_FORMAT::BASE_BYTES
|
formatUnderTest
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert back to a block
|
// Convert back to a block
|
||||||
const Block b_retrieved = ModuleDataFormatter::DecodeFormat(
|
const Block b_retrieved = ModuleDataFormatter::DecodeFormat(
|
||||||
b_format,
|
b_format,
|
||||||
Configuration::IOBASE_FORMAT::BASE_BYTES
|
formatUnderTest
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
// Do b_initial and b_retrieved match?
|
// Do b_initial and b_retrieved match?
|
||||||
REQUIRE(b_initial == b_retrieved);
|
REQUIRE(b_initial == b_retrieved);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user