extension_test.cc
Go to the documentation of this file.
00001 //
00002 // Copyright 2017 The Abseil Authors.
00003 //
00004 // Licensed under the Apache License, Version 2.0 (the "License");
00005 // you may not use this file except in compliance with the License.
00006 // You may obtain a copy of the License at
00007 //
00008 //      https://www.apache.org/licenses/LICENSE-2.0
00009 //
00010 // Unless required by applicable law or agreed to in writing, software
00011 // distributed under the License is distributed on an "AS IS" BASIS,
00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 // See the License for the specific language governing permissions and
00014 // limitations under the License.
00015 //
00016 
00017 #include "absl/strings/internal/str_format/extension.h"
00018 
00019 #include <random>
00020 #include <string>
00021 
00022 #include "absl/strings/str_format.h"
00023 
00024 #include "gtest/gtest.h"
00025 
00026 namespace {
00027 
00028 std::string MakeRandomString(size_t len) {
00029   std::random_device rd;
00030   std::mt19937 gen(rd());
00031   std::uniform_int_distribution<> dis('a', 'z');
00032   std::string s(len, '0');
00033   for (char& c : s) {
00034     c = dis(gen);
00035   }
00036   return s;
00037 }
00038 
00039 TEST(FormatExtensionTest, SinkAppendSubstring) {
00040   for (size_t chunk_size : {1, 10, 100, 1000, 10000}) {
00041     std::string expected, actual;
00042     absl::str_format_internal::FormatSinkImpl sink(&actual);
00043     for (size_t chunks = 0; chunks < 10; ++chunks) {
00044       std::string rand = MakeRandomString(chunk_size);
00045       expected += rand;
00046       sink.Append(rand);
00047     }
00048     sink.Flush();
00049     EXPECT_EQ(actual, expected);
00050   }
00051 }
00052 
00053 TEST(FormatExtensionTest, SinkAppendChars) {
00054   for (size_t chunk_size : {1, 10, 100, 1000, 10000}) {
00055     std::string expected, actual;
00056     absl::str_format_internal::FormatSinkImpl sink(&actual);
00057     for (size_t chunks = 0; chunks < 10; ++chunks) {
00058       std::string rand = MakeRandomString(1);
00059       expected.append(chunk_size, rand[0]);
00060       sink.Append(chunk_size, rand[0]);
00061     }
00062     sink.Flush();
00063     EXPECT_EQ(actual, expected);
00064   }
00065 }
00066 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14