Tests and documentation for base32.

This commit is contained in:
EinMByte 2015-07-23 14:46:35 +02:00
parent 28a4f4173d
commit 469981cce5
3 changed files with 63 additions and 12 deletions

View file

@ -9,12 +9,12 @@ using namespace i2p::data;
BOOST_AUTO_TEST_CASE(Base64EncodeEmpty)
{
ByteStreamToBase64(nullptr, 0, nullptr, 0);
BOOST_CHECK_EQUAL(ByteStreamToBase64(nullptr, 0, nullptr, 0), 0);
}
BOOST_AUTO_TEST_CASE(Base64DecodeEmpty)
{
Base64ToByteStream(nullptr, 0, nullptr, 0);
BOOST_CHECK_EQUAL(Base64ToByteStream(nullptr, 0, nullptr, 0), 0);
}
BOOST_AUTO_TEST_CASE(Base64Encode)
@ -43,7 +43,40 @@ BOOST_AUTO_TEST_CASE(Base64Decode)
BOOST_CHECK_EQUAL_COLLECTIONS(result, result + 25, output, output + 25);
}
BOOST_AUTO_TEST_CASE(Base32EncodeEmpty)
{
BOOST_CHECK_EQUAL(ByteStreamToBase32(nullptr, 0, nullptr, 0), 0);
}
BOOST_AUTO_TEST_CASE(Base32DecodeEmpty)
{
BOOST_CHECK_EQUAL(Base32ToByteStream(nullptr, 0, nullptr, 0), 0);
}
BOOST_AUTO_TEST_CASE(Base32Encode)
{
const uint8_t input[] = {
0x53, 0xd3, 0x60, 0xfa, 0xf9, 0x58, 0xd0, 0x5e, 0x41, 0xa9, 0x6c,
0xf1, 0x9f, 0xc4, 0xe, 0x23, 0x9b, 0xca, 0xb1, 0x61, 0xa7, 0x33, 0xcf,
0x1f, 0x30
};
const char* output = "kpjwb6xzldif4qnjntyz7raoeon4vmlbu4z46hzq";
char result[40];
ByteStreamToBase32(input, 25, result, 40);
BOOST_CHECK_EQUAL_COLLECTIONS(result, result + 40, output, output + 40);
}
BOOST_AUTO_TEST_CASE(Base32Decode)
{
const char* input = "kpjwb6xzldif4qnjntyz7raoeon4vmlbu4z46hzq";
const uint8_t output[] = {
0x53, 0xd3, 0x60, 0xfa, 0xf9, 0x58, 0xd0, 0x5e, 0x41, 0xa9, 0x6c,
0xf1, 0x9f, 0xc4, 0xe, 0x23, 0x9b, 0xca, 0xb1, 0x61, 0xa7, 0x33, 0xcf,
0x1f, 0x30
};
uint8_t result[25];
Base32ToByteStream(input, 40, result, 25);
BOOST_CHECK_EQUAL_COLLECTIONS(result, result + 25, output, output + 25);
}
BOOST_AUTO_TEST_SUITE_END()