OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/prefs/leveldb_pref_store.h" | |
6 | |
7 #include "base/file_util.h" | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
unused?
dgrogan
2014/02/25 03:32:08
Needed for PathExists.
| |
8 #include "base/files/scoped_temp_dir.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/path_service.h" | |
12 #include "base/run_loop.h" | |
13 #include "base/strings/string_number_conversions.h" | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
unused?
dgrogan
2014/02/25 03:32:08
Done.
| |
14 #include "base/strings/string_util.h" | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
unused?
dgrogan
2014/02/25 03:32:08
Done.
| |
15 #include "base/threading/sequenced_worker_pool.h" | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
unused?
dgrogan
2014/02/25 03:32:08
Done.
| |
16 #include "base/threading/thread.h" | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
unused?
dgrogan
2014/02/25 03:32:08
Done.
| |
17 #include "base/values.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 namespace base { | |
21 | |
22 class LevelDBPrefStoreTest : public testing::Test { | |
23 protected: | |
24 virtual void SetUp() OVERRIDE { | |
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
26 | |
27 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &data_dir_)); | |
28 data_dir_ = data_dir_.AppendASCII("prefs"); | |
29 ASSERT_TRUE(PathExists(data_dir_)); | |
30 } | |
31 | |
32 void Open() { | |
33 pref_store_ = new LevelDBPrefStore( | |
34 temp_dir_.path(), message_loop_.message_loop_proxy().get()); | |
35 DCHECK_EQ(LevelDBPrefStore::PREF_READ_ERROR_NONE, pref_store_->ReadPrefs()); | |
36 } | |
37 | |
38 void CloseAndReopen() { | |
39 pref_store_ = NULL; | |
40 Open(); | |
41 } | |
42 | |
43 // The path to temporary directory used to contain the test operations. | |
44 base::ScopedTempDir temp_dir_; | |
45 // The path to the directory where the test data is stored in the source tree. | |
46 base::FilePath data_dir_; | |
47 // A message loop that we can use as the file thread message loop. | |
48 MessageLoop message_loop_; | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
#include "base/message_loop/message_loop.h"
dgrogan
2014/02/25 03:32:08
Done.
| |
49 | |
50 scoped_refptr<LevelDBPrefStore> pref_store_; | |
51 }; | |
52 | |
53 TEST_F(LevelDBPrefStoreTest, PutAndGet) { | |
54 Open(); | |
55 const std::string key = "some.key"; | |
56 base::Value* value = new FundamentalValue(5); | |
57 pref_store_->SetValue(key, value); | |
58 RunLoop().RunUntilIdle(); | |
59 const base::Value* actual_value; | |
60 EXPECT_TRUE(pref_store_->GetValue(key, &actual_value)); | |
61 EXPECT_TRUE(value->Equals(actual_value)); | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
This is dangerous, value is now owned by pref_stor
dgrogan
2014/02/25 03:32:08
Fixed.
| |
62 } | |
63 | |
64 TEST_F(LevelDBPrefStoreTest, PutAndGetPersistent) { | |
65 Open(); | |
66 const std::string key = "some.key"; | |
67 base::Value* value = new FundamentalValue(5); | |
68 pref_store_->SetValue(key, value); | |
69 RunLoop().RunUntilIdle(); | |
70 | |
71 CloseAndReopen(); | |
72 const base::Value* actual_value = NULL; | |
73 value = new FundamentalValue(5); | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
|value| leaks.
dgrogan
2014/02/25 03:32:08
Done.
| |
74 EXPECT_TRUE(pref_store_->GetValue(key, &actual_value)); | |
75 EXPECT_TRUE(base::Value::Equals(value, actual_value)); | |
76 } | |
Mattias Nissler (ping if slow)
2014/02/24 09:00:40
I'd like to see more tests, in particular covering
dgrogan
2014/02/25 03:32:08
Included today is everything except various types
| |
77 | |
78 } // namespace base | |
OLD | NEW |