output_test.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
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 // https://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 
16 
17 #include <sstream>
18 #include <string>
19 
20 #include "gmock/gmock.h"
21 #include "gtest/gtest.h"
22 
23 namespace absl {
24 namespace {
25 
26 TEST(InvokeFlush, String) {
27  std::string str = "ABC";
29  EXPECT_EQ(str, "ABCDEF");
30 }
31 
32 TEST(InvokeFlush, Stream) {
33  std::stringstream str;
34  str << "ABC";
36  EXPECT_EQ(str.str(), "ABCDEF");
37 }
38 
39 TEST(BufferRawSink, Limits) {
40  char buf[16];
41  {
42  std::fill(std::begin(buf), std::end(buf), 'x');
43  str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
44  str_format_internal::InvokeFlush(&bufsink, "Hello World237");
45  EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World237xx");
46  }
47  {
48  std::fill(std::begin(buf), std::end(buf), 'x');
49  str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
50  str_format_internal::InvokeFlush(&bufsink, "Hello World237237");
51  EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World2372x");
52  }
53  {
54  std::fill(std::begin(buf), std::end(buf), 'x');
55  str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
56  str_format_internal::InvokeFlush(&bufsink, "Hello World");
57  str_format_internal::InvokeFlush(&bufsink, "237");
58  EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World237xx");
59  }
60  {
61  std::fill(std::begin(buf), std::end(buf), 'x');
62  str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
63  str_format_internal::InvokeFlush(&bufsink, "Hello World");
64  str_format_internal::InvokeFlush(&bufsink, "237237");
65  EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World2372x");
66  }
67 }
68 
69 } // namespace
70 } // namespace absl
71 
char * begin
TEST(NotificationTest, SanityTest)
auto InvokeFlush(T *out, string_view s) -> decltype(str_format_internal::AbslFormatFlush(out, s))
Definition: output.h:93
int fill
char * end
char buf[N]
Definition: algorithm.h:29


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