2 * Copyright 2013-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/experimental/symbolizer/LineReader.h>
19 #include <glog/logging.h>
21 #include <folly/FileUtil.h>
22 #include <folly/experimental/TestUtil.h>
23 #include <folly/portability/GTest.h>
26 namespace symbolizer {
29 using folly::test::TemporaryFile;
31 void writeAll(int fd, const char* str) {
32 ssize_t n = strlen(str);
33 CHECK_EQ(n, writeFull(fd, str, n));
36 void expect(LineReader& lr, const char* expected) {
38 size_t expectedLen = strlen(expected);
40 expectedLen != 0 ? LineReader::kReading : LineReader::kEof,
42 EXPECT_EQ(expectedLen, line.size());
43 EXPECT_EQ(std::string(expected, expectedLen), line.str());
46 TEST(LineReader, Simple) {
53 "This is a long line. It is longer than the other lines.\n"
55 "Incomplete last line");
58 CHECK_ERR(lseek(fd, 0, SEEK_SET));
60 LineReader lr(fd, buf, sizeof(buf));
62 expect(lr, "Hello worl");
64 expect(lr, "This is a ");
65 expect(lr, "long line.");
66 expect(lr, " It is lon");
67 expect(lr, "ger than t");
68 expect(lr, "he other l");
69 expect(lr, "ines.\n");
71 expect(lr, "Incomplete");
72 expect(lr, " last line");
77 CHECK_ERR(lseek(fd, 0, SEEK_SET));
79 LineReader lr(fd, buf, sizeof(buf));
81 expect(lr, "Hello world\n");
82 expect(lr, "This is a long line. It is longer than the other lines.\n");
84 expect(lr, "Incomplete last line");
89 } // namespace symbolizer