Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move bmqtst globals into a helper struct #533

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ static void test1_breathingTest()
{
bmqtst::TestHelper::printTestName("BREATHING TEST");
// Empty parameters
CommandLineArguments arguments(s_allocator_p);
Parameters params(arguments, s_allocator_p);
bslma::ManagedPtr<FileManager> fileManager(new (*s_allocator_p)
FileManagerMock(),
s_allocator_p);
CommandLineArguments arguments(bmqtst::TestHelperUtil::allocator());
Parameters params(arguments, bmqtst::TestHelperUtil::allocator());
bslma::ManagedPtr<FileManager> fileManager(
new (*bmqtst::TestHelperUtil::allocator()) FileManagerMock(),
bmqtst::TestHelperUtil::allocator());

bslma::ManagedPtr<CommandProcessor> cmdProcessor =
CommandProcessorFactory::createCommandProcessor(&params,
fileManager,
bsl::cout,
s_allocator_p);
CommandProcessorFactory::createCommandProcessor(
&params,
fileManager,
bsl::cout,
bmqtst::TestHelperUtil::allocator());
ASSERT(dynamic_cast<JournalFileProcessor*>(cmdProcessor.get()) != 0);
}

Expand All @@ -70,7 +71,7 @@ int main(int argc, char* argv[])
default: {
bsl::cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND."
<< bsl::endl;
s_testStatus = -1;
bmqtst::TestHelperUtil::testStatus() = -1;
} break;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ static void test1_breathingTest()
{
bmqtst::TestHelper::printTestName("BREATHING TEST");
// Empty parameters
CommandLineArguments arguments(s_allocator_p);
Parameters params(arguments, s_allocator_p);
bslma::ManagedPtr<FileManager> fileManager(new (*s_allocator_p)
FileManagerMock(),
s_allocator_p);
CommandLineArguments arguments(bmqtst::TestHelperUtil::allocator());
Parameters params(arguments, bmqtst::TestHelperUtil::allocator());
bslma::ManagedPtr<FileManager> fileManager(
new (*bmqtst::TestHelperUtil::allocator()) FileManagerMock(),
bmqtst::TestHelperUtil::allocator());

bsl::shared_ptr<SearchResult> searchResult =
SearchResultFactory::createSearchResult(&params,
fileManager,
bsl::cout,
s_allocator_p);
SearchResultFactory::createSearchResult(
&params,
fileManager,
bsl::cout,
bmqtst::TestHelperUtil::allocator());
ASSERT(dynamic_cast<SearchResult*>(searchResult.get()) != 0);
}

Expand All @@ -70,7 +71,7 @@ int main(int argc, char* argv[])
case 1: test1_breathingTest(); break;
default: {
cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl;
s_testStatus = -1;
bmqtst::TestHelperUtil::testStatus() = -1;
} break;
}

Expand Down
62 changes: 36 additions & 26 deletions src/applications/bmqtool/m_bmqtool_inpututil.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ static void test1_decodeHexDumpTest()
for (size_t idx = 0; idx < k_NUM_DATA; ++idx) {
const Test& test = k_DATA[idx];

bsl::istringstream input(bsl::string(test.d_hexdumpStr, s_allocator_p),
s_allocator_p);
bmqu::MemOutStream output(s_allocator_p);
bmqu::MemOutStream error(s_allocator_p);
const bool rc =
InputUtil::decodeHexDump(&output, &error, input, s_allocator_p);
bsl::istringstream input(
bsl::string(test.d_hexdumpStr,
bmqtst::TestHelperUtil::allocator()),
bmqtst::TestHelperUtil::allocator());
bmqu::MemOutStream output(bmqtst::TestHelperUtil::allocator());
bmqu::MemOutStream error(bmqtst::TestHelperUtil::allocator());
const bool rc = InputUtil::decodeHexDump(
&output,
&error,
input,
bmqtst::TestHelperUtil::allocator());
// Check rc
ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc);
// Check error
Expand Down Expand Up @@ -251,13 +256,14 @@ static void test2_loadMessageFromFileTest()

// Check wrong file path
{
bmqu::MemOutStream stream(s_allocator_p);
bmqu::MemOutStream error(s_allocator_p);
const bool rc = InputUtil::loadMessageFromFile(&stream,
&stream,
&error,
"wrongFilePath",
s_allocator_p);
bmqu::MemOutStream stream(bmqtst::TestHelperUtil::allocator());
bmqu::MemOutStream error(bmqtst::TestHelperUtil::allocator());
const bool rc = InputUtil::loadMessageFromFile(
&stream,
&stream,
&error,
"wrongFilePath",
bmqtst::TestHelperUtil::allocator());
ASSERT_EQ(rc, false);
ASSERT_EQ(error.str(), "Failed to open file: wrongFilePath");
}
Expand All @@ -267,32 +273,36 @@ static void test2_loadMessageFromFileTest()
const Test& test = k_DATA[idx];

// Create temp file and write content
bmqu::TempFile tempFile(s_allocator_p);
bmqu::TempFile tempFile(bmqtst::TestHelperUtil::allocator());
const bsl::string filePath = tempFile.path();
{
bsl::ofstream ofs(filePath.c_str());
ASSERT_EQ(ofs.is_open(), true);
ofs << test.d_fileContent;
}

bmqu::MemOutStream payload(s_allocator_p);
bsl::ostringstream properties(s_allocator_p);
bmqu::MemOutStream error(s_allocator_p);
const bool rc = InputUtil::loadMessageFromFile(&payload,
&properties,
&error,
filePath,
s_allocator_p);
bmqu::MemOutStream payload(bmqtst::TestHelperUtil::allocator());
bsl::ostringstream properties(bmqtst::TestHelperUtil::allocator());
bmqu::MemOutStream error(bmqtst::TestHelperUtil::allocator());
const bool rc = InputUtil::loadMessageFromFile(
&payload,
&properties,
&error,
filePath,
bmqtst::TestHelperUtil::allocator());
// Check rc
ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc);
// Check error
ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError);
// Check payload
ASSERT_EQ_D(test.d_line, payload.str(), test.d_expectedPayload);
// Check properties (deserialize into properties instance)
bdlbb::PooledBlobBufferFactory bufferFactory(128, s_allocator_p);
bdlbb::Blob blob(&bufferFactory, s_allocator_p);
bmqa::MessageProperties messageProperties(s_allocator_p);
bdlbb::PooledBlobBufferFactory bufferFactory(
128,
bmqtst::TestHelperUtil::allocator());
bdlbb::Blob blob(&bufferFactory, bmqtst::TestHelperUtil::allocator());
bmqa::MessageProperties messageProperties(
bmqtst::TestHelperUtil::allocator());
bdlbb::BlobUtil::append(&blob,
properties.str().c_str(),
static_cast<int>(properties.str().size()));
Expand All @@ -314,7 +324,7 @@ int main(int argc, char* argv[])
case 2: test2_loadMessageFromFileTest(); break;
default: {
cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl;
s_testStatus = -1;
bmqtst::TestHelperUtil::testStatus() = -1;
} break;
}

Expand Down
27 changes: 16 additions & 11 deletions src/groups/bmq/bmqa/bmqa_abstractsession.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static void test1_breathingTest()
// PROTOCOL TEST
// ------------------------------------------------------------------------
{
s_ignoreCheckDefAlloc = true;
bmqtst::TestHelperUtil::ignoreCheckDefAlloc() = true;
// The default allocator check fails in this test case because the
// 'markDone' methods of AbstractSession may sometimes return a
// memory-aware object without utilizing the parameter allocator.
Expand All @@ -302,7 +302,8 @@ static void test1_breathingTest()
bmqa::AbstractSession concreteObj;

PV("Creating a test object");
bsls::ProtocolTest<AbstractSessionTestImp> testObj(s_verbosityLevel > 2);
bsls::ProtocolTest<AbstractSessionTestImp> testObj(
bmqtst::TestHelperUtil::verbosityLevel() > 2);

PV("Verify that the protocol is NOT abstract");
ASSERT(!testObj.testAbstract());
Expand All @@ -327,9 +328,11 @@ static void test1_breathingTest()
bmqt::Uri dummyUri;
bsls::TimeInterval dummyTimeInterval(0);

bmqa::OpenQueueStatus openQueueResult(s_allocator_p);
bmqa::ConfigureQueueStatus configureQueueResult(s_allocator_p);
bmqa::CloseQueueStatus closeQueueResult(s_allocator_p);
bmqa::OpenQueueStatus openQueueResult(bmqtst::TestHelperUtil::allocator());
bmqa::ConfigureQueueStatus configureQueueResult(
bmqtst::TestHelperUtil::allocator());
bmqa::CloseQueueStatus closeQueueResult(
bmqtst::TestHelperUtil::allocator());

const bmqa::AbstractSession::OpenQueueCallback openQueueCallback;
const bmqa::AbstractSession::ConfigureQueueCallback configureQueueCallback;
Expand Down Expand Up @@ -442,7 +445,7 @@ static void test2_instanceInvariants()
// INSTANCE INVARIANTS
// ------------------------------------------------------------------------
{
s_ignoreCheckDefAlloc = true;
bmqtst::TestHelperUtil::ignoreCheckDefAlloc() = true;
// Can't ensure no default memory is allocated because a default
// QueueId is instantiated and that uses the default allocator to
// allocate memory for an automatically generated CorrelationId.
Expand All @@ -464,12 +467,14 @@ static void test2_instanceInvariants()
bmqa::QueueId* dummyQueueIdPtr = 0;
bmqt::CorrelationId dummyCorrelationId;
bmqt::QueueOptions dummyQueueOptions;
bmqt::Uri dummyUri(s_allocator_p);
bmqt::Uri dummyUri(bmqtst::TestHelperUtil::allocator());
bsls::TimeInterval dummyTimeInterval(0);

bmqa::OpenQueueStatus openQueueResult(s_allocator_p);
bmqa::ConfigureQueueStatus configureQueueResult(s_allocator_p);
bmqa::CloseQueueStatus closeQueueResult(s_allocator_p);
bmqa::OpenQueueStatus openQueueResult(bmqtst::TestHelperUtil::allocator());
bmqa::ConfigureQueueStatus configureQueueResult(
bmqtst::TestHelperUtil::allocator());
bmqa::CloseQueueStatus closeQueueResult(
bmqtst::TestHelperUtil::allocator());

const bmqa::AbstractSession::OpenQueueCallback openQueueCallback;
const bmqa::AbstractSession::ConfigureQueueCallback configureQueueCallback;
Expand Down Expand Up @@ -622,7 +627,7 @@ int main(int argc, char* argv[])
case 1: test1_breathingTest(); break;
default: {
cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl;
s_testStatus = -1;
bmqtst::TestHelperUtil::testStatus() = -1;
} break;
}

Expand Down
Loading
Loading