RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* json_handling_test.cc 00002 Jeremy Barnes, 29 March 2013 00003 Copyright (c) 2013 Datacratic Inc. All rights reserved. 00004 00005 Test of the functionality to handle JSON. 00006 */ 00007 00008 #define BOOST_TEST_MAIN 00009 #define BOOST_TEST_DYN_LINK 00010 00011 #include <boost/test/unit_test.hpp> 00012 #include <iostream> 00013 #include "jml/db/persistent.h" 00014 #include "soa/types/string.h" 00015 #include "soa/types/json_parsing.h" 00016 #include "soa/types/json_printing.h" 00017 00018 using namespace Datacratic; 00019 using namespace std; 00020 00021 BOOST_AUTO_TEST_CASE(test_utf8_round_trip_streaming_binary) 00022 { 00023 Utf8String str("\xe2\x80\xa2skin"); 00024 00025 std::ostringstream stream; 00026 00027 { 00028 StreamJsonPrintingContext context(stream); 00029 context.writeUtf8 = true; 00030 context.writeStringUtf8(str); 00031 } 00032 00033 cerr << stream.str() << endl; 00034 00035 BOOST_CHECK_EQUAL(stream.str(), "\"\xe2\x80\xa2skin\""); 00036 00037 { 00038 StringJsonParsingContext context(stream.str()); 00039 Utf8String str2 = context.expectStringUtf8(); 00040 BOOST_CHECK_EQUAL(str, str2); 00041 } 00042 } 00043 00044 BOOST_AUTO_TEST_CASE(test_utf8_round_trip_streaming_ascii) 00045 { 00046 Utf8String str("\xe2\x80\xa2skin"); 00047 00048 std::ostringstream stream; 00049 00050 { 00051 StreamJsonPrintingContext context(stream); 00052 context.writeUtf8 = false; 00053 context.writeStringUtf8(str); 00054 } 00055 00056 cerr << stream.str() << endl; 00057 00058 BOOST_CHECK_EQUAL(stream.str(), "\"\\u2022skin\""); 00059 00060 { 00061 StringJsonParsingContext context(stream.str()); 00062 Utf8String str2 = context.expectStringUtf8(); 00063 BOOST_CHECK_EQUAL(str, str2); 00064 } 00065 }