-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs_test.cc
62 lines (52 loc) · 1.84 KB
/
prefs_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "dlcservice/boot/boot_slot.h"
#include "dlcservice/dlc_base.h"
#include "dlcservice/prefs.h"
#include "dlcservice/system_state.h"
#include "dlcservice/test_utils.h"
#include "dlcservice/utils.h"
using base::FilePath;
using std::string;
namespace dlcservice {
class PrefsTest : public BaseTest {};
TEST_F(PrefsTest, DlcBaseCreateAndDelete) {
auto active_boot_slot = SystemState::Get()->active_boot_slot();
Prefs prefs(DlcBase("id"), active_boot_slot);
string key = "key";
EXPECT_TRUE(prefs.Create(key));
EXPECT_TRUE(prefs.Exists(key));
Prefs prefs_non_dlcbase(JoinPaths(SystemState::Get()->dlc_prefs_dir(), "id",
BootSlot::ToString(active_boot_slot)));
EXPECT_TRUE(prefs_non_dlcbase.Exists(key));
}
TEST_F(PrefsTest, CreateAndDelete) {
Prefs prefs(FilePath(SystemState::Get()->prefs_dir()));
string key = "key";
EXPECT_TRUE(prefs.Create(key));
EXPECT_TRUE(prefs.Exists(key));
EXPECT_TRUE(prefs.Delete(key));
EXPECT_FALSE(prefs.Exists(key));
}
TEST_F(PrefsTest, SetAndGetThenDelete) {
Prefs prefs(FilePath(SystemState::Get()->prefs_dir()));
string key = "key", value = "value";
EXPECT_TRUE(prefs.SetKey(key, value));
string actual_value;
EXPECT_TRUE(prefs.GetKey(key, &actual_value));
EXPECT_EQ(value, actual_value);
EXPECT_TRUE(prefs.Delete(key));
EXPECT_FALSE(prefs.Exists(key));
}
TEST_F(PrefsTest, RepeatedSet) {
Prefs prefs(FilePath(SystemState::Get()->prefs_dir()));
string key = "key", value = "value";
EXPECT_TRUE(prefs.SetKey(key, value));
EXPECT_TRUE(prefs.SetKey(key, value));
}
} // namespace dlcservice