| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 use_data = data; | 73 use_data = data; |
| 74 } | 74 } |
| 75 | 75 |
| 76 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 76 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 77 | 77 |
| 78 // TODO(adlr): see if we need a different file for build bots | 78 // TODO(adlr): see if we need a different file for build bots |
| 79 const string path("/tmp/DownloadActionTest"); | 79 const string path("/tmp/DownloadActionTest"); |
| 80 // takes ownership of passed in HttpFetcher | 80 // takes ownership of passed in HttpFetcher |
| 81 InstallPlan install_plan(compress, "", | 81 InstallPlan install_plan(compress, "", |
| 82 OmahaHashCalculator::OmahaHashOfData(use_data), | 82 OmahaHashCalculator::OmahaHashOfData(use_data), |
| 83 compress ? "" : path, compress ? path : ""); | 83 path); |
| 84 ObjectFeederAction<InstallPlan> feeder_action; | 84 ObjectFeederAction<InstallPlan> feeder_action; |
| 85 feeder_action.set_obj(install_plan); | 85 feeder_action.set_obj(install_plan); |
| 86 DownloadAction download_action(new MockHttpFetcher(&use_data[0], | 86 DownloadAction download_action(new MockHttpFetcher(&use_data[0], |
| 87 use_data.size())); | 87 use_data.size())); |
| 88 BondActions(&feeder_action, &download_action); | 88 BondActions(&feeder_action, &download_action); |
| 89 | 89 |
| 90 DownloadActionTestProcessorDelegate delegate; | 90 DownloadActionTestProcessorDelegate delegate; |
| 91 delegate.loop_ = loop; | 91 delegate.loop_ = loop; |
| 92 delegate.expected_data_ = data; | 92 delegate.expected_data_ = data; |
| 93 delegate.path_ = path; | 93 delegate.path_ = path; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 TEST(DownloadActionTest, TerminateEarlyTest) { | 150 TEST(DownloadActionTest, TerminateEarlyTest) { |
| 151 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 151 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 152 | 152 |
| 153 vector<char> data(kMockHttpFetcherChunkSize + kMockHttpFetcherChunkSize / 2); | 153 vector<char> data(kMockHttpFetcherChunkSize + kMockHttpFetcherChunkSize / 2); |
| 154 memset(&data[0], 0, data.size()); | 154 memset(&data[0], 0, data.size()); |
| 155 | 155 |
| 156 const string path("/tmp/DownloadActionTest"); | 156 const string path("/tmp/DownloadActionTest"); |
| 157 { | 157 { |
| 158 // takes ownership of passed in HttpFetcher | 158 // takes ownership of passed in HttpFetcher |
| 159 ObjectFeederAction<InstallPlan> feeder_action; | 159 ObjectFeederAction<InstallPlan> feeder_action; |
| 160 InstallPlan install_plan(false, "", "", path, ""); | 160 InstallPlan install_plan(false, "", "", path); |
| 161 feeder_action.set_obj(install_plan); | 161 feeder_action.set_obj(install_plan); |
| 162 DownloadAction download_action(new MockHttpFetcher(&data[0], data.size())); | 162 DownloadAction download_action(new MockHttpFetcher(&data[0], data.size())); |
| 163 TerminateEarlyTestProcessorDelegate delegate; | 163 TerminateEarlyTestProcessorDelegate delegate; |
| 164 delegate.loop_ = loop; | 164 delegate.loop_ = loop; |
| 165 ActionProcessor processor; | 165 ActionProcessor processor; |
| 166 processor.set_delegate(&delegate); | 166 processor.set_delegate(&delegate); |
| 167 processor.EnqueueAction(&feeder_action); | 167 processor.EnqueueAction(&feeder_action); |
| 168 processor.EnqueueAction(&download_action); | 168 processor.EnqueueAction(&download_action); |
| 169 BondActions(&feeder_action, &download_action); | 169 BondActions(&feeder_action, &download_action); |
| 170 | 170 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 gboolean PassObjectOutTestStarter(gpointer data) { | 224 gboolean PassObjectOutTestStarter(gpointer data) { |
| 225 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); | 225 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 226 processor->StartProcessing(); | 226 processor->StartProcessing(); |
| 227 return FALSE; | 227 return FALSE; |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 TEST(DownloadActionTest, PassObjectOutTest) { | 231 TEST(DownloadActionTest, PassObjectOutTest) { |
| 232 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 232 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 233 | 233 |
| 234 const string path("/tmp/DownloadActionTest"); | |
| 235 | |
| 236 // takes ownership of passed in HttpFetcher | 234 // takes ownership of passed in HttpFetcher |
| 237 InstallPlan install_plan(false, "", | 235 InstallPlan install_plan(false, "", |
| 238 OmahaHashCalculator::OmahaHashOfString("x"), path, | 236 OmahaHashCalculator::OmahaHashOfString("x"), |
| 239 ""); | 237 "/dev/null"); |
| 240 ObjectFeederAction<InstallPlan> feeder_action; | 238 ObjectFeederAction<InstallPlan> feeder_action; |
| 241 feeder_action.set_obj(install_plan); | 239 feeder_action.set_obj(install_plan); |
| 242 DownloadAction download_action(new MockHttpFetcher("x", 1)); | 240 DownloadAction download_action(new MockHttpFetcher("x", 1)); |
| 243 | 241 |
| 244 DownloadActionTestAction test_action; | 242 DownloadActionTestAction test_action; |
| 245 test_action.expected_input_object_ = install_plan; | 243 test_action.expected_input_object_ = install_plan; |
| 246 BondActions(&feeder_action, &download_action); | 244 BondActions(&feeder_action, &download_action); |
| 247 BondActions(&download_action, &test_action); | 245 BondActions(&download_action, &test_action); |
| 248 | 246 |
| 249 ActionProcessor processor; | 247 ActionProcessor processor; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 260 | 258 |
| 261 EXPECT_EQ(true, test_action.did_run_); | 259 EXPECT_EQ(true, test_action.did_run_); |
| 262 } | 260 } |
| 263 | 261 |
| 264 TEST(DownloadActionTest, BadOutFileTest) { | 262 TEST(DownloadActionTest, BadOutFileTest) { |
| 265 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 263 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 266 | 264 |
| 267 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); | 265 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); |
| 268 | 266 |
| 269 // takes ownership of passed in HttpFetcher | 267 // takes ownership of passed in HttpFetcher |
| 270 InstallPlan install_plan(false, "", "", path, ""); | 268 InstallPlan install_plan(false, "", "", path); |
| 271 ObjectFeederAction<InstallPlan> feeder_action; | 269 ObjectFeederAction<InstallPlan> feeder_action; |
| 272 feeder_action.set_obj(install_plan); | 270 feeder_action.set_obj(install_plan); |
| 273 DownloadAction download_action(new MockHttpFetcher("x", 1)); | 271 DownloadAction download_action(new MockHttpFetcher("x", 1)); |
| 274 BondActions(&feeder_action, &download_action); | 272 BondActions(&feeder_action, &download_action); |
| 275 | 273 |
| 276 ActionProcessor processor; | 274 ActionProcessor processor; |
| 277 processor.EnqueueAction(&feeder_action); | 275 processor.EnqueueAction(&feeder_action); |
| 278 processor.EnqueueAction(&download_action); | 276 processor.EnqueueAction(&download_action); |
| 279 processor.StartProcessing(); | 277 processor.StartProcessing(); |
| 280 ASSERT_FALSE(processor.IsRunning()); | 278 ASSERT_FALSE(processor.IsRunning()); |
| 281 | 279 |
| 282 g_main_loop_unref(loop); | 280 g_main_loop_unref(loop); |
| 283 } | 281 } |
| 284 | 282 |
| 285 } // namespace chromeos_update_engine | 283 } // namespace chromeos_update_engine |
| OLD | NEW |