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

Side by Side Diff: utils_unittest.cc

Issue 3706006: AU: Add a utility routine to get the filesystem size from a device. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: review comments 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 | 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
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "gtest/gtest.h" 13 #include <base/string_util.h>
14 #include <gtest/gtest.h>
15
16 #include "update_engine/test_utils.h"
14 #include "update_engine/utils.h" 17 #include "update_engine/utils.h"
15 18
16 using std::map; 19 using std::map;
17 using std::string; 20 using std::string;
18 using std::vector; 21 using std::vector;
19 22
20 namespace chromeos_update_engine { 23 namespace chromeos_update_engine {
21 24
22 class UtilsTest : public ::testing::Test { }; 25 class UtilsTest : public ::testing::Test { };
23 26
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 201
199 utils::ApplyMap(&collection, value_map); 202 utils::ApplyMap(&collection, value_map);
200 203
201 size_t index = 0; 204 size_t index = 0;
202 for (vector<int>::iterator it = collection.begin(), e = collection.end(); 205 for (vector<int>::iterator it = collection.begin(), e = collection.end();
203 it != e; ++it) { 206 it != e; ++it) {
204 EXPECT_EQ(expected_values[index++], *it); 207 EXPECT_EQ(expected_values[index++], *it);
205 } 208 }
206 } 209 }
207 210
211 TEST(UtilsTest, RunAsRootGetFilesystemSizeTest) {
212 string img;
213 EXPECT_TRUE(utils::MakeTempFile("/tmp/img.XXXXXX", &img, NULL));
214 ScopedPathUnlinker img_unlinker(img);
215 CreateExtImageAtPath(img, NULL);
216 // Extend the "partition" holding the file system from 10MiB to 20MiB.
217 EXPECT_EQ(0, System(base::StringPrintf(
218 "dd if=/dev/zero of=%s seek=20971519 bs=1 count=1",
219 img.c_str())));
220 EXPECT_EQ(20 * 1024 * 1024, utils::FileSize(img));
221 int block_count = 0;
222 int block_size = 0;
223 EXPECT_TRUE(utils::GetFilesystemSize(img, &block_count, &block_size));
224 EXPECT_EQ(4096, block_size);
225 EXPECT_EQ(10 * 1024 * 1024 / 4096, block_count);
226 }
227
208 } // namespace chromeos_update_engine 228 } // 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