mirror of
https://github.com/google/leveldb.git
synced 2024-12-03 05:29:03 +08:00
9bd23c7676
1. Correct the class/struct declaration order to be IAW the Google C++ style guide[1]. 2. For non-copyable classes, switched from non-implemented private methods to explicitly deleted[2] methods. 3. Minor const and member initialization fixes. [1] https://google.github.io/styleguide/cppguide.html#Declaration_Order [2] http://eel.is/c++draft/dcl.fct.def.delete PiperOrigin-RevId: 246521844
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
// Copyright (c) 2018 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#include "leveldb/env.h"
|
|
|
|
#include "port/port.h"
|
|
#include "util/env_windows_test_helper.h"
|
|
#include "util/testharness.h"
|
|
|
|
namespace leveldb {
|
|
|
|
static const int kMMapLimit = 4;
|
|
|
|
class EnvWindowsTest {
|
|
public:
|
|
static void SetFileLimits(int mmap_limit) {
|
|
EnvWindowsTestHelper::SetReadOnlyMMapLimit(mmap_limit);
|
|
}
|
|
|
|
EnvWindowsTest() : env_(Env::Default()) {}
|
|
|
|
Env* env_;
|
|
};
|
|
|
|
TEST(EnvWindowsTest, TestOpenOnRead) {
|
|
// Write some test data to a single file that will be opened |n| times.
|
|
std::string test_dir;
|
|
ASSERT_OK(env_->GetTestDirectory(&test_dir));
|
|
std::string test_file = test_dir + "/open_on_read.txt";
|
|
|
|
FILE* f = fopen(test_file.c_str(), "w");
|
|
ASSERT_TRUE(f != nullptr);
|
|
const char kFileData[] = "abcdefghijklmnopqrstuvwxyz";
|
|
fputs(kFileData, f);
|
|
fclose(f);
|
|
|
|
// Open test file some number above the sum of the two limits to force
|
|
// leveldb::WindowsEnv to switch from mapping the file into memory
|
|
// to basic file reading.
|
|
const int kNumFiles = kMMapLimit + 5;
|
|
leveldb::RandomAccessFile* files[kNumFiles] = {0};
|
|
for (int i = 0; i < kNumFiles; i++) {
|
|
ASSERT_OK(env_->NewRandomAccessFile(test_file, &files[i]));
|
|
}
|
|
char scratch;
|
|
Slice read_result;
|
|
for (int i = 0; i < kNumFiles; i++) {
|
|
ASSERT_OK(files[i]->Read(i, 1, &read_result, &scratch));
|
|
ASSERT_EQ(kFileData[i], read_result[0]);
|
|
}
|
|
for (int i = 0; i < kNumFiles; i++) {
|
|
delete files[i];
|
|
}
|
|
ASSERT_OK(env_->DeleteFile(test_file));
|
|
}
|
|
|
|
} // namespace leveldb
|
|
|
|
int main(int argc, char** argv) {
|
|
// All tests currently run with the same read-only file limits.
|
|
leveldb::EnvWindowsTest::SetFileLimits(leveldb::kMMapLimit);
|
|
return leveldb::test::RunAllTests();
|
|
}
|