blob: 8bb94cada0b794ad2a80756ec73f44c3393acb2a [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.
26struct ActionTestAction : public Action<ActionTestAction> {
27 typedef string InputObjectType;
28 typedef string OutputObjectType;
29 ActionPipe<string>* in_pipe() { return in_pipe_.get(); }
30 ActionPipe<string>* out_pipe() { return out_pipe_.get(); }
31 ActionProcessor* processor() { return processor_; }
32 void PerformAction() {}
33 void CompleteAction() {
34 ASSERT_TRUE(processor());
Darin Petkovc1a8b422010-07-19 11:34:49 -070035 processor()->ActionComplete(this, kActionCodeSuccess);
rspangler@google.com49fdf182009-10-10 00:57:34 +000036 }
37 string Type() const { return "ActionTestAction"; }
38};
39
40class ActionTest : public ::testing::Test { };
41
42// This test creates two simple Actions and sends a message via an ActionPipe
43// from one to the other.
44TEST(ActionTest, SimpleTest) {
45 ActionTestAction action;
46
47 EXPECT_FALSE(action.in_pipe());
48 EXPECT_FALSE(action.out_pipe());
49 EXPECT_FALSE(action.processor());
50 EXPECT_FALSE(action.IsRunning());
51
52 ActionProcessor action_processor;
53 action_processor.EnqueueAction(&action);
54 EXPECT_EQ(&action_processor, action.processor());
55
56 action_processor.StartProcessing();
57 EXPECT_TRUE(action.IsRunning());
58 action.CompleteAction();
59 EXPECT_FALSE(action.IsRunning());
60}
61
62} // namespace chromeos_update_engine