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

Side by Side Diff: utils_unittest.cc

Issue 3173041: Add 10 minute random fuzz to automatic update check event schedule. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: review comments Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <sys/stat.h> 5 #include <sys/stat.h>
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <errno.h> 7 #include <errno.h>
8
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 #include <gtest/gtest.h> 11
12 #include "gtest/gtest.h"
11 #include "update_engine/utils.h" 13 #include "update_engine/utils.h"
12 14
13 using std::string; 15 using std::string;
14 using std::vector; 16 using std::vector;
15 17
16 namespace chromeos_update_engine { 18 namespace chromeos_update_engine {
17 19
18 class UtilsTest : public ::testing::Test { }; 20 class UtilsTest : public ::testing::Test { };
19 21
20 TEST(UtilsTest, IsOfficialBuild) { 22 TEST(UtilsTest, IsOfficialBuild) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 TEST(UtilsTest, IsRemovableDeviceTest) { 152 TEST(UtilsTest, IsRemovableDeviceTest) {
151 EXPECT_FALSE(utils::IsRemovableDevice("")); 153 EXPECT_FALSE(utils::IsRemovableDevice(""));
152 EXPECT_FALSE(utils::IsRemovableDevice("/dev/non-existent-device")); 154 EXPECT_FALSE(utils::IsRemovableDevice("/dev/non-existent-device"));
153 } 155 }
154 156
155 TEST(UtilsTest, PartitionNumberTest) { 157 TEST(UtilsTest, PartitionNumberTest) {
156 EXPECT_EQ("3", utils::PartitionNumber("/dev/sda3")); 158 EXPECT_EQ("3", utils::PartitionNumber("/dev/sda3"));
157 EXPECT_EQ("3", utils::PartitionNumber("/dev/mmc0p3")); 159 EXPECT_EQ("3", utils::PartitionNumber("/dev/mmc0p3"));
158 } 160 }
159 161
160 TEST(UtilsTest, ComparePriorities) { 162 TEST(UtilsTest, ComparePrioritiesTest) {
161 EXPECT_LT(utils::ComparePriorities(utils::kProcessPriorityLow, 163 EXPECT_LT(utils::ComparePriorities(utils::kProcessPriorityLow,
162 utils::kProcessPriorityNormal), 0); 164 utils::kProcessPriorityNormal), 0);
163 EXPECT_GT(utils::ComparePriorities(utils::kProcessPriorityNormal, 165 EXPECT_GT(utils::ComparePriorities(utils::kProcessPriorityNormal,
164 utils::kProcessPriorityLow), 0); 166 utils::kProcessPriorityLow), 0);
165 EXPECT_EQ(utils::ComparePriorities(utils::kProcessPriorityNormal, 167 EXPECT_EQ(utils::ComparePriorities(utils::kProcessPriorityNormal,
166 utils::kProcessPriorityNormal), 0); 168 utils::kProcessPriorityNormal), 0);
167 EXPECT_GT(utils::ComparePriorities(utils::kProcessPriorityHigh, 169 EXPECT_GT(utils::ComparePriorities(utils::kProcessPriorityHigh,
168 utils::kProcessPriorityNormal), 0); 170 utils::kProcessPriorityNormal), 0);
169 } 171 }
170 172
173 TEST(UtilsTest, FuzzIntTest) {
174 static const unsigned int kRanges[] = { 0, 1, 2, 20 };
175 for (size_t r = 0; r < arraysize(kRanges); ++r) {
176 unsigned int range = kRanges[r];
177 const int kValue = 50;
178 for (int tries = 0; tries < 100; ++tries) {
179 int value = utils::FuzzInt(kValue, range);
180 EXPECT_GE(value, kValue - range / 2);
181 EXPECT_LE(value, kValue + range - range / 2);
182 }
183 }
184 }
185
171 } // namespace chromeos_update_engine 186 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698