35{
36 constexpr size_t long_rep_char_num = 1024;
37 const std::string a_long_list = std::string(long_rep_char_num, 'a');
38 const std::string b_long_list = std::string(long_rep_char_num, 'b');
39 {
40 const string format =
"${a} ${b} ${c}";
42 mu( "a", string( long_rep_char_num, 'a' ) );
43 mu( "b", string( long_rep_char_num, 'b' ) );
44 mu( "c", string( long_rep_char_num, 'c' ) );
46 BOOST_CHECK_LT(0, mu.
size());
47 const auto arg_limit_size = (1024 -
format.size()) / mu.
size();
48 BOOST_CHECK_EQUAL( result, string(arg_limit_size, 'a' ) + "... " + string(arg_limit_size, 'b' ) + "... " + string(arg_limit_size, 'c' ) + "..." );
49 BOOST_CHECK_LT(result.size(), 1024 + 3 * mu.
size());
50 }
51 {
53 mu( "str", a_long_list );
56 mu(
"blob",
blob({std::vector<char>(a_long_list.begin(), a_long_list.end())}) );
57 const string format_prefix = "Format string test: ";
58 const string format_str = format_prefix + "${str} ${obj} ${arr} {blob}";
60 BOOST_CHECK_LT(0, mu.
size());
61 const auto arg_limit_size = (1024 - format_str.size()) / mu.
size();
62 BOOST_CHECK_EQUAL( result, format_prefix + a_long_list.substr(0, arg_limit_size) + "..." + " ${obj} ${arr} {blob}");
63 BOOST_CHECK_LT(result.size(), 1024 + 3 * mu.
size());
64 }
65 {
66 const string format_prefix = "Format string test: ";
67 const string format_str = format_prefix + "${str} ${obj} ${arr} ${blob} ${var}";
68 BOOST_CHECK_LT(format_str.size(), 1024);
69 const size_t short_rep_char_num = (1024 - format_str.size()) / 5 - 1;
70 const std::string a_short_list = std::string(short_rep_char_num, 'a');
71 const std::string b_short_list = std::string(short_rep_char_num / 3, 'b');
72 const std::string c_short_list = std::string(short_rep_char_num / 3, 'c');
73 const std::string d_short_list = std::string(short_rep_char_num / 3, 'd');
74 const std::string e_short_list = std::string(short_rep_char_num / 3, 'e');
75 const std::string f_short_list = std::string(short_rep_char_num, 'f');
76 const std::string g_short_list = std::string(short_rep_char_num, 'g');
80 const blob a_blob({std::vector<char>(f_short_list.begin(), f_short_list.end())});
81 const variant a_variant(g_short_list);
82 mu( "str", a_short_list );
83 mu( "obj", vo);
84 mu( "arr", variant_list);
85 mu( "blob", a_blob);
86 mu( "var", a_variant);
88 const string target_result = format_prefix + a_short_list + " " +
89 "{" + "\"b\":\"" + b_short_list + "\",\"c\":\"" + c_short_list + "\"}" + " " +
90 "[\"" + d_short_list + "\",\"" + e_short_list + "\"]" + " " +
91 base64_encode( a_blob.data.data(), a_blob.data.size() ) +
"=" +
" " +
92 g_short_list;
93
94 BOOST_CHECK_EQUAL( result, target_result);
95 BOOST_CHECK_LT(result.size(), 1024 + 3 * mu.
size());
96 }
97}
std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
fc::string format_string(const fc::string &, const variant_object &, bool minimize=false)