From b233017523112c4c0f7fac80ea8799ec55aa49c9 Mon Sep 17 00:00:00 2001 From: Haavard Date: Mon, 6 Feb 2017 14:15:48 +0000 Subject: mapped file input in vespalib --- .../src/tests/io/mapped_file_input/CMakeLists.txt | 8 ++++++++ vespalib/src/tests/io/mapped_file_input/file.txt | 1 + .../mapped_file_input/mapped_file_input_test.cpp | 23 ++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 vespalib/src/tests/io/mapped_file_input/CMakeLists.txt create mode 100644 vespalib/src/tests/io/mapped_file_input/file.txt create mode 100644 vespalib/src/tests/io/mapped_file_input/mapped_file_input_test.cpp (limited to 'vespalib/src/tests/io') 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 +#include + +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(); } -- cgit v1.2.3