Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "update_engine/action.h" | 12 #include "update_engine/action.h" |
| 13 #include "update_engine/subprocess.h" | |
| 13 | 14 |
| 14 // These are some handy functions for unittests. | 15 // These are some handy functions for unittests. |
| 15 | 16 |
| 16 namespace chromeos_update_engine { | 17 namespace chromeos_update_engine { |
| 17 | 18 |
| 18 // Writes the data passed to path. The file at path will be overwritten if it | 19 // Writes the data passed to path. The file at path will be overwritten if it |
| 19 // exists. Returns true on success, false otherwise. | 20 // exists. Returns true on success, false otherwise. |
| 20 bool WriteFileVector(const std::string& path, const std::vector<char>& data); | 21 bool WriteFileVector(const std::string& path, const std::vector<char>& data); |
| 21 bool WriteFileString(const std::string& path, const std::string& data); | 22 bool WriteFileString(const std::string& path, const std::string& data); |
| 22 | 23 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 void CreateExtImageAtPath(const std::string& path, | 99 void CreateExtImageAtPath(const std::string& path, |
| 99 std::vector<std::string>* out_paths); | 100 std::vector<std::string>* out_paths); |
| 100 | 101 |
| 101 // Verifies that for each path in paths, it exists in the filesystem under | 102 // Verifies that for each path in paths, it exists in the filesystem under |
| 102 // parent. Also, verifies that no additional paths are present under parent. | 103 // parent. Also, verifies that no additional paths are present under parent. |
| 103 // Also tests properties of various files created by CreateExtImageAtPath(). | 104 // Also tests properties of various files created by CreateExtImageAtPath(). |
| 104 // Intentionally copies expected_paths. | 105 // Intentionally copies expected_paths. |
| 105 void VerifyAllPaths(const std::string& parent, | 106 void VerifyAllPaths(const std::string& parent, |
| 106 std::set<std::string> expected_paths); | 107 std::set<std::string> expected_paths); |
| 107 | 108 |
| 109 class ScopedLoopbackDeviceReleaser { | |
| 110 public: | |
| 111 explicit ScopedLoopbackDeviceReleaser(const std::string& dev) : dev_(dev) {} | |
| 112 ~ScopedLoopbackDeviceReleaser() { | |
| 113 std::vector<std::string> args; | |
| 114 args.push_back("/sbin/losetup"); | |
| 115 args.push_back("-d"); | |
| 116 args.push_back(dev_); | |
| 117 int return_code = 0; | |
| 118 EXPECT_TRUE(Subprocess::SynchronousExec(args, &return_code)); | |
| 119 EXPECT_EQ(0, return_code); | |
| 120 } | |
| 121 private: | |
| 122 const std::string dev_; | |
|
Daniel Erat
2010/04/23 17:47:25
add DISALLOW_COPY_AND_ASSIGN (especially for RAII-
adlr
2010/04/23 20:50:17
Done.
| |
| 123 }; | |
| 124 | |
| 108 // Useful actions for test | 125 // Useful actions for test |
| 109 | 126 |
| 110 class NoneType; | 127 class NoneType; |
| 111 | 128 |
| 112 template<typename T> | 129 template<typename T> |
| 113 class ObjectFeederAction; | 130 class ObjectFeederAction; |
| 114 | 131 |
| 115 template<typename T> | 132 template<typename T> |
| 116 class ActionTraits<ObjectFeederAction<T> > { | 133 class ActionTraits<ObjectFeederAction<T> > { |
| 117 public: | 134 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 static std::string StaticType() { return "ObjectCollectorAction"; } | 188 static std::string StaticType() { return "ObjectCollectorAction"; } |
| 172 std::string Type() const { return StaticType(); } | 189 std::string Type() const { return StaticType(); } |
| 173 const T& object() const { return object_; } | 190 const T& object() const { return object_; } |
| 174 private: | 191 private: |
| 175 T object_; | 192 T object_; |
| 176 }; | 193 }; |
| 177 | 194 |
| 178 } // namespace chromeos_update_engine | 195 } // namespace chromeos_update_engine |
| 179 | 196 |
| 180 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ | 197 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ |
| OLD | NEW |