| 14 | class Issue200 {}; |
| 15 | |
| 16 | TEST(Issue200, Test) { |
| 17 | // Get rid of any state from an old run. |
| 18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; |
| 19 | DestroyDB(dbpath, Options()); |
| 20 | |
| 21 | DB* db; |
| 22 | Options options; |
| 23 | options.create_if_missing = true; |
| 24 | ASSERT_OK(DB::Open(options, dbpath, &db)); |
| 25 | |
| 26 | WriteOptions write_options; |
| 27 | ASSERT_OK(db->Put(write_options, "1", "b")); |
| 28 | ASSERT_OK(db->Put(write_options, "2", "c")); |
| 29 | ASSERT_OK(db->Put(write_options, "3", "d")); |
| 30 | ASSERT_OK(db->Put(write_options, "4", "e")); |
| 31 | ASSERT_OK(db->Put(write_options, "5", "f")); |
| 32 | |
| 33 | ReadOptions read_options; |
| 34 | Iterator* iter = db->NewIterator(read_options); |
| 35 | |
| 36 | // Add an element that should not be reflected in the iterator. |
| 37 | ASSERT_OK(db->Put(write_options, "25", "cd")); |
| 38 | |
| 39 | iter->Seek("5"); |
| 40 | ASSERT_EQ(iter->key().ToString(), "5"); |
| 41 | iter->Prev(); |
| 42 | ASSERT_EQ(iter->key().ToString(), "4"); |
| 43 | iter->Prev(); |
| 44 | ASSERT_EQ(iter->key().ToString(), "3"); |
| 45 | iter->Next(); |
| 46 | ASSERT_EQ(iter->key().ToString(), "4"); |
| 47 | iter->Next(); |
| 48 | ASSERT_EQ(iter->key().ToString(), "5"); |
| 49 | |
| 50 | delete iter; |
| 51 | delete db; |
| 52 | DestroyDB(dbpath, options); |
| 53 | } |
| 54 | |
| 55 | } // namespace leveldb |
| 56 | |