output_test.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
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 }  // namespace
00070 }  // namespace absl
00071 


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