blob: dcdce17906e67bc231ef75335c262833e826abe4 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2010 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
rspangler@google.com49fdf182009-10-10 00:57:34 +000016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#include "update_engine/common/action.h"
Alex Deymoaab50e32014-11-10 19:55:35 -080018
rspangler@google.com49fdf182009-10-10 00:57:34 +000019#include <gtest/gtest.h>
Alex Deymo39910dc2015-11-09 17:04:30 -080020#include <string>
21#include "update_engine/common/action_processor.h"
rspangler@google.com49fdf182009-10-10 00:57:34 +000022
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080023using std::string;
24
rspangler@google.com49fdf182009-10-10 00:57:34 +000025namespace chromeos_update_engine {
26
27using chromeos_update_engine::ActionPipe;
28
29class ActionTestAction;
30
31template<>
32class ActionTraits<ActionTestAction> {
33 public:
34 typedef string OutputObjectType;
35 typedef string InputObjectType;
36};
37
38// This is a simple Action class for testing.
Yunlian Jianga178e5e2013-04-05 14:41:56 -070039class ActionTestAction : public Action<ActionTestAction> {
40 public:
rspangler@google.com49fdf182009-10-10 00:57:34 +000041 typedef string InputObjectType;
42 typedef string OutputObjectType;
43 ActionPipe<string>* in_pipe() { return in_pipe_.get(); }
44 ActionPipe<string>* out_pipe() { return out_pipe_.get(); }
45 ActionProcessor* processor() { return processor_; }
46 void PerformAction() {}
47 void CompleteAction() {
48 ASSERT_TRUE(processor());
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -070049 processor()->ActionComplete(this, ErrorCode::kSuccess);
rspangler@google.com49fdf182009-10-10 00:57:34 +000050 }
51 string Type() const { return "ActionTestAction"; }
52};
53
54class ActionTest : public ::testing::Test { };
55
56// This test creates two simple Actions and sends a message via an ActionPipe
57// from one to the other.
58TEST(ActionTest, SimpleTest) {
59 ActionTestAction action;
60
61 EXPECT_FALSE(action.in_pipe());
62 EXPECT_FALSE(action.out_pipe());
63 EXPECT_FALSE(action.processor());
64 EXPECT_FALSE(action.IsRunning());
65
66 ActionProcessor action_processor;
67 action_processor.EnqueueAction(&action);
68 EXPECT_EQ(&action_processor, action.processor());
69
70 action_processor.StartProcessing();
71 EXPECT_TRUE(action.IsRunning());
72 action.CompleteAction();
73 EXPECT_FALSE(action.IsRunning());
74}
75
76} // namespace chromeos_update_engine