1313// limitations under the License.
1414
1515#include " google/cloud/storage/internal/async/read_range.h"
16+ #include " google/cloud/storage/internal/hash_function.h"
17+ #include " google/cloud/storage/internal/hash_values.h"
1618#include " google/cloud/storage/testing/canonical_errors.h"
1719#include " google/cloud/testing_util/is_proto_equal.h"
1820#include " google/cloud/testing_util/status_matchers.h"
21+ #include " absl/strings/cord.h"
22+ #include " absl/strings/string_view.h"
1923#include < google/protobuf/text_format.h>
2024#include < gmock/gmock.h>
25+ #include < gtest/gtest.h>
26+ #include < memory>
27+ #include < string>
2128
2229namespace google {
2330namespace cloud {
@@ -31,11 +38,30 @@ using ::google::cloud::testing_util::IsOk;
3138using ::google::cloud::testing_util::IsProtoEqual;
3239using ::google::cloud::testing_util::StatusIs;
3340using ::google::protobuf::TextFormat;
41+ using ::testing::_;
42+ using ::testing::AtLeast;
3443using ::testing::ElementsAre;
3544using ::testing::Optional;
3645using ::testing::ResultOf;
3746using ::testing::VariantWith;
3847
48+ class MockHashFunction : public storage ::internal::HashFunction {
49+ public:
50+ MOCK_METHOD (void , Update, (absl::string_view buffer), (override ));
51+ MOCK_METHOD (Status, Update, (std::int64_t offset, absl::string_view buffer),
52+ (override ));
53+ MOCK_METHOD (Status, Update,
54+ (std::int64_t offset, absl::string_view buffer,
55+ std::uint32_t buffer_crc),
56+ (override ));
57+ MOCK_METHOD (Status, Update,
58+ (std::int64_t offset, absl::Cord const & buffer,
59+ std::uint32_t buffer_crc),
60+ (override ));
61+ MOCK_METHOD (std::string, Name, (), (const , override ));
62+ MOCK_METHOD (storage::internal::HashValues, Finish, (), (override ));
63+ };
64+
3965TEST (ReadRange, BasicLifecycle) {
4066 ReadRange actual (10000 , 40 );
4167 EXPECT_FALSE (actual.IsDone ());
@@ -156,6 +182,23 @@ TEST(ReadRange, Queue) {
156182 EXPECT_THAT (actual.Read ().get (), VariantWith<ReadPayload>(matcher));
157183}
158184
185+ TEST (ReadRange, HashFunctionCalled) {
186+ auto hash_function = std::make_shared<MockHashFunction>();
187+ absl::Cord contents (" 1234567890" );
188+ EXPECT_CALL (*hash_function, Update (0 , contents, _)).Times (AtLeast (1 ));
189+
190+ ReadRange actual (0 , 0 , hash_function);
191+ auto data = google::storage::v2::ObjectRangeData{};
192+ auto constexpr kData0 = R"pb(
193+ checksummed_data { content: "1234567890" }
194+ read_range { read_offset: 0 read_limit: 10 read_id: 7 }
195+ range_end: false
196+ )pb" ;
197+
198+ EXPECT_TRUE (TextFormat::ParseFromString (kData0 , &data));
199+ actual.OnRead (std::move (data));
200+ }
201+
159202} // namespace
160203GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
161204} // namespace storage_internal
0 commit comments