OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "components/leveldb/public/cpp/remote_iterator.h" | 8 #include "components/leveldb/public/cpp/remote_iterator.h" |
9 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 9 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
10 #include "mojo/common/common_type_converters.h" | 10 #include "mojo/common/common_type_converters.h" |
| 11 #include "services/shell/public/cpp/service_test.h" |
11 #include "services/shell/public/cpp/shell_connection.h" | 12 #include "services/shell/public/cpp/shell_connection.h" |
12 #include "services/shell/public/cpp/shell_test.h" | |
13 | 13 |
14 namespace leveldb { | 14 namespace leveldb { |
15 namespace { | 15 namespace { |
16 | 16 |
17 template <typename T> | 17 template <typename T> |
18 void DoCapture(T* t, T got_t) { *t = std::move(got_t); } | 18 void DoCapture(T* t, T got_t) { *t = std::move(got_t); } |
19 | 19 |
20 template <typename T1> | 20 template <typename T1> |
21 base::Callback<void(T1)> Capture(T1* t1) { | 21 base::Callback<void(T1)> Capture(T1* t1) { |
22 return base::Bind(&DoCapture<T1>, t1); | 22 return base::Bind(&DoCapture<T1>, t1); |
23 } | 23 } |
24 | 24 |
25 class RemoteIteratorTest : public shell::test::ShellTest { | 25 class RemoteIteratorTest : public shell::test::ServiceTest { |
26 public: | 26 public: |
27 RemoteIteratorTest() : ShellTest("exe:leveldb_service_unittests") {} | 27 RemoteIteratorTest() : ServiceTest("exe:leveldb_service_unittests") {} |
28 ~RemoteIteratorTest() override {} | 28 ~RemoteIteratorTest() override {} |
29 | 29 |
30 protected: | 30 protected: |
31 // Overridden from mojo::test::ApplicationTestBase: | 31 // Overridden from mojo::test::ApplicationTestBase: |
32 void SetUp() override { | 32 void SetUp() override { |
33 ShellTest::SetUp(); | 33 ServiceTest::SetUp(); |
34 connector()->ConnectToInterface("mojo:leveldb", &leveldb_); | 34 connector()->ConnectToInterface("mojo:leveldb", &leveldb_); |
35 | 35 |
36 mojom::DatabaseError error; | 36 mojom::DatabaseError error; |
37 leveldb()->OpenInMemory(GetProxy(&database_), Capture(&error)); | 37 leveldb()->OpenInMemory(GetProxy(&database_), Capture(&error)); |
38 ASSERT_TRUE(leveldb().WaitForIncomingResponse()); | 38 ASSERT_TRUE(leveldb().WaitForIncomingResponse()); |
39 EXPECT_EQ(mojom::DatabaseError::OK, error); | 39 EXPECT_EQ(mojom::DatabaseError::OK, error); |
40 | 40 |
41 std::map<std::string, std::string> data{ | 41 std::map<std::string, std::string> data{ |
42 {"a", "first"}, {"b:suffix", "second"}, {"c", "third"}}; | 42 {"a", "first"}, {"b:suffix", "second"}, {"c", "third"}}; |
43 | 43 |
44 for (auto p : data) { | 44 for (auto p : data) { |
45 // Write a key to the database. | 45 // Write a key to the database. |
46 error = mojom::DatabaseError::INVALID_ARGUMENT; | 46 error = mojom::DatabaseError::INVALID_ARGUMENT; |
47 database_->Put(mojo::Array<uint8_t>::From(p.first), | 47 database_->Put(mojo::Array<uint8_t>::From(p.first), |
48 mojo::Array<uint8_t>::From(p.second), Capture(&error)); | 48 mojo::Array<uint8_t>::From(p.second), Capture(&error)); |
49 ASSERT_TRUE(database_.WaitForIncomingResponse()); | 49 ASSERT_TRUE(database_.WaitForIncomingResponse()); |
50 EXPECT_EQ(mojom::DatabaseError::OK, error); | 50 EXPECT_EQ(mojom::DatabaseError::OK, error); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 void TearDown() override { | 54 void TearDown() override { |
55 leveldb_.reset(); | 55 leveldb_.reset(); |
56 ShellTest::TearDown(); | 56 ServiceTest::TearDown(); |
57 } | 57 } |
58 | 58 |
59 mojom::LevelDBServicePtr& leveldb() { return leveldb_; } | 59 mojom::LevelDBServicePtr& leveldb() { return leveldb_; } |
60 mojom::LevelDBDatabasePtr& database() { return database_; } | 60 mojom::LevelDBDatabasePtr& database() { return database_; } |
61 | 61 |
62 private: | 62 private: |
63 mojom::LevelDBServicePtr leveldb_; | 63 mojom::LevelDBServicePtr leveldb_; |
64 mojom::LevelDBDatabasePtr database_; | 64 mojom::LevelDBDatabasePtr database_; |
65 | 65 |
66 DISALLOW_COPY_AND_ASSIGN(RemoteIteratorTest); | 66 DISALLOW_COPY_AND_ASSIGN(RemoteIteratorTest); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 EXPECT_TRUE(it.Valid()); | 142 EXPECT_TRUE(it.Valid()); |
143 EXPECT_EQ("a", it.key()); | 143 EXPECT_EQ("a", it.key()); |
144 EXPECT_EQ("first", it.value()); | 144 EXPECT_EQ("first", it.value()); |
145 | 145 |
146 it.Prev(); | 146 it.Prev(); |
147 EXPECT_FALSE(it.Valid()); | 147 EXPECT_FALSE(it.Valid()); |
148 } | 148 } |
149 | 149 |
150 } // namespace | 150 } // namespace |
151 } // namespace leveldb | 151 } // namespace leveldb |
OLD | NEW |