| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 base::ScopedTempDir temp_directory_; | 110 base::ScopedTempDir temp_directory_; |
| 111 SimpleComparator comparator_; | 111 SimpleComparator comparator_; |
| 112 std::unique_ptr<LevelDBDatabase> leveldb_; | 112 std::unique_ptr<LevelDBDatabase> leveldb_; |
| 113 | 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(LevelDBTransactionTest); | 114 DISALLOW_COPY_AND_ASSIGN(LevelDBTransactionTest); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 TEST_F(LevelDBTransactionTest, GetAndPut) { | 117 TEST_F(LevelDBTransactionTest, GetPutDelete) { |
| 118 leveldb::Status status; | 118 leveldb::Status status; |
| 119 | 119 |
| 120 const std::string key("key"); | 120 const std::string key("key"); |
| 121 std::string got_value; | 121 std::string got_value; |
| 122 | 122 |
| 123 const std::string old_value("value"); | 123 const std::string old_value("value"); |
| 124 Put(key, old_value); | 124 Put(key, old_value); |
| 125 | 125 |
| 126 scoped_refptr<LevelDBTransaction> transaction = new LevelDBTransaction(db()); | 126 scoped_refptr<LevelDBTransaction> transaction = new LevelDBTransaction(db()); |
| 127 | 127 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 143 Put(added_key, added_value); | 143 Put(added_key, added_value); |
| 144 | 144 |
| 145 Get(added_key, &got_value, &found); | 145 Get(added_key, &got_value, &found); |
| 146 EXPECT_TRUE(found); | 146 EXPECT_TRUE(found); |
| 147 EXPECT_EQ(Compare(got_value, added_value), 0); | 147 EXPECT_EQ(Compare(got_value, added_value), 0); |
| 148 | 148 |
| 149 EXPECT_FALSE(TransactionHas(transaction.get(), added_key)); | 149 EXPECT_FALSE(TransactionHas(transaction.get(), added_key)); |
| 150 | 150 |
| 151 const std::string another_key("another key"); | 151 const std::string another_key("another key"); |
| 152 const std::string another_value("another value"); | 152 const std::string another_value("another value"); |
| 153 EXPECT_EQ(0ull, transaction->GetTransactionSize()); |
| 153 TransactionPut(transaction.get(), another_key, another_value); | 154 TransactionPut(transaction.get(), another_key, another_value); |
| 155 EXPECT_EQ(46ull, transaction->GetTransactionSize()); |
| 154 | 156 |
| 155 status = transaction->Get(another_key, &got_value, &found); | 157 status = transaction->Get(another_key, &got_value, &found); |
| 156 EXPECT_TRUE(status.ok()); | 158 EXPECT_TRUE(status.ok()); |
| 157 EXPECT_TRUE(found); | 159 EXPECT_TRUE(found); |
| 158 EXPECT_EQ(Compare(got_value, another_value), 0); | 160 EXPECT_EQ(Compare(got_value, another_value), 0); |
| 161 |
| 162 transaction->Remove(another_key); |
| 163 EXPECT_EQ(33ull, transaction->GetTransactionSize()); |
| 159 } | 164 } |
| 160 | 165 |
| 161 TEST_F(LevelDBTransactionTest, Iterator) { | 166 TEST_F(LevelDBTransactionTest, Iterator) { |
| 162 const std::string key1("key1"); | 167 const std::string key1("key1"); |
| 163 const std::string value1("value1"); | 168 const std::string value1("value1"); |
| 164 const std::string key2("key2"); | 169 const std::string key2("key2"); |
| 165 const std::string value2("value2"); | 170 const std::string value2("value2"); |
| 166 | 171 |
| 167 Put(key1, value1); | 172 Put(key1, value1); |
| 168 Put(key2, value2); | 173 Put(key2, value2); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 EXPECT_EQ(Compare(key_after_range_, it->Key()), 0); | 428 EXPECT_EQ(Compare(key_after_range_, it->Key()), 0); |
| 424 } | 429 } |
| 425 | 430 |
| 426 INSTANTIATE_TEST_CASE_P(LevelDBTransactionRangeTests, | 431 INSTANTIATE_TEST_CASE_P(LevelDBTransactionRangeTests, |
| 427 LevelDBTransactionRangeTest, | 432 LevelDBTransactionRangeTest, |
| 428 ::testing::Values(DataInMemory, | 433 ::testing::Values(DataInMemory, |
| 429 DataInDatabase, | 434 DataInDatabase, |
| 430 DataMixed)); | 435 DataMixed)); |
| 431 | 436 |
| 432 } // namespace content | 437 } // namespace content |
| OLD | NEW |