| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void TestWithData(const vector<char>& data) { | 68 void TestWithData(const vector<char>& data) { |
| 69 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 69 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 70 | 70 |
| 71 // TODO(adlr): see if we need a different file for build bots | 71 // TODO(adlr): see if we need a different file for build bots |
| 72 ScopedTempFile output_temp_file; | 72 ScopedTempFile output_temp_file; |
| 73 DirectFileWriter writer; | 73 DirectFileWriter writer; |
| 74 | 74 |
| 75 // takes ownership of passed in HttpFetcher | 75 // takes ownership of passed in HttpFetcher |
| 76 InstallPlan install_plan(true, | 76 InstallPlan install_plan(true, |
| 77 "", | 77 "", |
| 78 0, |
| 78 OmahaHashCalculator::OmahaHashOfData(data), | 79 OmahaHashCalculator::OmahaHashOfData(data), |
| 79 output_temp_file.GetPath(), | 80 output_temp_file.GetPath(), |
| 80 ""); | 81 ""); |
| 81 ObjectFeederAction<InstallPlan> feeder_action; | 82 ObjectFeederAction<InstallPlan> feeder_action; |
| 82 feeder_action.set_obj(install_plan); | 83 feeder_action.set_obj(install_plan); |
| 83 DownloadAction download_action(new MockHttpFetcher(&data[0], | 84 DownloadAction download_action(new MockHttpFetcher(&data[0], |
| 84 data.size())); | 85 data.size())); |
| 85 download_action.SetTestFileWriter(&writer); | 86 download_action.SetTestFileWriter(&writer); |
| 86 BondActions(&feeder_action, &download_action); | 87 BondActions(&feeder_action, &download_action); |
| 87 | 88 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 146 |
| 146 vector<char> data(kMockHttpFetcherChunkSize + kMockHttpFetcherChunkSize / 2); | 147 vector<char> data(kMockHttpFetcherChunkSize + kMockHttpFetcherChunkSize / 2); |
| 147 memset(&data[0], 0, data.size()); | 148 memset(&data[0], 0, data.size()); |
| 148 | 149 |
| 149 ScopedTempFile temp_file; | 150 ScopedTempFile temp_file; |
| 150 { | 151 { |
| 151 DirectFileWriter writer; | 152 DirectFileWriter writer; |
| 152 | 153 |
| 153 // takes ownership of passed in HttpFetcher | 154 // takes ownership of passed in HttpFetcher |
| 154 ObjectFeederAction<InstallPlan> feeder_action; | 155 ObjectFeederAction<InstallPlan> feeder_action; |
| 155 InstallPlan install_plan(true, "", "", temp_file.GetPath(), ""); | 156 InstallPlan install_plan(true, "", 0, "", temp_file.GetPath(), ""); |
| 156 feeder_action.set_obj(install_plan); | 157 feeder_action.set_obj(install_plan); |
| 157 DownloadAction download_action(new MockHttpFetcher(&data[0], data.size())); | 158 DownloadAction download_action(new MockHttpFetcher(&data[0], data.size())); |
| 158 download_action.SetTestFileWriter(&writer); | 159 download_action.SetTestFileWriter(&writer); |
| 159 TerminateEarlyTestProcessorDelegate delegate; | 160 TerminateEarlyTestProcessorDelegate delegate; |
| 160 delegate.loop_ = loop; | 161 delegate.loop_ = loop; |
| 161 ActionProcessor processor; | 162 ActionProcessor processor; |
| 162 processor.set_delegate(&delegate); | 163 processor.set_delegate(&delegate); |
| 163 processor.EnqueueAction(&feeder_action); | 164 processor.EnqueueAction(&feeder_action); |
| 164 processor.EnqueueAction(&download_action); | 165 processor.EnqueueAction(&download_action); |
| 165 BondActions(&feeder_action, &download_action); | 166 BondActions(&feeder_action, &download_action); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 227 } |
| 227 | 228 |
| 228 TEST(DownloadActionTest, PassObjectOutTest) { | 229 TEST(DownloadActionTest, PassObjectOutTest) { |
| 229 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 230 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 230 | 231 |
| 231 DirectFileWriter writer; | 232 DirectFileWriter writer; |
| 232 | 233 |
| 233 // takes ownership of passed in HttpFetcher | 234 // takes ownership of passed in HttpFetcher |
| 234 InstallPlan install_plan(true, | 235 InstallPlan install_plan(true, |
| 235 "", | 236 "", |
| 237 0, |
| 236 OmahaHashCalculator::OmahaHashOfString("x"), | 238 OmahaHashCalculator::OmahaHashOfString("x"), |
| 237 "/dev/null", | 239 "/dev/null", |
| 238 "/dev/null"); | 240 "/dev/null"); |
| 239 ObjectFeederAction<InstallPlan> feeder_action; | 241 ObjectFeederAction<InstallPlan> feeder_action; |
| 240 feeder_action.set_obj(install_plan); | 242 feeder_action.set_obj(install_plan); |
| 241 DownloadAction download_action(new MockHttpFetcher("x", 1)); | 243 DownloadAction download_action(new MockHttpFetcher("x", 1)); |
| 242 download_action.SetTestFileWriter(&writer); | 244 download_action.SetTestFileWriter(&writer); |
| 243 | 245 |
| 244 DownloadActionTestAction test_action; | 246 DownloadActionTestAction test_action; |
| 245 test_action.expected_input_object_ = install_plan; | 247 test_action.expected_input_object_ = install_plan; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 261 EXPECT_EQ(true, test_action.did_run_); | 263 EXPECT_EQ(true, test_action.did_run_); |
| 262 } | 264 } |
| 263 | 265 |
| 264 TEST(DownloadActionTest, BadOutFileTest) { | 266 TEST(DownloadActionTest, BadOutFileTest) { |
| 265 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 267 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 266 | 268 |
| 267 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); | 269 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); |
| 268 DirectFileWriter writer; | 270 DirectFileWriter writer; |
| 269 | 271 |
| 270 // takes ownership of passed in HttpFetcher | 272 // takes ownership of passed in HttpFetcher |
| 271 InstallPlan install_plan(true, "", "", path, ""); | 273 InstallPlan install_plan(true, "", 0, "", path, ""); |
| 272 ObjectFeederAction<InstallPlan> feeder_action; | 274 ObjectFeederAction<InstallPlan> feeder_action; |
| 273 feeder_action.set_obj(install_plan); | 275 feeder_action.set_obj(install_plan); |
| 274 DownloadAction download_action(new MockHttpFetcher("x", 1)); | 276 DownloadAction download_action(new MockHttpFetcher("x", 1)); |
| 275 download_action.SetTestFileWriter(&writer); | 277 download_action.SetTestFileWriter(&writer); |
| 276 | 278 |
| 277 BondActions(&feeder_action, &download_action); | 279 BondActions(&feeder_action, &download_action); |
| 278 | 280 |
| 279 ActionProcessor processor; | 281 ActionProcessor processor; |
| 280 processor.EnqueueAction(&feeder_action); | 282 processor.EnqueueAction(&feeder_action); |
| 281 processor.EnqueueAction(&download_action); | 283 processor.EnqueueAction(&download_action); |
| 282 processor.StartProcessing(); | 284 processor.StartProcessing(); |
| 283 ASSERT_FALSE(processor.IsRunning()); | 285 ASSERT_FALSE(processor.IsRunning()); |
| 284 | 286 |
| 285 g_main_loop_unref(loop); | 287 g_main_loop_unref(loop); |
| 286 } | 288 } |
| 287 | 289 |
| 288 } // namespace chromeos_update_engine | 290 } // namespace chromeos_update_engine |
| OLD | NEW |