16 #include "absl/strings/str_split.h"
27 TEST(FileTest, JoinPath) {
28 EXPECT_EQ(
"/abc/def", File::JoinPath(
"/abc",
"def"));
29 EXPECT_EQ(
"/abc/def", File::JoinPath(
"/abc/",
"def"));
30 EXPECT_EQ(
"def", File::JoinPath(
"",
"def"));
33 TEST(OutputBufferTest, WriteString) {
34 const int kMaxBufSize = 128;
35 char buffer[kMaxBufSize];
36 for (
int i = 0; i < kMaxBufSize; ++i) buffer[i] =
'\0';
37 FILE* fp = fmemopen(buffer, kMaxBufSize,
"w");
41 std::unique_ptr<OutputBuffer> output(
new OutputBuffer(fp));
42 output->WriteString(
"Hello ");
43 output->WriteString(
"world!");
45 EXPECT_STREQ(
"Hello world!", buffer);
48 TEST(InputBufferTest, Read) {
49 const int kMaxBufSize = 128;
50 char buffer[kMaxBufSize];
51 snprintf(buffer, kMaxBufSize,
"Hello\n world!");
52 EXPECT_STREQ(
"Hello\n world!", buffer);
53 FILE* fp = fmemopen(buffer, kMaxBufSize,
"r");
57 std::unique_ptr<InputBuffer> input(
new InputBuffer(fp));
58 EXPECT_TRUE(input->Read(&str));
59 std::vector<std::string> lines = absl::StrSplit(str,
'\n', absl::SkipEmpty());
60 EXPECT_EQ(2, lines.size());
61 EXPECT_EQ(
"Hello", lines[0]);
62 EXPECT_EQ(
" world!", lines[1]);