// // json_binder_test_terminate.t.h // json // // Created by Sam Jaffe on 2/26/17. // #pragma once #include #include "json/json_binder.hpp" using namespace json::binder; using namespace json::parser; class json_binder_terminate_TestSuite : public CxxTest::TestSuite { public: void test_whitespace_breaks_parsing_numeric_token() { char data[] = "10 0"; int out = 0; value_binder binder{}; TS_ASSERT_THROWS_NOTHING(parse(bind(out, binder), data, allow_all)); TS_ASSERT_EQUALS(out, 10); } void test_unterminated_input_causes_exception_when_flagged() { char data[] = "10 0"; int out = 0; value_binder binder{}; TS_ASSERT_THROWS(parse(bind(out, binder), data, disable_concatenated_json_bodies), json::malformed_json_exception); } void test_does_not_crash_if_terminates_early() { char data[] = "\"This is a \"string"; std::string out = ""; value_binder binder{}; TS_ASSERT_THROWS_NOTHING(parse(json::binder::bind(out, binder), data, allow_all)); TS_ASSERT_EQUALS(out, "This is a "); } void test_will_crash_if_terminates_with_remaining_with_option() { char data[] = "\"This is a \"string"; std::string out = ""; value_binder binder{}; TS_ASSERT_THROWS(parse(json::binder::bind(out, binder), data, disable_concatenated_json_bodies), json::malformed_json_exception); } void test_will_not_crash_if_terminates_with_remaining_only_whitespace() { char data[] = "\"This is a \" "; std::string out = ""; value_binder binder{}; TS_ASSERT_THROWS_NOTHING(parse(json::binder::bind(out, binder), data, disable_concatenated_json_bodies)); } void test_will_crash_if_terminates_with_remaining_buffered_by_whitespace() { char data[] = "\"This is a \" string"; std::string out = ""; value_binder binder{}; TS_ASSERT_THROWS(parse(json::binder::bind(out, binder), data, disable_concatenated_json_bodies), json::malformed_json_exception); } };