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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 #include <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/string_util.h" | |
petkov
2010/12/10 00:46:55
since you've touched the headers -- "new" style is
thieule
2010/12/14 23:11:21
Done.
| |
13 #include "update_engine/action.h" | 14 #include "update_engine/action.h" |
14 #include "update_engine/subprocess.h" | 15 #include "update_engine/subprocess.h" |
15 #include "update_engine/utils.h" | 16 #include "update_engine/utils.h" |
16 | 17 |
17 // These are some handy functions for unittests. | 18 // These are some handy functions for unittests. |
18 | 19 |
19 namespace chromeos_update_engine { | 20 namespace chromeos_update_engine { |
20 | 21 |
21 // Writes the data passed to path. The file at path will be overwritten if it | 22 // Writes the data passed to path. The file at path will be overwritten if it |
22 // exists. Returns true on success, false otherwise. | 23 // exists. Returns true on success, false otherwise. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 0xe8, 0x05, 0x08, 0xa1, 0x45, 0x70, 0x5b, 0x8c, | 86 0xe8, 0x05, 0x08, 0xa1, 0x45, 0x70, 0x5b, 0x8c, |
86 0x39, 0x28, 0xab, 0xe9, 0x6b, 0x51, 0xd2, 0xcb, | 87 0x39, 0x28, 0xab, 0xe9, 0x6b, 0x51, 0xd2, 0xcb, |
87 0x30, 0x04, 0xea, 0x7d, 0x2f, 0x6e, 0x6c, 0x3b, | 88 0x30, 0x04, 0xea, 0x7d, 0x2f, 0x6e, 0x6c, 0x3b, |
88 0x5f, 0x82, 0xd9, 0x5b, 0x89, 0x37, 0x65, 0x65, | 89 0x5f, 0x82, 0xd9, 0x5b, 0x89, 0x37, 0x65, 0x65, |
89 0xbe, 0x9f, 0xa3, 0x5d | 90 0xbe, 0x9f, 0xa3, 0x5d |
90 }; | 91 }; |
91 | 92 |
92 const char* const kMountPath = "/tmp/UpdateEngineTests_mnt"; | 93 const char* const kMountPath = "/tmp/UpdateEngineTests_mnt"; |
93 } // namespace {} | 94 } // namespace {} |
94 | 95 |
96 // Creates an empty ext image. | |
petkov
2010/12/10 00:46:55
ext2, ext3, ext4?
thieule
2010/12/14 23:11:21
This is a little bit more involved than just here.
| |
97 void CreateEmptyExtImageAtPath(const std::string& path, | |
98 size_t size, | |
99 int block_size); | |
100 | |
95 // Creates an ext image with some files in it. The paths creates are | 101 // Creates an ext image with some files in it. The paths creates are |
96 // returned in out_paths. | 102 // returned in out_paths. |
97 void CreateExtImageAtPath(const std::string& path, | 103 void CreateExtImageAtPath(const std::string& path, |
98 std::vector<std::string>* out_paths); | 104 std::vector<std::string>* out_paths); |
99 | 105 |
100 // Verifies that for each path in paths, it exists in the filesystem under | 106 // Verifies that for each path in paths, it exists in the filesystem under |
101 // parent. Also, verifies that no additional paths are present under parent. | 107 // parent. Also, verifies that no additional paths are present under parent. |
102 // Also tests properties of various files created by CreateExtImageAtPath(). | 108 // Also tests properties of various files created by CreateExtImageAtPath(). |
103 // Intentionally copies expected_paths. | 109 // Intentionally copies expected_paths. |
104 void VerifyAllPaths(const std::string& parent, | 110 void VerifyAllPaths(const std::string& parent, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 } | 210 } |
205 this->processor_->ActionComplete(this, kActionCodeSuccess); | 211 this->processor_->ActionComplete(this, kActionCodeSuccess); |
206 } | 212 } |
207 static std::string StaticType() { return "ObjectCollectorAction"; } | 213 static std::string StaticType() { return "ObjectCollectorAction"; } |
208 std::string Type() const { return StaticType(); } | 214 std::string Type() const { return StaticType(); } |
209 const T& object() const { return object_; } | 215 const T& object() const { return object_; } |
210 private: | 216 private: |
211 T object_; | 217 T object_; |
212 }; | 218 }; |
213 | 219 |
220 class ScopedLoopMounter { | |
221 public: | |
222 explicit ScopedLoopMounter(const std::string& file_path, | |
223 std::string* mnt_path, | |
224 unsigned long flags) { | |
225 EXPECT_TRUE(utils::MakeTempDirectory("/tmp/mnt.XXXXXX", mnt_path)); | |
petkov
2010/12/10 00:46:55
lots of code for a header file. could you please m
thieule
2010/12/14 23:11:21
Done.
| |
226 dir_remover_.reset(new ScopedDirRemover(*mnt_path)); | |
227 | |
228 std::string loop_dev = GetUnusedLoopDevice(); | |
229 EXPECT_EQ(0, system(StringPrintf("losetup %s %s", loop_dev.c_str(), | |
230 file_path.c_str()).c_str())); | |
231 loop_releaser_.reset(new ScopedLoopbackDeviceReleaser(loop_dev)); | |
232 | |
233 EXPECT_TRUE(utils::MountFilesystem(loop_dev, *mnt_path, flags)); | |
234 unmounter_.reset(new ScopedFilesystemUnmounter(*mnt_path)); | |
235 } | |
236 private: | |
petkov
2010/12/10 00:46:55
blank line before private
thieule
2010/12/14 23:11:21
Done.
| |
237 scoped_ptr<ScopedDirRemover> dir_remover_; | |
petkov
2010/12/10 00:46:55
i guess this is not new code but... is there any r
thieule
2010/12/14 23:11:21
There is an explicit order that these objects must
| |
238 scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser_; | |
239 scoped_ptr<ScopedFilesystemUnmounter> unmounter_; | |
240 }; | |
241 | |
214 } // namespace chromeos_update_engine | 242 } // namespace chromeos_update_engine |
215 | 243 |
216 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ | 244 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ |
OLD | NEW |