@@ -23,39 +23,9 @@ namespace storage_internal {
2323GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2424namespace {
2525
26- using ::testing::ElementsAre;
2726using ::testing::IsEmpty;
2827using ::testing::Not;
2928
30- template <typename Collection,
31- typename std::enable_if<std::is_same<Collection, std::string>::value,
32- int >::type = 0 >
33- Collection ToCollection (std::string v) {
34- // This is not motivated by a desire to optimize this test helper function
35- // (though that is nice). The issue is that I (coryan@) could not figure out
36- // how to write a generic version of this function that works with
37- // `std::vector<std::byte>` and `std::string`.
38- return v;
39- }
40-
41- template <typename Collection,
42- typename std::enable_if<!std::is_same<Collection, std::string>::value,
43- int >::type = 0 >
44- Collection ToCollection (std::string v) {
45- Collection result (v.size ());
46- std::transform (v.begin (), v.end (), result.begin (), [](auto c) {
47- return static_cast <typename Collection::value_type>(c);
48- });
49- return result;
50- }
51-
52- template <typename Collection>
53- Collection RandomData (internal::DefaultPRNG& generator, std::size_t size) {
54- auto data = internal::Sample (generator, static_cast <int >(size),
55- " abcdefghijklmnopqrstuvwxyz0123456789" );
56- return ToCollection<Collection>(std::move (data));
57- }
58-
5929TEST (WritePayloadImpl, Default) {
6030 auto const actual = storage_experimental::WritePayload ();
6131 EXPECT_TRUE (actual.empty ());
@@ -81,13 +51,6 @@ TEST(WritePayloadImpl, GetImpl) {
8151 EXPECT_EQ (WritePayloadImpl::GetImpl (actual), absl::Cord (expected));
8252}
8353
84- TEST (WritePayloadImpl, IsPayloadType) {
85- EXPECT_TRUE (IsPayloadType<char >::value);
86- EXPECT_TRUE (IsPayloadType<std::uint8_t >::value);
87- EXPECT_FALSE (IsPayloadType<std::string>::value);
88- EXPECT_FALSE (IsPayloadType<std::uint32_t >::value);
89- }
90-
9154template <typename T>
9255class Typed : public ::testing::Test {
9356 public:
@@ -103,26 +66,14 @@ using TestVariations = ::testing::Types<
10366
10467TYPED_TEST_SUITE (Typed, TestVariations);
10568
106- TYPED_TEST (Typed, MakeCord) {
107- using Collection = typename TestFixture::TestType;
108- static auto generator = internal::MakeDefaultPRNG ();
109- auto constexpr kTestDataSize = 8 * 1024 * 1024L ;
110- auto const buffer = RandomData<Collection>(generator, kTestDataSize );
111- auto const view = absl::string_view (
112- reinterpret_cast <char const *>(buffer.data ()), buffer.size ());
113-
114- auto const actual = MakeCord (buffer);
115- auto chunks = actual.Chunks ();
116- EXPECT_THAT (chunks, ElementsAre (view));
117- }
118-
11969TYPED_TEST (Typed, MakeWritePayload) {
12070 using Collection = typename TestFixture::TestType;
12171
12272 auto const expected =
12373 std::string{" The quick brown fox jumps over the lazy dog" };
12474
125- auto const actual = MakeWritePayload (ToCollection<Collection>(expected));
75+ auto const actual =
76+ MakeWritePayload (internal::RandomDataToCollection<Collection>(expected));
12677 EXPECT_FALSE (actual.empty ());
12778 EXPECT_EQ (actual.size (), expected.size ());
12879 EXPECT_THAT (actual.payload (), Not (IsEmpty ()));
@@ -135,11 +86,12 @@ TYPED_TEST(Typed, MakeWritePayloadFromVector) {
13586
13687 static auto generator = internal::MakeDefaultPRNG ();
13788 auto constexpr kTestDataSize = 1024 ;
138- auto const part = RandomData<std::string>(generator, kTestDataSize );
89+ auto const part = internal:: RandomData<std::string>(generator, kTestDataSize );
13990 auto const expected = part + part + part;
14091 auto const actual = MakeWritePayload (std::vector<Collection>{
141- {ToCollection<Collection>(part), ToCollection<Collection>(part),
142- ToCollection<Collection>(part)}});
92+ {internal::RandomDataToCollection<Collection>(part),
93+ internal::RandomDataToCollection<Collection>(part),
94+ internal::RandomDataToCollection<Collection>(part)}});
14395 EXPECT_FALSE (actual.empty ());
14496 EXPECT_EQ (actual.size (), expected.size ());
14597 EXPECT_THAT (actual.payload (), Not (IsEmpty ()));
0 commit comments