Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }