diff options
Diffstat (limited to 'src')
4 files changed, 27 insertions, 35 deletions
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 3ffa9539..e6c3b36a 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -447,7 +447,7 @@ string JSOneofIndex(const OneofDescriptor* oneof) { // Decodes a codepoint in \x0000 -- \xFFFF. Since JS strings are UTF-16, we only // need to handle the BMP (16-bit range) here. -uint16_t DecodeUTF8Codepoint(uint8_t* bytes, size_t* length) { +uint16 DecodeUTF8Codepoint(uint8* bytes, size_t* length) { if (*length == 0) { return 0; } @@ -491,14 +491,14 @@ string EscapeJSString(const string& in, bool is_utf8) { string result; size_t decoded = 0; for (size_t i = 0; i < in.size(); i += decoded) { - uint16_t codepoint = 0; + uint16 codepoint = 0; if (is_utf8) { // Decode the next UTF-8 codepoint. size_t have_bytes = in.size() - i; - uint8_t bytes[3] = { - static_cast<uint8_t>(in[i]), - static_cast<uint8_t>(((i + 1) < in.size()) ? in[i + 1] : 0), - static_cast<uint8_t>(((i + 2) < in.size()) ? in[i + 2] : 0), + uint8 bytes[3] = { + static_cast<uint8>(in[i]), + static_cast<uint8>(((i + 1) < in.size()) ? in[i + 1] : 0), + static_cast<uint8>(((i + 2) < in.size()) ? in[i + 2] : 0), }; codepoint = DecodeUTF8Codepoint(bytes, &have_bytes); if (have_bytes == 0) { @@ -506,7 +506,7 @@ string EscapeJSString(const string& in, bool is_utf8) { } decoded = have_bytes; } else { - codepoint = static_cast<uint16_t>(static_cast<uint8_t>(in[i])); + codepoint = static_cast<uint16>(static_cast<uint8>(in[i])); decoded = 1; } diff --git a/src/google/protobuf/stubs/stringpiece_unittest.cc b/src/google/protobuf/stubs/stringpiece_unittest.cc index 43737a57..a52d81f8 100644 --- a/src/google/protobuf/stubs/stringpiece_unittest.cc +++ b/src/google/protobuf/stubs/stringpiece_unittest.cc @@ -746,23 +746,6 @@ TEST(StringPiece, Comparisons2) { EXPECT_TRUE(abc.ends_with("nopqrstuvwxyz")); } -TEST(StringPiece, HashFunction) { - hash_set<StringPiece> set; - - set.insert(StringPiece("hello")); - EXPECT_EQ(1, set.size()); - - // Insert a StringPiece of the same value again and should NOT increment - // size of the set. - set.insert(StringPiece("hello")); - EXPECT_EQ(1, set.size()); - - // Insert a StringPiece with different value and check that size of the set - // has been increment by one. - set.insert(StringPiece("world")); - EXPECT_EQ(2, set.size()); -} - TEST(ComparisonOpsTest, StringCompareNotAmbiguous) { EXPECT_EQ("hello", string("hello")); EXPECT_LT("hello", string("world")); diff --git a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc index c7667c21..5f9ffb95 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc @@ -1685,13 +1685,17 @@ TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyMustBeEscapedCorrectly) { TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyCanContainAnyChars) { FieldMaskTest expected; expected.mutable_single_mask()->add_paths( - "path.to.map[\"(),[],\\\"'!@#$%^&*123_|War孙天涌,./?><\\\\\"]"); + // \xE5\xAD\x99 is the UTF-8 byte sequence for chinese character 孙. + // We cannot embed non-ASCII characters in the code directly because + // some windows compilers will try to interpret them using the system's + // current encoding and end up with invalid UTF-8 byte sequence. + "path.to.map[\"(),[],\\\"'!@#$%^&*123_|War\xE5\xAD\x99,./?><\\\\\"]"); expected.mutable_single_mask()->add_paths("path.to.map[\"key2\"]"); ow_->StartObject(""); ow_->RenderString( "single_mask", - "path.to.map[\"(),[],\\\"'!@#$%^&*123_|War孙天涌,./?><\\\\\"]," + "path.to.map[\"(),[],\\\"'!@#$%^&*123_|War\xE5\xAD\x99,./?><\\\\\"]," "path.to.map[\"key2\"]"); ow_->EndObject(); diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index 16f151af..a867c881 100755 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -2816,15 +2816,20 @@ class MatchingTest : public testing::Test { const Message& msg1, const Message& msg2, bool result) { string output; - io::StringOutputStream output_stream(&output); - MessageDifferencer::StreamReporter reporter(&output_stream); - reporter.set_report_modified_aggregates(true); - differencer->set_report_matches(true); - differencer->ReportDifferencesTo(&reporter); - if (result) { - EXPECT_TRUE(differencer->Compare(msg1, msg2)); - } else { - EXPECT_FALSE(differencer->Compare(msg1, msg2)); + { + // Before we return the "output" string, we must make sure the + // StreamReporter is destructored because its destructor will + // flush the stream. + io::StringOutputStream output_stream(&output); + MessageDifferencer::StreamReporter reporter(&output_stream); + reporter.set_report_modified_aggregates(true); + differencer->set_report_matches(true); + differencer->ReportDifferencesTo(&reporter); + if (result) { + EXPECT_TRUE(differencer->Compare(msg1, msg2)); + } else { + EXPECT_FALSE(differencer->Compare(msg1, msg2)); + } } return output; } |