Renamed method, and added first test to cli

This commit is contained in:
Leonetienne 2022-05-27 15:34:16 +02:00
parent 612157bcac
commit 2fa67b6860
No known key found for this signature in database
GPG Key ID: C33879CD92E9708C
4 changed files with 33 additions and 11 deletions

View File

@ -15,13 +15,13 @@ class ModuleDataFormatter {
static std::string FormatBlock(const Block& block, const Configuration::IOBASE_FORMAT base);
//! Will parse a string of a given iobase to a block
static Block StringToBlock(const std::string& str, const Configuration::IOBASE_FORMAT base);
static Block DecodeFormat(const std::string& str, const Configuration::IOBASE_FORMAT base);
//! Will format a vector of blocks to a given iobase
static std::string FormatBlocks(const std::vector<Block>& blocks, const Configuration::IOBASE_FORMAT base);
//! Will format a string making up multiple block in a given iobase into a vector of block
static std::vector<Block> StringToBlocks(const std::string& str, const Configuration::IOBASE_FORMAT base);
static std::vector<Block> DecodeFormatMultiblock(const std::string& str, const Configuration::IOBASE_FORMAT base);
private:

View File

@ -89,7 +89,7 @@ std::string ModuleDataFormatter::FormatBlocks(
return ss.str();
}
Block ModuleDataFormatter::StringToBlock(
Block ModuleDataFormatter::DecodeFormat(
const std::string& str,
const Configuration::IOBASE_FORMAT base
) {
@ -163,7 +163,7 @@ Block ModuleDataFormatter::StringToBlock(
return b;
}
std::vector<Block> ModuleDataFormatter::StringToBlocks(
std::vector<Block> ModuleDataFormatter::DecodeFormatMultiblock(
const std::string& str,
const Configuration::IOBASE_FORMAT base
) {
@ -194,7 +194,7 @@ std::vector<Block> ModuleDataFormatter::StringToBlocks(
const std::string subs = str.substr(i, blockWidth);
Block newBlock = StringToBlock(
Block newBlock = DecodeFormat(
subs,
base
);
@ -221,7 +221,7 @@ std::vector<Block> ModuleDataFormatter::StringToBlocks(
i - blockStart
);
Block newBlock = StringToBlock(
Block newBlock = DecodeFormat(
subs,
base
);

View File

@ -27,7 +27,7 @@ int main(int argc, char* const* argv) {
std::cout << "Formatted: " << formattedBlocks << std::endl << std::endl;
const std::vector<Block> retrievedBlocks =
ModuleDataFormatter::StringToBlocks(
ModuleDataFormatter::DecodeFormatMultiblock(
formattedBlocks,
Configuration::iobaseFormat
);
@ -90,7 +90,7 @@ int main(int argc, char* const* argv) {
*/
std::cout
<< ModuleDataFormatter::StringToBlock(
<< ModuleDataFormatter::DecodeFormat(
ModuleDataFormatter::FormatBlock(
ModulePrepareKey::GetKey(),
Configuration::iobaseFormat

View File

@ -1,9 +1,31 @@
#include "ModuleDataFormatter.h"
#include <ModuleDataFormatter.h>
#include <GCrypt/Key.h>
#include "Catch2.h"
using namespace Leonetienne::GCrypt;
// Empty test
TEST_CASE(__FILE__"", "[ModuleDataFormatter]") {
// Tests that recoding byte iobase works
TEST_CASE(__FILE__"RecodingSingleBlock-bytes", "[ModuleDataFormatter]") {
// Setup
Block b_initial;
b_initial = Key::Random();
// Exercise
// Convert to bytes
const std::string b_format = ModuleDataFormatter::FormatBlock(
b_initial,
Configuration::IOBASE_FORMAT::BASE_BYTES
);
// Convert back to a block
const Block b_retrieved = ModuleDataFormatter::DecodeFormat(
b_format,
Configuration::IOBASE_FORMAT::BASE_BYTES
);
// Verify
// Do b_initial and b_retrieved match?
REQUIRE(b_initial == b_retrieved);
}