aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/io/mapped_file_input/mapped_file_input_test.cpp
blob: c787f7f91440dade2ae2a6f5fab28de7255073b2 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/io/mapped_file_input.h>

using namespace vespalib;

TEST("require that missing file is invalid") {
    MappedFileInput file(TEST_PATH("not_found.txt"));
    EXPECT_TRUE(!file.valid());
}

TEST("require that file can be accessed as in input") {
    MappedFileInput file(TEST_PATH("file.txt"));
    EXPECT_TRUE(file.valid());
    EXPECT_EQUAL(file.get(), Memory("file content\n"));
    EXPECT_EQUAL(file.obtain(), Memory("file content\n"));
    file.evict(5);
    EXPECT_EQUAL(file.obtain(), Memory("content\n"));
    file.evict(8);
    EXPECT_EQUAL(file.obtain(), Memory());
}

TEST_MAIN() { TEST_RUN_ALL(); }