blob: a5f7b11e40f817bf3674a925eb0d1720e13de89c [file] [log] [blame]
Darin Petkovc1a8b422010-07-19 11:34:49 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
rspangler@google.com49fdf182009-10-10 00:57:34 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Deymoaab50e32014-11-10 19:55:35 -08005#include "update_engine/action.h"
6
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -08007#include <string>
rspangler@google.com49fdf182009-10-10 00:57:34 +00008#include <gtest/gtest.h>
rspangler@google.com49fdf182009-10-10 00:57:34 +00009#include "update_engine/action_processor.h"
10
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080011using std::string;
12
rspangler@google.com49fdf182009-10-10 00:57:34 +000013namespace chromeos_update_engine {
14
15using chromeos_update_engine::ActionPipe;
16
17class ActionTestAction;
18
19template<>
20class ActionTraits<ActionTestAction> {
21 public:
22 typedef string OutputObjectType;
23 typedef string InputObjectType;
24};
25
26// This is a simple Action class for testing.
Yunlian Jianga178e5e2013-04-05 14:41:56 -070027class ActionTestAction : public Action<ActionTestAction> {
28 public:
rspangler@google.com49fdf182009-10-10 00:57:34 +000029 typedef string InputObjectType;
30 typedef string OutputObjectType;
31 ActionPipe<string>* in_pipe() { return in_pipe_.get(); }
32 ActionPipe<string>* out_pipe() { return out_pipe_.get(); }
33 ActionProcessor* processor() { return processor_; }
34 void PerformAction() {}
35 void CompleteAction() {
36 ASSERT_TRUE(processor());
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -070037 processor()->ActionComplete(this, ErrorCode::kSuccess);
rspangler@google.com49fdf182009-10-10 00:57:34 +000038 }
39 string Type() const { return "ActionTestAction"; }
40};
41
42class ActionTest : public ::testing::Test { };
43
44// This test creates two simple Actions and sends a message via an ActionPipe
45// from one to the other.
46TEST(ActionTest, SimpleTest) {
47 ActionTestAction action;
48
49 EXPECT_FALSE(action.in_pipe());
50 EXPECT_FALSE(action.out_pipe());
51 EXPECT_FALSE(action.processor());
52 EXPECT_FALSE(action.IsRunning());
53
54 ActionProcessor action_processor;
55 action_processor.EnqueueAction(&action);
56 EXPECT_EQ(&action_processor, action.processor());
57
58 action_processor.StartProcessing();
59 EXPECT_TRUE(action.IsRunning());
60 action.CompleteAction();
61 EXPECT_FALSE(action.IsRunning());
62}
63
64} // namespace chromeos_update_engine