| 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 "base/scoped_ptr.h" |
| 12 #include "update_engine/action.h" | 13 #include "update_engine/action.h" |
| 13 #include "update_engine/subprocess.h" | 14 #include "update_engine/subprocess.h" |
| 15 #include "update_engine/utils.h" |
| 14 | 16 |
| 15 // These are some handy functions for unittests. | 17 // These are some handy functions for unittests. |
| 16 | 18 |
| 17 namespace chromeos_update_engine { | 19 namespace chromeos_update_engine { |
| 18 | 20 |
| 19 // Writes the data passed to path. The file at path will be overwritten if it | 21 // Writes the data passed to path. The file at path will be overwritten if it |
| 20 // exists. Returns true on success, false otherwise. | 22 // exists. Returns true on success, false otherwise. |
| 21 bool WriteFileVector(const std::string& path, const std::vector<char>& data); | 23 bool WriteFileVector(const std::string& path, const std::vector<char>& data); |
| 22 bool WriteFileString(const std::string& path, const std::string& data); | 24 bool WriteFileString(const std::string& path, const std::string& data); |
| 23 | 25 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 args.push_back(dev_); | 114 args.push_back(dev_); |
| 113 int return_code = 0; | 115 int return_code = 0; |
| 114 EXPECT_TRUE(Subprocess::SynchronousExec(args, &return_code)); | 116 EXPECT_TRUE(Subprocess::SynchronousExec(args, &return_code)); |
| 115 EXPECT_EQ(0, return_code); | 117 EXPECT_EQ(0, return_code); |
| 116 } | 118 } |
| 117 private: | 119 private: |
| 118 const std::string dev_; | 120 const std::string dev_; |
| 119 DISALLOW_COPY_AND_ASSIGN(ScopedLoopbackDeviceReleaser); | 121 DISALLOW_COPY_AND_ASSIGN(ScopedLoopbackDeviceReleaser); |
| 120 }; | 122 }; |
| 121 | 123 |
| 124 class ScopedTempFile { |
| 125 public: |
| 126 ScopedTempFile() { |
| 127 EXPECT_TRUE(utils::MakeTempFile("/tmp/update_engine_test_temp_file.XXXXXX", |
| 128 &path_, |
| 129 NULL)); |
| 130 unlinker_.reset(new ScopedPathUnlinker(path_)); |
| 131 } |
| 132 const std::string& GetPath() { return path_; } |
| 133 private: |
| 134 std::string path_; |
| 135 scoped_ptr<ScopedPathUnlinker> unlinker_; |
| 136 }; |
| 137 |
| 122 // Useful actions for test | 138 // Useful actions for test |
| 123 | 139 |
| 124 class NoneType; | 140 class NoneType; |
| 125 | 141 |
| 126 template<typename T> | 142 template<typename T> |
| 127 class ObjectFeederAction; | 143 class ObjectFeederAction; |
| 128 | 144 |
| 129 template<typename T> | 145 template<typename T> |
| 130 class ActionTraits<ObjectFeederAction<T> > { | 146 class ActionTraits<ObjectFeederAction<T> > { |
| 131 public: | 147 public: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 200 } |
| 185 static std::string StaticType() { return "ObjectCollectorAction"; } | 201 static std::string StaticType() { return "ObjectCollectorAction"; } |
| 186 std::string Type() const { return StaticType(); } | 202 std::string Type() const { return StaticType(); } |
| 187 const T& object() const { return object_; } | 203 const T& object() const { return object_; } |
| 188 private: | 204 private: |
| 189 T object_; | 205 T object_; |
| 190 }; | 206 }; |
| 191 | 207 |
| 192 } // namespace chromeos_update_engine | 208 } // namespace chromeos_update_engine |
| 193 | 209 |
| 194 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ | 210 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TEST_UTILS_H__ |
| OLD | NEW |