Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 5 | #include <string> |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 6 | #include <gtest/gtest.h> |
| 7 | #include "update_engine/action.h" |
| 8 | #include "update_engine/action_processor.h" |
| 9 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 10 | using std::string; |
| 11 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | using chromeos_update_engine::ActionPipe; |
| 15 | |
| 16 | class ActionTestAction; |
| 17 | |
| 18 | template<> |
| 19 | class ActionTraits<ActionTestAction> { |
| 20 | public: |
| 21 | typedef string OutputObjectType; |
| 22 | typedef string InputObjectType; |
| 23 | }; |
| 24 | |
| 25 | // This is a simple Action class for testing. |
Yunlian Jiang | a178e5e | 2013-04-05 14:41:56 -0700 | [diff] [blame] | 26 | class ActionTestAction : public Action<ActionTestAction> { |
| 27 | public: |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 28 | typedef string InputObjectType; |
| 29 | typedef string OutputObjectType; |
| 30 | ActionPipe<string>* in_pipe() { return in_pipe_.get(); } |
| 31 | ActionPipe<string>* out_pipe() { return out_pipe_.get(); } |
| 32 | ActionProcessor* processor() { return processor_; } |
| 33 | void PerformAction() {} |
| 34 | void CompleteAction() { |
| 35 | ASSERT_TRUE(processor()); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 36 | processor()->ActionComplete(this, kErrorCodeSuccess); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 37 | } |
| 38 | string Type() const { return "ActionTestAction"; } |
| 39 | }; |
| 40 | |
| 41 | class ActionTest : public ::testing::Test { }; |
| 42 | |
| 43 | // This test creates two simple Actions and sends a message via an ActionPipe |
| 44 | // from one to the other. |
| 45 | TEST(ActionTest, SimpleTest) { |
| 46 | ActionTestAction action; |
| 47 | |
| 48 | EXPECT_FALSE(action.in_pipe()); |
| 49 | EXPECT_FALSE(action.out_pipe()); |
| 50 | EXPECT_FALSE(action.processor()); |
| 51 | EXPECT_FALSE(action.IsRunning()); |
| 52 | |
| 53 | ActionProcessor action_processor; |
| 54 | action_processor.EnqueueAction(&action); |
| 55 | EXPECT_EQ(&action_processor, action.processor()); |
| 56 | |
| 57 | action_processor.StartProcessing(); |
| 58 | EXPECT_TRUE(action.IsRunning()); |
| 59 | action.CompleteAction(); |
| 60 | EXPECT_FALSE(action.IsRunning()); |
| 61 | } |
| 62 | |
| 63 | } // namespace chromeos_update_engine |