diff options
author | Victor Costan <costan@google.com> | 2019-11-21 13:09:53 -0800 |
---|---|---|
committer | Victor Costan <pwnall@chromium.org> | 2019-11-21 13:11:40 -0800 |
commit | 1c58902bdcc8d129f3883606bbd8e59085b48878 (patch) | |
tree | 8ca631cdc3575fa2f33be0dc28b9d94d610202a1 /issues | |
parent | 2c9c80bd539ca5aad5ea864ee6dd81c1ee3eb91e (diff) | |
download | leveldb-1c58902bdcc8d129f3883606bbd8e59085b48878.tar.gz |
Switch testing harness to googletest.
PiperOrigin-RevId: 281815695
Diffstat (limited to 'issues')
-rw-r--r-- | issues/issue178_test.cc | 20 | ||||
-rw-r--r-- | issues/issue200_test.cc | 26 | ||||
-rw-r--r-- | issues/issue320_test.cc | 19 |
3 files changed, 36 insertions, 29 deletions
diff --git a/issues/issue178_test.cc b/issues/issue178_test.cc index d50ffeb..4a52a1b 100644 --- a/issues/issue178_test.cc +++ b/issues/issue178_test.cc @@ -7,9 +7,10 @@ #include <iostream> #include <sstream> +#include "third_party/googletest/googletest/include/gtest/gtest.h" #include "leveldb/db.h" #include "leveldb/write_batch.h" -#include "util/testharness.h" +#include "util/testutil.h" namespace { @@ -23,11 +24,9 @@ std::string Key1(int i) { std::string Key2(int i) { return Key1(i) + "_xxx"; } -class Issue178 {}; - 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 @@ -37,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); @@ -85,4 +84,7 @@ TEST(Issue178, Test) { } // anonymous namespace -int main(int argc, char** argv) { return leveldb::test::RunAllTests(); } +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/issues/issue200_test.cc b/issues/issue200_test.cc index 877b2af..ee08bc6 100644 --- a/issues/issue200_test.cc +++ b/issues/issue200_test.cc @@ -6,35 +6,34 @@ // to forward, the current key can be yielded unexpectedly if a new // mutation has been added just before the current key. +#include "third_party/googletest/googletest/include/gtest/gtest.h" #include "leveldb/db.h" -#include "util/testharness.h" +#include "util/testutil.h" namespace leveldb { -class Issue200 {}; - TEST(Issue200, Test) { // Get rid of any state from an old run. - std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; + std::string dbpath = testing::TempDir() + "leveldb_issue200_test"; DestroyDB(dbpath, Options()); DB* db; Options options; options.create_if_missing = true; - ASSERT_OK(DB::Open(options, dbpath, &db)); + ASSERT_LEVELDB_OK(DB::Open(options, dbpath, &db)); WriteOptions write_options; - ASSERT_OK(db->Put(write_options, "1", "b")); - ASSERT_OK(db->Put(write_options, "2", "c")); - ASSERT_OK(db->Put(write_options, "3", "d")); - ASSERT_OK(db->Put(write_options, "4", "e")); - ASSERT_OK(db->Put(write_options, "5", "f")); + 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_OK(db->Put(write_options, "25", "cd")); + ASSERT_LEVELDB_OK(db->Put(write_options, "25", "cd")); iter->Seek("5"); ASSERT_EQ(iter->key().ToString(), "5"); @@ -54,4 +53,7 @@ TEST(Issue200, Test) { } // namespace leveldb -int main(int argc, char** argv) { return leveldb::test::RunAllTests(); } +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/issues/issue320_test.cc b/issues/issue320_test.cc index c5fcbfc..c289ab4 100644 --- a/issues/issue320_test.cc +++ b/issues/issue320_test.cc @@ -9,9 +9,10 @@ #include <string> #include <vector> +#include "third_party/googletest/googletest/include/gtest/gtest.h" #include "leveldb/db.h" #include "leveldb/write_batch.h" -#include "util/testharness.h" +#include "util/testutil.h" namespace leveldb { @@ -37,8 +38,6 @@ std::string CreateRandomString(int32_t index) { } // namespace -class Issue320 {}; - TEST(Issue320, Test) { std::srand(0); @@ -53,8 +52,8 @@ TEST(Issue320, Test) { Options options; options.create_if_missing = true; - std::string dbpath = test::TmpDir() + "/leveldb_issue320_test"; - ASSERT_OK(DB::Open(options, dbpath, &db)); + std::string dbpath = testing::TempDir() + "leveldb_issue320_test"; + ASSERT_LEVELDB_OK(DB::Open(options, dbpath, &db)); uint32_t target_size = 10000; uint32_t num_items = 0; @@ -78,7 +77,8 @@ TEST(Issue320, Test) { CreateRandomString(index), CreateRandomString(index))); batch.Put(test_map[index]->first, test_map[index]->second); } else { - ASSERT_OK(db->Get(readOptions, test_map[index]->first, &old_value)); + ASSERT_LEVELDB_OK( + db->Get(readOptions, test_map[index]->first, &old_value)); if (old_value != test_map[index]->second) { std::cout << "ERROR incorrect value returned by Get" << std::endl; std::cout << " count=" << count << std::endl; @@ -102,7 +102,7 @@ TEST(Issue320, Test) { } } - ASSERT_OK(db->Write(writeOptions, &batch)); + ASSERT_LEVELDB_OK(db->Write(writeOptions, &batch)); if (keep_snapshots && GenerateRandomNumber(10) == 0) { int i = GenerateRandomNumber(snapshots.size()); @@ -125,4 +125,7 @@ TEST(Issue320, Test) { } // namespace leveldb -int main(int argc, char** argv) { return leveldb::test::RunAllTests(); } +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} |