Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_unittest.cc

Issue 2316043002: //content: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <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 30 matching lines...) Expand all
41 base::ScopedTempDir temp_directory; 41 base::ScopedTempDir temp_directory;
42 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 42 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
43 43
44 const std::string key("key"); 44 const std::string key("key");
45 const std::string value("value"); 45 const std::string value("value");
46 std::string put_value; 46 std::string put_value;
47 std::string got_value; 47 std::string got_value;
48 SimpleComparator comparator; 48 SimpleComparator comparator;
49 49
50 std::unique_ptr<LevelDBDatabase> leveldb; 50 std::unique_ptr<LevelDBDatabase> leveldb;
51 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); 51 LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
52 EXPECT_TRUE(leveldb); 52 EXPECT_TRUE(leveldb);
53 put_value = value; 53 put_value = value;
54 leveldb::Status status = leveldb->Put(key, &put_value); 54 leveldb::Status status = leveldb->Put(key, &put_value);
55 EXPECT_TRUE(status.ok()); 55 EXPECT_TRUE(status.ok());
56 leveldb.reset(); 56 leveldb.reset();
57 EXPECT_FALSE(leveldb); 57 EXPECT_FALSE(leveldb);
58 58
59 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); 59 LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
60 EXPECT_TRUE(leveldb); 60 EXPECT_TRUE(leveldb);
61 bool found = false; 61 bool found = false;
62 status = leveldb->Get(key, &got_value, &found); 62 status = leveldb->Get(key, &got_value, &found);
63 EXPECT_TRUE(status.ok()); 63 EXPECT_TRUE(status.ok());
64 EXPECT_TRUE(found); 64 EXPECT_TRUE(found);
65 EXPECT_EQ(value, got_value); 65 EXPECT_EQ(value, got_value);
66 leveldb.reset(); 66 leveldb.reset();
67 EXPECT_FALSE(leveldb); 67 EXPECT_FALSE(leveldb);
68 68
69 base::FilePath file_path = temp_directory.path().AppendASCII("CURRENT"); 69 base::FilePath file_path = temp_directory.GetPath().AppendASCII("CURRENT");
70 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_WRITE); 70 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_WRITE);
71 file.SetLength(0); 71 file.SetLength(0);
72 file.Close(); 72 file.Close();
73 73
74 status = LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); 74 status =
75 LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
75 EXPECT_FALSE(leveldb); 76 EXPECT_FALSE(leveldb);
76 EXPECT_FALSE(status.ok()); 77 EXPECT_FALSE(status.ok());
77 EXPECT_TRUE(status.IsCorruption()); 78 EXPECT_TRUE(status.IsCorruption());
78 79
79 status = LevelDBDatabase::Destroy(temp_directory.path()); 80 status = LevelDBDatabase::Destroy(temp_directory.GetPath());
80 EXPECT_TRUE(status.ok()); 81 EXPECT_TRUE(status.ok());
81 82
82 status = LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); 83 status =
84 LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
83 EXPECT_TRUE(status.ok()); 85 EXPECT_TRUE(status.ok());
84 EXPECT_TRUE(leveldb); 86 EXPECT_TRUE(leveldb);
85 status = leveldb->Get(key, &got_value, &found); 87 status = leveldb->Get(key, &got_value, &found);
86 EXPECT_TRUE(status.ok()); 88 EXPECT_TRUE(status.ok());
87 EXPECT_FALSE(found); 89 EXPECT_FALSE(found);
88 } 90 }
89 91
90 TEST(LevelDBDatabaseTest, Transaction) { 92 TEST(LevelDBDatabaseTest, Transaction) {
91 base::ScopedTempDir temp_directory; 93 base::ScopedTempDir temp_directory;
92 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 94 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
93 95
94 const std::string key("key"); 96 const std::string key("key");
95 std::string got_value; 97 std::string got_value;
96 std::string put_value; 98 std::string put_value;
97 SimpleComparator comparator; 99 SimpleComparator comparator;
98 100
99 std::unique_ptr<LevelDBDatabase> leveldb; 101 std::unique_ptr<LevelDBDatabase> leveldb;
100 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); 102 LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
101 EXPECT_TRUE(leveldb); 103 EXPECT_TRUE(leveldb);
102 104
103 const std::string old_value("value"); 105 const std::string old_value("value");
104 put_value = old_value; 106 put_value = old_value;
105 leveldb::Status status = leveldb->Put(key, &put_value); 107 leveldb::Status status = leveldb->Put(key, &put_value);
106 EXPECT_TRUE(status.ok()); 108 EXPECT_TRUE(status.ok());
107 109
108 scoped_refptr<LevelDBTransaction> transaction = 110 scoped_refptr<LevelDBTransaction> transaction =
109 new LevelDBTransaction(leveldb.get()); 111 new LevelDBTransaction(leveldb.get());
110 112
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 158 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
157 159
158 const std::string key1("key1"); 160 const std::string key1("key1");
159 const std::string value1("value1"); 161 const std::string value1("value1");
160 const std::string key2("key2"); 162 const std::string key2("key2");
161 const std::string value2("value2"); 163 const std::string value2("value2");
162 std::string put_value; 164 std::string put_value;
163 SimpleComparator comparator; 165 SimpleComparator comparator;
164 166
165 std::unique_ptr<LevelDBDatabase> leveldb; 167 std::unique_ptr<LevelDBDatabase> leveldb;
166 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); 168 LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
167 EXPECT_TRUE(leveldb); 169 EXPECT_TRUE(leveldb);
168 170
169 put_value = value1; 171 put_value = value1;
170 leveldb::Status s = leveldb->Put(key1, &put_value); 172 leveldb::Status s = leveldb->Put(key1, &put_value);
171 EXPECT_TRUE(s.ok()); 173 EXPECT_TRUE(s.ok());
172 put_value = value2; 174 put_value = value2;
173 s = leveldb->Put(key2, &put_value); 175 s = leveldb->Put(key2, &put_value);
174 EXPECT_TRUE(s.ok()); 176 EXPECT_TRUE(s.ok());
175 177
176 scoped_refptr<LevelDBTransaction> transaction = 178 scoped_refptr<LevelDBTransaction> transaction =
(...skipping 30 matching lines...) Expand all
207 const std::string value1("value1"); 209 const std::string value1("value1");
208 const std::string value2("value2"); 210 const std::string value2("value2");
209 const std::string value3("value3"); 211 const std::string value3("value3");
210 212
211 std::string put_value; 213 std::string put_value;
212 std::string got_value; 214 std::string got_value;
213 SimpleComparator comparator; 215 SimpleComparator comparator;
214 bool found; 216 bool found;
215 217
216 std::unique_ptr<LevelDBDatabase> leveldb; 218 std::unique_ptr<LevelDBDatabase> leveldb;
217 LevelDBDatabase::Open(temp_directory.path(), &comparator, &leveldb); 219 LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
218 EXPECT_TRUE(leveldb); 220 EXPECT_TRUE(leveldb);
219 221
220 scoped_refptr<LevelDBTransaction> transaction = 222 scoped_refptr<LevelDBTransaction> transaction =
221 new LevelDBTransaction(leveldb.get()); 223 new LevelDBTransaction(leveldb.get());
222 224
223 put_value = value1; 225 put_value = value1;
224 transaction->Put(key1, &put_value); 226 transaction->Put(key1, &put_value);
225 227
226 put_value = value2; 228 put_value = value2;
227 transaction->Put(key2, &put_value); 229 transaction->Put(key2, &put_value);
(...skipping 13 matching lines...) Expand all
241 EXPECT_TRUE(status.ok()); 243 EXPECT_TRUE(status.ok());
242 EXPECT_TRUE(found); 244 EXPECT_TRUE(found);
243 EXPECT_EQ(value3, got_value); 245 EXPECT_EQ(value3, got_value);
244 } 246 }
245 247
246 TEST(LevelDB, Locking) { 248 TEST(LevelDB, Locking) {
247 base::ScopedTempDir temp_directory; 249 base::ScopedTempDir temp_directory;
248 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 250 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
249 251
250 leveldb::Env* env = LevelDBEnv::Get(); 252 leveldb::Env* env = LevelDBEnv::Get();
251 base::FilePath file = temp_directory.path().AppendASCII("LOCK"); 253 base::FilePath file = temp_directory.GetPath().AppendASCII("LOCK");
252 leveldb::FileLock* lock; 254 leveldb::FileLock* lock;
253 leveldb::Status status = env->LockFile(file.AsUTF8Unsafe(), &lock); 255 leveldb::Status status = env->LockFile(file.AsUTF8Unsafe(), &lock);
254 EXPECT_TRUE(status.ok()); 256 EXPECT_TRUE(status.ok());
255 257
256 status = env->UnlockFile(lock); 258 status = env->UnlockFile(lock);
257 EXPECT_TRUE(status.ok()); 259 EXPECT_TRUE(status.ok());
258 260
259 status = env->LockFile(file.AsUTF8Unsafe(), &lock); 261 status = env->LockFile(file.AsUTF8Unsafe(), &lock);
260 EXPECT_TRUE(status.ok()); 262 EXPECT_TRUE(status.ok());
261 263
262 leveldb::FileLock* lock2; 264 leveldb::FileLock* lock2;
263 status = env->LockFile(file.AsUTF8Unsafe(), &lock2); 265 status = env->LockFile(file.AsUTF8Unsafe(), &lock2);
264 EXPECT_FALSE(status.ok()); 266 EXPECT_FALSE(status.ok());
265 267
266 status = env->UnlockFile(lock); 268 status = env->UnlockFile(lock);
267 EXPECT_TRUE(status.ok()); 269 EXPECT_TRUE(status.ok());
268 } 270 }
269 271
270 } // namespace content 272 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_unittest.cc ('k') | content/browser/net/quota_policy_cookie_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698