| 57 | } |
| 58 | |
| 59 | TEST_F(ProtobufJsonTest, json_to_pb_normal_case) { |
| 60 | const int N = 1000; |
| 61 | int64_t total_tm = 0; |
| 62 | int64_t total_tm2 = 0; |
| 63 | for (int i = 0; i < N; ++i) { |
| 64 | std::string info3 = "{\"content\":[{\"distance\":1,\"unknown_member\":2,\"ext\":" |
| 65 | "{\"age\":1666666666, \"databyte\":\"d2VsY29tZQ==\", \"enumtype\":1}," |
| 66 | "\"uid\":\"someone\"},{\"distance\":10,\"unknown_member\":20," |
| 67 | "\"ext\":{\"age\":1666666660, \"databyte\":\"d2VsY29tZQ==\"," |
| 68 | "\"enumtype\":2},\"uid\":\"someone0\"}], \"judge\":false," |
| 69 | "\"spur\":2, \"data\":[1,2,3,4,5,6,7,8,9,10]}"; |
| 70 | std::string error; |
| 71 | |
| 72 | JsonContextBody data; |
| 73 | const int64_t tm1 = gettimeofday_us(); |
| 74 | const bool ret = json2pb::JsonToProtoMessage(info3, &data, &error); |
| 75 | const int64_t tm2 = gettimeofday_us(); |
| 76 | total_tm += tm2 - tm1; |
| 77 | ASSERT_TRUE(ret); |
| 78 | |
| 79 | std::string info4; |
| 80 | std::string error1; |
| 81 | const int64_t tm3 = gettimeofday_us(); |
| 82 | bool ret2 = json2pb::ProtoMessageToJson(data, &info4, &error1); |
| 83 | const int64_t tm4 = gettimeofday_us(); |
| 84 | ASSERT_TRUE(ret2); |
| 85 | total_tm2 += tm4 - tm3; |
| 86 | #ifndef RAPIDJSON_VERSION_0_1 |
| 87 | ASSERT_STREQ("{\"data\":[1,2,3,4,5,6,7,8,9,10]," |
| 88 | "\"judge\":false,\"spur\":2.0,\"content\":[{\"uid\":\"someone\"," |
| 89 | "\"distance\":1.0,\"ext\":{\"age\":1666666666,\"databyte\":\"d2VsY29tZQ==\"," |
| 90 | "\"enumtype\":\"HOME\"}},\{\"uid\":\"someone0\",\"distance\":10.0,\"ext\":" |
| 91 | "{\"age\":1666666660,\"databyte\":\"d2VsY29tZQ==\",\"enumtype\":\"WORK\"}}]}", |
| 92 | info4.data()); |
| 93 | #else |
| 94 | ASSERT_STREQ("{\"data\":[1,2,3,4,5,6,7,8,9,10]," |
| 95 | "\"judge\":false,\"spur\":2,\"content\":[{\"uid\":\"someone\"," |
| 96 | "\"distance\":1,\"ext\":{\"age\":1666666666,\"databyte\":\"d2VsY29tZQ==\"," |
| 97 | "\"enumtype\":\"HOME\"}},\{\"uid\":\"someone0\",\"distance\":10,\"ext\":" |
| 98 | "{\"age\":1666666660,\"databyte\":\"d2VsY29tZQ==\",\"enumtype\":\"WORK\"}}]}", |
| 99 | info4.data()); |
| 100 | #endif |
| 101 | } |
| 102 | std::cout << "json2pb=" << total_tm / N |
| 103 | << "us pb2json=" << total_tm2 / N << "us" |
| 104 | << std::endl; |
| 105 | } |
| 106 | |
| 107 | TEST_F(ProtobufJsonTest, json_base64_string_to_pb_types_case) { |
| 108 | std::string info3 = "{\"content\":[{\"distance\":1,\"unknown_member\":2,\"ext\":" |
nothing calls this directly
no test coverage detected