summaryrefslogtreecommitdiffstats
path: root/vbench/src/tests/line_reader/line_reader_test.cpp
blob: 631b2ffc7652fc7128a9ab83374cc97529fd9c49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/testapp.h>
#include <vbench/test/all.h>

using namespace vbench;

TEST("line reader") {
    SimpleBuffer buffer;
    {
        BufferedOutput dst(buffer, 64);
        dst.append("foo\n");
        dst.append("bar\r\n");
        dst.append("\n");
        dst.append("\rbaz\n");
        dst.append("\r\n");
        dst.append("zzz");
    }
    {
        LineReader src(buffer, 3);
        string str;
        EXPECT_TRUE(src.readLine(str));
        EXPECT_EQUAL("foo", str);
        EXPECT_TRUE(src.readLine(str));
        EXPECT_EQUAL("bar", str);
        EXPECT_TRUE(src.readLine(str));
        EXPECT_EQUAL("", str);
        EXPECT_TRUE(src.readLine(str));
        EXPECT_EQUAL("\rbaz", str);
        EXPECT_TRUE(src.readLine(str));
        EXPECT_EQUAL("", str);
        EXPECT_TRUE(src.readLine(str));
        EXPECT_EQUAL("zzz", str);
        EXPECT_TRUE(!src.readLine(str));
        EXPECT_EQUAL("", str);
    }
}

TEST_MAIN() { TEST_RUN_ALL(); }