blob: e09967f5320ed970f99cde20f6025eab8e2252c6 [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
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -08005#include <string>
rspangler@google.com49fdf182009-10-10 00:57:34 +00006#include <gtest/gtest.h>
7#include "update_engine/action.h"
8#include "update_engine/action_processor.h"
9
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080010using std::string;
11
rspangler@google.com49fdf182009-10-10 00:57:34 +000012namespace chromeos_update_engine {
13
14using chromeos_update_engine::ActionPipe;
15
16class ActionTestAction;
17
18template<>
19class ActionTraits<ActionTestAction> {
20 public:
21 typedef string OutputObjectType;
22 typedef string InputObjectType;
23};
24
25// This is a simple Action class for testing.
Yunlian Jianga178e5e2013-04-05 14:41:56 -070026class ActionTestAction : public Action<ActionTestAction> {
27 public:
rspangler@google.com49fdf182009-10-10 00:57:34 +000028 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 Zeuthena99981f2013-04-29 13:42:47 -070036 processor()->ActionComplete(this, kErrorCodeSuccess);
rspangler@google.com49fdf182009-10-10 00:57:34 +000037 }
38 string Type() const { return "ActionTestAction"; }
39};
40
41class 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.
45TEST(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