| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |