diff options
author | Haavard <havardpe@yahoo-inc.com> | 2017-02-06 14:15:48 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2017-02-07 10:13:22 +0000 |
commit | b233017523112c4c0f7fac80ea8799ec55aa49c9 (patch) | |
tree | 9b9b6d38c8acc49a1166d4ff8d3d16af15733542 /vespalib/src/tests | |
parent | acde58693f8731405c551e6edfc95e546c7a14b0 (diff) |
mapped file input in vespalib
Diffstat (limited to 'vespalib/src/tests')
3 files changed, 32 insertions, 0 deletions
diff --git a/vespalib/src/tests/io/mapped_file_input/CMakeLists.txt b/vespalib/src/tests/io/mapped_file_input/CMakeLists.txt new file mode 100644 index 00000000000..2c637cd84a3 --- /dev/null +++ b/vespalib/src/tests/io/mapped_file_input/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespalib_mapped_file_input_test_app TEST + SOURCES + mapped_file_input_test.cpp + DEPENDS + vespalib +) +vespa_add_test(NAME vespalib_mapped_file_input_test_app COMMAND vespalib_mapped_file_input_test_app) diff --git a/vespalib/src/tests/io/mapped_file_input/file.txt b/vespalib/src/tests/io/mapped_file_input/file.txt new file mode 100644 index 00000000000..dd59d098638 --- /dev/null +++ b/vespalib/src/tests/io/mapped_file_input/file.txt @@ -0,0 +1 @@ +file content diff --git a/vespalib/src/tests/io/mapped_file_input/mapped_file_input_test.cpp b/vespalib/src/tests/io/mapped_file_input/mapped_file_input_test.cpp new file mode 100644 index 00000000000..14e3eb6a822 --- /dev/null +++ b/vespalib/src/tests/io/mapped_file_input/mapped_file_input_test.cpp @@ -0,0 +1,23 @@ +// Copyright 2016 Yahoo Inc. 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(); } |