1818#include " google/cloud/testing_util/is_proto_equal.h"
1919#include " google/cloud/testing_util/status_matchers.h"
2020#include " absl/strings/cord.h"
21+ #include < google/protobuf/text_format.h>
2122#include < google/type/date.pb.h>
2223#include < gmock/gmock.h>
2324#include < cmath>
@@ -39,6 +40,7 @@ namespace {
3940using ::google::cloud::testing_util::IsOk;
4041using ::google::cloud::testing_util::IsOkAndHolds;
4142using ::google::cloud::testing_util::IsProtoEqual;
43+ using ::google::protobuf::TextFormat;
4244using ::testing::Not;
4345
4446absl::Time MakeTime (std::int64_t sec, int nanos) {
@@ -169,8 +171,6 @@ TEST(Value, BasicSemantics) {
169171 for (auto ts : TestTimes ()) {
170172 SCOPED_TRACE (" Testing: google::cloud::bigtable::Timestamp " +
171173 bigtable_internal::TimestampToRFC3339 (ts));
172- std::cout << " Testing: google::cloud::bigtable::Timestamp "
173- << bigtable_internal::TimestampToRFC3339 (ts) << std::endl;
174174 TestBasicSemantics (ts);
175175 std::vector<Timestamp> v (5 , ts);
176176 TestBasicSemantics (v);
@@ -1004,6 +1004,56 @@ TEST(Value, ProtoConversionMap) {
10041004 EXPECT_TRUE (p.first .has_map_type ());
10051005}
10061006
1007+ TEST (Value, ProtoMapWithDuplicateKeys) {
1008+ auto constexpr kTypeProto = R"""(
1009+ map_type {
1010+ key_type {
1011+ bytes_type {
1012+ }
1013+ }
1014+ value_type {
1015+ string_type {
1016+ }
1017+ }
1018+ }
1019+ )""" ;
1020+ google::bigtable::v2::Type type_proto;
1021+ ASSERT_TRUE (TextFormat::ParseFromString (kTypeProto , &type_proto));
1022+
1023+ auto constexpr kValueProto = R"""(
1024+ array_value {
1025+ values {
1026+ array_value {
1027+ values {
1028+ bytes_value: "foo"
1029+ }
1030+ values {
1031+ string_value: "foo"
1032+ }
1033+ }
1034+ }
1035+ values {
1036+ array_value {
1037+ values {
1038+ bytes_value: "foo"
1039+ }
1040+ values {
1041+ string_value: "bar"
1042+ }
1043+ }
1044+ }
1045+ }
1046+ )""" ;
1047+ google::bigtable::v2::Value value_proto;
1048+ ASSERT_TRUE (TextFormat::ParseFromString (kValueProto , &value_proto));
1049+
1050+ auto value = bigtable_internal::FromProto (type_proto, value_proto);
1051+ auto map = value.get <std::unordered_map<Bytes, std::string>>();
1052+ ASSERT_STATUS_OK (map);
1053+ EXPECT_THAT (*map, ::testing::UnorderedElementsAre (
1054+ ::testing::Pair (Bytes(" foo" ), "bar")));
1055+ }
1056+
10071057void SetNullProtoKind (Value& v) {
10081058 auto p = bigtable_internal::ToProto (v);
10091059 p.second .clear_kind ();
0 commit comments