22 #include "goby/util/base_convert.h" 23 #include "goby/util/binary.h" 31 void intprint(
const std::string& s)
33 for (
int i = s.size() - 1, n = 0; i >= n; --i)
34 std::cout << std::hex <<
int(s[i] & 0xFF) <<
" " << std::dec;
35 std::cout << std::endl;
38 void test255(
const std::string& in,
bool output =
true)
48 goby::util::base_convert(in, &out, 256, 255);
57 goby::util::base_convert(out, &in2, 255, 256);
64 std::cout <<
"Encoded string is " << (
int)out.size() - (
int)in.size()
65 <<
" bytes larger than original string (" << in.size() <<
" bytes)" << std::endl;
70 std::string randstring(
int size)
72 std::string
test(size, 0);
73 for (
int i = 0; i < size; ++i) {
test[i] = rand() % 256; }
80 char chin[10] = {2, 1, 0, 0, 2, 2, 2, 0, 1, 1};
81 std::string in(chin, 10);
82 char chout[5] = {5, 0, 8, 2, 4};
85 goby::util::base_convert(in, &out, 3, 9);
90 assert(out == std::string(chout, 5));
94 test255(std::string(4, 0xff));
96 test255(randstring(125));
97 test255(randstring(255));
98 test255(randstring(1500));
99 test255(randstring(15000),
false);
101 test255(goby::util::hex_decode(
"01020000"));
103 test255(goby::util::hex_decode(
104 "080e100a300138016040680172400ecf026800793cac69341a8d46a3d16834da376bcf2f0f21fef979e3000000" 105 "d700eec35f2e82010000fcfce0e5e939e4984a6c62ff7a94584eb71cc471e1f53efd364000"));
107 std::cout <<
"all tests passed" << std::endl;