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 | |
12 #include <base/scoped_ptr.h> | |
11 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
12 #include "base/scoped_ptr.h" | 14 |
13 #include "update_engine/action.h" | 15 #include "update_engine/action.h" |
14 #include "update_engine/subprocess.h" | 16 #include "update_engine/subprocess.h" |
15 #include "update_engine/utils.h" | 17 #include "update_engine/utils.h" |
16 | 18 |
17 // These are some handy functions for unittests. | 19 // These are some handy functions for unittests. |
18 | 20 |
19 namespace chromeos_update_engine { | 21 namespace chromeos_update_engine { |
20 | 22 |
21 // Writes the data passed to path. The file at path will be overwritten if it | 23 // Writes the data passed to path. The file at path will be overwritten if it |
22 // exists. Returns true on success, false otherwise. | 24 // 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, | 87 0xe8, 0x05, 0x08, 0xa1, 0x45, 0x70, 0x5b, 0x8c, |
86 0x39, 0x28, 0xab, 0xe9, 0x6b, 0x51, 0xd2, 0xcb, | 88 0x39, 0x28, 0xab, 0xe9, 0x6b, 0x51, 0xd2, 0xcb, |
87 0x30, 0x04, 0xea, 0x7d, 0x2f, 0x6e, 0x6c, 0x3b, | 89 0x30, 0x04, 0xea, 0x7d, 0x2f, 0x6e, 0x6c, 0x3b, |
88 0x5f, 0x82, 0xd9, 0x5b, 0x89, 0x37, 0x65, 0x65, | 90 0x5f, 0x82, 0xd9, 0x5b, 0x89, 0x37, 0x65, 0x65, |
89 0xbe, 0x9f, 0xa3, 0x5d | 91 0xbe, 0x9f, 0xa3, 0x5d |
90 }; | 92 }; |
91 | 93 |
92 const char* const kMountPath = "/tmp/UpdateEngineTests_mnt"; | 94 const char* const kMountPath = "/tmp/UpdateEngineTests_mnt"; |
93 } // namespace {} | 95 } // namespace {} |
94 | 96 |
97 // Creates an empty ext image. | |
98 void CreateEmptyExtImageAtPath(const std::string& path, | |
99 size_t size, | |
100 int block_size); | |
101 | |
95 // Creates an ext image with some files in it. The paths creates are | 102 // Creates an ext image with some files in it. The paths creates are |
96 // returned in out_paths. | 103 // returned in out_paths. |
97 void CreateExtImageAtPath(const std::string& path, | 104 void CreateExtImageAtPath(const std::string& path, |
98 std::vector<std::string>* out_paths); | 105 std::vector<std::string>* out_paths); |
99 | 106 |
100 // Verifies that for each path in paths, it exists in the filesystem under | 107 // 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. | 108 // parent. Also, verifies that no additional paths are present under parent. |
102 // Also tests properties of various files created by CreateExtImageAtPath(). | 109 // Also tests properties of various files created by CreateExtImageAtPath(). |
103 // Intentionally copies expected_paths. | 110 // Intentionally copies expected_paths. |
104 void VerifyAllPaths(const std::string& parent, | 111 void VerifyAllPaths(const std::string& parent, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 } | 211 } |
205 this->processor_->ActionComplete(this, kActionCodeSuccess); | 212 this->processor_->ActionComplete(this, kActionCodeSuccess); |
206 } | 213 } |
207 static std::string StaticType() { return "ObjectCollectorAction"; } | 214 static std::string StaticType() { return "ObjectCollectorAction"; } |
208 std::string Type() const { return StaticType(); } | 215 std::string Type() const { return StaticType(); } |
209 const T& object() const { return object_; } | 216 const T& object() const { return object_; } |
210 private: | 217 private: |
211 T object_; | 218 T object_; |
212 }; | 219 }; |
213 | 220 |
221 class ScopedLoopMounter { | |
222 public: | |
223 explicit ScopedLoopMounter(const std::string& file_path, | |
224 std::string* mnt_path, | |
225 unsigned long flags); | |
226 | |
227 private: | |
228 // These objects must be destructed in the following order: | |
petkov
2010/12/15 23:30:16
Does C++ standard ensure the destruction order?
thieule
2010/12/15 23:43:39
Yes, nonstatic members are destroyed in reverse or
| |
229 // ScopedFilesystemUnmounter (the file system must be unmounted first) | |
230 // ScopedLoopbackDeviceReleaser (then the loop device can be deleted) | |
231 // ScopedDirRemover (then the mount point can be deleted) | |
232 scoped_ptr<ScopedDirRemover> dir_remover_; | |
233 scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser_; | |
234 scoped_ptr<ScopedFilesystemUnmounter> unmounter_; | |
235 }; | |
236 | |
214 } // namespace chromeos_update_engine | 237 } // namespace chromeos_update_engine |
215 | 238 |
216 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ | 239 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ |
OLD | NEW |