| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/leveldb_proto/proto_database_impl.h" | 5 #include "components/leveldb_proto/proto_database_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "components/leveldb_proto/leveldb_database.h" | 14 #include "components/leveldb_proto/leveldb_database.h" |
| 15 #include "components/leveldb_proto/testing/proto/test.pb.h" | 15 #include "components/leveldb_proto/testing/proto/test.pb.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
| 18 | 19 |
| 19 using base::MessageLoop; | 20 using base::MessageLoop; |
| 20 using base::ScopedTempDir; | 21 using base::ScopedTempDir; |
| 21 using testing::Invoke; | 22 using testing::Invoke; |
| 22 using testing::Return; | 23 using testing::Return; |
| 23 using testing::_; | 24 using testing::_; |
| 24 | 25 |
| 25 namespace leveldb_proto { | 26 namespace leveldb_proto { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 388 } |
| 388 | 389 |
| 389 TEST(ProtoDatabaseImplLevelDBTest, TestDBSaveAndLoad) { | 390 TEST(ProtoDatabaseImplLevelDBTest, TestDBSaveAndLoad) { |
| 390 TestLevelDBSaveAndLoad(false); | 391 TestLevelDBSaveAndLoad(false); |
| 391 } | 392 } |
| 392 | 393 |
| 393 TEST(ProtoDatabaseImplLevelDBTest, TestDBCloseAndReopen) { | 394 TEST(ProtoDatabaseImplLevelDBTest, TestDBCloseAndReopen) { |
| 394 TestLevelDBSaveAndLoad(true); | 395 TestLevelDBSaveAndLoad(true); |
| 395 } | 396 } |
| 396 | 397 |
| 398 TEST(ProtoDatabaseImplLevelDBTest, TestDBInitFail) { |
| 399 ScopedTempDir temp_dir; |
| 400 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 401 |
| 402 leveldb::Options options; |
| 403 options.create_if_missing = false; |
| 404 scoped_ptr<LevelDB> db(new LevelDB()); |
| 405 |
| 406 KeyValueVector save_entries; |
| 407 std::vector<std::string> load_entries; |
| 408 KeyVector remove_keys; |
| 409 |
| 410 EXPECT_FALSE(db->InitWithOptions(temp_dir.path(), options)); |
| 411 EXPECT_FALSE(db->Load(&load_entries)); |
| 412 EXPECT_FALSE(db->Save(save_entries, remove_keys)); |
| 413 } |
| 414 |
| 397 } // namespace leveldb_proto | 415 } // namespace leveldb_proto |
| OLD | NEW |