Skip to content

Commit

Permalink
Rename gtest conflicting test macros
Browse files Browse the repository at this point in the history
bmqtst provides several gtest-like compatibility macros, but this
prevents us from using gtest or gmock directly because it uses the exact
same names as the test macros from that library. Since we want to
support at least using gmock in our tests, we rename them to avoid conflict.

Signed-off-by: Taylor Foxhall <[email protected]>
  • Loading branch information
hallfox committed Dec 4, 2024
1 parent 94d9784 commit 175e30d
Show file tree
Hide file tree
Showing 195 changed files with 14,743 additions and 13,700 deletions.
29 changes: 0 additions & 29 deletions src/applications/bmqstoragetool/m_bmqstoragetool_filemanagermock.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,8 @@
#include <m_bmqstoragetool_filemanager.h>
#include <m_bmqstoragetool_journalfile.h>

// GMOCK
// If bmqst_testhelper.h was defined before gtest.h, preserve macroses values.
// If not, undefine values from gtest.h.
#pragma push_macro("ASSERT_EQ")
#pragma push_macro("ASSERT_NE")
#pragma push_macro("ASSERT_LT")
#pragma push_macro("ASSERT_LE")
#pragma push_macro("ASSERT_GT")
#pragma push_macro("ASSERT_GE")
#pragma push_macro("TEST_F")
#pragma push_macro("TEST")

#include <gmock/gmock.h>

#undef ASSERT_EQ
#undef ASSERT_NE
#undef ASSERT_LT
#undef ASSERT_LE
#undef ASSERT_GT
#undef ASSERT_GE
#undef TEST_F
#undef TEST
#pragma pop_macro("ASSERT_EQ")
#pragma pop_macro("ASSERT_NE")
#pragma pop_macro("ASSERT_LT")
#pragma pop_macro("ASSERT_LE")
#pragma pop_macro("ASSERT_GT")
#pragma pop_macro("ASSERT_GE")
#pragma pop_macro("TEST_F")
#pragma pop_macro("TEST")

namespace BloombergLP {

namespace m_bmqstoragetool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static void test1_breathingTest()
expectedStream << foundMessagesCount << " message GUID(s) found."
<< bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test2_searchGuidTest()
Expand Down Expand Up @@ -288,7 +288,7 @@ static void test2_searchGuidTest()
expectedStream << searchGuids.size() << " message GUID(s) found."
<< bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test3_searchNonExistingGuidTest()
Expand Down Expand Up @@ -349,7 +349,7 @@ static void test3_searchNonExistingGuidTest()
expectedStream << searchGuids[0] << bsl::endl
<< searchGuids[1] << bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test4_searchExistingAndNonExistingGuidTest()
Expand Down Expand Up @@ -433,7 +433,7 @@ static void test4_searchExistingAndNonExistingGuidTest()
expectedStream << searchGuids[2] << bsl::endl
<< searchGuids[3] << bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test5_searchOutstandingMessagesTest()
Expand Down Expand Up @@ -498,7 +498,7 @@ static void test5_searchOutstandingMessagesTest()
<< outstandingGUIDS.size() << "/" << messageCount << ")"
<< bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test6_searchConfirmedMessagesTest()
Expand Down Expand Up @@ -562,7 +562,7 @@ static void test6_searchConfirmedMessagesTest()
<< (messageCount - confirmedGUIDS.size()) << "/"
<< messageCount << ")" << bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test7_searchPartiallyConfirmedMessagesTest()
Expand Down Expand Up @@ -629,7 +629,7 @@ static void test7_searchPartiallyConfirmedMessagesTest()
<< partiallyConfirmedGUIDS.size() + 1 << "/" << messageCount
<< ")" << bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test8_searchMessagesByQueueKeyTest()
Expand Down Expand Up @@ -690,7 +690,7 @@ static void test8_searchMessagesByQueueKeyTest()
expectedStream << foundMessagesCount << " message GUID(s) found."
<< bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test9_searchMessagesByQueueNameTest()
Expand Down Expand Up @@ -761,7 +761,7 @@ static void test9_searchMessagesByQueueNameTest()
expectedStream << foundMessagesCount << " message GUID(s) found."
<< bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test10_searchMessagesByQueueNameAndQueueKeyTest()
Expand Down Expand Up @@ -836,7 +836,7 @@ static void test10_searchMessagesByQueueNameAndQueueKeyTest()
expectedStream << foundMessagesCount << " message GUID(s) found."
<< bsl::endl;

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test11_searchMessagesByTimestamp()
Expand Down Expand Up @@ -902,7 +902,7 @@ static void test11_searchMessagesByTimestamp()
bmqtst::TestHelperUtil::allocator());
searchProcessor->process();

ASSERT_EQ(resultStream.str(), expectedStream.str());
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test12_printMessagesDetailsTest()
Expand Down Expand Up @@ -1048,7 +1048,7 @@ static void test13_searchMessagesWithPayloadDumpTest()
k_NUM_MSGS,
messageOffsets);
ASSERT(pd != 0);
ASSERT_GT(mfdData.fileSize(), 0ULL);
BMQTST_ASSERT_GT(mfdData.fileSize(), 0ULL);
// Create data file iterator
DataFileIterator dataIt(&mfdData, fileHeader);

Expand Down Expand Up @@ -1211,15 +1211,15 @@ static void test15_timestampSearchTest()
static void check(mqbs::JournalFileIterator& it,
const bsls::Types::Uint64& ts)
{
ASSERT_GT(it.recordHeader().timestamp(), ts);
BMQTST_ASSERT_GT(it.recordHeader().timestamp(), ts);
ASSERT(!it.isReverseMode());
// Check previous record
it.flipDirection();
ASSERT_EQ(it.nextRecord(), 1);
ASSERT_LE(it.recordHeader().timestamp(), ts);
BMQTST_ASSERT_EQ(it.nextRecord(), 1);
BMQTST_ASSERT_LE(it.recordHeader().timestamp(), ts);
// Set 'it' to its original state
it.flipDirection();
ASSERT_EQ(it.nextRecord(), 1);
BMQTST_ASSERT_EQ(it.nextRecord(), 1);
}
};

Expand All @@ -1232,8 +1232,10 @@ static void test15_timestampSearchTest()
journalFile.fileHeader(),
false);
// Move the iterator to the beginning of the file
ASSERT_EQ(journalFileIt.nextRecord(), 1);
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts), 1);
BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1);
BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt,
ts),
1);
ResultChecker::check(journalFileIt, ts);
}

Expand All @@ -1247,35 +1249,43 @@ static void test15_timestampSearchTest()
false);

// Move the iterator to the center of the file
ASSERT_EQ(journalFileIt.nextRecord(), 1);
ASSERT_EQ(journalFileIt.advance(k_NUM_RECORDS / 2), 1);
BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1);
BMQTST_ASSERT_EQ(journalFileIt.advance(k_NUM_RECORDS / 2), 1);

// Find record with lower timestamp than the record pointed by the
// specified iterator, which is initially forward
ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1);
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts1), 1);
BMQTST_ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1);
BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt,
ts1),
1);
ResultChecker::check(journalFileIt, ts1);

// Find record with higher timestamp than the record pointed by the
// specified iterator, which is initially forward
ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2);
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts2), 1);
BMQTST_ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2);
BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt,
ts2),
1);
ResultChecker::check(journalFileIt, ts2);

// Find record with lower timestamp than the record pointed by the
// specified iterator, which is initially backward
ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1);
BMQTST_ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1);
journalFileIt.flipDirection();
ASSERT(journalFileIt.isReverseMode());
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts1), 1);
BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt,
ts1),
1);
ResultChecker::check(journalFileIt, ts1);

// Find record with higher timestamp than the record pointed by the
// specified iterator, which is initially backward
ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2);
BMQTST_ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2);
journalFileIt.flipDirection();
ASSERT(journalFileIt.isReverseMode());
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts2), 1);
BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt,
ts2),
1);
ResultChecker::check(journalFileIt, ts2);
}

Expand All @@ -1288,10 +1298,12 @@ static void test15_timestampSearchTest()
journalFile.fileHeader(),
false);
// Move the iterator to the beginning of the file
ASSERT_EQ(journalFileIt.nextRecord(), 1);
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts), 0);
ASSERT_EQ(journalFileIt.recordIndex(), k_NUM_RECORDS - 1);
ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts);
BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1);
BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt,
ts),
0);
BMQTST_ASSERT_EQ(journalFileIt.recordIndex(), k_NUM_RECORDS - 1);
BMQTST_ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts);
ASSERT(!journalFileIt.isReverseMode());
}

Expand All @@ -1303,10 +1315,12 @@ static void test15_timestampSearchTest()
journalFile.fileHeader(),
false);
// Move the iterator to the beginning of the file
ASSERT_EQ(journalFileIt.nextRecord(), 1);
ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts), 1);
ASSERT_EQ(journalFileIt.recordIndex(), 0U);
ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts);
BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1);
BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt,
ts),
1);
BMQTST_ASSERT_EQ(journalFileIt.recordIndex(), 0U);
BMQTST_ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts);
ASSERT(!journalFileIt.isReverseMode());
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/applications/bmqtool/m_bmqtool_inpututil.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ static void test1_decodeHexDumpTest()
input,
bmqtst::TestHelperUtil::allocator());
// Check rc
ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc);
BMQTST_ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc);
// Check error
ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError);
BMQTST_ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError);
// Check output
ASSERT_EQ_D(test.d_line, output.str(), test.d_expectedOutput);
BMQTST_ASSERT_EQ_D(test.d_line, output.str(), test.d_expectedOutput);
}
}

Expand Down Expand Up @@ -264,8 +264,8 @@ static void test2_loadMessageFromFileTest()
&error,
"wrongFilePath",
bmqtst::TestHelperUtil::allocator());
ASSERT_EQ(rc, false);
ASSERT_EQ(error.str(), "Failed to open file: wrongFilePath");
BMQTST_ASSERT_EQ(rc, false);
BMQTST_ASSERT_EQ(error.str(), "Failed to open file: wrongFilePath");
}

const size_t k_NUM_DATA = sizeof(k_DATA) / sizeof(*k_DATA);
Expand All @@ -277,7 +277,7 @@ static void test2_loadMessageFromFileTest()
const bsl::string filePath = tempFile.path();
{
bsl::ofstream ofs(filePath.c_str());
ASSERT_EQ(ofs.is_open(), true);
BMQTST_ASSERT_EQ(ofs.is_open(), true);
ofs << test.d_fileContent;
}

Expand All @@ -291,11 +291,11 @@ static void test2_loadMessageFromFileTest()
filePath,
bmqtst::TestHelperUtil::allocator());
// Check rc
ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc);
BMQTST_ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc);
// Check error
ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError);
BMQTST_ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError);
// Check payload
ASSERT_EQ_D(test.d_line, payload.str(), test.d_expectedPayload);
BMQTST_ASSERT_EQ_D(test.d_line, payload.str(), test.d_expectedPayload);
// Check properties (deserialize into properties instance)
bdlbb::PooledBlobBufferFactory bufferFactory(
128,
Expand All @@ -306,7 +306,7 @@ static void test2_loadMessageFromFileTest()
bdlbb::BlobUtil::append(&blob,
properties.str().c_str(),
static_cast<int>(properties.str().size()));
ASSERT_EQ_D(test.d_line, messageProperties.streamIn(blob), 0);
BMQTST_ASSERT_EQ_D(test.d_line, messageProperties.streamIn(blob), 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/groups/bmq/bmqa/bmqa_abstractsession.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static void test2_instanceInvariants()
PV("Verify that overriden methods execute as intended");

ASSERT_OPT_PASS(testObj.configureMessageDumping(""));
ASSERT_EQ(testObj.configureMessageDumping(""), -1497);
BMQTST_ASSERT_EQ(testObj.configureMessageDumping(""), -1497);
}

// ============================================================================
Expand Down
Loading

0 comments on commit 175e30d

Please sign in to comment.