1717#include " google/cloud/spanner/database.h"
1818#include " google/cloud/spanner/mutations.h"
1919#include " google/cloud/spanner/testing/database_integration_test.h"
20+ #include " google/cloud/spanner/testing/singer.pb.h"
2021#include " google/cloud/spanner/timestamp.h"
2122#include " google/cloud/testing_util/status_matchers.h"
2223#include " absl/time/time.h"
2324#include < gmock/gmock.h>
25+ #include < cstdint>
26+ #include < string>
2427#include < vector>
2528
2629namespace google {
@@ -43,6 +46,16 @@ absl::Time MakeTime(std::time_t sec, int nanos) {
4346 return absl::FromTimeT (sec) + absl::Nanoseconds (nanos);
4447}
4548
49+ testing::SingerInfo MakeSinger (std::int64_t singer_id, std::string birth_date,
50+ std::string nationality, testing::Genre genre) {
51+ testing::SingerInfo singer;
52+ singer.set_singer_id (singer_id);
53+ singer.set_birth_date (std::move (birth_date));
54+ singer.set_nationality (std::move (nationality));
55+ singer.set_genre (genre);
56+ return singer;
57+ }
58+
4659// A helper function used in the test fixtures below. This function writes the
4760// given data to the DataTypes table, then it reads all the data back and
4861// returns it to the caller.
@@ -292,6 +305,30 @@ TEST_F(PgDataTypeIntegrationTest, WriteReadNumeric) {
292305 EXPECT_THAT (result, IsOkAndHolds (UnorderedElementsAreArray (data)));
293306}
294307
308+ TEST_F (DataTypeIntegrationTest, WriteReadProtoEnum) {
309+ if (UsingEmulator ()) GTEST_SKIP () << " emulator does not support PROTO" ;
310+
311+ std::vector<ProtoEnum<testing::Genre>> const data = {
312+ testing::Genre::POP,
313+ testing::Genre::JAZZ,
314+ testing::Genre::FOLK,
315+ testing::Genre::ROCK,
316+ };
317+ auto result = WriteReadData (*client_, data, " SingerGenre" );
318+ EXPECT_THAT (result, IsOkAndHolds (UnorderedElementsAreArray (data)));
319+ }
320+
321+ TEST_F (DataTypeIntegrationTest, WriteReadProtoMessage) {
322+ if (UsingEmulator ()) GTEST_SKIP () << " emulator does not support PROTO" ;
323+
324+ std::vector<ProtoMessage<testing::SingerInfo>> const data = {
325+ MakeSinger (1 , " 1817-05-25" , " French" , testing::Genre::FOLK),
326+ MakeSinger (2123139547 , " 1942-06-18" , " British" , testing::Genre::POP),
327+ };
328+ auto result = WriteReadData (*client_, data, " SingerInfo" );
329+ EXPECT_THAT (result, IsOkAndHolds (UnorderedElementsAreArray (data)));
330+ }
331+
295332TEST_F (DataTypeIntegrationTest, WriteReadArrayBool) {
296333 std::vector<std::vector<bool >> const data = {
297334 std::vector<bool >{},
@@ -434,6 +471,36 @@ TEST_F(PgDataTypeIntegrationTest, WriteReadArrayNumeric) {
434471 EXPECT_THAT (result, IsOkAndHolds (UnorderedElementsAreArray (data)));
435472}
436473
474+ TEST_F (DataTypeIntegrationTest, WriteReadArrayProtoEnum) {
475+ if (UsingEmulator ()) GTEST_SKIP () << " emulator does not support PROTO" ;
476+
477+ std::vector<std::vector<ProtoEnum<testing::Genre>>> const data = {
478+ std::vector<ProtoEnum<testing::Genre>>{},
479+ std::vector<ProtoEnum<testing::Genre>>{
480+ testing::Genre::POP,
481+ testing::Genre::JAZZ,
482+ testing::Genre::FOLK,
483+ testing::Genre::ROCK,
484+ },
485+ };
486+ auto result = WriteReadData (*client_, data, " ArraySingerGenre" );
487+ EXPECT_THAT (result, IsOkAndHolds (UnorderedElementsAreArray (data)));
488+ }
489+
490+ TEST_F (DataTypeIntegrationTest, WriteReadArrayProtoMessage) {
491+ if (UsingEmulator ()) GTEST_SKIP () << " emulator does not support PROTO" ;
492+
493+ std::vector<std::vector<ProtoMessage<testing::SingerInfo>>> const data = {
494+ std::vector<ProtoMessage<testing::SingerInfo>>{},
495+ std::vector<ProtoMessage<testing::SingerInfo>>{
496+ MakeSinger (1 , " 1817-05-25" , " French" , testing::Genre::FOLK),
497+ MakeSinger (2123139547 , " 1942-06-18" , " British" , testing::Genre::POP),
498+ },
499+ };
500+ auto result = WriteReadData (*client_, data, " ArraySingerInfo" );
501+ EXPECT_THAT (result, IsOkAndHolds (UnorderedElementsAreArray (data)));
502+ }
503+
437504TEST_F (DataTypeIntegrationTest, JsonIndexAndPrimaryKey) {
438505 spanner_admin::DatabaseAdminClient admin_client (
439506 spanner_admin::MakeDatabaseAdminConnection ());
@@ -573,6 +640,25 @@ TEST_F(PgDataTypeIntegrationTest, NumericPrimaryKey) {
573640 HasSubstr (" part of the primary key" ))));
574641}
575642
643+ TEST_F (DataTypeIntegrationTest, InsertAndQueryWithProtoEnumKey) {
644+ if (UsingEmulator ()) GTEST_SKIP () << " emulator does not support PROTO" ;
645+
646+ auto & client = *client_;
647+ auto const key = testing::Genre::POP;
648+
649+ auto commit_result = client.Commit (
650+ Mutations{InsertOrUpdateMutationBuilder (" ProtoEnumKey" , {" Key" })
651+ .EmplaceRow (key)
652+ .Build ()});
653+ ASSERT_STATUS_OK (commit_result);
654+
655+ auto rows = client.Read (" ProtoEnumKey" , KeySet::All (), {" Key" });
656+ using RowType = std::tuple<ProtoEnum<testing::Genre>>;
657+ auto row = GetSingularRow (StreamOf<RowType>(rows));
658+ ASSERT_STATUS_OK (row);
659+ EXPECT_EQ (std::get<0 >(*std::move (row)), key);
660+ }
661+
576662TEST_F (DataTypeIntegrationTest, DmlReturning) {
577663 if (UsingEmulator ()) GTEST_SKIP () << " emulator does not support THEN RETURN" ;
578664
0 commit comments