This commit is contained in:
@ -27,9 +27,3 @@ TEST(Exception, code)
|
||||
EXPECT_EQ(uint32_t(e.code()), uint32_t(basen::Exception::Code::BASE));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@ -21,9 +21,3 @@ TEST(base58, decodeCheck)
|
||||
EXPECT_EQ(test.first, hex::encode(decodeCheck(test.second)));
|
||||
EXPECT_THROW(decodeCheck("incorrect"), basen::Exception);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
61
test/base64.cpp
Normal file
61
test/base64.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <utility>
|
||||
|
||||
#include <basen/base64.hpp>
|
||||
#include <basen/Exception.hpp>
|
||||
#include <basen/hex.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace base64 {
|
||||
|
||||
TEST(base64, isValid)
|
||||
{
|
||||
std::vector<std::pair<bool, std::string>> tests = {
|
||||
{true, "12=="},
|
||||
{true, "123="},
|
||||
{true, "1234"},
|
||||
{false, "1==="},
|
||||
{false, "?!*"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, isValid(it.second));
|
||||
}
|
||||
std::vector<std::pair<std::string, std::string>> tests = {
|
||||
{"", ""},
|
||||
{"BKUEpQ==", "04a504a5"},
|
||||
{"aGVsbG8=", "68656c6c6f"},
|
||||
{"aGVsbG9v", "68656c6c6f6f"},
|
||||
};
|
||||
TEST(base64, encode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, encode(hex::decode(it.second)));
|
||||
|
||||
std::vector<uint8_t> data = {0x74, 0x65, 0x73, 0x74};
|
||||
std::string str = "";
|
||||
EXPECT_THROW(encode(data.data(), std::numeric_limits<size_t>::max(), str.data(), str.size()), basen::Exception);
|
||||
EXPECT_THROW(encode(data.data(), data.size(), str.data(), str.size()), basen::Exception);
|
||||
EXPECT_NO_THROW(encode(data.data(), 0, str.data(), str.size()));
|
||||
}
|
||||
TEST(base64, encode_1e7)
|
||||
{
|
||||
std::vector<uint8_t> data(1e7);
|
||||
encode(data);
|
||||
}
|
||||
TEST(base64, decode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(hex::encode(decode(it.first)), it.second);
|
||||
|
||||
std::vector<uint8_t> data = {0x61, 0x6e, 0x6f};
|
||||
EXPECT_THROW(decode("FFF", 3, data.data(), data.size()), basen::Exception);
|
||||
EXPECT_THROW(decode("!@#!", 4, data.data(), data.size()), basen::Exception);
|
||||
EXPECT_THROW(decode("FF==", 2, data.data(), 0), basen::Exception);
|
||||
EXPECT_NO_THROW(decode("", 0, data.data(), 0));
|
||||
}
|
||||
TEST(base64, decode_1e7)
|
||||
{
|
||||
std::string str(1e7, '0');
|
||||
decode(str);
|
||||
}
|
||||
|
||||
}
|
||||
85
test/baseN.cpp
Normal file
85
test/baseN.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include <utility>
|
||||
|
||||
#include <basen/base58.hpp>
|
||||
#include <basen/baseN.hpp>
|
||||
#include <basen/Exception.hpp>
|
||||
#include <basen/hex.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace baseN {
|
||||
|
||||
TEST(baseN, digitsMap)
|
||||
{
|
||||
uint8_t map[256];
|
||||
digitsMap(base58::digits, 58, map);
|
||||
EXPECT_TRUE(std::equal(map, map + 256, base58::map));
|
||||
|
||||
EXPECT_THROW(digitsMap("11", 2, map), basen::Exception);
|
||||
}
|
||||
TEST(baseN, isValid)
|
||||
{
|
||||
std::vector<std::pair<bool, std::string>> tests = {
|
||||
{true, "123"},
|
||||
{false, "@#$"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, isValid(it.second, base58::map));
|
||||
}
|
||||
TEST(baseN, sizeEncoded)
|
||||
{
|
||||
std::vector<std::pair<size_t, std::string>> tests = {
|
||||
{6, "12341234"},
|
||||
{5, "00000000"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, sizeEncoded(hex::decode(it.second), 58));
|
||||
|
||||
EXPECT_THROW(sizeEncoded(hex::decode(""), 0), basen::Exception);
|
||||
}
|
||||
TEST(baseN, sizeDecoded)
|
||||
{
|
||||
std::vector<std::pair<size_t, std::string>> tests = {
|
||||
{3, "qwer"},
|
||||
{5, "1111"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, sizeDecoded(it.second, 58, base58::digits));
|
||||
|
||||
EXPECT_THROW(sizeDecoded("", 0, base58::digits), basen::Exception);
|
||||
}
|
||||
std::vector<std::pair<std::string, std::string>> tests = {
|
||||
{"", ""},
|
||||
{"Ky", "044c"},
|
||||
{"KyK", "f94a"},
|
||||
{"KyKX", "387ae2"},
|
||||
{"KyKXa", "0ccbd755"},
|
||||
{"KyKXaa", "02e62ec963"},
|
||||
{"111KyKX", "000000387ae2"},
|
||||
{"4uqWDRyJZUpS6KKwLAiitndmv7TPFt2bfxVVfhJhgTn3Rh6aQtGHQY6PhhNDpCwSNU8a",
|
||||
"057902f9cebebb68879911002aae743280140a78c4a077405b057902f9cebebb68879911002aae743280140a78c4a077405b"},
|
||||
};
|
||||
TEST(baseN, encode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, encode(hex::decode(it.second), 58, base58::digits));
|
||||
}
|
||||
TEST(baseN, encode_1e3)
|
||||
{
|
||||
std::vector<uint8_t> data(1e3);
|
||||
std::fill(data.begin(), data.end(), 1);
|
||||
encode(data, 58, base58::digits);
|
||||
}
|
||||
TEST(baseN, decode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(hex::encode(decode(it.first, 58, base58::digits, base58::map)), it.second);
|
||||
|
||||
EXPECT_THROW(decode("!@#", 58, base58::digits, base58::map), basen::Exception);
|
||||
}
|
||||
TEST(baseN, decode_1e3)
|
||||
{
|
||||
std::string str(1e3, '2');
|
||||
decode(str, 58, base58::digits, base58::map);
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,9 +16,3 @@ TEST(hash, sha256_1e4)
|
||||
sha256(data);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@ -45,9 +45,3 @@ TEST(hex, decode_1e7)
|
||||
std::string str(1e7, '0');
|
||||
decode(str);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
14
test/meson.build
Normal file
14
test/meson.build
Normal file
@ -0,0 +1,14 @@
|
||||
gtest_dep = dependency('gtest', main: true)
|
||||
|
||||
test_exe = executable(
|
||||
'test_exe',
|
||||
'hex.cpp',
|
||||
'baseN.cpp',
|
||||
'base58.cpp',
|
||||
'base64.cpp',
|
||||
'Exception.cpp',
|
||||
'hash/sha256.cpp',
|
||||
dependencies: [basen_dep, gtest_dep],
|
||||
)
|
||||
|
||||
test('lib', test_exe)
|
||||
@ -1,65 +0,0 @@
|
||||
#include <utility>
|
||||
|
||||
#include <basen/base64.hpp>
|
||||
#include <basen/Exception.hpp>
|
||||
#include <basen/hex.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace base64;
|
||||
|
||||
TEST(base64, isValid)
|
||||
{
|
||||
std::vector<std::pair<bool, std::string>> tests = {
|
||||
{true, "12=="},
|
||||
{true, "123="},
|
||||
{true, "1234"},
|
||||
{false, "1==="},
|
||||
{false, "?!*"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, isValid(it.second));
|
||||
}
|
||||
std::vector<std::pair<std::string, std::string>> tests = {
|
||||
{"", ""},
|
||||
{"BKUEpQ==", "04a504a5"},
|
||||
{"aGVsbG8=", "68656c6c6f"},
|
||||
{"aGVsbG9v", "68656c6c6f6f"},
|
||||
};
|
||||
TEST(base64, encode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, encode(hex::decode(it.second)));
|
||||
|
||||
std::vector<uint8_t> data = {0x74, 0x65, 0x73, 0x74};
|
||||
std::string str = "";
|
||||
EXPECT_THROW(encode(data.data(), std::numeric_limits<size_t>::max(), str.data(), str.size()), basen::Exception);
|
||||
EXPECT_THROW(encode(data.data(), data.size(), str.data(), str.size()), basen::Exception);
|
||||
EXPECT_NO_THROW(encode(data.data(), 0, str.data(), str.size()));
|
||||
}
|
||||
TEST(base64, encode_1e7)
|
||||
{
|
||||
std::vector<uint8_t> data(1e7);
|
||||
encode(data);
|
||||
}
|
||||
TEST(base64, decode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(hex::encode(decode(it.first)), it.second);
|
||||
|
||||
std::vector<uint8_t> data = {0x61, 0x6e, 0x6f};
|
||||
EXPECT_THROW(decode("FFF", 3, data.data(), data.size()), basen::Exception);
|
||||
EXPECT_THROW(decode("!@#!", 4, data.data(), data.size()), basen::Exception);
|
||||
EXPECT_THROW(decode("FF==", 2, data.data(), 0), basen::Exception);
|
||||
EXPECT_NO_THROW(decode("", 0, data.data(), 0));
|
||||
}
|
||||
TEST(base64, decode_1e7)
|
||||
{
|
||||
std::string str(1e7, '0');
|
||||
decode(str);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
#include <utility>
|
||||
|
||||
#include <basen/base58.hpp>
|
||||
#include <basen/baseN.hpp>
|
||||
#include <basen/Exception.hpp>
|
||||
#include <basen/hex.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace baseN;
|
||||
|
||||
TEST(baseN, digitsMap)
|
||||
{
|
||||
uint8_t map[256];
|
||||
digitsMap(base58::digits, 58, map);
|
||||
EXPECT_TRUE(std::equal(map, map + 256, base58::map));
|
||||
|
||||
EXPECT_THROW(digitsMap("11", 2, map), basen::Exception);
|
||||
}
|
||||
TEST(baseN, isValid)
|
||||
{
|
||||
std::vector<std::pair<bool, std::string>> tests = {
|
||||
{true, "123"},
|
||||
{false, "@#$"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, isValid(it.second, base58::map));
|
||||
}
|
||||
TEST(baseN, sizeEncoded)
|
||||
{
|
||||
std::vector<std::pair<size_t, std::string>> tests = {
|
||||
{6, "12341234"},
|
||||
{5, "00000000"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, sizeEncoded(hex::decode(it.second), 58));
|
||||
|
||||
EXPECT_THROW(sizeEncoded(hex::decode(""), 0), basen::Exception);
|
||||
}
|
||||
TEST(baseN, sizeDecoded)
|
||||
{
|
||||
std::vector<std::pair<size_t, std::string>> tests = {
|
||||
{3, "qwer"},
|
||||
{5, "1111"},
|
||||
};
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, sizeDecoded(it.second, 58, base58::digits));
|
||||
|
||||
EXPECT_THROW(sizeDecoded("", 0, base58::digits), basen::Exception);
|
||||
}
|
||||
std::vector<std::pair<std::string, std::string>> tests = {
|
||||
{"", ""},
|
||||
{"Ky", "044c"},
|
||||
{"KyK", "f94a"},
|
||||
{"KyKX", "387ae2"},
|
||||
{"KyKXa", "0ccbd755"},
|
||||
{"KyKXaa", "02e62ec963"},
|
||||
{"111KyKX", "000000387ae2"},
|
||||
{"4uqWDRyJZUpS6KKwLAiitndmv7TPFt2bfxVVfhJhgTn3Rh6aQtGHQY6PhhNDpCwSNU8a",
|
||||
"057902f9cebebb68879911002aae743280140a78c4a077405b057902f9cebebb68879911002aae743280140a78c4a077405b"},
|
||||
};
|
||||
TEST(baseN, encode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(it.first, encode(hex::decode(it.second), 58, base58::digits));
|
||||
}
|
||||
TEST(baseN, encode_1e3)
|
||||
{
|
||||
std::vector<uint8_t> data(1e3);
|
||||
std::fill(data.begin(), data.end(), 1);
|
||||
encode(data, 58, base58::digits);
|
||||
}
|
||||
TEST(baseN, decode)
|
||||
{
|
||||
for (auto it : tests)
|
||||
EXPECT_EQ(hex::encode(decode(it.first, 58, base58::digits, base58::map)), it.second);
|
||||
|
||||
EXPECT_THROW(decode("!@#", 58, base58::digits, base58::map), basen::Exception);
|
||||
}
|
||||
TEST(baseN, decode_1e3)
|
||||
{
|
||||
std::string str(1e3, '2');
|
||||
decode(str, 58, base58::digits, base58::map);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user