forked from rsocket/rsocket-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameTransportTest.cpp
More file actions
70 lines (51 loc) · 2.12 KB
/
FrameTransportTest.cpp
File metadata and controls
70 lines (51 loc) · 2.12 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2004-present Facebook. All Rights Reserved.
#include <gtest/gtest.h>
#include "rsocket/framing/FrameTransportImpl.h"
#include "rsocket/test/test_utils/MockDuplexConnection.h"
#include "rsocket/test/test_utils/MockFrameProcessor.h"
using namespace rsocket;
using namespace testing;
namespace {
/*
* Compare a `const folly::IOBuf&` against a `const std::string&`.
*/
MATCHER_P(IOBufStringEq, s, "") {
return folly::IOBufEqual()(*arg, *folly::IOBuf::copyBuffer(s));
}
} // namespace
TEST(FrameTransport, Close) {
auto connection = std::make_unique<StrictMock<MockDuplexConnection>>();
EXPECT_CALL(*connection, setInput_(_));
auto transport = yarpl::make_ref<FrameTransportImpl>(std::move(connection));
transport->setFrameProcessor(
std::make_shared<StrictMock<MockFrameProcessor>>());
transport->close();
}
TEST(FrameTransport, SimpleNoQueue) {
auto connection = std::make_unique<StrictMock<MockDuplexConnection>>();
EXPECT_CALL(*connection, setInput_(_));
EXPECT_CALL(*connection, send_(IOBufStringEq("Hello")));
EXPECT_CALL(*connection, send_(IOBufStringEq("World")));
auto transport = yarpl::make_ref<FrameTransportImpl>(std::move(connection));
transport->setFrameProcessor(
std::make_shared<StrictMock<MockFrameProcessor>>());
transport->outputFrameOrDrop(folly::IOBuf::copyBuffer("Hello"));
transport->outputFrameOrDrop(folly::IOBuf::copyBuffer("World"));
transport->close();
}
TEST(FrameTransport, InputSendsError) {
auto connection =
std::make_unique<StrictMock<MockDuplexConnection>>([](auto input) {
auto subscription =
yarpl::make_ref<StrictMock<yarpl::mocks::MockSubscription>>();
EXPECT_CALL(*subscription, request_(_));
EXPECT_CALL(*subscription, cancel_());
input->onSubscribe(std::move(subscription));
input->onError(std::runtime_error("Oops"));
});
auto transport = yarpl::make_ref<FrameTransportImpl>(std::move(connection));
auto processor = std::make_shared<StrictMock<MockFrameProcessor>>();
EXPECT_CALL(*processor, onTerminal_(_));
transport->setFrameProcessor(std::move(processor));
transport->close();
}