| 17 | namespace toft { |
| 18 | |
| 19 | TEST(JsonFormtTest, PrintToJson) { |
| 20 | toft::Person p; |
| 21 | p.set_age(30); |
| 22 | toft::NameInfo* name = p.mutable_name(); |
| 23 | name->set_first_name("Ye"); |
| 24 | name->set_second_name("Shunping"); |
| 25 | p.set_address("beijing"); |
| 26 | p.add_phone_number("15100000000"); |
| 27 | p.add_phone_number("15100000001"); |
| 28 | p.set_address_id(434798436777434024L); |
| 29 | p.set_people_type(toft::HAN_ZU); |
| 30 | LOG(INFO)<< "Text format for Message:\n" << p.Utf8DebugString(); |
| 31 | |
| 32 | std::string styled_str; |
| 33 | ProtoJsonFormat::PrintToStyledString(p, &styled_str); |
| 34 | std::string expected_styled_str; |
| 35 | toft::File::ReadAll("json_styled_string.txt", &expected_styled_str); |
| 36 | EXPECT_EQ(styled_str, expected_styled_str); |
| 37 | |
| 38 | std::string fast_str; |
| 39 | ProtoJsonFormat::PrintToFastString(p, &fast_str); |
| 40 | VLOG(3)<< "FastString json format for Message:\n" << fast_str; |
| 41 | std::string expected_fast_str; |
| 42 | toft::File::ReadAll("json_fast_string.txt", &expected_fast_str); |
| 43 | EXPECT_EQ(fast_str, expected_fast_str); |
| 44 | } |
| 45 | |
| 46 | void TestJsonString(const std::string& json_file) { |
| 47 | std::string styled_str; |
nothing calls this directly
no test coverage detected