OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <algorithm> | 5 #include <algorithm> |
6 #include <cstring> | 6 #include <cstring> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 EXPECT_TRUE(it->IsValid()); | 191 EXPECT_TRUE(it->IsValid()); |
192 EXPECT_EQ(comparator.Compare(it->Key(), key2), 0); | 192 EXPECT_EQ(comparator.Compare(it->Key(), key2), 0); |
193 EXPECT_EQ(comparator.Compare(it->Value(), value2), 0); | 193 EXPECT_EQ(comparator.Compare(it->Value(), value2), 0); |
194 | 194 |
195 it->Next(); | 195 it->Next(); |
196 | 196 |
197 EXPECT_FALSE(it->IsValid()); | 197 EXPECT_FALSE(it->IsValid()); |
198 } | 198 } |
199 | 199 |
| 200 TEST(LevelDBDatabaseTest, TransactionCommitTest) { |
| 201 base::ScopedTempDir temp_directory; |
| 202 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 203 |
| 204 const std::string key1("key1"); |
| 205 const std::string key2("key2"); |
| 206 const std::string value1("value1"); |
| 207 const std::string value2("value2"); |
| 208 const std::string value3("value3"); |
| 209 |
| 210 std::string put_value; |
| 211 std::string got_value; |
| 212 SimpleComparator comparator; |
| 213 bool success; |
| 214 bool found; |
| 215 |
| 216 scoped_ptr<LevelDBDatabase> leveldb; |
| 217 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); |
| 218 EXPECT_TRUE(leveldb); |
| 219 |
| 220 scoped_refptr<LevelDBTransaction> transaction = |
| 221 new LevelDBTransaction(leveldb.get()); |
| 222 |
| 223 put_value = value1; |
| 224 transaction->Put(key1, &put_value); |
| 225 |
| 226 put_value = value2; |
| 227 transaction->Put(key2, &put_value); |
| 228 |
| 229 put_value = value3; |
| 230 transaction->Put(key2, &put_value); |
| 231 |
| 232 success = transaction->Commit(); |
| 233 EXPECT_TRUE(success); |
| 234 |
| 235 success = leveldb->Get(key1, &got_value, &found); |
| 236 EXPECT_TRUE(success); |
| 237 EXPECT_TRUE(found); |
| 238 EXPECT_EQ(value1, got_value); |
| 239 |
| 240 success = leveldb->Get(key2, &got_value, &found); |
| 241 EXPECT_TRUE(success); |
| 242 EXPECT_TRUE(found); |
| 243 EXPECT_EQ(value3, got_value); |
| 244 } |
| 245 |
200 } // namespace | 246 } // namespace |
201 | 247 |
202 } // namespace content | 248 } // namespace content |
OLD | NEW |