Skip to content

Commit eda419b

Browse files
Mateusz Machalicalehecka
authored andcommitted
Fixed FrameBufferAllocatorTest. (#18)
1 parent a796202 commit eda419b

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

reactivesocket-cpp/src/Frame.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ namespace lithium {
2525
namespace reactivesocket {
2626

2727
std::unique_ptr<folly::IOBuf> FrameBufferAllocator::allocate(size_t size) {
28-
return folly::Singleton<FrameBufferAllocator>::get()->allocateBuffer(
29-
size);
28+
return folly::Singleton<FrameBufferAllocator>::get()->allocateBuffer(size);
3029
}
3130

3231
std::unique_ptr<folly::IOBuf> FrameBufferAllocator::allocateBuffer(

reactivesocket-cpp/src/Frame.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ std::ostream& operator<<(std::ostream&, const FrameHeader&);
101101

102102
class FrameBufferAllocator {
103103
public:
104-
virtual ~FrameBufferAllocator() = default;
105104
static std::unique_ptr<folly::IOBuf> allocate(size_t size);
106105

106+
virtual ~FrameBufferAllocator() = default;
107+
107108
private:
108109
virtual std::unique_ptr<folly::IOBuf> allocateBuffer(size_t size);
109110
};

reactivesocket-cpp/test/FrameTest.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using namespace ::testing;
1616
using namespace ::lithium::reactivesocket;
1717

18-
class FrameBufferAllocationTest : public ::testing::Test {
18+
class FrameTest : public ::testing::Test {
1919
void SetUp() override {
2020
EXPECT_CALL(allocator, allocateBuffer_(_))
2121
.WillOnce(Invoke([](size_t size) {
@@ -26,25 +26,25 @@ class FrameBufferAllocationTest : public ::testing::Test {
2626
}));
2727

2828
folly::Singleton<lithium::reactivesocket::FrameBufferAllocator>::make_mock(
29-
[&] { return &allocator; }, /*no tear down*/ [](void*) {});
29+
[&] { return &allocator; }, /* no tear down */ [](void*) {});
3030
}
3131

3232
void TearDown() override {
3333
folly::SingletonVault::singleton()->destroyInstances();
34+
// Bring the default allocator.
35+
folly::Singleton<lithium::reactivesocket::FrameBufferAllocator>::make_mock(
36+
nullptr);
3437
folly::SingletonVault::singleton()->reenableInstances();
3538
}
3639

37-
class MyBufferAllocator
38-
: public lithium::reactivesocket::FrameBufferAllocator {
40+
class MockBufferAllocator : public FrameBufferAllocator {
3941
public:
4042
MOCK_METHOD1(allocateBuffer_, folly::IOBuf*(size_t size));
4143

4244
std::unique_ptr<folly::IOBuf> allocateBuffer(size_t size) override {
4345
return std::unique_ptr<folly::IOBuf>(allocateBuffer_(size));
4446
}
45-
};
46-
47-
MyBufferAllocator allocator;
47+
} allocator;
4848
};
4949

5050
// TODO(stupaq): tests with malformed frames
@@ -68,7 +68,7 @@ void expectHeader(
6868
EXPECT_EQ(flags, frame.header_.flags_);
6969
}
7070

71-
TEST_F(FrameBufferAllocationTest, Frame_REQUEST_CHANNEL) {
71+
TEST_F(FrameTest, Frame_REQUEST_CHANNEL) {
7272
uint32_t streamId = 42;
7373
FrameFlags flags = FrameFlags_COMPLETE | FrameFlags_REQN_PRESENT;
7474
uint32_t requestN = 3;
@@ -81,7 +81,7 @@ TEST_F(FrameBufferAllocationTest, Frame_REQUEST_CHANNEL) {
8181
EXPECT_TRUE(folly::IOBufEqual()(*data, *frame.data_));
8282
}
8383

84-
TEST_F(FrameBufferAllocationTest, Frame_REQUEST_N) {
84+
TEST_F(FrameTest, Frame_REQUEST_N) {
8585
uint32_t streamId = 42;
8686
uint32_t requestN = 24;
8787
auto frame = reserialize<Frame_REQUEST_N>(streamId, requestN);
@@ -90,14 +90,14 @@ TEST_F(FrameBufferAllocationTest, Frame_REQUEST_N) {
9090
EXPECT_EQ(requestN, frame.requestN_);
9191
}
9292

93-
TEST_F(FrameBufferAllocationTest, Frame_CANCEL) {
93+
TEST_F(FrameTest, Frame_CANCEL) {
9494
uint32_t streamId = 42;
9595
auto frame = reserialize<Frame_CANCEL>(streamId);
9696

9797
expectHeader(FrameType::CANCEL, FrameFlags_EMPTY, streamId, frame);
9898
}
9999

100-
TEST_F(FrameBufferAllocationTest, Frame_RESPONE) {
100+
TEST_F(FrameTest, Frame_RESPONE) {
101101
uint32_t streamId = 42;
102102
FrameFlags flags = FrameFlags_COMPLETE;
103103
auto data = folly::IOBuf::copyBuffer("424242");
@@ -107,7 +107,7 @@ TEST_F(FrameBufferAllocationTest, Frame_RESPONE) {
107107
EXPECT_TRUE(folly::IOBufEqual()(*data, *frame.data_));
108108
}
109109

110-
TEST_F(FrameBufferAllocationTest, Frame_ERROR) {
110+
TEST_F(FrameTest, Frame_ERROR) {
111111
uint32_t streamId = 42;
112112
auto errorCode = ErrorCode::REJECTED;
113113
auto frame = reserialize<Frame_ERROR>(streamId, errorCode);

0 commit comments

Comments
 (0)