diff options
Diffstat (limited to 'issues/issue178_test.cc')
-rw-r--r-- | issues/issue178_test.cc | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/issues/issue178_test.cc b/issues/issue178_test.cc index 1b1cf8b..5cd5862 100644 --- a/issues/issue178_test.cc +++ b/issues/issue178_test.cc @@ -3,13 +3,14 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. // Test for issue 178: a manual compaction causes deleted data to reappear. +#include <cstdlib> #include <iostream> #include <sstream> -#include <cstdlib> +#include "gtest/gtest.h" #include "leveldb/db.h" #include "leveldb/write_batch.h" -#include "util/testharness.h" +#include "util/testutil.h" namespace { @@ -17,19 +18,15 @@ const int kNumKeys = 1100000; std::string Key1(int i) { char buf[100]; - snprintf(buf, sizeof(buf), "my_key_%d", i); + std::snprintf(buf, sizeof(buf), "my_key_%d", i); return buf; } -std::string Key2(int i) { - return Key1(i) + "_xxx"; -} - -class Issue178 { }; +std::string Key2(int i) { return Key1(i) + "_xxx"; } TEST(Issue178, Test) { // Get rid of any state from an old run. - std::string dbpath = leveldb::test::TmpDir() + "/leveldb_cbug_test"; + std::string dbpath = testing::TempDir() + "leveldb_cbug_test"; DestroyDB(dbpath, leveldb::Options()); // Open database. Disable compression since it affects the creation @@ -39,28 +36,28 @@ TEST(Issue178, Test) { leveldb::Options db_options; db_options.create_if_missing = true; db_options.compression = leveldb::kNoCompression; - ASSERT_OK(leveldb::DB::Open(db_options, dbpath, &db)); + ASSERT_LEVELDB_OK(leveldb::DB::Open(db_options, dbpath, &db)); // create first key range leveldb::WriteBatch batch; for (size_t i = 0; i < kNumKeys; i++) { batch.Put(Key1(i), "value for range 1 key"); } - ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); + ASSERT_LEVELDB_OK(db->Write(leveldb::WriteOptions(), &batch)); // create second key range batch.Clear(); for (size_t i = 0; i < kNumKeys; i++) { batch.Put(Key2(i), "value for range 2 key"); } - ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); + ASSERT_LEVELDB_OK(db->Write(leveldb::WriteOptions(), &batch)); // delete second key range batch.Clear(); for (size_t i = 0; i < kNumKeys; i++) { batch.Delete(Key2(i)); } - ASSERT_OK(db->Write(leveldb::WriteOptions(), &batch)); + ASSERT_LEVELDB_OK(db->Write(leveldb::WriteOptions(), &batch)); // compact database std::string start_key = Key1(0); @@ -86,7 +83,3 @@ TEST(Issue178, Test) { } } // anonymous namespace - -int main(int argc, char** argv) { - return leveldb::test::RunAllTests(); -} |