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.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" | 14 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" |
15 #include "content/browser/indexed_db/leveldb/leveldb_database.h" | 15 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
16 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 16 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
17 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 17 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/leveldatabase/env_chromium.h" | 19 #include "third_party/leveldatabase/env_chromium.h" |
20 #include "third_party/leveldatabase/env_idb.h" | 20 #include "third_party/leveldatabase/env_idb.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class SimpleComparator : public LevelDBComparator { | 26 class SimpleComparator : public LevelDBComparator { |
27 public: | 27 public: |
28 virtual int Compare(const base::StringPiece& a, | 28 virtual int Compare(const base::StringPiece& a, |
29 const base::StringPiece& b) const OVERRIDE { | 29 const base::StringPiece& b) const override { |
30 size_t len = std::min(a.size(), b.size()); | 30 size_t len = std::min(a.size(), b.size()); |
31 return memcmp(a.begin(), b.begin(), len); | 31 return memcmp(a.begin(), b.begin(), len); |
32 } | 32 } |
33 virtual const char* Name() const OVERRIDE { return "temp_comparator"; } | 33 virtual const char* Name() const override { return "temp_comparator"; } |
34 }; | 34 }; |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 TEST(LevelDBDatabaseTest, CorruptionTest) { | 38 TEST(LevelDBDatabaseTest, CorruptionTest) { |
39 base::ScopedTempDir temp_directory; | 39 base::ScopedTempDir temp_directory; |
40 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 40 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
41 | 41 |
42 const std::string key("key"); | 42 const std::string key("key"); |
43 const std::string value("value"); | 43 const std::string value("value"); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 leveldb::FileLock* lock2; | 259 leveldb::FileLock* lock2; |
260 status = env->LockFile(file.AsUTF8Unsafe(), &lock2); | 260 status = env->LockFile(file.AsUTF8Unsafe(), &lock2); |
261 EXPECT_FALSE(status.ok()); | 261 EXPECT_FALSE(status.ok()); |
262 | 262 |
263 status = env->UnlockFile(lock); | 263 status = env->UnlockFile(lock); |
264 EXPECT_TRUE(status.ok()); | 264 EXPECT_TRUE(status.ok()); |
265 } | 265 } |
266 | 266 |
267 } // namespace content | 267 } // namespace content |
OLD | NEW |