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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 std::string put_value; | 44 std::string put_value; |
45 std::string got_value; | 45 std::string got_value; |
46 SimpleComparator comparator; | 46 SimpleComparator comparator; |
47 | 47 |
48 scoped_ptr<LevelDBDatabase> leveldb; | 48 scoped_ptr<LevelDBDatabase> leveldb; |
49 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); | 49 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); |
50 EXPECT_TRUE(leveldb); | 50 EXPECT_TRUE(leveldb); |
51 put_value = value; | 51 put_value = value; |
52 leveldb::Status status = leveldb->Put(key, &put_value); | 52 leveldb::Status status = leveldb->Put(key, &put_value); |
53 EXPECT_TRUE(status.ok()); | 53 EXPECT_TRUE(status.ok()); |
54 leveldb.Pass(); | 54 leveldb.reset(); |
55 EXPECT_FALSE(leveldb); | 55 EXPECT_FALSE(leveldb); |
56 | 56 |
57 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); | 57 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); |
58 EXPECT_TRUE(leveldb); | 58 EXPECT_TRUE(leveldb); |
59 bool found = false; | 59 bool found = false; |
60 status = leveldb->Get(key, &got_value, &found); | 60 status = leveldb->Get(key, &got_value, &found); |
61 EXPECT_TRUE(status.ok()); | 61 EXPECT_TRUE(status.ok()); |
62 EXPECT_TRUE(found); | 62 EXPECT_TRUE(found); |
63 EXPECT_EQ(value, got_value); | 63 EXPECT_EQ(value, got_value); |
64 leveldb.Pass(); | 64 leveldb.reset(); |
65 EXPECT_FALSE(leveldb); | 65 EXPECT_FALSE(leveldb); |
66 | 66 |
67 base::FilePath file_path = temp_directory.path().AppendASCII("CURRENT"); | 67 base::FilePath file_path = temp_directory.path().AppendASCII("CURRENT"); |
68 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_WRITE); | 68 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
69 file.SetLength(0); | 69 file.SetLength(0); |
70 file.Close(); | 70 file.Close(); |
71 | 71 |
72 status = LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); | 72 status = LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); |
73 EXPECT_FALSE(leveldb); | 73 EXPECT_FALSE(leveldb); |
74 EXPECT_FALSE(status.ok()); | 74 EXPECT_FALSE(status.ok()); |
(...skipping 183 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 |