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

Side by Side Diff: utils_unittest.cc

Issue 3530011: AU: ApplyMap utility function (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: fixes for review Created 10 years, 2 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
« no previous file with comments | « utils.h ('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
9 #include <map>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "gtest/gtest.h" 13 #include "gtest/gtest.h"
13 #include "update_engine/utils.h" 14 #include "update_engine/utils.h"
14 15
16 using std::map;
15 using std::string; 17 using std::string;
16 using std::vector; 18 using std::vector;
17 19
18 namespace chromeos_update_engine { 20 namespace chromeos_update_engine {
19 21
20 class UtilsTest : public ::testing::Test { }; 22 class UtilsTest : public ::testing::Test { };
21 23
22 TEST(UtilsTest, IsOfficialBuild) { 24 TEST(UtilsTest, IsOfficialBuild) {
23 // Pretty lame test... 25 // Pretty lame test...
24 EXPECT_TRUE(utils::IsOfficialBuild()); 26 EXPECT_TRUE(utils::IsOfficialBuild());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 unsigned int range = kRanges[r]; 178 unsigned int range = kRanges[r];
177 const int kValue = 50; 179 const int kValue = 50;
178 for (int tries = 0; tries < 100; ++tries) { 180 for (int tries = 0; tries < 100; ++tries) {
179 int value = utils::FuzzInt(kValue, range); 181 int value = utils::FuzzInt(kValue, range);
180 EXPECT_GE(value, kValue - range / 2); 182 EXPECT_GE(value, kValue - range / 2);
181 EXPECT_LE(value, kValue + range - range / 2); 183 EXPECT_LE(value, kValue + range - range / 2);
182 } 184 }
183 } 185 }
184 } 186 }
185 187
188 TEST(UtilsTest, ApplyMapTest) {
189 int initial_values[] = {1, 2, 3, 4, 6};
190 vector<int> collection(&initial_values[0],
191 initial_values + arraysize(initial_values));
192 EXPECT_EQ(arraysize(initial_values), collection.size());
193 int expected_values[] = {1, 2, 5, 4, 8};
194 map<int, int> value_map;
195 value_map[3] = 5;
196 value_map[6] = 8;
197 value_map[5] = 10;
198
199 utils::ApplyMap(&collection, value_map);
200
201 size_t index = 0;
202 for (vector<int>::iterator it = collection.begin(), e = collection.end();
203 it != e; ++it) {
204 EXPECT_EQ(expected_values[index++], *it);
205 }
206 }
207
186 } // namespace chromeos_update_engine 208 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698