OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2008 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 static const std::string kEmptyString = ""; | 28 static const std::string kEmptyString = ""; |
29 static const char kOptionWithUtf8[] = {'O', 'p', 't', '\302', '\256', 'i', 'o', | 29 static const char kOptionWithUtf8[] = {'O', 'p', 't', '\302', '\256', 'i', 'o', |
30 'n', '\342', '\204', '\242', '\0'}; // Opt(R)io(TM). | 30 'n', '\342', '\204', '\242', '\0'}; // Opt(R)io(TM). |
31 static const char kValueWithUtf8[] = {'V', 'a', 'l', '\302', '\256', 'v', 'e', | 31 static const char kValueWithUtf8[] = {'V', 'a', 'l', '\302', '\256', 'v', 'e', |
32 '\342', '\204', '\242', '\0'}; // Val(R)ue(TM). | 32 '\342', '\204', '\242', '\0'}; // Val(R)ue(TM). |
33 static int kTestInt1 = 12345; | 33 static int kTestInt1 = 12345; |
34 static int kTestInt2 = 67890; | 34 static int kTestInt2 = 67890; |
35 static int kNegInt = -634; | 35 static int kNegInt = -634; |
36 static int kZero = 0; | 36 static int kZero = 0; |
37 | 37 |
38 class OptionsFileTest : public testing::Test { | 38 #if defined (WEBRTC_ANDROID) |
| 39 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. |
| 40 #define MAYBE_OptionsFileTest DISABLED_OptionsFileTest |
| 41 #else |
| 42 #define MAYBE_OptionsFileTest OptionsFileTest |
| 43 #endif |
| 44 |
| 45 class MAYBE_OptionsFileTest : public testing::Test { |
39 public: | 46 public: |
40 OptionsFileTest() { | 47 MAYBE_OptionsFileTest() { |
41 Pathname dir; | 48 Pathname dir; |
42 ASSERT(Filesystem::GetTemporaryFolder(dir, true, NULL)); | 49 ASSERT(Filesystem::GetTemporaryFolder(dir, true, NULL)); |
43 test_file_ = Filesystem::TempFilename(dir, ".testfile"); | 50 test_file_ = Filesystem::TempFilename(dir, ".testfile"); |
44 OpenStore(); | 51 OpenStore(); |
45 } | 52 } |
46 | 53 |
47 ~OptionsFileTest() override { | 54 ~MAYBE_OptionsFileTest() override { |
48 remove(test_file_.c_str()); | 55 remove(test_file_.c_str()); |
49 } | 56 } |
50 | 57 |
51 protected: | 58 protected: |
52 void OpenStore() { | 59 void OpenStore() { |
53 store_.reset(new OptionsFile(test_file_)); | 60 store_.reset(new OptionsFile(test_file_)); |
54 } | 61 } |
55 | 62 |
56 std::unique_ptr<OptionsFile> store_; | 63 std::unique_ptr<OptionsFile> store_; |
57 | 64 |
58 private: | 65 private: |
59 std::string test_file_; | 66 std::string test_file_; |
60 }; | 67 }; |
61 | 68 |
62 TEST_F(OptionsFileTest, GetSetString) { | 69 TEST_F(MAYBE_OptionsFileTest, GetSetString) { |
63 // Clear contents of the file on disk. | 70 // Clear contents of the file on disk. |
64 EXPECT_TRUE(store_->Save()); | 71 EXPECT_TRUE(store_->Save()); |
65 std::string out1, out2; | 72 std::string out1, out2; |
66 EXPECT_FALSE(store_->GetStringValue(kTestOptionA, &out1)); | 73 EXPECT_FALSE(store_->GetStringValue(kTestOptionA, &out1)); |
67 EXPECT_FALSE(store_->GetStringValue(kTestOptionB, &out2)); | 74 EXPECT_FALSE(store_->GetStringValue(kTestOptionB, &out2)); |
68 EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1)); | 75 EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1)); |
69 EXPECT_TRUE(store_->Save()); | 76 EXPECT_TRUE(store_->Save()); |
70 EXPECT_TRUE(store_->Load()); | 77 EXPECT_TRUE(store_->Load()); |
71 EXPECT_TRUE(store_->SetStringValue(kTestOptionB, kTestString2)); | 78 EXPECT_TRUE(store_->SetStringValue(kTestOptionB, kTestString2)); |
72 EXPECT_TRUE(store_->Save()); | 79 EXPECT_TRUE(store_->Save()); |
73 EXPECT_TRUE(store_->Load()); | 80 EXPECT_TRUE(store_->Load()); |
74 EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out1)); | 81 EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out1)); |
75 EXPECT_TRUE(store_->GetStringValue(kTestOptionB, &out2)); | 82 EXPECT_TRUE(store_->GetStringValue(kTestOptionB, &out2)); |
76 EXPECT_EQ(kTestString1, out1); | 83 EXPECT_EQ(kTestString1, out1); |
77 EXPECT_EQ(kTestString2, out2); | 84 EXPECT_EQ(kTestString2, out2); |
78 EXPECT_TRUE(store_->RemoveValue(kTestOptionA)); | 85 EXPECT_TRUE(store_->RemoveValue(kTestOptionA)); |
79 EXPECT_TRUE(store_->Save()); | 86 EXPECT_TRUE(store_->Save()); |
80 EXPECT_TRUE(store_->Load()); | 87 EXPECT_TRUE(store_->Load()); |
81 EXPECT_TRUE(store_->RemoveValue(kTestOptionB)); | 88 EXPECT_TRUE(store_->RemoveValue(kTestOptionB)); |
82 EXPECT_TRUE(store_->Save()); | 89 EXPECT_TRUE(store_->Save()); |
83 EXPECT_TRUE(store_->Load()); | 90 EXPECT_TRUE(store_->Load()); |
84 EXPECT_FALSE(store_->GetStringValue(kTestOptionA, &out1)); | 91 EXPECT_FALSE(store_->GetStringValue(kTestOptionA, &out1)); |
85 EXPECT_FALSE(store_->GetStringValue(kTestOptionB, &out2)); | 92 EXPECT_FALSE(store_->GetStringValue(kTestOptionB, &out2)); |
86 } | 93 } |
87 | 94 |
88 TEST_F(OptionsFileTest, GetSetInt) { | 95 TEST_F(MAYBE_OptionsFileTest, GetSetInt) { |
89 // Clear contents of the file on disk. | 96 // Clear contents of the file on disk. |
90 EXPECT_TRUE(store_->Save()); | 97 EXPECT_TRUE(store_->Save()); |
91 int out1, out2; | 98 int out1, out2; |
92 EXPECT_FALSE(store_->GetIntValue(kTestOptionA, &out1)); | 99 EXPECT_FALSE(store_->GetIntValue(kTestOptionA, &out1)); |
93 EXPECT_FALSE(store_->GetIntValue(kTestOptionB, &out2)); | 100 EXPECT_FALSE(store_->GetIntValue(kTestOptionB, &out2)); |
94 EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kTestInt1)); | 101 EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kTestInt1)); |
95 EXPECT_TRUE(store_->Save()); | 102 EXPECT_TRUE(store_->Save()); |
96 EXPECT_TRUE(store_->Load()); | 103 EXPECT_TRUE(store_->Load()); |
97 EXPECT_TRUE(store_->SetIntValue(kTestOptionB, kTestInt2)); | 104 EXPECT_TRUE(store_->SetIntValue(kTestOptionB, kTestInt2)); |
98 EXPECT_TRUE(store_->Save()); | 105 EXPECT_TRUE(store_->Save()); |
(...skipping 11 matching lines...) Expand all Loading... |
110 EXPECT_FALSE(store_->GetIntValue(kTestOptionA, &out1)); | 117 EXPECT_FALSE(store_->GetIntValue(kTestOptionA, &out1)); |
111 EXPECT_FALSE(store_->GetIntValue(kTestOptionB, &out2)); | 118 EXPECT_FALSE(store_->GetIntValue(kTestOptionB, &out2)); |
112 EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kNegInt)); | 119 EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kNegInt)); |
113 EXPECT_TRUE(store_->GetIntValue(kTestOptionA, &out1)); | 120 EXPECT_TRUE(store_->GetIntValue(kTestOptionA, &out1)); |
114 EXPECT_EQ(kNegInt, out1); | 121 EXPECT_EQ(kNegInt, out1); |
115 EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kZero)); | 122 EXPECT_TRUE(store_->SetIntValue(kTestOptionA, kZero)); |
116 EXPECT_TRUE(store_->GetIntValue(kTestOptionA, &out1)); | 123 EXPECT_TRUE(store_->GetIntValue(kTestOptionA, &out1)); |
117 EXPECT_EQ(kZero, out1); | 124 EXPECT_EQ(kZero, out1); |
118 } | 125 } |
119 | 126 |
120 TEST_F(OptionsFileTest, Persist) { | 127 TEST_F(MAYBE_OptionsFileTest, Persist) { |
121 // Clear contents of the file on disk. | 128 // Clear contents of the file on disk. |
122 EXPECT_TRUE(store_->Save()); | 129 EXPECT_TRUE(store_->Save()); |
123 EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1)); | 130 EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1)); |
124 EXPECT_TRUE(store_->SetIntValue(kTestOptionB, kNegInt)); | 131 EXPECT_TRUE(store_->SetIntValue(kTestOptionB, kNegInt)); |
125 EXPECT_TRUE(store_->Save()); | 132 EXPECT_TRUE(store_->Save()); |
126 | 133 |
127 // Load the saved contents from above. | 134 // Load the saved contents from above. |
128 OpenStore(); | 135 OpenStore(); |
129 EXPECT_TRUE(store_->Load()); | 136 EXPECT_TRUE(store_->Load()); |
130 std::string out1; | 137 std::string out1; |
131 int out2; | 138 int out2; |
132 EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out1)); | 139 EXPECT_TRUE(store_->GetStringValue(kTestOptionA, &out1)); |
133 EXPECT_TRUE(store_->GetIntValue(kTestOptionB, &out2)); | 140 EXPECT_TRUE(store_->GetIntValue(kTestOptionB, &out2)); |
134 EXPECT_EQ(kTestString1, out1); | 141 EXPECT_EQ(kTestString1, out1); |
135 EXPECT_EQ(kNegInt, out2); | 142 EXPECT_EQ(kNegInt, out2); |
136 } | 143 } |
137 | 144 |
138 TEST_F(OptionsFileTest, SpecialCharacters) { | 145 TEST_F(MAYBE_OptionsFileTest, SpecialCharacters) { |
139 // Clear contents of the file on disk. | 146 // Clear contents of the file on disk. |
140 EXPECT_TRUE(store_->Save()); | 147 EXPECT_TRUE(store_->Save()); |
141 std::string out; | 148 std::string out; |
142 EXPECT_FALSE(store_->SetStringValue(kOptionWithEquals, kTestString1)); | 149 EXPECT_FALSE(store_->SetStringValue(kOptionWithEquals, kTestString1)); |
143 EXPECT_FALSE(store_->GetStringValue(kOptionWithEquals, &out)); | 150 EXPECT_FALSE(store_->GetStringValue(kOptionWithEquals, &out)); |
144 EXPECT_FALSE(store_->SetStringValue(kOptionWithNewline, kTestString1)); | 151 EXPECT_FALSE(store_->SetStringValue(kOptionWithNewline, kTestString1)); |
145 EXPECT_FALSE(store_->GetStringValue(kOptionWithNewline, &out)); | 152 EXPECT_FALSE(store_->GetStringValue(kOptionWithNewline, &out)); |
146 EXPECT_TRUE(store_->SetStringValue(kOptionWithUtf8, kValueWithUtf8)); | 153 EXPECT_TRUE(store_->SetStringValue(kOptionWithUtf8, kValueWithUtf8)); |
147 EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1)); | 154 EXPECT_TRUE(store_->SetStringValue(kTestOptionA, kTestString1)); |
148 EXPECT_TRUE(store_->Save()); | 155 EXPECT_TRUE(store_->Save()); |
(...skipping 16 matching lines...) Expand all Loading... |
165 EXPECT_TRUE(store_->GetStringValue(kEmptyString, &out)); | 172 EXPECT_TRUE(store_->GetStringValue(kEmptyString, &out)); |
166 EXPECT_EQ(kTestString2, out); | 173 EXPECT_EQ(kTestString2, out); |
167 EXPECT_TRUE(store_->SetStringValue(kTestOptionB, kEmptyString)); | 174 EXPECT_TRUE(store_->SetStringValue(kTestOptionB, kEmptyString)); |
168 EXPECT_TRUE(store_->Save()); | 175 EXPECT_TRUE(store_->Save()); |
169 EXPECT_TRUE(store_->Load()); | 176 EXPECT_TRUE(store_->Load()); |
170 EXPECT_TRUE(store_->GetStringValue(kTestOptionB, &out)); | 177 EXPECT_TRUE(store_->GetStringValue(kTestOptionB, &out)); |
171 EXPECT_EQ(kEmptyString, out); | 178 EXPECT_EQ(kEmptyString, out); |
172 } | 179 } |
173 | 180 |
174 } // namespace rtc | 181 } // namespace rtc |
OLD | NEW |