Skip to content

Commit 074308c

Browse files
authored
[orc-rt] Support multiple copies of OpCounter unittest utility. (#161985)
This commit templatizes OpCounter with a size_t argument, allowing multiple copies of OpCounter to be easily created. This functionality will be used in upcoming unit tests that need to count operations on several types at once.
1 parent 795a115 commit 074308c

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

orc-rt/unittests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ add_orc_rt_unittest(CoreTests
1515
AllocActionTest.cpp
1616
BitmaskEnumTest.cpp
1717
CallableTraitsHelperTest.cpp
18-
CommonTestUtils.cpp
1918
ErrorTest.cpp
2019
ExecutorAddressTest.cpp
2120
IntervalMapTest.cpp

orc-rt/unittests/CommonTestUtils.cpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

orc-rt/unittests/CommonTestUtils.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <cstddef>
1313

14-
class OpCounter {
14+
template <size_t Idx = 0> class OpCounter {
1515
public:
1616
OpCounter() { ++DefaultConstructions; }
1717
OpCounter(const OpCounter &Other) { ++CopyConstructions; }
@@ -57,4 +57,11 @@ class OpCounter {
5757
static size_t Destructions;
5858
};
5959

60+
template <size_t Idx> size_t OpCounter<Idx>::DefaultConstructions = 0;
61+
template <size_t Idx> size_t OpCounter<Idx>::CopyConstructions = 0;
62+
template <size_t Idx> size_t OpCounter<Idx>::CopyAssignments = 0;
63+
template <size_t Idx> size_t OpCounter<Idx>::MoveConstructions = 0;
64+
template <size_t Idx> size_t OpCounter<Idx>::MoveAssignments = 0;
65+
template <size_t Idx> size_t OpCounter<Idx>::Destructions = 0;
66+
6067
#endif // ORC_RT_UNITTEST_COMMONTESTUTILS_H

orc-rt/unittests/bind-test.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ TEST(BindTest, LambdaCapture) {
4747
}
4848

4949
TEST(BindTest, MinimalMoves) {
50-
OpCounter::reset();
50+
OpCounter<>::reset();
5151
{
52-
auto B = bind_front([](OpCounter &O, int) {}, OpCounter());
52+
auto B = bind_front([](OpCounter<> &O, int) {}, OpCounter<>());
5353
B(0);
5454
}
55-
EXPECT_EQ(OpCounter::defaultConstructions(), 1U);
56-
EXPECT_EQ(OpCounter::copies(), 0U);
57-
EXPECT_EQ(OpCounter::moves(), 1U);
58-
EXPECT_EQ(OpCounter::destructions(), 2U);
55+
EXPECT_EQ(OpCounter<>::defaultConstructions(), 1U);
56+
EXPECT_EQ(OpCounter<>::copies(), 0U);
57+
EXPECT_EQ(OpCounter<>::moves(), 1U);
58+
EXPECT_EQ(OpCounter<>::destructions(), 2U);
5959
}
6060

6161
TEST(BindTest, MinimalCopies) {
62-
OpCounter::reset();
62+
OpCounter<>::reset();
6363
{
64-
OpCounter O;
65-
auto B = bind_front([](OpCounter &O, int) {}, O);
64+
OpCounter<> O;
65+
auto B = bind_front([](OpCounter<> &O, int) {}, O);
6666
B(0);
6767
}
68-
EXPECT_EQ(OpCounter::defaultConstructions(), 1U);
69-
EXPECT_EQ(OpCounter::copies(), 1U);
70-
EXPECT_EQ(OpCounter::moves(), 0U);
71-
EXPECT_EQ(OpCounter::destructions(), 2U);
68+
EXPECT_EQ(OpCounter<>::defaultConstructions(), 1U);
69+
EXPECT_EQ(OpCounter<>::copies(), 1U);
70+
EXPECT_EQ(OpCounter<>::moves(), 0U);
71+
EXPECT_EQ(OpCounter<>::destructions(), 2U);
7272
}
7373

7474
TEST(BindTest, ForwardUnboundArgs) {

0 commit comments

Comments
 (0)