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 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 #include <glib.h> | 7 #include <glib.h> |
8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
9 #include "update_engine/action_pipe.h" | 9 #include "update_engine/action_pipe.h" |
10 #include "update_engine/download_action.h" | 10 #include "update_engine/download_action.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class DownloadActionTest : public ::testing::Test { }; | 21 class DownloadActionTest : public ::testing::Test { }; |
22 | 22 |
23 namespace { | 23 namespace { |
24 class DownloadActionTestProcessorDelegate : public ActionProcessorDelegate { | 24 class DownloadActionTestProcessorDelegate : public ActionProcessorDelegate { |
25 public: | 25 public: |
26 DownloadActionTestProcessorDelegate() | 26 DownloadActionTestProcessorDelegate() |
27 : loop_(NULL), processing_done_called_(false) {} | 27 : loop_(NULL), processing_done_called_(false) {} |
28 virtual ~DownloadActionTestProcessorDelegate() { | 28 virtual ~DownloadActionTestProcessorDelegate() { |
29 EXPECT_TRUE(processing_done_called_); | 29 EXPECT_TRUE(processing_done_called_); |
30 } | 30 } |
31 virtual void ProcessingDone(const ActionProcessor* processor, bool success) { | 31 virtual void ProcessingDone(const ActionProcessor* processor, |
| 32 ActionExitCode code) { |
32 ASSERT_TRUE(loop_); | 33 ASSERT_TRUE(loop_); |
33 g_main_loop_quit(loop_); | 34 g_main_loop_quit(loop_); |
34 vector<char> found_data; | 35 vector<char> found_data; |
35 ASSERT_TRUE(utils::ReadFile(path_, &found_data)); | 36 ASSERT_TRUE(utils::ReadFile(path_, &found_data)); |
36 ASSERT_EQ(expected_data_.size(), found_data.size()); | 37 ASSERT_EQ(expected_data_.size(), found_data.size()); |
37 for (unsigned i = 0; i < expected_data_.size(); i++) { | 38 for (unsigned i = 0; i < expected_data_.size(); i++) { |
38 EXPECT_EQ(expected_data_[i], found_data[i]); | 39 EXPECT_EQ(expected_data_[i], found_data[i]); |
39 } | 40 } |
40 processing_done_called_ = true; | 41 processing_done_called_ = true; |
41 } | 42 } |
42 | 43 |
43 virtual void ActionCompleted(ActionProcessor* processor, | 44 virtual void ActionCompleted(ActionProcessor* processor, |
44 AbstractAction* action, | 45 AbstractAction* action, |
45 bool success) { | 46 ActionExitCode code) { |
46 // make sure actions always succeed | 47 // make sure actions always succeed |
47 EXPECT_TRUE(success); | 48 EXPECT_EQ(kActionCodeSuccess, code); |
48 } | 49 } |
49 | 50 |
50 GMainLoop *loop_; | 51 GMainLoop *loop_; |
51 string path_; | 52 string path_; |
52 vector<char> expected_data_; | 53 vector<char> expected_data_; |
53 bool processing_done_called_; | 54 bool processing_done_called_; |
54 }; | 55 }; |
55 | 56 |
56 struct EntryPointArgs { | 57 struct EntryPointArgs { |
57 const vector<char> *data; | 58 const vector<char> *data; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 typedef InstallPlan InputObjectType; | 193 typedef InstallPlan InputObjectType; |
193 typedef InstallPlan OutputObjectType; | 194 typedef InstallPlan OutputObjectType; |
194 ActionPipe<InstallPlan>* in_pipe() { return in_pipe_.get(); } | 195 ActionPipe<InstallPlan>* in_pipe() { return in_pipe_.get(); } |
195 ActionPipe<InstallPlan>* out_pipe() { return out_pipe_.get(); } | 196 ActionPipe<InstallPlan>* out_pipe() { return out_pipe_.get(); } |
196 ActionProcessor* processor() { return processor_; } | 197 ActionProcessor* processor() { return processor_; } |
197 void PerformAction() { | 198 void PerformAction() { |
198 did_run_ = true; | 199 did_run_ = true; |
199 ASSERT_TRUE(HasInputObject()); | 200 ASSERT_TRUE(HasInputObject()); |
200 EXPECT_TRUE(expected_input_object_ == GetInputObject()); | 201 EXPECT_TRUE(expected_input_object_ == GetInputObject()); |
201 ASSERT_TRUE(processor()); | 202 ASSERT_TRUE(processor()); |
202 processor()->ActionComplete(this, true); | 203 processor()->ActionComplete(this, kActionCodeSuccess); |
203 } | 204 } |
204 string Type() const { return "DownloadActionTestAction"; } | 205 string Type() const { return "DownloadActionTestAction"; } |
205 InstallPlan expected_input_object_; | 206 InstallPlan expected_input_object_; |
206 bool did_run_; | 207 bool did_run_; |
207 }; | 208 }; |
208 | 209 |
209 namespace { | 210 namespace { |
210 // This class is an ActionProcessorDelegate that simply terminates the | 211 // This class is an ActionProcessorDelegate that simply terminates the |
211 // run loop when the ActionProcessor has completed processing. It's used | 212 // run loop when the ActionProcessor has completed processing. It's used |
212 // only by the test PassObjectOutTest. | 213 // only by the test PassObjectOutTest. |
213 class PassObjectOutTestProcessorDelegate : public ActionProcessorDelegate { | 214 class PassObjectOutTestProcessorDelegate : public ActionProcessorDelegate { |
214 public: | 215 public: |
215 void ProcessingDone(const ActionProcessor* processor, bool success) { | 216 void ProcessingDone(const ActionProcessor* processor, ActionExitCode code) { |
216 ASSERT_TRUE(loop_); | 217 ASSERT_TRUE(loop_); |
217 g_main_loop_quit(loop_); | 218 g_main_loop_quit(loop_); |
218 } | 219 } |
219 GMainLoop *loop_; | 220 GMainLoop *loop_; |
220 }; | 221 }; |
221 | 222 |
222 gboolean PassObjectOutTestStarter(gpointer data) { | 223 gboolean PassObjectOutTestStarter(gpointer data) { |
223 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); | 224 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
224 processor->StartProcessing(); | 225 processor->StartProcessing(); |
225 return FALSE; | 226 return FALSE; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 269 |
269 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); | 270 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); |
270 DirectFileWriter writer; | 271 DirectFileWriter writer; |
271 | 272 |
272 // takes ownership of passed in HttpFetcher | 273 // takes ownership of passed in HttpFetcher |
273 InstallPlan install_plan(true, "", 0, "", path, ""); | 274 InstallPlan install_plan(true, "", 0, "", path, ""); |
274 ObjectFeederAction<InstallPlan> feeder_action; | 275 ObjectFeederAction<InstallPlan> feeder_action; |
275 feeder_action.set_obj(install_plan); | 276 feeder_action.set_obj(install_plan); |
276 DownloadAction download_action(new MockHttpFetcher("x", 1)); | 277 DownloadAction download_action(new MockHttpFetcher("x", 1)); |
277 download_action.SetTestFileWriter(&writer); | 278 download_action.SetTestFileWriter(&writer); |
278 | 279 |
279 BondActions(&feeder_action, &download_action); | 280 BondActions(&feeder_action, &download_action); |
280 | 281 |
281 ActionProcessor processor; | 282 ActionProcessor processor; |
282 processor.EnqueueAction(&feeder_action); | 283 processor.EnqueueAction(&feeder_action); |
283 processor.EnqueueAction(&download_action); | 284 processor.EnqueueAction(&download_action); |
284 processor.StartProcessing(); | 285 processor.StartProcessing(); |
285 ASSERT_FALSE(processor.IsRunning()); | 286 ASSERT_FALSE(processor.IsRunning()); |
286 | 287 |
287 g_main_loop_unref(loop); | 288 g_main_loop_unref(loop); |
288 } | 289 } |
289 | 290 |
290 } // namespace chromeos_update_engine | 291 } // namespace chromeos_update_engine |
OLD | NEW |