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

Side by Side Diff: components/dom_distiller/core/dom_distiller_test_util.cc

Issue 330833002: Extract protobuf database into a new 'leveldb_proto' component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/dom_distiller/core/dom_distiller_test_util.h" 5 #include "components/dom_distiller/core/dom_distiller_test_util.h"
6 6
7 #include "components/dom_distiller/core/dom_distiller_store.h" 7 #include "components/dom_distiller/core/dom_distiller_store.h"
8 #include "components/dom_distiller/core/fake_distiller.h" 8 #include "components/dom_distiller/core/fake_distiller.h"
9 9
10 using leveldb_proto::test::FakeDB;
11
10 namespace dom_distiller { 12 namespace dom_distiller {
11 namespace test { 13 namespace test {
12 namespace util { 14 namespace util {
13 15
14 namespace { 16 namespace {
15 17
16 std::vector<ArticleEntry> EntryMapToList(const FakeDB::EntryMap& entries) { 18 std::vector<ArticleEntry> EntryMapToList(
19 const FakeDB<ArticleEntry>::EntryMap& entries) {
17 std::vector<ArticleEntry> entry_list; 20 std::vector<ArticleEntry> entry_list;
18 for (FakeDB::EntryMap::const_iterator it = entries.begin(); 21 for (FakeDB<ArticleEntry>::EntryMap::const_iterator it = entries.begin();
19 it != entries.end(); 22 it != entries.end(); ++it) {
20 ++it) {
21 entry_list.push_back(it->second); 23 entry_list.push_back(it->second);
22 } 24 }
23 return entry_list; 25 return entry_list;
24 } 26 }
25 } // namespace 27 } // namespace
26 28
27 ObserverUpdatesMatcher::ObserverUpdatesMatcher( 29 ObserverUpdatesMatcher::ObserverUpdatesMatcher(
28 const std::vector<DomDistillerObserver::ArticleUpdate>& expected_updates) 30 const std::vector<DomDistillerObserver::ArticleUpdate>& expected_updates)
29 : expected_updates_(expected_updates) {} 31 : expected_updates_(expected_updates) {}
30 32
31 bool ObserverUpdatesMatcher::MatchAndExplain( 33 bool ObserverUpdatesMatcher::MatchAndExplain(
32 const std::vector<DomDistillerObserver::ArticleUpdate>& actual_updates, 34 const std::vector<DomDistillerObserver::ArticleUpdate>& actual_updates,
33 testing::MatchResultListener* listener) const { 35 testing::MatchResultListener* listener) const {
34 if (actual_updates.size() != expected_updates_.size()) { 36 if (actual_updates.size() != expected_updates_.size()) {
35 *listener << "Incorrect number of updates. Expected: " 37 *listener << "Incorrect number of updates. Expected: "
36 << expected_updates_.size() << " got: " << actual_updates.size(); 38 << expected_updates_.size() << " got: " << actual_updates.size();
37 return false; 39 return false;
38 } 40 }
39 std::vector<DomDistillerObserver::ArticleUpdate>::const_iterator expected, 41 std::vector<DomDistillerObserver::ArticleUpdate>::const_iterator expected,
40 actual; 42 actual;
41 for (expected = expected_updates_.begin(), actual = actual_updates.begin(); 43 for (expected = expected_updates_.begin(), actual = actual_updates.begin();
42 expected != expected_updates_.end(); 44 expected != expected_updates_.end(); ++expected, ++actual) {
43 ++expected, ++actual) {
44 if (expected->entry_id != actual->entry_id) { 45 if (expected->entry_id != actual->entry_id) {
45 *listener << " Mismatched entry id. Expected: " << expected->entry_id 46 *listener << " Mismatched entry id. Expected: " << expected->entry_id
46 << " actual: " << actual->entry_id; 47 << " actual: " << actual->entry_id;
47 return false; 48 return false;
48 } 49 }
49 if (expected->update_type != actual->update_type) { 50 if (expected->update_type != actual->update_type) {
50 *listener << " Mismatched update for entryid:" << expected->entry_id 51 *listener << " Mismatched update for entryid:" << expected->entry_id
51 << ". Expected: " << expected->update_type 52 << ". Expected: " << expected->update_type
52 << " actual: " << actual->update_type; 53 << " actual: " << actual->update_type;
53 return false; 54 return false;
54 } 55 }
55 } 56 }
56 return true; 57 return true;
57 } 58 }
58 59
59 void ObserverUpdatesMatcher::DescribeUpdates(std::ostream* os) const { 60 void ObserverUpdatesMatcher::DescribeUpdates(std::ostream* os) const {
60 bool start = true; 61 bool start = true;
61 for (std::vector<DomDistillerObserver::ArticleUpdate>::const_iterator i = 62 for (std::vector<DomDistillerObserver::ArticleUpdate>::const_iterator i =
62 expected_updates_.begin(); 63 expected_updates_.begin();
63 i != expected_updates_.end(); 64 i != expected_updates_.end(); ++i) {
64 ++i) {
65 if (start) { 65 if (start) {
66 start = false; 66 start = false;
67 } else { 67 } else {
68 *os << ", "; 68 *os << ", ";
69 } 69 }
70 *os << "( EntryId: " << i->entry_id << ", UpdateType: " << i->update_type 70 *os << "( EntryId: " << i->entry_id << ", UpdateType: " << i->update_type
71 << " )"; 71 << " )";
72 } 72 }
73 } 73 }
74 74
75 void ObserverUpdatesMatcher::DescribeTo(std::ostream* os) const { 75 void ObserverUpdatesMatcher::DescribeTo(std::ostream* os) const {
76 *os << " has updates: { "; 76 *os << " has updates: { ";
77 DescribeUpdates(os); 77 DescribeUpdates(os);
78 *os << "}"; 78 *os << "}";
79 } 79 }
80 void ObserverUpdatesMatcher::DescribeNegationTo(std::ostream* os) const { 80 void ObserverUpdatesMatcher::DescribeNegationTo(std::ostream* os) const {
81 *os << " does not have updates: { "; 81 *os << " does not have updates: { ";
82 DescribeUpdates(os); 82 DescribeUpdates(os);
83 *os << "}"; 83 *os << "}";
84 } 84 }
85 85
86 testing::Matcher<const std::vector<DomDistillerObserver::ArticleUpdate>&> 86 testing::Matcher<const std::vector<DomDistillerObserver::ArticleUpdate>&>
87 HasExpectedUpdates( 87 HasExpectedUpdates(
88 const std::vector<DomDistillerObserver::ArticleUpdate>& expected_updates) { 88 const std::vector<DomDistillerObserver::ArticleUpdate>& expected_updates) {
89 return testing::MakeMatcher(new ObserverUpdatesMatcher(expected_updates)); 89 return testing::MakeMatcher(new ObserverUpdatesMatcher(expected_updates));
90 } 90 }
91 91
92 // static 92 // static
93 DomDistillerStore* CreateStoreWithFakeDB(FakeDB* fake_db, 93 DomDistillerStore* CreateStoreWithFakeDB(
94 const FakeDB::EntryMap& store_model) { 94 FakeDB<ArticleEntry>* fake_db,
95 const FakeDB<ArticleEntry>::EntryMap& store_model) {
95 return new DomDistillerStore( 96 return new DomDistillerStore(
96 scoped_ptr<DomDistillerDatabaseInterface>(fake_db), 97 scoped_ptr<leveldb_proto::ProtoDatabase<ArticleEntry> >(fake_db),
97 EntryMapToList(store_model), 98 EntryMapToList(store_model), FakeDB<ArticleEntry>::DirectoryForTestDB());
98 FakeDB::DirectoryForTestDB());
99 } 99 }
100 100
101 } // namespace util 101 } // namespace util
102 } // namespace test 102 } // namespace test
103 } // namespace dom_distiller 103 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_test_util.h ('k') | components/dom_distiller/core/fake_db.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698