Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: action_processor_unittest.cc

Issue 3022008: For actions, switch bool success into an exit code. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: switch to all positive error codes. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « action_processor.cc ('k') | action_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <gtest/gtest.h> 6 #include <gtest/gtest.h>
7 #include "update_engine/action.h" 7 #include "update_engine/action.h"
8 #include "update_engine/action_processor.h" 8 #include "update_engine/action_processor.h"
9 9
10 using std::string; 10 using std::string;
(...skipping 14 matching lines...) Expand all
25 // This is a simple Action class for testing. 25 // This is a simple Action class for testing.
26 struct ActionProcessorTestAction : public Action<ActionProcessorTestAction> { 26 struct ActionProcessorTestAction : public Action<ActionProcessorTestAction> {
27 typedef string InputObjectType; 27 typedef string InputObjectType;
28 typedef string OutputObjectType; 28 typedef string OutputObjectType;
29 ActionPipe<string>* in_pipe() { return in_pipe_.get(); } 29 ActionPipe<string>* in_pipe() { return in_pipe_.get(); }
30 ActionPipe<string>* out_pipe() { return out_pipe_.get(); } 30 ActionPipe<string>* out_pipe() { return out_pipe_.get(); }
31 ActionProcessor* processor() { return processor_; } 31 ActionProcessor* processor() { return processor_; }
32 void PerformAction() {} 32 void PerformAction() {}
33 void CompleteAction() { 33 void CompleteAction() {
34 ASSERT_TRUE(processor()); 34 ASSERT_TRUE(processor());
35 processor()->ActionComplete(this, true); 35 processor()->ActionComplete(this, kActionCodeSuccess);
36 } 36 }
37 string Type() const { return "ActionProcessorTestAction"; } 37 string Type() const { return "ActionProcessorTestAction"; }
38 }; 38 };
39 39
40 class ActionProcessorTest : public ::testing::Test { }; 40 class ActionProcessorTest : public ::testing::Test { };
41 41
42 // This test creates two simple Actions and sends a message via an ActionPipe 42 // This test creates two simple Actions and sends a message via an ActionPipe
43 // from one to the other. 43 // from one to the other.
44 TEST(ActionProcessorTest, SimpleTest) { 44 TEST(ActionProcessorTest, SimpleTest) {
45 ActionProcessorTestAction action; 45 ActionProcessorTestAction action;
(...skipping 12 matching lines...) Expand all
58 } 58 }
59 59
60 namespace { 60 namespace {
61 class MyActionProcessorDelegate : public ActionProcessorDelegate { 61 class MyActionProcessorDelegate : public ActionProcessorDelegate {
62 public: 62 public:
63 explicit MyActionProcessorDelegate(const ActionProcessor* processor) 63 explicit MyActionProcessorDelegate(const ActionProcessor* processor)
64 : processor_(processor), 64 : processor_(processor),
65 processing_done_called_(false), 65 processing_done_called_(false),
66 processing_stopped_called_(false), 66 processing_stopped_called_(false),
67 action_completed_called_(false), 67 action_completed_called_(false),
68 action_completed_success_(false) {} 68 action_exit_code_(kActionCodeError) {}
69 69
70 virtual void ProcessingDone(const ActionProcessor* processor, bool success) { 70 virtual void ProcessingDone(const ActionProcessor* processor,
71 ActionExitCode code) {
71 EXPECT_EQ(processor_, processor); 72 EXPECT_EQ(processor_, processor);
72 EXPECT_FALSE(processing_done_called_); 73 EXPECT_FALSE(processing_done_called_);
73 processing_done_called_ = true; 74 processing_done_called_ = true;
74 } 75 }
75 virtual void ProcessingStopped(const ActionProcessor* processor) { 76 virtual void ProcessingStopped(const ActionProcessor* processor) {
76 EXPECT_EQ(processor_, processor); 77 EXPECT_EQ(processor_, processor);
77 EXPECT_FALSE(processing_stopped_called_); 78 EXPECT_FALSE(processing_stopped_called_);
78 processing_stopped_called_ = true; 79 processing_stopped_called_ = true;
79 } 80 }
80 virtual void ActionCompleted(ActionProcessor* processor, 81 virtual void ActionCompleted(ActionProcessor* processor,
81 AbstractAction* action, 82 AbstractAction* action,
82 bool success) { 83 ActionExitCode code) {
83 EXPECT_EQ(processor_, processor); 84 EXPECT_EQ(processor_, processor);
84 EXPECT_FALSE(action_completed_called_); 85 EXPECT_FALSE(action_completed_called_);
85 action_completed_called_ = true; 86 action_completed_called_ = true;
86 action_completed_success_ = success; 87 action_exit_code_ = code;
87 } 88 }
88 89
89 const ActionProcessor* processor_; 90 const ActionProcessor* processor_;
90 bool processing_done_called_; 91 bool processing_done_called_;
91 bool processing_stopped_called_; 92 bool processing_stopped_called_;
92 bool action_completed_called_; 93 bool action_completed_called_;
93 bool action_completed_success_; 94 ActionExitCode action_exit_code_;
94 }; 95 };
95 } // namespace {} 96 } // namespace {}
96 97
97 TEST(ActionProcessorTest, DelegateTest) { 98 TEST(ActionProcessorTest, DelegateTest) {
98 ActionProcessorTestAction action; 99 ActionProcessorTestAction action;
99 ActionProcessor action_processor; 100 ActionProcessor action_processor;
100 MyActionProcessorDelegate delegate(&action_processor); 101 MyActionProcessorDelegate delegate(&action_processor);
101 action_processor.set_delegate(&delegate); 102 action_processor.set_delegate(&delegate);
102 103
103 action_processor.EnqueueAction(&action); 104 action_processor.EnqueueAction(&action);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 action.CompleteAction(); 167 action.CompleteAction();
167 168
168 action_processor.EnqueueAction(&action); 169 action_processor.EnqueueAction(&action);
169 action_processor.StartProcessing(); 170 action_processor.StartProcessing();
170 action_processor.StopProcessing(); 171 action_processor.StopProcessing();
171 172
172 action_processor.set_delegate(NULL); 173 action_processor.set_delegate(NULL);
173 } 174 }
174 175
175 } // namespace chromeos_update_engine 176 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « action_processor.cc ('k') | action_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698