Skip to content

Commit

Permalink
add test cases for json
Browse files Browse the repository at this point in the history
  • Loading branch information
allenhan2 committed Mar 12, 2020
1 parent e824559 commit edc0b1f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/fc/io/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace fc
};
using yield_func = std::function<void(std::ostream&)>;
static constexpr uint64_t max_length_limit = std::numeric_limits<uint64_t>::max();
static constexpr size_t escape_string_yeild_check_count = 128;
static ostream& to_stream( ostream& out, const fc::string&, const yield_func& yield );
static ostream& to_stream( ostream& out, const variant& v, const yield_func& yield, output_formatting format = stringify_large_ints_and_doubles );
static ostream& to_stream( ostream& out, const variants& v, const yield_func& yield, output_formatting format = stringify_large_ints_and_doubles );
Expand Down Expand Up @@ -80,6 +81,7 @@ namespace fc
}
};

void escape_string( const string& str, std::ostream& os, const json::yield_func& yield );
} // fc

#undef DEFAULT_MAX_RECURSION_DEPTH
2 changes: 1 addition & 1 deletion src/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ namespace fc
size_t i = 0;
for( auto itr = str.begin(); itr != str.end(); ++i,++itr )
{
if( i % 128 == 0 ) yield(os);
if( i % json::escape_string_yeild_check_count == 0 ) yield(os);
switch( *itr )
{
case '\b': // \x08
Expand Down
2 changes: 1 addition & 1 deletion src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ string format_string( const string& frmt, const variant_object& args, bool minim
if( minimize && (result.size() >= minimize_max_size)) {
replaced = false;
} else {
const auto max_length = minimize ? minimize_sub_max_size : std::numeric_limits<uint64_t>::max();
try {
const auto max_length = minimize ? minimize_sub_max_size : json::max_length_limit;
result += json::to_string(val->value(), fc::time_point::maximum(), max_length);
} catch (...) {
replaced = false;
Expand Down
8 changes: 7 additions & 1 deletion test/io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
add_executable( test_io test_cfile.cpp)
add_executable( test_io test_cfile.cpp )
target_link_libraries( test_io fc )

add_executable( test_json test_json.cpp )
target_link_libraries( test_json fc )

add_test(NAME test_io COMMAND libraries/fc/test/io/test_io WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_test(NAME test_json COMMAND libraries/fc/test/io/test_io WORKING_DIRECTORY ${CMAKE_BINARY_DIR})


0 comments on commit edc0b1f

Please sign in to comment.