| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "components/leveldb/public/cpp/remote_iterator.h" | 10 #include "components/leveldb/public/cpp/remote_iterator.h" |
| 11 #include "components/leveldb/public/cpp/util.h" |
| 11 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 12 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
| 12 #include "mojo/common/common_type_converters.h" | |
| 13 #include "services/shell/public/cpp/service_context.h" | 13 #include "services/shell/public/cpp/service_context.h" |
| 14 #include "services/shell/public/cpp/service_test.h" | 14 #include "services/shell/public/cpp/service_test.h" |
| 15 | 15 |
| 16 namespace leveldb { | 16 namespace leveldb { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 template <typename T> | 19 template <typename T> |
| 20 void DoCapture(T* t, const base::Closure& quit_closure, T got_t) { | 20 void DoCapture(T* t, const base::Closure& quit_closure, T got_t) { |
| 21 *t = std::move(got_t); | 21 *t = std::move(got_t); |
| 22 if (!quit_closure.is_null()) | 22 if (!quit_closure.is_null()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 48 run_loop.Run(); | 48 run_loop.Run(); |
| 49 EXPECT_EQ(mojom::DatabaseError::OK, error); | 49 EXPECT_EQ(mojom::DatabaseError::OK, error); |
| 50 | 50 |
| 51 std::map<std::string, std::string> data{ | 51 std::map<std::string, std::string> data{ |
| 52 {"a", "first"}, {"b:suffix", "second"}, {"c", "third"}}; | 52 {"a", "first"}, {"b:suffix", "second"}, {"c", "third"}}; |
| 53 | 53 |
| 54 for (auto p : data) { | 54 for (auto p : data) { |
| 55 // Write a key to the database. | 55 // Write a key to the database. |
| 56 error = mojom::DatabaseError::INVALID_ARGUMENT; | 56 error = mojom::DatabaseError::INVALID_ARGUMENT; |
| 57 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
| 58 database_->Put(mojo::Array<uint8_t>::From(p.first), | 58 database_->Put(StdStringToUint8Vector(p.first), |
| 59 mojo::Array<uint8_t>::From(p.second), | 59 StdStringToUint8Vector(p.second), |
| 60 Capture(&error, run_loop.QuitClosure())); | 60 Capture(&error, run_loop.QuitClosure())); |
| 61 run_loop.Run(); | 61 run_loop.Run(); |
| 62 EXPECT_EQ(mojom::DatabaseError::OK, error); | 62 EXPECT_EQ(mojom::DatabaseError::OK, error); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void TearDown() override { | 66 void TearDown() override { |
| 67 leveldb_.reset(); | 67 leveldb_.reset(); |
| 68 ServiceTest::TearDown(); | 68 ServiceTest::TearDown(); |
| 69 } | 69 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 EXPECT_TRUE(it.Valid()); | 157 EXPECT_TRUE(it.Valid()); |
| 158 EXPECT_EQ("a", it.key()); | 158 EXPECT_EQ("a", it.key()); |
| 159 EXPECT_EQ("first", it.value()); | 159 EXPECT_EQ("first", it.value()); |
| 160 | 160 |
| 161 it.Prev(); | 161 it.Prev(); |
| 162 EXPECT_FALSE(it.Valid()); | 162 EXPECT_FALSE(it.Valid()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace | 165 } // namespace |
| 166 } // namespace leveldb | 166 } // namespace leveldb |
| OLD | NEW |