#include #include /////////////////////////////////////////////////////////////////////////////// static constexpr char input[] = "foobar"; /////////////////////////////////////////////////////////////////////////////// // test vectors from rfc4648 template struct output { static const char *value[std::size (input)]; }; //----------------------------------------------------------------------------- template <> const char* output<64>::value[] = { "", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy", }; //----------------------------------------------------------------------------- template <> const char* output<32>::value[] { "", "MY======", "MZXQ====", "MZXW6===", "MZXW6YQ=", "MZXW6YTB", "MZXW6YTBOI======" }; //----------------------------------------------------------------------------- #if 0 template <> const char* output<32h>::value[] { "", "CO======", "CPNG====", "CPNMU===", "CPNMUOG=", "CPNMUOJ1", "CPNMUOJ1E8======", } #endif //----------------------------------------------------------------------------- template <> const char *output<16>::value[] = { "", "66", "666F", "666F6F", "666F6F62", "666F6F6261", "666F6F626172" }; //----------------------------------------------------------------------------- template const auto output_v = output::value; /////////////////////////////////////////////////////////////////////////////// template void test_size (cruft::TAP::logger &tap) { for (unsigned i = 0; i < std::size (input); ++i) { const auto fragment = cruft::make_view (input, input + i); std::string encoded; cruft::encode::base::encode ( std::back_inserter (encoded), fragment ); tap.expect_eq ( encoded, output_v[i], "{} character base{} encode; '{}' is '{}'", i, Size, encoded, output_v[i] ); std::string decoded; cruft::encode::base::decode ( std::back_inserter (decoded), cruft::make_view (encoded) ); tap.expect_eq (decoded, fragment, "{} character base{} decode, '{}'", i, Size, decoded); } } /////////////////////////////////////////////////////////////////////////////// int main () { cruft::TAP::logger tap; test_size<16> (tap); test_size<32> (tap); test_size<64> (tap); return tap.status (); }