mirror of
https://github.com/google/leveldb.git
synced 2024-11-23 19:48:59 +08:00
8f464e7f68
This gives some flexibility to embedders. Currently, embedders have to build a binary for each test file. After this CL, embedders can still choose to have a binary for each test file, by linking each test file with a googletest target that includes main() (usually "gtest_main"). Embedders can also choose to build a single binary for almost all test files, and link with a googletest target that includes main(). The latter is more convenient for projects that have very few test binaries, like Chromium. PiperOrigin-RevId: 419470798
55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
// Copyright (c) 2013 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.
|
|
|
|
// Test for issue 200: when iterator switches direction from backward
|
|
// to forward, the current key can be yielded unexpectedly if a new
|
|
// mutation has been added just before the current key.
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "leveldb/db.h"
|
|
#include "util/testutil.h"
|
|
|
|
namespace leveldb {
|
|
|
|
TEST(Issue200, Test) {
|
|
// Get rid of any state from an old run.
|
|
std::string dbpath = testing::TempDir() + "leveldb_issue200_test";
|
|
DestroyDB(dbpath, Options());
|
|
|
|
DB* db;
|
|
Options options;
|
|
options.create_if_missing = true;
|
|
ASSERT_LEVELDB_OK(DB::Open(options, dbpath, &db));
|
|
|
|
WriteOptions write_options;
|
|
ASSERT_LEVELDB_OK(db->Put(write_options, "1", "b"));
|
|
ASSERT_LEVELDB_OK(db->Put(write_options, "2", "c"));
|
|
ASSERT_LEVELDB_OK(db->Put(write_options, "3", "d"));
|
|
ASSERT_LEVELDB_OK(db->Put(write_options, "4", "e"));
|
|
ASSERT_LEVELDB_OK(db->Put(write_options, "5", "f"));
|
|
|
|
ReadOptions read_options;
|
|
Iterator* iter = db->NewIterator(read_options);
|
|
|
|
// Add an element that should not be reflected in the iterator.
|
|
ASSERT_LEVELDB_OK(db->Put(write_options, "25", "cd"));
|
|
|
|
iter->Seek("5");
|
|
ASSERT_EQ(iter->key().ToString(), "5");
|
|
iter->Prev();
|
|
ASSERT_EQ(iter->key().ToString(), "4");
|
|
iter->Prev();
|
|
ASSERT_EQ(iter->key().ToString(), "3");
|
|
iter->Next();
|
|
ASSERT_EQ(iter->key().ToString(), "4");
|
|
iter->Next();
|
|
ASSERT_EQ(iter->key().ToString(), "5");
|
|
|
|
delete iter;
|
|
delete db;
|
|
DestroyDB(dbpath, options);
|
|
}
|
|
|
|
} // namespace leveldb
|