summaryrefslogtreecommitdiffstats
path: root/components/leveldb_proto/proto_database_impl_unittest.cc
diff options
context:
space:
mode:
authorcjhopman <cjhopman@chromium.org>2014-11-19 16:30:06 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-20 00:30:34 +0000
commit1aad174b259bc655e7b9e973fadfc79bc5c00e51 (patch)
tree0f5d45b5f7e5f75adf1a4a89bdcde683566c31a9 /components/leveldb_proto/proto_database_impl_unittest.cc
parent14bcfc52eb12a1b08cca13198ba2b25a7156f2ce (diff)
downloadchromium_src-1aad174b259bc655e7b9e973fadfc79bc5c00e51.zip
chromium_src-1aad174b259bc655e7b9e973fadfc79bc5c00e51.tar.gz
chromium_src-1aad174b259bc655e7b9e973fadfc79bc5c00e51.tar.bz2
Make ProtoDatabase properly handle failed Init
When Init fails, further Save/Load calls should just fail (and not crash). This makes the underlying LevelDB properly handle the Init failed case and adds tests for that. Adds LevelDB::InitWithOptions to make it easy to have the Init fail in tests. Review URL: https://codereview.chromium.org/735823004 Cr-Commit-Position: refs/heads/master@{#304944}
Diffstat (limited to 'components/leveldb_proto/proto_database_impl_unittest.cc')
-rw-r--r--components/leveldb_proto/proto_database_impl_unittest.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/components/leveldb_proto/proto_database_impl_unittest.cc b/components/leveldb_proto/proto_database_impl_unittest.cc
index 095b9d4..e1d3144 100644
--- a/components/leveldb_proto/proto_database_impl_unittest.cc
+++ b/components/leveldb_proto/proto_database_impl_unittest.cc
@@ -15,6 +15,7 @@
#include "components/leveldb_proto/testing/proto/test.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/leveldatabase/src/include/leveldb/options.h"
using base::MessageLoop;
using base::ScopedTempDir;
@@ -394,4 +395,21 @@ TEST(ProtoDatabaseImplLevelDBTest, TestDBCloseAndReopen) {
TestLevelDBSaveAndLoad(true);
}
+TEST(ProtoDatabaseImplLevelDBTest, TestDBInitFail) {
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ leveldb::Options options;
+ options.create_if_missing = false;
+ scoped_ptr<LevelDB> db(new LevelDB());
+
+ KeyValueVector save_entries;
+ std::vector<std::string> load_entries;
+ KeyVector remove_keys;
+
+ EXPECT_FALSE(db->InitWithOptions(temp_dir.path(), options));
+ EXPECT_FALSE(db->Load(&load_entries));
+ EXPECT_FALSE(db->Save(save_entries, remove_keys));
+}
+
} // namespace leveldb_proto