jsoncpptest.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "perftest.h"
  2. #if TEST_JSONCPP
  3. #include "jsoncpp/src/lib_json/json_reader.cpp"
  4. #include "jsoncpp/src/lib_json/json_value.cpp"
  5. #include "jsoncpp/src/lib_json/json_writer.cpp"
  6. using namespace Json;
  7. class JsonCpp : public PerfTest {
  8. public:
  9. virtual void SetUp() {
  10. PerfTest::SetUp();
  11. Reader reader;
  12. ASSERT_TRUE(reader.parse(json_, root_));
  13. }
  14. protected:
  15. Value root_;
  16. };
  17. TEST_F(JsonCpp, ReaderParse) {
  18. for (int i = 0; i < kTrialCount; i++) {
  19. Value root;
  20. Reader reader;
  21. ASSERT_TRUE(reader.parse(json_, root));
  22. }
  23. }
  24. TEST_F(JsonCpp, FastWriter) {
  25. for (int i = 0; i < kTrialCount; i++) {
  26. FastWriter writer;
  27. std::string str = writer.write(root_);
  28. //if (i == 0)
  29. // std::cout << str.length() << std::endl;
  30. }
  31. }
  32. TEST_F(JsonCpp, StyledWriter) {
  33. for (int i = 0; i < kTrialCount; i++) {
  34. StyledWriter writer;
  35. std::string str = writer.write(root_);
  36. //if (i == 0)
  37. // std::cout << str.length() << std::endl;
  38. }
  39. }
  40. TEST_F(JsonCpp, Whitespace) {
  41. for (int i = 0; i < kTrialCount; i++) {
  42. Value root;
  43. Reader reader;
  44. ASSERT_TRUE(reader.parse(whitespace_, root));
  45. }
  46. }
  47. #endif // TEST_JSONCPP