1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/bigtable/row.h"
16 #include <gtest/gtest.h>
17 
18 namespace google {
19 namespace cloud {
20 namespace bigtable {
21 inline namespace BIGTABLE_CLIENT_NS {
22 namespace {
23 
24 /// @test Verify Row instantiation and trivial accessors.
TEST(RowTest,RowInstantiation)25 TEST(RowTest, RowInstantiation) {
26   std::string row_key = "row";
27   Cell cell(row_key, "family", "column", 42, "value");
28   Row row(row_key, {cell});
29 
30   EXPECT_EQ(1, row.cells().size());
31   EXPECT_EQ(row_key, row.cells().begin()->row_key());
32 
33   Row empty_row(row_key, {});
34   EXPECT_EQ(0, empty_row.cells().size());
35   EXPECT_EQ(empty_row.cells().begin(), empty_row.cells().end());
36 
37   Cell cell2(row_key, "family", "column", 43, "val");
38   Row two_cells_row(row_key, {cell, cell2});
39   EXPECT_EQ(2, two_cells_row.cells().size());
40   EXPECT_EQ(std::next(two_cells_row.cells().begin())->value(), cell2.value());
41 }
42 
TEST(RowTest,MoveOverload)43 TEST(RowTest, MoveOverload) {
44   std::string row_key = "row";
45   Cell cell(row_key, "family", "column", 42, "value");
46   Row row(row_key, {cell});
47 
48   static_assert(
49       !std::is_lvalue_reference<decltype(std::move(row).cells())>::value,
50       "Member function `cells` is expected to return a value from an r-value "
51       "reference to row.");
52 
53   std::vector<Cell> moved_cells = std::move(row).cells();
54   EXPECT_EQ(1U, moved_cells.size());
55   EXPECT_EQ("family", moved_cells[0].family_name());
56   EXPECT_EQ("column", moved_cells[0].column_qualifier());
57   EXPECT_EQ(42, moved_cells[0].timestamp().count());
58   EXPECT_EQ("value", moved_cells[0].value());
59 }
60 
61 }  // namespace
62 }  // namespace BIGTABLE_CLIENT_NS
63 }  // namespace bigtable
64 }  // namespace cloud
65 }  // namespace google
66