RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
soa/jsoncpp/testing/reader_test.cc
00001 /* date_test.cc
00002    Copyright (c) 2010 Datacratic.  All rights reserved.
00003 */
00004 
00005 #define BOOST_TEST_MAIN
00006 #define BOOST_TEST_DYN_LINK
00007 #include <boost/test/unit_test.hpp>
00008 #include "soa/jsoncpp/json.h"
00009 #include <stdexcept>
00010 #include "jml/arch/exception.h"
00011 #include "jml/arch/exception_handler.h"
00012 
00013 using namespace std;
00014 
00015 
00016 BOOST_AUTO_TEST_CASE( test_free_reader )
00017 {
00018     Json::Value x = Json::parse("{\"a\":\"b\"}");
00019     BOOST_CHECK_EQUAL(x["a"], "b");
00020 }
00021 
00022 BOOST_AUTO_TEST_CASE( test_single_quotes )
00023 {
00024     Json::Value x = Json::parse("{'a':'b'}");
00025     BOOST_CHECK_EQUAL(x["a"], "b");
00026 }
00027 
00028 BOOST_AUTO_TEST_CASE( test_escapes )
00029 {
00030     {
00031         Json::Value x = Json::parse("{'a':'b\\'s'}");
00032         BOOST_CHECK_EQUAL(x["a"], "b's");
00033     }
00034 
00035     {
00036         Json::Value x = Json::parse("{'a':'b\"s'}");
00037         BOOST_CHECK_EQUAL(x["a"], "b\"s");
00038     }
00039 
00040     {
00041         Json::Value x = Json::parse("{'a':'b\\\"s'}");
00042         BOOST_CHECK_EQUAL(x["a"], "b\"s");
00043     }
00044 
00045     {
00046         Json::Value x = Json::parse("{\"a\":\"b\\\"s\"}");
00047         BOOST_CHECK_EQUAL(x["a"], "b\"s");
00048     }
00049 
00050     {
00051         Json::Value x = Json::parse("{\"a\":\"b's\"}");
00052         BOOST_CHECK_EQUAL(x["a"], "b's");
00053     }
00054 
00055     {
00056         Json::Value x = Json::parse("{\"a\":\"b\\'s\"}");
00057         BOOST_CHECK_EQUAL(x["a"], "b's");
00058     }
00059 }
00060 
00061 BOOST_AUTO_TEST_CASE( test_bad_parse )
00062 {
00063     JML_TRACE_EXCEPTIONS(false);
00064     BOOST_CHECK_THROW(auto x = Json::parse("foo");, Json::Exception);
00065     BOOST_CHECK_THROW(auto x = Json::parse("{'a's':'a'}");, Json::Exception);
00066     BOOST_CHECK_THROW(auto x = Json::parse("{\"a\"s\":\"b\"}");, Json::Exception);
00067 }
00068 
00069 BOOST_AUTO_TEST_CASE( test_no_assert )
00070 {
00071     JML_TRACE_EXCEPTIONS(false);
00072     Json::Value x = 1;
00073     BOOST_CHECK_THROW(x[0u], std::runtime_error);
00074 }
00075 
00076 
00077 BOOST_AUTO_TEST_CASE( test_iterators )
00078 {
00079     Json::Value x;
00080     x[0u] = "elem0";
00081     x[1u] = "elem1";
00082     x[2u] = "elem2";
00083 
00084     std::vector<Json::Value> xCopy(3);
00085 
00086     std::copy(x.begin(), x.end(), xCopy.begin());
00087 
00088     BOOST_CHECK_EQUAL_COLLECTIONS(x.begin(), x.end(), xCopy.begin(), xCopy.end());
00089 
00090 }
00091 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator