feat: add CMake build configuration and unit tests for XRabbitMQClient

This commit is contained in:
bing
2026-04-03 15:36:34 +08:00
parent b704b006c1
commit fee1555166
58 changed files with 6183 additions and 8 deletions

19
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,19 @@
find_package(xgoogletest CONFIG REQUIRED)
add_executable(xrabbitmqclient_test
test_rabbitmq_client.cpp
)
target_link_libraries(xrabbitmqclient_test PRIVATE
xrabbitmqclient
xgoogletest::xgoogletest
)
# Important for MSVC encoding issues
if(MSVC)
target_compile_options(xrabbitmqclient_test PRIVATE /utf-8)
endif()
# Register with CTest
include(GoogleTest)
gtest_discover_tests(xrabbitmqclient_test)

View File

@@ -0,0 +1,26 @@
#include <gtest/gtest.h>
#include "RabbitMQClient.h"
// Note: A real RabbitMQ broker is needed to fully test this wrapper.
// Since we might not have a broker running locally on the build server,
// these tests will check for proper failure handling or basic instantiations.
// For full integration tests, a mocked simpleamqpclient or a local broker is required.
TEST(RabbitMQClientTest, InvalidCredentialsFail) {
RabbitMQClient client("localhost", 5672, "invalid_user", "invalid_password");
// Connect should fail with incorrect credentials or no server
EXPECT_FALSE(client.Connect());
}
TEST(RabbitMQClientTest, DisconnectedPublish) {
RabbitMQClient client("localhost", 5672, "guest", "guest");
// Without a successful connection, publish must fail
EXPECT_FALSE(client.Publish("test_queue", "Hello World"));
}
TEST(RabbitMQClientTest, DisconnectedConsume) {
RabbitMQClient client("localhost", 5672, "guest", "guest");
// Consume without connection should probably throw or return empty
std::string msg = client.Consume("test_queue");
EXPECT_TRUE(msg.empty());
}