summaryrefslogtreecommitdiffstats
path: root/media/base/state_matrix_unittest.cc
blob: 599ea6f75b0d31f907356d4f4a9ac6b8fb3281dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/state_matrix.h"
#include "testing/gmock/include/gmock/gmock.h"

using ::testing::Return;

namespace media {

class MockStateHandler {
 public:
  enum State {
    A,
    B,
    C,
  };

  MOCK_METHOD0(HandleA, int());
  MOCK_METHOD0(HandleB, int());
  MOCK_METHOD0(HandleC, int());
};

TEST(StateMatrixTest, AddState) {
  MockStateHandler handler;
  StateMatrix sm;

  EXPECT_FALSE(sm.IsStateDefined(MockStateHandler::A));
  EXPECT_FALSE(sm.IsStateDefined(MockStateHandler::B));
  EXPECT_FALSE(sm.IsStateDefined(MockStateHandler::C));

  sm.AddState(MockStateHandler::A, &MockStateHandler::HandleA);

  EXPECT_TRUE(sm.IsStateDefined(MockStateHandler::A));
  EXPECT_FALSE(sm.IsStateDefined(MockStateHandler::B));
  EXPECT_FALSE(sm.IsStateDefined(MockStateHandler::C));
}

TEST(StateMatrixTest, ExecuteHandler) {
  MockStateHandler handler;
  StateMatrix sm;

  sm.AddState(MockStateHandler::A, &MockStateHandler::HandleA);

  EXPECT_CALL(handler, HandleA())
      .WillOnce(Return(MockStateHandler::B));

  EXPECT_EQ(MockStateHandler::B,
            sm.ExecuteHandler(&handler, MockStateHandler::A));
}

}  // namespace media