Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "absl/strings/internal/str_format/output.h"
00016
00017 #include <sstream>
00018 #include <string>
00019
00020 #include "gmock/gmock.h"
00021 #include "gtest/gtest.h"
00022
00023 namespace absl {
00024 namespace {
00025
00026 TEST(InvokeFlush, String) {
00027 std::string str = "ABC";
00028 str_format_internal::InvokeFlush(&str, "DEF");
00029 EXPECT_EQ(str, "ABCDEF");
00030 }
00031
00032 TEST(InvokeFlush, Stream) {
00033 std::stringstream str;
00034 str << "ABC";
00035 str_format_internal::InvokeFlush(&str, "DEF");
00036 EXPECT_EQ(str.str(), "ABCDEF");
00037 }
00038
00039 TEST(BufferRawSink, Limits) {
00040 char buf[16];
00041 {
00042 std::fill(std::begin(buf), std::end(buf), 'x');
00043 str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
00044 str_format_internal::InvokeFlush(&bufsink, "Hello World237");
00045 EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World237xx");
00046 }
00047 {
00048 std::fill(std::begin(buf), std::end(buf), 'x');
00049 str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
00050 str_format_internal::InvokeFlush(&bufsink, "Hello World237237");
00051 EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World2372x");
00052 }
00053 {
00054 std::fill(std::begin(buf), std::end(buf), 'x');
00055 str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
00056 str_format_internal::InvokeFlush(&bufsink, "Hello World");
00057 str_format_internal::InvokeFlush(&bufsink, "237");
00058 EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World237xx");
00059 }
00060 {
00061 std::fill(std::begin(buf), std::end(buf), 'x');
00062 str_format_internal::BufferRawSink bufsink(buf, sizeof(buf) - 1);
00063 str_format_internal::InvokeFlush(&bufsink, "Hello World");
00064 str_format_internal::InvokeFlush(&bufsink, "237237");
00065 EXPECT_EQ(std::string(buf, sizeof(buf)), "Hello World2372x");
00066 }
00067 }
00068
00069 }
00070 }
00071