Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: components/leveldb_proto/proto_database_impl_unittest.cc

Issue 2340983002: [tracing] Memory dump provider for leveldb_proto (Closed)
Patch Set: fix tests. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 base::RunLoop run_loop; 480 base::RunLoop run_loop;
481 db_thread.task_runner()->PostTaskAndReply( 481 db_thread.task_runner()->PostTaskAndReply(
482 FROM_HERE, base::Bind(base::DoNothing), run_loop.QuitClosure()); 482 FROM_HERE, base::Bind(base::DoNothing), run_loop.QuitClosure());
483 run_loop.Run(); 483 run_loop.Run();
484 } 484 }
485 485
486 // Test that the LevelDB properly saves entries and that load returns the saved 486 // Test that the LevelDB properly saves entries and that load returns the saved
487 // entries. If |close_after_save| is true, the database will be closed after 487 // entries. If |close_after_save| is true, the database will be closed after
488 // saving and then re-opened to ensure that the data is properly persisted. 488 // saving and then re-opened to ensure that the data is properly persisted.
489 void TestLevelDBSaveAndLoad(bool close_after_save) { 489 void TestLevelDBSaveAndLoad(bool close_after_save) {
490 base::MessageLoop main_loop;
491
490 ScopedTempDir temp_dir; 492 ScopedTempDir temp_dir;
491 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 493 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
492 494
493 EntryMap model = GetSmallModel(); 495 EntryMap model = GetSmallModel();
494 496
495 KeyValueVector save_entries; 497 KeyValueVector save_entries;
496 std::vector<std::string> load_entries; 498 std::vector<std::string> load_entries;
497 KeyVector remove_keys; 499 KeyVector remove_keys;
498 500
499 for (const auto& pair : model) { 501 for (const auto& pair : model) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 KeyValueVector save_entries; 544 KeyValueVector save_entries;
543 std::vector<std::string> load_entries; 545 std::vector<std::string> load_entries;
544 KeyVector remove_keys; 546 KeyVector remove_keys;
545 547
546 EXPECT_FALSE(db->InitWithOptions(temp_dir.GetPath(), options)); 548 EXPECT_FALSE(db->InitWithOptions(temp_dir.GetPath(), options));
547 EXPECT_FALSE(db->Load(&load_entries)); 549 EXPECT_FALSE(db->Load(&load_entries));
548 EXPECT_FALSE(db->Save(save_entries, remove_keys)); 550 EXPECT_FALSE(db->Save(save_entries, remove_keys));
549 } 551 }
550 552
551 TEST(ProtoDatabaseImplLevelDBTest, TestMemoryDatabase) { 553 TEST(ProtoDatabaseImplLevelDBTest, TestMemoryDatabase) {
554 base::MessageLoop main_loop;
555
552 std::unique_ptr<LevelDB> db(new LevelDB(kTestLevelDBClientName)); 556 std::unique_ptr<LevelDB> db(new LevelDB(kTestLevelDBClientName));
553 557
554 std::vector<std::string> load_entries; 558 std::vector<std::string> load_entries;
555 559
556 ASSERT_TRUE(db->Init(base::FilePath())); 560 ASSERT_TRUE(db->Init(base::FilePath()));
557 561
558 ASSERT_TRUE(db->Load(&load_entries)); 562 ASSERT_TRUE(db->Load(&load_entries));
559 EXPECT_EQ(0u, load_entries.size()); 563 EXPECT_EQ(0u, load_entries.size());
560 564
561 KeyValueVector save_entries(1, std::make_pair("foo", "bar")); 565 KeyValueVector save_entries(1, std::make_pair("foo", "bar"));
562 KeyVector remove_keys; 566 KeyVector remove_keys;
563 567
564 ASSERT_TRUE(db->Save(save_entries, remove_keys)); 568 ASSERT_TRUE(db->Save(save_entries, remove_keys));
565 569
566 std::vector<std::string> second_load_entries; 570 std::vector<std::string> second_load_entries;
567 571
568 ASSERT_TRUE(db->Load(&second_load_entries)); 572 ASSERT_TRUE(db->Load(&second_load_entries));
569 EXPECT_EQ(1u, second_load_entries.size()); 573 EXPECT_EQ(1u, second_load_entries.size());
570 } 574 }
571 575
572 } // namespace leveldb_proto 576 } // namespace leveldb_proto
OLDNEW
« components/leveldb_proto/leveldb_database.cc ('K') | « components/leveldb_proto/leveldb_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698