diff options
45 files changed, 530 insertions, 503 deletions
diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index 67c90397..8fa9f53c 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -677,7 +677,7 @@ void ConformanceTestSuite::SetFailureList(const string& filename, std::inserter(expected_to_fail_, expected_to_fail_.end())); } -bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check, +bool ConformanceTestSuite::CheckSetEmpty(const std::set<string>& set_to_check, const std::string& write_to_file, const std::string& msg) { if (set_to_check.empty()) { @@ -685,7 +685,7 @@ bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check, } else { StringAppendF(&output_, "\n"); StringAppendF(&output_, "%s\n\n", msg.c_str()); - for (set<string>::const_iterator iter = set_to_check.begin(); + for (std::set<string>::const_iterator iter = set_to_check.begin(); iter != set_to_check.end(); ++iter) { StringAppendF(&output_, " %s\n", iter->c_str()); } @@ -694,7 +694,7 @@ bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check, if (!write_to_file.empty()) { std::ofstream os(write_to_file); if (os) { - for (set<string>::const_iterator iter = set_to_check.begin(); + for (std::set<string>::const_iterator iter = set_to_check.begin(); iter != set_to_check.end(); ++iter) { os << *iter << "\n"; } diff --git a/conformance/conformance_test.h b/conformance/conformance_test.h index 4e40a6ac..581c7472 100644 --- a/conformance/conformance_test.h +++ b/conformance/conformance_test.h @@ -205,7 +205,7 @@ class ConformanceTestSuite { void TestValidDataForType( google::protobuf::FieldDescriptor::Type, std::vector<std::pair<std::string, std::string>> values); - bool CheckSetEmpty(const set<string>& set_to_check, + bool CheckSetEmpty(const std::set<string>& set_to_check, const std::string& write_to_file, const std::string& msg); ConformanceTestRunner* runner_; int successes_; diff --git a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs index 9d3d69af..68b4de45 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs @@ -540,6 +540,22 @@ namespace Google.Protobuf.Collections Assert.Throws<ArgumentException>(() => map.ToString()); } +#if !NET35 + [Test] + public void IDictionaryKeys_Equals_IReadOnlyDictionaryKeys() + { + var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } }; + CollectionAssert.AreEquivalent(((IDictionary<string, string>)map).Keys, ((IReadOnlyDictionary<string, string>)map).Keys); + } + + [Test] + public void IDictionaryValues_Equals_IReadOnlyDictionaryValues() + { + var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } }; + CollectionAssert.AreEquivalent(((IDictionary<string, string>)map).Values, ((IReadOnlyDictionary<string, string>)map).Values); + } +#endif + private static KeyValuePair<TKey, TValue> NewKeyValuePair<TKey, TValue>(TKey key, TValue value) { return new KeyValuePair<TKey, TValue>(key, value); diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index ef5651c9..8dac8e30 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -67,6 +67,9 @@ namespace Google.Protobuf.Collections /// </para> /// </remarks> public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValue>>, IDictionary<TKey, TValue>, IEquatable<MapField<TKey, TValue>>, IDictionary +#if !NET35 + , IReadOnlyDictionary<TKey, TValue> +#endif { // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.) private readonly Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>> map = @@ -548,6 +551,14 @@ namespace Google.Protobuf.Collections } #endregion + #region IReadOnlyDictionary explicit interface implementation +#if !NET35 + IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Keys; + + IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values; +#endif + #endregion + private class DictionaryEnumerator : IDictionaryEnumerator { private readonly IEnumerator<KeyValuePair<TKey, TValue>> enumerator; diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 4eebd99e..46418e39 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -16,7 +16,7 @@ <PackageProjectUrl>https://github.com/google/protobuf</PackageProjectUrl> <PackageLicenseUrl>https://github.com/google/protobuf/blob/master/LICENSE</PackageLicenseUrl> <RepositoryType>git</RepositoryType> - <RepositoryUrl>https://github.com/nodatime/nodatime.git</RepositoryUrl> + <RepositoryUrl>https://github.com/google/protobuf.git</RepositoryUrl> <IncludeSymbols>true</IncludeSymbols> <IncludeSource>true</IncludeSource> </PropertyGroup> diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index b07abfa7..ef3d4cf6 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -474,7 +474,7 @@ static void map_slot_init(void* memory, upb_fieldtype_t type, zval* cache) { *(zval***)memory = holder; #else *(zval**)memory = cache; - // PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1); + PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1); #endif break; } diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index e2912ad4..2ea360b2 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -14,432 +14,432 @@ use Foo\TestUnpackedMessage; class EncodeDecodeTest extends TestBase { -# public function testEncode() -# { -# $from = new TestMessage(); -# $this->expectEmptyFields($from); -# $this->setFields($from); -# $this->expectFields($from); -# -# $data = $from->serializeToString(); -# $this->assertSame(bin2hex(TestUtil::getGoldenTestMessage()), -# bin2hex($data)); -# } -# -# public function testDecode() -# { -# $to = new TestMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestMessage()); -# $this->expectFields($to); -# } -# -# public function testEncodeDecode() -# { -# $from = new TestMessage(); -# $this->expectEmptyFields($from); -# $this->setFields($from); -# $this->expectFields($from); -# -# $data = $from->serializeToString(); -# -# $to = new TestMessage(); -# $to->mergeFromString($data); -# $this->expectFields($to); -# } -# -# public function testEncodeDecodeEmpty() -# { -# $from = new TestMessage(); -# $this->expectEmptyFields($from); -# -# $data = $from->serializeToString(); -# -# $to = new TestMessage(); -# $to->mergeFromString($data); -# $this->expectEmptyFields($to); -# } + public function testEncode() + { + $from = new TestMessage(); + $this->expectEmptyFields($from); + $this->setFields($from); + $this->expectFields($from); + + $data = $from->serializeToString(); + $this->assertSame(bin2hex(TestUtil::getGoldenTestMessage()), + bin2hex($data)); + } + + public function testDecode() + { + $to = new TestMessage(); + $to->mergeFromString(TestUtil::getGoldenTestMessage()); + $this->expectFields($to); + } + + public function testEncodeDecode() + { + $from = new TestMessage(); + $this->expectEmptyFields($from); + $this->setFields($from); + $this->expectFields($from); + + $data = $from->serializeToString(); + + $to = new TestMessage(); + $to->mergeFromString($data); + $this->expectFields($to); + } + + public function testEncodeDecodeEmpty() + { + $from = new TestMessage(); + $this->expectEmptyFields($from); + + $data = $from->serializeToString(); + + $to = new TestMessage(); + $to->mergeFromString($data); + $this->expectEmptyFields($to); + } public function testEncodeDecodeOneof() { $m = new TestMessage(); -# $m->setOneofInt32(1); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame(1, $n->getOneofInt32()); -# -# $m->setOneofFloat(2.0); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame(2.0, $n->getOneofFloat()); -# -# $m->setOneofString('abc'); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame('abc', $n->getOneofString()); -# -# $sub_m = new TestMessage_Sub(); -# $sub_m->setA(1); -# $m->setOneofMessage($sub_m); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame(1, $n->getOneofMessage()->getA()); + $m->setOneofInt32(1); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame(1, $n->getOneofInt32()); + + $m->setOneofFloat(2.0); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame(2.0, $n->getOneofFloat()); + + $m->setOneofString('abc'); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame('abc', $n->getOneofString()); + + $sub_m = new TestMessage_Sub(); + $sub_m->setA(1); + $m->setOneofMessage($sub_m); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame(1, $n->getOneofMessage()->getA()); // Encode default value -# $m->setOneofEnum(TestEnum::ZERO); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame("oneof_enum", $n->getMyOneof()); -# $this->assertSame(TestEnum::ZERO, $n->getOneofEnum()); + $m->setOneofEnum(TestEnum::ZERO); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame("oneof_enum", $n->getMyOneof()); + $this->assertSame(TestEnum::ZERO, $n->getOneofEnum()); $m->setOneofString(""); $data = $m->serializeToString(); $n = new TestMessage(); $n->mergeFromString($data); $this->assertSame("oneof_string", $n->getMyOneof()); - $this->assertSame("", $n->getOneofString()); - -# $sub_m = new TestMessage_Sub(); -# $m->setOneofMessage($sub_m); -# $data = $m->serializeToString(); -# $n = new TestMessage(); -# $n->mergeFromString($data); -# $this->assertSame("oneof_message", $n->getMyOneof()); -# $this->assertFalse(is_null($n->getOneofMessage())); - - } - -# public function testPackedEncode() -# { -# $from = new TestPackedMessage(); -# TestUtil::setTestPackedMessage($from); -# $this->assertSame(TestUtil::getGoldenTestPackedMessage(), -# $from->serializeToString()); -# } -# -# public function testPackedDecodePacked() -# { -# $to = new TestPackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testPackedDecodeUnpacked() -# { -# $to = new TestPackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testUnpackedEncode() -# { -# $from = new TestUnpackedMessage(); -# TestUtil::setTestPackedMessage($from); -# $this->assertSame(TestUtil::getGoldenTestUnpackedMessage(), -# $from->serializeToString()); -# } -# -# public function testUnpackedDecodePacked() -# { -# $to = new TestUnpackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testUnpackedDecodeUnpacked() -# { -# $to = new TestUnpackedMessage(); -# $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); -# TestUtil::assertTestPackedMessage($to); -# } -# -# public function testDecodeInt64() -# { -# // Read 64 testing -# $testVals = array( -# '10' => '100a', -# '100' => '1064', -# '800' => '10a006', -# '6400' => '108032', -# '70400' => '1080a604', -# '774400' => '1080a22f', -# '9292800' => '108098b704', -# '74342400' => '1080c0b923', -# '743424000' => '108080bfe202', -# '8177664000' => '108080b5bb1e', -# '65421312000' => '108080a8dbf301', -# '785055744000' => '108080e0c7ec16', -# '9420668928000' => '10808080dd969202', -# '103627358208000' => '10808080fff9c717', -# '1139900940288000' => '10808080f5bd978302', -# '13678811283456000' => '10808080fce699a618', -# '109430490267648000' => '10808080e0b7ceb1c201', -# '984874412408832000' => '10808080e0f5c1bed50d', -# ); -# -# $msg = new TestMessage(); -# foreach ($testVals as $original => $encoded) { -# $msg->setOptionalInt64($original); -# $data = $msg->serializeToString(); -# $this->assertSame($encoded, bin2hex($data)); -# $msg->setOptionalInt64(0); -# $msg->mergeFromString($data); -# $this->assertEquals($original, $msg->getOptionalInt64()); -# } -# } -# -# public function testDecodeToExistingMessage() -# { -# $m1 = new TestMessage(); -# $this->setFields($m1); -# $this->expectFields($m1); -# -# $m2 = new TestMessage(); -# $this->setFields2($m2); -# $data = $m2->serializeToString(); -# -# $m1->mergeFromString($data); -# $this->expectFieldsMerged($m1); -# } -# -# public function testDecodeFieldNonExist() -# { -# $data = hex2bin('c80501'); -# $m = new TestMessage(); -# $m->mergeFromString($data); -# } -# -# public function testEncodeNegativeInt32() -# { -# $m = new TestMessage(); -# $m->setOptionalInt32(-1); -# $data = $m->serializeToString(); -# $this->assertSame("08ffffffffffffffffff01", bin2hex($data)); -# } -# -# public function testDecodeNegativeInt32() -# { -# $m = new TestMessage(); -# $this->assertEquals(0, $m->getOptionalInt32()); -# $m->mergeFromString(hex2bin("08ffffffffffffffffff01")); -# $this->assertEquals(-1, $m->getOptionalInt32()); -# -# $m = new TestMessage(); -# $this->assertEquals(0, $m->getOptionalInt32()); -# $m->mergeFromString(hex2bin("08ffffffff0f")); -# $this->assertEquals(-1, $m->getOptionalInt32()); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidInt32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('08')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSubMessage() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('9A010108')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidInt64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('10')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidUInt32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('18')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidUInt64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('20')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSInt32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('28')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSInt64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('30')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidFixed32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('3D')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidFixed64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('41')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSFixed32() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('4D')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidSFixed64() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('51')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidFloat() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('5D')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidDouble() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('61')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidBool() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('68')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidStringLengthMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('72')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidStringDataMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('7201')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidBytesLengthMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('7A')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidBytesDataMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('7A01')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidEnum() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('8001')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidMessageLengthMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('8A01')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidMessageDataMiss() -# { -# $m = new TestMessage(); -# $m->mergeFromString(hex2bin('8A0101')); -# } -# -# /** -# * @expectedException Exception -# */ -# public function testDecodeInvalidPackedMessageLength() -# { -# $m = new TestPackedMessage(); -# $m->mergeFromString(hex2bin('D205')); -# } -# -# public function testJsonEncode() -# { -# $from = new TestMessage(); -# $this->setFields($from); -# $data = $from->serializeToJsonString(); -# $to = new TestMessage(); -# $to->mergeFromJsonString($data); -# $this->expectFields($to); -# } + $this->assertSame("", $n->getOneofString()); + + $sub_m = new TestMessage_Sub(); + $m->setOneofMessage($sub_m); + $data = $m->serializeToString(); + $n = new TestMessage(); + $n->mergeFromString($data); + $this->assertSame("oneof_message", $n->getMyOneof()); + $this->assertFalse(is_null($n->getOneofMessage())); + + } + + public function testPackedEncode() + { + $from = new TestPackedMessage(); + TestUtil::setTestPackedMessage($from); + $this->assertSame(TestUtil::getGoldenTestPackedMessage(), + $from->serializeToString()); + } + + public function testPackedDecodePacked() + { + $to = new TestPackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testPackedDecodeUnpacked() + { + $to = new TestPackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testUnpackedEncode() + { + $from = new TestUnpackedMessage(); + TestUtil::setTestPackedMessage($from); + $this->assertSame(TestUtil::getGoldenTestUnpackedMessage(), + $from->serializeToString()); + } + + public function testUnpackedDecodePacked() + { + $to = new TestUnpackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestPackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testUnpackedDecodeUnpacked() + { + $to = new TestUnpackedMessage(); + $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage()); + TestUtil::assertTestPackedMessage($to); + } + + public function testDecodeInt64() + { + // Read 64 testing + $testVals = array( + '10' => '100a', + '100' => '1064', + '800' => '10a006', + '6400' => '108032', + '70400' => '1080a604', + '774400' => '1080a22f', + '9292800' => '108098b704', + '74342400' => '1080c0b923', + '743424000' => '108080bfe202', + '8177664000' => '108080b5bb1e', + '65421312000' => '108080a8dbf301', + '785055744000' => '108080e0c7ec16', + '9420668928000' => '10808080dd969202', + '103627358208000' => '10808080fff9c717', + '1139900940288000' => '10808080f5bd978302', + '13678811283456000' => '10808080fce699a618', + '109430490267648000' => '10808080e0b7ceb1c201', + '984874412408832000' => '10808080e0f5c1bed50d', + ); + + $msg = new TestMessage(); + foreach ($testVals as $original => $encoded) { + $msg->setOptionalInt64($original); + $data = $msg->serializeToString(); + $this->assertSame($encoded, bin2hex($data)); + $msg->setOptionalInt64(0); + $msg->mergeFromString($data); + $this->assertEquals($original, $msg->getOptionalInt64()); + } + } + + public function testDecodeToExistingMessage() + { + $m1 = new TestMessage(); + $this->setFields($m1); + $this->expectFields($m1); + + $m2 = new TestMessage(); + $this->setFields2($m2); + $data = $m2->serializeToString(); + + $m1->mergeFromString($data); + $this->expectFieldsMerged($m1); + } + + public function testDecodeFieldNonExist() + { + $data = hex2bin('c80501'); + $m = new TestMessage(); + $m->mergeFromString($data); + } + + public function testEncodeNegativeInt32() + { + $m = new TestMessage(); + $m->setOptionalInt32(-1); + $data = $m->serializeToString(); + $this->assertSame("08ffffffffffffffffff01", bin2hex($data)); + } + + public function testDecodeNegativeInt32() + { + $m = new TestMessage(); + $this->assertEquals(0, $m->getOptionalInt32()); + $m->mergeFromString(hex2bin("08ffffffffffffffffff01")); + $this->assertEquals(-1, $m->getOptionalInt32()); + + $m = new TestMessage(); + $this->assertEquals(0, $m->getOptionalInt32()); + $m->mergeFromString(hex2bin("08ffffffff0f")); + $this->assertEquals(-1, $m->getOptionalInt32()); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidInt32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('08')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSubMessage() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('9A010108')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidInt64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('10')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidUInt32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('18')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidUInt64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('20')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSInt32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('28')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSInt64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('30')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidFixed32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('3D')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidFixed64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('41')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSFixed32() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('4D')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidSFixed64() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('51')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidFloat() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('5D')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidDouble() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('61')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidBool() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('68')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidStringLengthMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('72')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidStringDataMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('7201')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidBytesLengthMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('7A')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidBytesDataMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('7A01')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidEnum() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('8001')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidMessageLengthMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('8A01')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidMessageDataMiss() + { + $m = new TestMessage(); + $m->mergeFromString(hex2bin('8A0101')); + } + + /** + * @expectedException Exception + */ + public function testDecodeInvalidPackedMessageLength() + { + $m = new TestPackedMessage(); + $m->mergeFromString(hex2bin('D205')); + } + + public function testJsonEncode() + { + $from = new TestMessage(); + $this->setFields($from); + $data = $from->serializeToJsonString(); + $to = new TestMessage(); + $to->mergeFromJsonString($data); + $this->expectFields($to); + } } diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index ebb8fbc2..ecf29ece 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -54,7 +54,7 @@ namespace compiler { namespace csharp { void FieldGeneratorBase::SetCommonFieldVariables( - map<string, string>* variables) { + std::map<string, string>* variables) { // Note: this will be valid even though the tag emitted for packed and unpacked versions of // repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which // never effects the tag size. @@ -92,7 +92,7 @@ void FieldGeneratorBase::SetCommonFieldVariables( } void FieldGeneratorBase::SetCommonOneofFieldVariables( - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["oneof_name"] = oneof_name(); (*variables)["has_property_check"] = oneof_name() + "Case_ == " + oneof_property_name() + diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 4109f3ca..df26853b 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -66,14 +66,14 @@ class FieldGeneratorBase : public SourceGeneratorBase { protected: const FieldDescriptor* descriptor_; const int fieldOrdinal_; - map<string, string> variables_; + std::map<string, string> variables_; void AddDeprecatedFlag(io::Printer* printer); void AddNullCheck(io::Printer* printer); void AddNullCheck(io::Printer* printer, const std::string& name); void AddPublicMemberAttributes(io::Printer* printer); - void SetCommonOneofFieldVariables(map<string, string>* variables); + void SetCommonOneofFieldVariables(std::map<string, string>* variables); std::string oneof_property_name(); std::string oneof_name(); @@ -89,7 +89,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { std::string capitalized_type_name(); private: - void SetCommonFieldVariables(map<string, string>* variables); + void SetCommonFieldVariables(std::map<string, string>* variables); std::string GetStringDefaultValueInternal(); std::string GetBytesDefaultValueInternal(); diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 0f00a438..5ef0e4e8 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -105,7 +105,7 @@ void MessageGenerator::AddDeprecatedFlag(io::Printer* printer) { } void MessageGenerator::Generate(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["class_name"] = class_name(); vars["access_level"] = class_access_level(); @@ -280,7 +280,7 @@ bool MessageGenerator::HasNestedGeneratedTypes() } void MessageGenerator::GenerateCloningCode(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; WriteGeneratedCodeAttributes(printer); vars["class_name"] = class_name(); printer->Print( @@ -333,7 +333,7 @@ void MessageGenerator::GenerateFreezingCode(io::Printer* printer) { } void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["class_name"] = class_name(); // Equality @@ -432,7 +432,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { // Note: These are separate from GenerateMessageSerializationMethods() // because they need to be generated even for messages that are optimized // for code size. - map<string, string> vars; + std::map<string, string> vars; vars["class_name"] = class_name(); WriteGeneratedCodeAttributes(printer); diff --git a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc index 7666db38..26bc7f85 100644 --- a/src/google/protobuf/compiler/javanano/javanano_enum_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_enum_field.cc @@ -52,7 +52,7 @@ namespace { // TODO(kenton): Factor out a "SetCommonFieldVariables()" to get rid of // repeat code between this and the other field types. void SetEnumVariables(const Params& params, - const FieldDescriptor* descriptor, map<string, string>* variables) { + const FieldDescriptor* descriptor, std::map<string, string>* variables) { (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); (*variables)["capitalized_name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_enum_field.h b/src/google/protobuf/compiler/javanano/javanano_enum_field.h index b94790d6..1be25d10 100644 --- a/src/google/protobuf/compiler/javanano/javanano_enum_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_enum_field.h @@ -62,7 +62,7 @@ class EnumFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; vector<string> canonical_values_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); @@ -85,7 +85,7 @@ class AccessorEnumFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; vector<string> canonical_values_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AccessorEnumFieldGenerator); @@ -112,7 +112,7 @@ class RepeatedEnumFieldGenerator : public FieldGenerator { void GenerateRepeatedDataSizeCode(io::Printer* printer) const; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; vector<string> canonical_values_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); diff --git a/src/google/protobuf/compiler/javanano/javanano_extension.cc b/src/google/protobuf/compiler/javanano/javanano_extension.cc index 0b9d1d8d..4c61f915 100644 --- a/src/google/protobuf/compiler/javanano/javanano_extension.cc +++ b/src/google/protobuf/compiler/javanano/javanano_extension.cc @@ -78,7 +78,7 @@ const char* GetTypeConstantName(const FieldDescriptor::Type type) { } // namespace void SetVariables(const FieldDescriptor* descriptor, const Params params, - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["extends"] = ClassName(params, descriptor->containing_type()); (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); bool repeated = descriptor->is_repeated(); diff --git a/src/google/protobuf/compiler/javanano/javanano_extension.h b/src/google/protobuf/compiler/javanano/javanano_extension.h index 4843e296..f4e9eb2d 100644 --- a/src/google/protobuf/compiler/javanano/javanano_extension.h +++ b/src/google/protobuf/compiler/javanano/javanano_extension.h @@ -61,7 +61,7 @@ class ExtensionGenerator { private: const Params& params_; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); }; diff --git a/src/google/protobuf/compiler/javanano/javanano_field.cc b/src/google/protobuf/compiler/javanano/javanano_field.cc index 85257f3f..e31d1177 100644 --- a/src/google/protobuf/compiler/javanano/javanano_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_field.cc @@ -151,7 +151,7 @@ const FieldGenerator& FieldGeneratorMap::get( } void SetCommonOneofVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["oneof_name"] = UnderscoresToCamelCase(descriptor->containing_oneof()); (*variables)["oneof_capitalized_name"] = @@ -169,7 +169,7 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor, } void GenerateOneofFieldEquals(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer) { if (GetJavaType(descriptor) == JAVATYPE_BYTES) { printer->Print(variables, @@ -190,7 +190,7 @@ void GenerateOneofFieldEquals(const FieldDescriptor* descriptor, } void GenerateOneofFieldHashCode(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer) { if (GetJavaType(descriptor) == JAVATYPE_BYTES) { printer->Print(variables, diff --git a/src/google/protobuf/compiler/javanano/javanano_field.h b/src/google/protobuf/compiler/javanano/javanano_field.h index 57c221f4..347c888c 100644 --- a/src/google/protobuf/compiler/javanano/javanano_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_field.h @@ -114,12 +114,12 @@ class FieldGeneratorMap { }; void SetCommonOneofVariables(const FieldDescriptor* descriptor, - map<string, string>* variables); + std::map<string, string>* variables); void GenerateOneofFieldEquals(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer); void GenerateOneofFieldHashCode(const FieldDescriptor* descriptor, - const map<string, string>& variables, + const std::map<string, string>& variables, io::Printer* printer); } // namespace javanano diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/src/google/protobuf/compiler/javanano/javanano_helpers.cc index 5018250c..1927ba12 100644 --- a/src/google/protobuf/compiler/javanano/javanano_helpers.cc +++ b/src/google/protobuf/compiler/javanano/javanano_helpers.cc @@ -567,7 +567,7 @@ string GenerateDifferentBit(int bit_index) { } void SetBitOperationVariables(const string name, - int bitIndex, map<string, string>* variables) { + int bitIndex, std::map<string, string>* variables) { (*variables)["get_" + name] = GenerateGetBit(bitIndex); (*variables)["set_" + name] = GenerateSetBit(bitIndex); (*variables)["clear_" + name] = GenerateClearBit(bitIndex); diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.h b/src/google/protobuf/compiler/javanano/javanano_helpers.h index 014c85ae..04b2d633 100644 --- a/src/google/protobuf/compiler/javanano/javanano_helpers.h +++ b/src/google/protobuf/compiler/javanano/javanano_helpers.h @@ -181,7 +181,7 @@ string GenerateDifferentBit(int bit_index); // the given name of the bit, to the appropriate Java expressions for the given // bit index. void SetBitOperationVariables(const string name, - int bitIndex, map<string, string>* variables); + int bitIndex, std::map<string, string>* variables); inline bool IsMapEntry(const Descriptor* descriptor) { // TODO(liujisi): Add an option to turn on maps for proto2 syntax as well. diff --git a/src/google/protobuf/compiler/javanano/javanano_map_field.cc b/src/google/protobuf/compiler/javanano/javanano_map_field.cc index 83b2b0ce..a4ab8858 100644 --- a/src/google/protobuf/compiler/javanano/javanano_map_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_map_field.cc @@ -84,7 +84,7 @@ const FieldDescriptor* ValueField(const FieldDescriptor* descriptor) { } void SetMapVariables(const Params& params, - const FieldDescriptor* descriptor, map<string, string>* variables) { + const FieldDescriptor* descriptor, std::map<string, string>* variables) { const FieldDescriptor* key = KeyField(descriptor); const FieldDescriptor* value = ValueField(descriptor); (*variables)["name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_map_field.h b/src/google/protobuf/compiler/javanano/javanano_map_field.h index c01bde38..81e5915d 100644 --- a/src/google/protobuf/compiler/javanano/javanano_map_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_map_field.h @@ -58,7 +58,7 @@ class MapFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator); }; diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc index f81f7f9a..78421887 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message.cc +++ b/src/google/protobuf/compiler/javanano/javanano_message.cc @@ -182,7 +182,7 @@ void MessageGenerator::Generate(io::Printer* printer) { } // oneof - map<string, string> vars; + std::map<string, string> vars; vars["message_name"] = descriptor_->name(); for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { const OneofDescriptor* oneof_desc = descriptor_->oneof_decl(i); diff --git a/src/google/protobuf/compiler/javanano/javanano_message_field.cc b/src/google/protobuf/compiler/javanano/javanano_message_field.cc index d1d04b52..2ed8a3aa 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_message_field.cc @@ -54,7 +54,7 @@ namespace { // TODO(kenton): Factor out a "SetCommonFieldVariables()" to get rid of // repeat code between this and the other field types. void SetMessageVariables(const Params& params, - const FieldDescriptor* descriptor, map<string, string>* variables) { + const FieldDescriptor* descriptor, std::map<string, string>* variables) { (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); (*variables)["capitalized_name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_message_field.h b/src/google/protobuf/compiler/javanano/javanano_message_field.h index e074735c..0ae8879b 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_message_field.h @@ -62,7 +62,7 @@ class MessageFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); }; @@ -85,7 +85,7 @@ class MessageOneofFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator); }; @@ -108,7 +108,7 @@ class RepeatedMessageFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); }; diff --git a/src/google/protobuf/compiler/javanano/javanano_params.h b/src/google/protobuf/compiler/javanano/javanano_params.h index e3b4bb93..3594767d 100644 --- a/src/google/protobuf/compiler/javanano/javanano_params.h +++ b/src/google/protobuf/compiler/javanano/javanano_params.h @@ -47,8 +47,8 @@ enum eMultipleFiles { JAVANANO_MUL_UNSET, JAVANANO_MUL_FALSE, JAVANANO_MUL_TRUE // Parameters for used by the generators class Params { public: - typedef map<string, string> NameMap; - typedef set<string> NameSet; + typedef std::map<string, string> NameMap; + typedef std::set<string> NameSet; private: string empty_; string base_name_; diff --git a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc index 978abf2c..66a0ff05 100644 --- a/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc @@ -166,7 +166,7 @@ bool AllAscii(const string& text) { void SetPrimitiveVariables(const FieldDescriptor* descriptor, const Params params, - map<string, string>* variables) { + std::map<string, string>* variables) { (*variables)["name"] = RenameJavaKeywords(UnderscoresToCamelCase(descriptor)); (*variables)["capitalized_name"] = diff --git a/src/google/protobuf/compiler/javanano/javanano_primitive_field.h b/src/google/protobuf/compiler/javanano/javanano_primitive_field.h index a01981dd..d7d72d57 100644 --- a/src/google/protobuf/compiler/javanano/javanano_primitive_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_primitive_field.h @@ -65,7 +65,7 @@ class PrimitiveFieldGenerator : public FieldGenerator { void GenerateSerializationConditional(io::Printer* printer) const; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); }; @@ -89,7 +89,7 @@ class AccessorPrimitiveFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AccessorPrimitiveFieldGenerator); }; @@ -111,7 +111,7 @@ class PrimitiveOneofFieldGenerator : public FieldGenerator { private: const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveOneofFieldGenerator); }; @@ -137,7 +137,7 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator { void GenerateRepeatedDataSizeCode(io::Printer* printer) const; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); }; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc index 7a774a09..8899a13a 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc @@ -46,7 +46,7 @@ namespace objectivec { namespace { void SetEnumVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { string type = EnumName(descriptor->enum_type()); (*variables)["storage_type"] = type; // For non repeated fields, if it was defined in a different file, the @@ -118,7 +118,7 @@ void EnumFieldGenerator::GenerateCFunctionImplementations( } void EnumFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { SingleFieldGenerator::DetermineForwardDeclarations(fwd_decls); // If it is an enum defined in a different file, then we'll need a forward // declaration for it. When it is in our file, all the enums are output diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h index 946faa81..ae56c069 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h @@ -47,7 +47,7 @@ class EnumFieldGenerator : public SingleFieldGenerator { public: virtual void GenerateCFunctionDeclarations(io::Printer* printer) const; virtual void GenerateCFunctionImplementations(io::Printer* printer) const; - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; protected: EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc index 73e4b86e..b788d0a3 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc @@ -59,7 +59,7 @@ ExtensionGenerator::ExtensionGenerator(const string& root_class_name, ExtensionGenerator::~ExtensionGenerator() {} void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["method_name"] = method_name_; SourceLocation location; if (descriptor_->GetSourceLocation(&location)) { @@ -77,7 +77,7 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { void ExtensionGenerator::GenerateStaticVariablesInitialization( io::Printer* printer) { - map<string, string> vars; + std::map<string, string> vars; vars["root_class_and_method_name"] = root_class_and_method_name_; vars["extended_type"] = ClassName(descriptor_->containing_type()); vars["number"] = SimpleItoa(descriptor_->number()); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index 9f7e84f2..b6123fad 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -49,7 +49,7 @@ namespace objectivec { namespace { void SetCommonFieldVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { string camel_case_name = FieldName(descriptor); string raw_field_name; if (descriptor->type() == FieldDescriptor::TYPE_GROUP) { @@ -178,7 +178,7 @@ void FieldGenerator::GenerateCFunctionImplementations( } void FieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { // Nothing } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.h b/src/google/protobuf/compiler/objectivec/objectivec_field.h index a3a4b1b6..6bd5db2e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.h @@ -67,7 +67,7 @@ class FieldGenerator { virtual void GenerateCFunctionImplementations(io::Printer* printer) const; // Exposed for subclasses, should always call it on the parent class also. - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; // Used during generation, not intended to be extended by subclasses. void GenerateFieldDescription( @@ -100,7 +100,7 @@ class FieldGenerator { virtual bool WantsHasProperty(void) const = 0; const FieldDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 7ad127bb..954b2688 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -89,7 +89,7 @@ bool FileContainsExtensions(const FileDescriptor* file) { void PruneFileAndDepsMarkingAsVisited( const FileDescriptor* file, vector<const FileDescriptor*>* files, - set<const FileDescriptor*>* files_visited) { + std::set<const FileDescriptor*>* files_visited) { vector<const FileDescriptor*>::iterator iter = std::find(files->begin(), files->end(), file); if (iter != files->end()) { @@ -105,7 +105,7 @@ void PruneFileAndDepsMarkingAsVisited( void CollectMinimalFileDepsContainingExtensionsWorker( const FileDescriptor* file, vector<const FileDescriptor*>* files, - set<const FileDescriptor*>* files_visited) { + std::set<const FileDescriptor*>* files_visited) { if (files_visited->find(file) != files_visited->end()) { return; } @@ -138,7 +138,7 @@ void CollectMinimalFileDepsContainingExtensionsWorker( void CollectMinimalFileDepsContainingExtensions( const FileDescriptor* file, vector<const FileDescriptor*>* files) { - set<const FileDescriptor*> files_visited; + std::set<const FileDescriptor*> files_visited; for (int i = 0; i < file->dependency_count(); i++) { const FileDescriptor* dep = file->dependency(i); CollectMinimalFileDepsContainingExtensionsWorker(dep, files, @@ -229,12 +229,12 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { "CF_EXTERN_C_BEGIN\n" "\n"); - set<string> fwd_decls; + std::set<string> fwd_decls; for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); iter != message_generators_.end(); ++iter) { (*iter)->DetermineForwardDeclarations(&fwd_decls); } - for (set<string>::const_iterator i(fwd_decls.begin()); + for (std::set<string>::const_iterator i(fwd_decls.begin()); i != fwd_decls.end(); ++i) { printer->Print("$value$;\n", "value", *i); } @@ -325,7 +325,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) { // #import the headers for anything that a plain dependency of this proto // file (that means they were just an include, not a "public" include). - set<string> public_import_names; + std::set<string> public_import_names; for (int i = 0; i < file_->public_dependency_count(); i++) { public_import_names.insert(file_->public_dependency(i)->name()); } @@ -468,7 +468,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) { // File descriptor only needed if there are messages to use it. if (message_generators_.size() > 0) { - map<string, string> vars; + std::map<string, string> vars; vars["root_class_name"] = root_class_name_; vars["package"] = file_->package(); vars["objc_prefix"] = FileClassPrefix(file_); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index bb8170a9..e347ef1e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -980,13 +980,13 @@ namespace { class ExpectedPrefixesCollector : public LineConsumer { public: - ExpectedPrefixesCollector(map<string, string>* inout_package_to_prefix_map) + ExpectedPrefixesCollector(std::map<string, string>* inout_package_to_prefix_map) : prefix_map_(inout_package_to_prefix_map) {} virtual bool ConsumeLine(const StringPiece& line, string* out_error); private: - map<string, string>* prefix_map_; + std::map<string, string>* prefix_map_; }; bool ExpectedPrefixesCollector::ConsumeLine( @@ -1009,7 +1009,7 @@ bool ExpectedPrefixesCollector::ConsumeLine( } bool LoadExpectedPackagePrefixes(const Options &generation_options, - map<string, string>* prefix_map, + std::map<string, string>* prefix_map, string* out_error) { if (generation_options.expected_prefixes_path.empty()) { return true; @@ -1023,7 +1023,7 @@ bool LoadExpectedPackagePrefixes(const Options &generation_options, bool ValidateObjCClassPrefix( const FileDescriptor* file, const string& expected_prefixes_path, - const map<string, string>& expected_package_prefixes, + const std::map<string, string>& expected_package_prefixes, string* out_error) { const string prefix = file->options().objc_class_prefix(); const string package = file->package(); @@ -1033,7 +1033,7 @@ bool ValidateObjCClassPrefix( // Check: Error - See if there was an expected prefix for the package and // report if it doesn't match (wrong or missing). - map<string, string>::const_iterator package_match = + std::map<string, string>::const_iterator package_match = expected_package_prefixes.find(package); if (package_match != expected_package_prefixes.end()) { // There was an entry, and... @@ -1082,7 +1082,7 @@ bool ValidateObjCClassPrefix( // Look for any other package that uses the same prefix. string other_package_for_prefix; - for (map<string, string>::const_iterator i = expected_package_prefixes.begin(); + for (std::map<string, string>::const_iterator i = expected_package_prefixes.begin(); i != expected_package_prefixes.end(); ++i) { if (i->second == prefix) { other_package_for_prefix = i->first; @@ -1150,7 +1150,7 @@ bool ValidateObjCClassPrefixes(const vector<const FileDescriptor*>& files, const Options& generation_options, string* out_error) { // Load the expected package prefixes, if available, to validate against. - map<string, string> expected_package_prefixes; + std::map<string, string> expected_package_prefixes; if (!LoadExpectedPackagePrefixes(generation_options, &expected_package_prefixes, out_error)) { @@ -1519,7 +1519,7 @@ void ImportWriter::AddFile(const FileDescriptor* file, ParseFrameworkMappings(); } - map<string, string>::iterator proto_lookup = + std::map<string, string>::iterator proto_lookup = proto_file_to_framework_name_.find(file->name()); if (proto_lookup != proto_file_to_framework_name_.end()) { other_framework_imports_.push_back( @@ -1640,7 +1640,7 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( StringPiece proto_file(proto_file_list, start, offset - start); StringPieceTrimWhitespace(&proto_file); if (proto_file.size() != 0) { - map<string, string>::iterator existing_entry = + std::map<string, string>::iterator existing_entry = map_->find(proto_file.ToString()); if (existing_entry != map_->end()) { std::cerr << "warning: duplicate proto file reference, replacing framework entry for '" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index c99262a1..daea7609 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -262,20 +262,20 @@ class LIBPROTOC_EXPORT ImportWriter { private: class ProtoFrameworkCollector : public LineConsumer { public: - ProtoFrameworkCollector(map<string, string>* inout_proto_file_to_framework_name) + ProtoFrameworkCollector(std::map<string, string>* inout_proto_file_to_framework_name) : map_(inout_proto_file_to_framework_name) {} virtual bool ConsumeLine(const StringPiece& line, string* out_error); private: - map<string, string>* map_; + std::map<string, string>* map_; }; void ParseFrameworkMappings(); const string generate_for_named_framework_; const string named_framework_to_proto_path_mappings_path_; - map<string, string> proto_file_to_framework_name_; + std::map<string, string> proto_file_to_framework_name_; bool need_to_parse_mapping_file_; vector<string> protobuf_framework_imports_; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc index 0bc9dc10..bcaf5709 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc @@ -162,7 +162,7 @@ void MapFieldGenerator::FinishInitialization(void) { } void MapFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls); const FieldDescriptor* value_descriptor = descriptor_->message_type()->FindFieldByName("value"); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h index bc68a682..6664d849 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h @@ -51,7 +51,7 @@ class MapFieldGenerator : public RepeatedFieldGenerator { MapFieldGenerator(const FieldDescriptor* descriptor, const Options& options); virtual ~MapFieldGenerator(); - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; private: scoped_ptr<FieldGenerator> value_field_generator_; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 0a554a83..4f22e290 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -233,7 +233,7 @@ void MessageGenerator::GenerateStaticVariablesInitialization( } } -void MessageGenerator::DetermineForwardDeclarations(set<string>* fwd_decls) { +void MessageGenerator::DetermineForwardDeclarations(std::set<string>* fwd_decls) { if (!IsMapEntryMessage(descriptor_)) { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* fieldDescriptor = descriptor_->field(i); @@ -514,7 +514,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { " };\n"); } - map<string, string> vars; + std::map<string, string> vars; vars["classname"] = class_name_; vars["rootclassname"] = root_classname_; vars["fields"] = has_fields ? "fields" : "NULL"; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 0fb78bc0..8f317ac0 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -64,7 +64,7 @@ class MessageGenerator { void GenerateMessageHeader(io::Printer* printer); void GenerateSource(io::Printer* printer); void GenerateExtensionRegistrationSource(io::Printer* printer); - void DetermineForwardDeclarations(set<string>* fwd_decls); + void DetermineForwardDeclarations(std::set<string>* fwd_decls); // Checks if the message or a nested message includes a oneof definition. bool IncludesOneOfDefinition() const; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc index d6ccd6d1..699d25b3 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc @@ -45,7 +45,7 @@ namespace objectivec { namespace { void SetMessageVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { const string& message_type = ClassName(descriptor->message_type()); (*variables)["type"] = message_type; (*variables)["containing_class"] = ClassName(descriptor->containing_type()); @@ -67,7 +67,7 @@ MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor, MessageFieldGenerator::~MessageFieldGenerator() {} void MessageFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { ObjCObjFieldGenerator::DetermineForwardDeclarations(fwd_decls); // Class name is already in "storage_type". fwd_decls->insert("@class " + variable("storage_type")); @@ -95,7 +95,7 @@ RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {} void RepeatedMessageFieldGenerator::DetermineForwardDeclarations( - set<string>* fwd_decls) const { + std::set<string>* fwd_decls) const { RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls); // Class name is already in "storage_type". fwd_decls->insert("@class " + variable("storage_type")); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h index d2dba153..50f4b6d4 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h @@ -51,7 +51,7 @@ class MessageFieldGenerator : public ObjCObjFieldGenerator { virtual bool WantsHasProperty(void) const; public: - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); @@ -67,7 +67,7 @@ class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator { virtual ~RepeatedMessageFieldGenerator(); public: - virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + virtual void DetermineForwardDeclarations(std::set<string>* fwd_decls) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h index 3d9df4db..ff353a6c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h @@ -67,7 +67,7 @@ class OneofGenerator { private: const OneofDescriptor* descriptor_; - map<string, string> variables_; + std::map<string, string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofGenerator); }; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index d49350f4..aa8ac324 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -118,7 +118,7 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) { } void SetPrimitiveVariables(const FieldDescriptor* descriptor, - map<string, string>* variables) { + std::map<string, string>* variables) { std::string primitive_name = PrimitiveTypeName(descriptor); (*variables)["type"] = primitive_name; (*variables)["storage_type"] = primitive_name; diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 60874e09..19d59843 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -227,10 +227,8 @@ class FatalException : public std::exception { // in some versions of MSVC. // TODO(acozzette): remove these using statements using std::istream; -using std::map; using std::ostream; using std::pair; -using std::set; using std::string; using std::vector; diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index a997e04b..5924de98 100644 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -40,7 +40,6 @@ #define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 #define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 -#define GOOGLE_PROTOBUF_HAVE_64BIT_HASH 1 // Use C++11 unordered_{map|set} if available. #if ((_LIBCPP_STD_VER >= 11) || \ @@ -93,8 +92,11 @@ # define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set # endif +// GCC <= 4.1 does not define std::tr1::hash for `long long int` or `long long unsigned int` # if __GNUC__ == 4 && __GNUC__MINOR__ <= 1 -# undef GOOGLE_PROTOBUF_HAVE_64BIT_HASH +# define GOOGLE_PROTOBUF_MISSING_HASH +# include <map> +# include <set> # endif // Version checks for MSC. diff --git a/src/google/protobuf/testing/googletest.h b/src/google/protobuf/testing/googletest.h index c0d99e69..bf8bf282 100644 --- a/src/google/protobuf/testing/googletest.h +++ b/src/google/protobuf/testing/googletest.h @@ -85,7 +85,7 @@ class ScopedMemoryLog { const vector<string>& GetMessages(LogLevel error); private: - map<LogLevel, vector<string> > messages_; + std::map<LogLevel, vector<string> > messages_; LogHandler* old_handler_; static void HandleLog(LogLevel level, const char* filename, int line, |