Skip to content

Commit 2845c48

Browse files
avalonalexfacebook-github-bot
authored andcommitted
minor refactor tests to consolidate common types
Summary: this is a minor refactor for frame parser tests to consolidate common test types to `TestUtil.h` Reviewed By: AkramaMirza Differential Revision: D59638541 fbshipit-source-id: 9526a55098a24103f6fae140e666429505a0fcaf
1 parent b0001c6 commit 2845c48

File tree

4 files changed

+38
-48
lines changed

4 files changed

+38
-48
lines changed

thrift/lib/cpp2/transport/rocket/framing/parser/test/AllocatingParserStrategyTest.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,12 @@
1616

1717
#include <gtest/gtest.h>
1818
#include <thrift/lib/cpp2/transport/rocket/framing/parser/AllocatingParserStrategy.h>
19+
#include <thrift/lib/cpp2/transport/rocket/framing/parser/test/TestUtil.h>
1920

2021
namespace apache {
2122
namespace thrift {
2223
namespace rocket {
2324

24-
class FakeOwner {
25-
public:
26-
void handleFrame(std::unique_ptr<folly::IOBuf> buf) {
27-
frames_.push_back(std::move(buf));
28-
}
29-
bool incMemoryUsage(uint32_t n) {
30-
memoryCounter_ += n;
31-
return true;
32-
}
33-
void decMemoryUsage(uint32_t n) { memoryCounter_ -= n; }
34-
35-
std::vector<std::unique_ptr<folly::IOBuf>> frames_{};
36-
37-
uint32_t memoryCounter_ = 0;
38-
};
39-
4025
ParserAllocatorType alloc = ParserAllocatorType();
4126

4227
TEST(AllocatingParserStrategyTest, testAppendFrame) {

thrift/lib/cpp2/transport/rocket/framing/parser/test/FrameLengthParserStrategyTest.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,12 @@
1818

1919
#include <folly/io/IOBuf.h>
2020
#include <thrift/lib/cpp2/transport/rocket/framing/parser/FrameLengthParserStrategy.h>
21+
#include <thrift/lib/cpp2/transport/rocket/framing/parser/test/TestUtil.h>
2122

2223
namespace apache {
2324
namespace thrift {
2425
namespace rocket {
2526

26-
class FakeOwner {
27-
public:
28-
void handleFrame(std::unique_ptr<folly::IOBuf> buf) {
29-
frames_.push_back(std::move(buf));
30-
}
31-
bool incMemoryUsage(uint32_t n) {
32-
memoryCounter_ += n;
33-
return true;
34-
}
35-
void decMemoryUsage(uint32_t n) { memoryCounter_ -= n; }
36-
37-
std::vector<std::unique_ptr<folly::IOBuf>> frames_{};
38-
39-
uint32_t memoryCounter_ = 0;
40-
};
41-
4227
TEST(FrameLengthParserTest, testAppendFrame) {
4328
FakeOwner owner;
4429
FrameLengthParserStrategy<FakeOwner> parser(owner);

thrift/lib/cpp2/transport/rocket/framing/parser/test/ParserStrategyTest.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,12 @@
1919
#include <folly/io/IOBuf.h>
2020
#include <thrift/lib/cpp2/transport/rocket/framing/parser/FrameLengthParserStrategy.h>
2121
#include <thrift/lib/cpp2/transport/rocket/framing/parser/ParserStrategy.h>
22+
#include <thrift/lib/cpp2/transport/rocket/framing/parser/test/TestUtil.h>
2223

2324
namespace apache {
2425
namespace thrift {
2526
namespace rocket {
2627

27-
class FakeOwner {
28-
public:
29-
void handleFrame(std::unique_ptr<folly::IOBuf> buf) {
30-
frames_.push_back(std::move(buf));
31-
}
32-
bool incMemoryUsage(uint32_t n) {
33-
memoryCounter_ += n;
34-
return true;
35-
}
36-
void decMemoryUsage(uint32_t n) { memoryCounter_ -= n; }
37-
38-
std::vector<std::unique_ptr<folly::IOBuf>> frames_{};
39-
40-
uint32_t memoryCounter_ = 0;
41-
};
42-
4328
TEST(ParserTest, testAppendFrame) {
4429
FakeOwner owner;
4530
ParserStrategy<FakeOwner, FrameLengthParserStrategy> parser(owner);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
namespace apache::thrift::rocket {
20+
class FakeOwner {
21+
public:
22+
void handleFrame(std::unique_ptr<folly::IOBuf> buf) {
23+
frames_.push_back(std::move(buf));
24+
}
25+
bool incMemoryUsage(uint32_t n) {
26+
memoryCounter_ += n;
27+
return true;
28+
}
29+
void decMemoryUsage(uint32_t n) { memoryCounter_ -= n; }
30+
31+
std::vector<std::unique_ptr<folly::IOBuf>> frames_{};
32+
33+
uint32_t memoryCounter_ = 0;
34+
};
35+
} // namespace apache::thrift::rocket

0 commit comments

Comments
 (0)