Skip to content

Commit 2571992

Browse files
authored
Update rrdUnitTestRunner.cpp
1 parent 1d7601a commit 2571992

1 file changed

Lines changed: 72 additions & 48 deletions

File tree

src/unittest/rrdUnitTestRunner.cpp

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5322,45 +5322,57 @@ struct MockRBusProperty {
53225322
rbusValueType_t type;
53235323
} g_mockRbusProperty;
53245324

5325-
#ifdef GTEST_ENABLE
5326-
// Mock RBUS functions for profile handler tests
5327-
extern "C" {
5328-
char const* rbusProperty_GetName(rbusProperty_t property) {
5329-
(void)property;
5330-
return g_mockRbusProperty.name.c_str();
5331-
}
5332-
5333-
rbusValue_t rbusProperty_GetValue(rbusProperty_t property) {
5334-
(void)property;
5335-
return (rbusValue_t)g_mockRbusProperty.value.c_str();
5336-
}
5337-
5338-
rbusValueType_t rbusValue_GetType(rbusValue_t value) {
5339-
(void)value;
5340-
return g_mockRbusProperty.type;
5341-
}
5342-
5343-
char const* rbusValue_GetString(rbusValue_t value, int* len) {
5344-
(void)value;
5345-
if (len) *len = g_mockRbusProperty.value.length();
5346-
return g_mockRbusProperty.value.c_str();
5347-
}
5348-
5349-
void rbusProperty_SetValue(rbusProperty_t property, rbusValue_t value) {
5350-
(void)property; (void)value;
5351-
}
5352-
5353-
void rbusValue_Release(rbusValue_t value) {
5354-
(void)value;
5355-
}
5325+
// Mock RBUS function implementations for profile handler tests
5326+
static char const* mock_rbusProperty_GetName(rbusProperty_t property) {
5327+
(void)property;
5328+
return g_mockRbusProperty.name.c_str();
5329+
}
5330+
5331+
static rbusValue_t mock_rbusProperty_GetValue(rbusProperty_t property) {
5332+
(void)property;
5333+
return (rbusValue_t)g_mockRbusProperty.value.c_str();
5334+
}
5335+
5336+
static rbusValueType_t mock_rbusValue_GetType(rbusValue_t value) {
5337+
(void)value;
5338+
return g_mockRbusProperty.type;
5339+
}
5340+
5341+
static char const* mock_rbusValue_GetString(rbusValue_t value, int* len) {
5342+
(void)value;
5343+
if (len) *len = g_mockRbusProperty.value.length();
5344+
return g_mockRbusProperty.value.c_str();
5345+
}
5346+
5347+
static void mock_rbusProperty_SetValue(rbusProperty_t property, rbusValue_t value) {
5348+
(void)property; (void)value;
5349+
}
5350+
5351+
static void mock_rbusValue_Release(rbusValue_t value) {
5352+
(void)value;
53565353
}
5357-
#endif
5354+
5355+
// External declarations for function pointers from Client_Mock.cpp
5356+
extern char const* (*rbusProperty_GetName)(rbusProperty_t);
5357+
extern rbusValue_t (*rbusProperty_GetValue)(rbusProperty_t);
5358+
extern rbusValueType_t (*rbusValue_GetType)(rbusValue_t);
5359+
extern char const* (*rbusValue_GetString)(rbusValue_t, int*);
5360+
extern void (*rbusProperty_SetValue)(rbusProperty_t, rbusValue_t);
5361+
extern void (*rbusValue_Release)(rbusValue_t);
53585362

53595363
// Test fixture for RRD Profile Handler tests
53605364
class RRDProfileHandlerTest : public ::testing::Test {
53615365
protected:
53625366
RBusProfileMock mockRBusApi;
53635367

5368+
// Store original function pointers
5369+
char const* (*orig_rbusProperty_GetName)(rbusProperty_t);
5370+
rbusValue_t (*orig_rbusProperty_GetValue)(rbusProperty_t);
5371+
rbusValueType_t (*orig_rbusValue_GetType)(rbusValue_t);
5372+
char const* (*orig_rbusValue_GetString)(rbusValue_t, int*);
5373+
void (*orig_rbusProperty_SetValue)(rbusProperty_t, rbusValue_t);
5374+
void (*orig_rbusValue_Release)(rbusValue_t);
5375+
53645376
void SetUp() override {
53655377
// Reset global state
53665378
memset(RRDProfileCategory, 0, sizeof(RRDProfileCategory));
@@ -5376,6 +5388,22 @@ class RRDProfileHandlerTest : public ::testing::Test {
53765388
g_mockRbusProperty.name.clear();
53775389
g_mockRbusProperty.value.clear();
53785390
g_mockRbusProperty.type = RBUS_STRING;
5391+
5392+
// Store original function pointers
5393+
orig_rbusProperty_GetName = rbusProperty_GetName;
5394+
orig_rbusProperty_GetValue = rbusProperty_GetValue;
5395+
orig_rbusValue_GetType = rbusValue_GetType;
5396+
orig_rbusValue_GetString = rbusValue_GetString;
5397+
orig_rbusProperty_SetValue = rbusProperty_SetValue;
5398+
orig_rbusValue_Release = rbusValue_Release;
5399+
5400+
// Redirect to mock implementations
5401+
rbusProperty_GetName = mock_rbusProperty_GetName;
5402+
rbusProperty_GetValue = mock_rbusProperty_GetValue;
5403+
rbusValue_GetType = mock_rbusValue_GetType;
5404+
rbusValue_GetString = mock_rbusValue_GetString;
5405+
rbusProperty_SetValue = mock_rbusProperty_SetValue;
5406+
rbusValue_Release = mock_rbusValue_Release;
53795407
}
53805408

53815409
void TearDown() override {
@@ -5388,6 +5416,14 @@ class RRDProfileHandlerTest : public ::testing::Test {
53885416

53895417
// Reset global mock property
53905418
memset(&g_mockRbusProperty, 0, sizeof(g_mockRbusProperty));
5419+
5420+
// Restore original function pointers
5421+
rbusProperty_GetName = orig_rbusProperty_GetName;
5422+
rbusProperty_GetValue = orig_rbusProperty_GetValue;
5423+
rbusValue_GetType = orig_rbusValue_GetType;
5424+
rbusValue_GetString = orig_rbusValue_GetString;
5425+
rbusProperty_SetValue = orig_rbusProperty_SetValue;
5426+
rbusValue_Release = orig_rbusValue_Release;
53915427
}
53925428
};
53935429

@@ -5811,25 +5847,13 @@ TEST_F(RRDProfileHandlerTest, SetHandler_MaxLengthString)
58115847
// Create a string of exactly 255 characters (max allowed)
58125848
std::string maxString(255, 'A');
58135849

5814-
mockRBusApi.mockPropertyName = RRD_SET_PROFILE_EVENT;
5815-
mockRBusApi.mockPropertyValue = maxString;
5816-
mockRBusApi.mockValueType = RBUS_STRING;
5850+
g_mockRbusProperty.name = RRD_SET_PROFILE_EVENT;
5851+
g_mockRbusProperty.value = maxString;
5852+
g_mockRbusProperty.type = RBUS_STRING;
58175853

5818-
rbusProperty_t mockProp = (rbusProperty_t)&mockRBusApi;
5854+
rbusProperty_t mockProp = (rbusProperty_t)&g_mockRbusProperty;
58195855
rbusError_t result = rrd_SetHandler(nullptr, mockProp, nullptr);
58205856

58215857
EXPECT_EQ(result, RBUS_ERROR_SUCCESS);
58225858
EXPECT_STREQ(RRDProfileCategory, maxString.c_str());
58235859
}
5824-
5825-
5826-
5827-
5828-
5829-
5830-
5831-
5832-
5833-
5834-
5835-

0 commit comments

Comments
 (0)