blob: ca48bee2417b4ecd806b6cea0b55e02f5cfb53ac [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
Alex Deymo39910dc2015-11-09 17:04:30 -080019#include <string>
Amin Hassanid3f4bea2018-04-30 14:52:40 -070020#include <utility>
21
22#include <gtest/gtest.h>
23
Alex Deymo39910dc2015-11-09 17:04:30 -080024#include "update_engine/common/action_processor.h"
rspangler@google.com49fdf182009-10-10 00:57:34 +000025
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080026using std::string;
27
rspangler@google.com49fdf182009-10-10 00:57:34 +000028namespace chromeos_update_engine {
29
30using chromeos_update_engine::ActionPipe;
31
32class ActionTestAction;
33
Amin Hassanib2689592019-01-13 17:04:28 -080034template <>
rspangler@google.com49fdf182009-10-10 00:57:34 +000035class ActionTraits<ActionTestAction> {
36 public:
37 typedef string OutputObjectType;
38 typedef string InputObjectType;
39};
40
41// This is a simple Action class for testing.
Yunlian Jianga178e5e2013-04-05 14:41:56 -070042class ActionTestAction : public Action<ActionTestAction> {
43 public:
rspangler@google.com49fdf182009-10-10 00:57:34 +000044 typedef string InputObjectType;
45 typedef string OutputObjectType;
46 ActionPipe<string>* in_pipe() { return in_pipe_.get(); }
47 ActionPipe<string>* out_pipe() { return out_pipe_.get(); }
48 ActionProcessor* processor() { return processor_; }
49 void PerformAction() {}
50 void CompleteAction() {
51 ASSERT_TRUE(processor());
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -070052 processor()->ActionComplete(this, ErrorCode::kSuccess);
rspangler@google.com49fdf182009-10-10 00:57:34 +000053 }
54 string Type() const { return "ActionTestAction"; }
55};
56
Amin Hassanib2689592019-01-13 17:04:28 -080057class ActionTest : public ::testing::Test {};
rspangler@google.com49fdf182009-10-10 00:57:34 +000058
59// This test creates two simple Actions and sends a message via an ActionPipe
60// from one to the other.
61TEST(ActionTest, SimpleTest) {
Amin Hassanid3f4bea2018-04-30 14:52:40 -070062 auto action = std::make_unique<ActionTestAction>();
63 auto action_ptr = action.get();
64 EXPECT_FALSE(action->in_pipe());
65 EXPECT_FALSE(action->out_pipe());
66 EXPECT_FALSE(action->processor());
67 EXPECT_FALSE(action->IsRunning());
rspangler@google.com49fdf182009-10-10 00:57:34 +000068
69 ActionProcessor action_processor;
Amin Hassanid3f4bea2018-04-30 14:52:40 -070070 action_processor.EnqueueAction(std::move(action));
71 EXPECT_EQ(&action_processor, action_ptr->processor());
rspangler@google.com49fdf182009-10-10 00:57:34 +000072 action_processor.StartProcessing();
Amin Hassanid3f4bea2018-04-30 14:52:40 -070073 EXPECT_TRUE(action_ptr->IsRunning());
74 action_ptr->CompleteAction();
rspangler@google.com49fdf182009-10-10 00:57:34 +000075}
76
77} // namespace chromeos_update_engine