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