OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium 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 // Uniitest for data encryption functions. | |
6 | |
7 #include "blimp/common/net/message_dispatcher.h" | |
8 | |
9 #include "base/logging.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using testing::Ref; | |
14 using testing::Return; | |
15 | |
16 namespace blimp { | |
17 | |
18 class MockHandler : public MessageDispatcher::Handler { | |
19 public: | |
20 MOCK_CONST_METHOD1(Validate, bool(const BlimpMessage& message)); | |
21 MOCK_METHOD1(OnMessage, void(const BlimpMessage& message)); | |
22 }; | |
23 | |
24 TEST(MessageDispatcherTest, AllInteractions) { | |
25 BlimpMessage input_msg; | |
26 BlimpMessage compositor_msg; | |
27 | |
28 input_msg.set_type(BlimpMessage::INPUT); | |
29 compositor_msg.set_type(BlimpMessage::COMPOSITOR); | |
30 | |
31 MessageDispatcher dispatcher; | |
32 MockHandler handler1; | |
33 MockHandler handler2; | |
34 | |
35 dispatcher.AddHandler(BlimpMessage::INPUT, &handler1); | |
36 dispatcher.AddHandler(BlimpMessage::COMPOSITOR, &handler2); | |
37 | |
38 // First message passes validation and is given to the handler for processing. | |
39 EXPECT_CALL(handler1, Validate(Ref(input_msg))).WillOnce(Return(true)); | |
40 EXPECT_CALL(handler1, OnMessage(Ref(input_msg))); | |
41 dispatcher.Dispatch(input_msg); | |
42 | |
43 // Second message fails validation. | |
44 EXPECT_CALL(handler2, Validate(Ref(compositor_msg))).WillOnce(Return(false)); | |
45 dispatcher.Dispatch(compositor_msg); | |
Wez
2015/10/07 00:20:15
Verify that the Dispatcher returns an error in thi
| |
46 } | |
47 | |
48 } // namespace blimp | |
OLD | NEW |