15
15
using namespace ::testing;
16
16
using namespace ::lithium::reactivesocket;
17
17
18
- class FrameBufferAllocationTest : public ::testing::Test {
18
+ class FrameTest : public ::testing::Test {
19
19
void SetUp () override {
20
20
EXPECT_CALL (allocator, allocateBuffer_ (_))
21
21
.WillOnce (Invoke ([](size_t size) {
@@ -26,25 +26,25 @@ class FrameBufferAllocationTest : public ::testing::Test {
26
26
}));
27
27
28
28
folly::Singleton<lithium::reactivesocket::FrameBufferAllocator>::make_mock (
29
- [&] { return &allocator; }, /* no tear down*/ [](void *) {});
29
+ [&] { return &allocator; }, /* no tear down */ [](void *) {});
30
30
}
31
31
32
32
void TearDown () override {
33
33
folly::SingletonVault::singleton ()->destroyInstances ();
34
+ // Bring the default allocator.
35
+ folly::Singleton<lithium::reactivesocket::FrameBufferAllocator>::make_mock (
36
+ nullptr );
34
37
folly::SingletonVault::singleton ()->reenableInstances ();
35
38
}
36
39
37
- class MyBufferAllocator
38
- : public lithium::reactivesocket::FrameBufferAllocator {
40
+ class MockBufferAllocator : public FrameBufferAllocator {
39
41
public:
40
42
MOCK_METHOD1 (allocateBuffer_, folly::IOBuf*(size_t size));
41
43
42
44
std::unique_ptr<folly::IOBuf> allocateBuffer (size_t size) override {
43
45
return std::unique_ptr<folly::IOBuf>(allocateBuffer_ (size));
44
46
}
45
- };
46
-
47
- MyBufferAllocator allocator;
47
+ } allocator;
48
48
};
49
49
50
50
// TODO(stupaq): tests with malformed frames
@@ -68,7 +68,7 @@ void expectHeader(
68
68
EXPECT_EQ (flags, frame.header_ .flags_ );
69
69
}
70
70
71
- TEST_F (FrameBufferAllocationTest , Frame_REQUEST_CHANNEL) {
71
+ TEST_F (FrameTest , Frame_REQUEST_CHANNEL) {
72
72
uint32_t streamId = 42 ;
73
73
FrameFlags flags = FrameFlags_COMPLETE | FrameFlags_REQN_PRESENT;
74
74
uint32_t requestN = 3 ;
@@ -81,7 +81,7 @@ TEST_F(FrameBufferAllocationTest, Frame_REQUEST_CHANNEL) {
81
81
EXPECT_TRUE (folly::IOBufEqual ()(*data, *frame.data_ ));
82
82
}
83
83
84
- TEST_F (FrameBufferAllocationTest , Frame_REQUEST_N) {
84
+ TEST_F (FrameTest , Frame_REQUEST_N) {
85
85
uint32_t streamId = 42 ;
86
86
uint32_t requestN = 24 ;
87
87
auto frame = reserialize<Frame_REQUEST_N>(streamId, requestN);
@@ -90,14 +90,14 @@ TEST_F(FrameBufferAllocationTest, Frame_REQUEST_N) {
90
90
EXPECT_EQ (requestN, frame.requestN_ );
91
91
}
92
92
93
- TEST_F (FrameBufferAllocationTest , Frame_CANCEL) {
93
+ TEST_F (FrameTest , Frame_CANCEL) {
94
94
uint32_t streamId = 42 ;
95
95
auto frame = reserialize<Frame_CANCEL>(streamId);
96
96
97
97
expectHeader (FrameType::CANCEL, FrameFlags_EMPTY, streamId, frame);
98
98
}
99
99
100
- TEST_F (FrameBufferAllocationTest , Frame_RESPONE) {
100
+ TEST_F (FrameTest , Frame_RESPONE) {
101
101
uint32_t streamId = 42 ;
102
102
FrameFlags flags = FrameFlags_COMPLETE;
103
103
auto data = folly::IOBuf::copyBuffer (" 424242" );
@@ -107,7 +107,7 @@ TEST_F(FrameBufferAllocationTest, Frame_RESPONE) {
107
107
EXPECT_TRUE (folly::IOBufEqual ()(*data, *frame.data_ ));
108
108
}
109
109
110
- TEST_F (FrameBufferAllocationTest , Frame_ERROR) {
110
+ TEST_F (FrameTest , Frame_ERROR) {
111
111
uint32_t streamId = 42 ;
112
112
auto errorCode = ErrorCode::REJECTED;
113
113
auto frame = reserialize<Frame_ERROR>(streamId, errorCode);
0 commit comments