diff --git a/test/test-base64.cpp b/test/test-base64.cpp index 0587768..610926f 100644 --- a/test/test-base64.cpp +++ b/test/test-base64.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -6,19 +8,26 @@ using namespace base64; TEST(base64, isValid) { - EXPECT_TRUE(isValid("12==")); - EXPECT_TRUE(isValid("123=")); - EXPECT_TRUE(isValid("1234")); - - EXPECT_FALSE(isValid("1===")); - EXPECT_FALSE(isValid("?!*")); + std::vector> tests = { + {true, "12=="}, + {true, "123="}, + {true, "1234"}, + {false, "1==="}, + {false, "?!*"}, + }; + for (auto it : tests) + EXPECT_EQ(it.first, isValid(it.second)); } TEST(base64, encode) { - EXPECT_EQ(encode(hex::decode("")), ""); - EXPECT_EQ(encode(hex::decode("04a504a5")), "BKUEpQ=="); - EXPECT_EQ(encode(hex::decode("04a504a500")), "BKUEpQA="); - EXPECT_EQ(encode(hex::decode("04a504a50000")), "BKUEpQAA"); + std::vector> tests = { + {"", ""}, + {"BKUEpQ==", "04a504a5"}, + {"BKUEpQA=", "04a504a500"}, + {"BKUEpQAA", "04a504a50000"}, + }; + for (auto it : tests) + EXPECT_EQ(it.first, encode(hex::decode(it.second))); } TEST(base64, encode_1e7) { @@ -27,10 +36,14 @@ TEST(base64, encode_1e7) } TEST(base64, decode) { - EXPECT_EQ(hex::encode(decode("")), ""); - EXPECT_EQ(hex::encode(decode("BKUEpQ==")), "04a504a5"); - EXPECT_EQ(hex::encode(decode("BKUEpQA=")), "04a504a500"); - EXPECT_EQ(hex::encode(decode("BKUEpQAA")), "04a504a50000"); + std::vector> tests = { + {"", ""}, + {"BKUEpQ==", "04a504a5"}, + {"BKUEpQA=", "04a504a500"}, + {"BKUEpQAA", "04a504a50000"}, + }; + for (auto it : tests) + EXPECT_EQ(hex::encode(decode(it.first)), it.second); } TEST(base64, decode_1e7) { diff --git a/test/test-baseN.cpp b/test/test-baseN.cpp index d895d9b..776d472 100644 --- a/test/test-baseN.cpp +++ b/test/test-baseN.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -29,17 +31,25 @@ static const int8_t b58map[] = { TEST(baseN, isValid) { - EXPECT_EQ(true, isValid("123", b58map)); - EXPECT_EQ(false, isValid("@#$", b58map)); + std::vector> tests = { + {true, "123"}, + {false, "@#$"}, + }; + for (auto it : tests) + EXPECT_EQ(it.first, isValid(it.second, b58map)); } TEST(baseN, encode) { - EXPECT_EQ("", encode(hex::decode(""), 58, b58digits)); - EXPECT_EQ("Ky", encode(hex::decode("044c"), 58, b58digits)); - EXPECT_EQ("KyK", encode(hex::decode("f94a"), 58, b58digits)); - EXPECT_EQ("KyKX", encode(hex::decode("387ae2"), 58, b58digits)); - EXPECT_EQ("KyKXa", encode(hex::decode("0ccbd755"), 58, b58digits)); - EXPECT_EQ("KyKXaa", encode(hex::decode("02e62ec963"), 58, b58digits)); + std::vector> tests = { + {"", ""}, + {"Ky", "044c"}, + {"KyK", "f94a"}, + {"KyKX", "387ae2"}, + {"KyKXa", "0ccbd755"}, + {"KyKXaa", "02e62ec963"}, + }; + for (auto it : tests) + EXPECT_EQ(it.first, encode(hex::decode(it.second), 58, b58digits)); } TEST(baseN, encode_1e3) { @@ -49,12 +59,16 @@ TEST(baseN, encode_1e3) } TEST(baseN, decode) { - EXPECT_EQ(hex::encode(decode("", 58, b58digits, b58map)), ""); - EXPECT_EQ(hex::encode(decode("Ky", 58, b58digits, b58map)), "044c"); - EXPECT_EQ(hex::encode(decode("KyK", 58, b58digits, b58map)), "f94a"); - EXPECT_EQ(hex::encode(decode("KyKX", 58, b58digits, b58map)), "387ae2"); - EXPECT_EQ(hex::encode(decode("KyKXa", 58, b58digits, b58map)), "0ccbd755"); - EXPECT_EQ(hex::encode(decode("KyKXaa", 58, b58digits, b58map)), "02e62ec963"); + std::vector> tests = { + {"", ""}, + {"Ky", "044c"}, + {"KyK", "f94a"}, + {"KyKX", "387ae2"}, + {"KyKXa", "0ccbd755"}, + {"KyKXaa", "02e62ec963"}, + }; + for (auto it : tests) + EXPECT_EQ(hex::encode(decode(it.first, 58, b58digits, b58map)), it.second); } TEST(baseN, decode_1e3) {