OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 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; |
11 | 11 |
(...skipping 13 matching lines...) Expand all Loading... |
25 // This is a simple Action class for testing. | 25 // This is a simple Action class for testing. |
26 struct ActionTestAction : public Action<ActionTestAction> { | 26 struct ActionTestAction : public Action<ActionTestAction> { |
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 "ActionTestAction"; } | 37 string Type() const { return "ActionTestAction"; } |
38 }; | 38 }; |
39 | 39 |
40 class ActionTest : public ::testing::Test { }; | 40 class ActionTest : 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(ActionTest, SimpleTest) { | 44 TEST(ActionTest, SimpleTest) { |
45 ActionTestAction action; | 45 ActionTestAction action; |
46 | 46 |
47 EXPECT_FALSE(action.in_pipe()); | 47 EXPECT_FALSE(action.in_pipe()); |
48 EXPECT_FALSE(action.out_pipe()); | 48 EXPECT_FALSE(action.out_pipe()); |
49 EXPECT_FALSE(action.processor()); | 49 EXPECT_FALSE(action.processor()); |
50 EXPECT_FALSE(action.IsRunning()); | 50 EXPECT_FALSE(action.IsRunning()); |
51 | 51 |
52 ActionProcessor action_processor; | 52 ActionProcessor action_processor; |
53 action_processor.EnqueueAction(&action); | 53 action_processor.EnqueueAction(&action); |
54 EXPECT_EQ(&action_processor, action.processor()); | 54 EXPECT_EQ(&action_processor, action.processor()); |
55 | 55 |
56 action_processor.StartProcessing(); | 56 action_processor.StartProcessing(); |
57 EXPECT_TRUE(action.IsRunning()); | 57 EXPECT_TRUE(action.IsRunning()); |
58 action.CompleteAction(); | 58 action.CompleteAction(); |
59 EXPECT_FALSE(action.IsRunning()); | 59 EXPECT_FALSE(action.IsRunning()); |
60 } | 60 } |
61 | 61 |
62 } // namespace chromeos_update_engine | 62 } // namespace chromeos_update_engine |
OLD | NEW |