Skip to content

Commit

Permalink
Merge pull request #255 from suvi-123/rbus_unit_test
Browse files Browse the repository at this point in the history
webpa_rbus.c unit test
  • Loading branch information
sadhyama authored Dec 11, 2023
2 parents 71c2107 + a5a2f4f commit 51286b8
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 6 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ jobs:
mkdir _install
mkdir _install/lib
cp ${RBUS_INSTALL_DIR}/usr/lib/librbus* _install/lib
build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make all
build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make all test
- name: Test
working-directory: build
# ARGS=-VV make test # use this version for debugging

- name: Stop rtrouted
run: |
# ARGS=-VV make test # use this version for debugging
make test
killall -9 rtrouted
- name: Merge GCOV Reports for Sonarcloud
working-directory: build
Expand Down
2 changes: 1 addition & 1 deletion source/broadband/webpa_rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ WDMP_STATUS webpaRbusInit(const char *pComponentName)
return WDMP_SUCCESS;
}

static void webpaRbus_Uninit()
void webpaRbus_Uninit()
{
rbus_close(rbus_handle);
}
Expand Down
1 change: 1 addition & 0 deletions source/include/webpa_rbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
bool isRbusEnabled();
bool isRbusInitialized();
WDMP_STATUS webpaRbusInit(const char *pComponentName);
void webpaRbus_Uninit();
rbusError_t setTraceContext(char* traceContext[]);
rbusError_t getTraceContext(char* traceContext[]);
rbusError_t clearTraceContext();
Expand Down
8 changes: 8 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ add_executable(test_libpd test_libpd.c ../source/app/libpd.c)
target_link_libraries (test_libpd -lwrp-c ${WEBPA_COMMON_LIBS} -llibparodus)
target_link_libraries (test_libpd gcov -Wl,--no-as-needed )

#-------------------------------------------------------------------------------
# test_webpa_rbus
#-------------------------------------------------------------------------------
add_test(NAME test_webpa_rbus COMMAND ${MEMORY_CHECK} ./test_webpa_rbus)
add_executable(test_webpa_rbus test_webpa_rbus.c ../source/broadband/webpa_rbus.c)
target_link_libraries (test_webpa_rbus ${WEBPA_COMMON_LIBS} -llibparodus -lrbus)
target_link_libraries (test_webpa_rbus gcov -Wl,--no-as-needed )

# #-------------------------------------------------------------------------------
# # test_webpa_adapter
# #-------------------------------------------------------------------------------
Expand Down
140 changes: 140 additions & 0 deletions tests/test_webpa_rbus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#include<stdio.h>
#include <CUnit/Basic.h>

#include "../source/include/webpa_rbus.h"
rbusHandle_t handle;

// Test case for isRbusEnabled
void test_isRbusEnabled_success()
{
WalInfo("\n**************************************************\n");
bool result = isRbusEnabled();
CU_ASSERT_TRUE(result);
}

// Test case for isRbusInitialized success
void test_isRbusInitialized_success()
{
WalInfo("\n**************************************************\n");
webpaRbusInit("componentName");
bool result = isRbusInitialized();
printf("The bool value is %d\n", result);

CU_ASSERT_TRUE(result);
webpaRbus_Uninit();
}

void test_webpaRbusInit_success()
{
WalInfo("\n**************************************************\n");
int result = webpaRbusInit("component");
CU_ASSERT_EQUAL(result, 0);
webpaRbus_Uninit();
}

//Successcase for setTraceContext
void test_setTraceContext_success()
{
WalInfo("\n**************************************************\n");
rbusError_t rc = RBUS_ERROR_BUS_ERROR;
char* traceContext[2];

//allocating moemory for each element
traceContext[0] = strdup("randomvalueone");
traceContext[1] = strdup("randomvaluetwo");
rc = setTraceContext(traceContext);
CU_ASSERT_EQUAL(0,rc);
free(traceContext[0]);
free(traceContext[1]);
}

//traceContext header NULL
void test_setTraceContext_header_NULL()
{
WalInfo("\n**************************************************\n");
rbusError_t rc = RBUS_ERROR_BUS_ERROR;
char* traceContext[2];
traceContext[0] = NULL;
traceContext[1] = NULL;
rc = setTraceContext(traceContext);
CU_ASSERT_EQUAL(1,rc);
}

//traceContext header empty
void test_setTraceContext_header_empty()
{
WalInfo("\n**************************************************\n");
rbusError_t rc = RBUS_ERROR_BUS_ERROR;
char* traceContext[2];
traceContext[0] = "";
traceContext[1] = "";
rc = setTraceContext(traceContext);
CU_ASSERT_EQUAL(1,rc);
}

void test_getTraceContext_success()
{
WalInfo("\n**************************************************\n");
rbusError_t rc = RBUS_ERROR_BUS_ERROR;
char* traceContext[2];

//allocating moemory for each element
traceContext[0] = strdup("randomvalueone");
traceContext[1] = strdup("randomvaluetwo");
rc = setTraceContext(traceContext);
CU_ASSERT_EQUAL(0,rc);

getTraceContext(traceContext);
CU_ASSERT_EQUAL(0,rc);
clearTraceContext();
}

void test_getTraceContext_empty()
{
WalInfo("\n**************************************************\n");
rbusError_t rc = RBUS_ERROR_BUS_ERROR;
char* traceContext[2];

getTraceContext(traceContext);
CU_ASSERT_EQUAL(1,rc);
}

void add_suites( CU_pSuite *suite )
{
*suite = CU_add_suite( "tests", NULL, NULL );
CU_add_test( *suite, "test isRbusEnabled_success", test_isRbusEnabled_success);
CU_add_test( *suite, "test isRbusInitialized_success", test_isRbusInitialized_success);
CU_add_test( *suite, "test webpaRbusInit_success", test_webpaRbusInit_success);
CU_add_test( *suite, "test setTraceContext_success", test_setTraceContext_success);
CU_add_test( *suite, "test setTraceContext_header_NULL", test_setTraceContext_header_NULL);
CU_add_test( *suite, "test setTraceContext_header_empty", test_setTraceContext_header_empty);
CU_add_test( *suite, "test getTraceContext_success", test_getTraceContext_success);
CU_add_test( *suite, "test getTraceContext_empty", test_getTraceContext_empty);
}


int main( int argc, char *argv[] )
{
unsigned rv = 1;
CU_pSuite suite = NULL;

(void ) argc;
(void ) argv;

if( CUE_SUCCESS == CU_initialize_registry() ) {
add_suites( &suite );

if( NULL != suite ) {
CU_basic_set_mode( CU_BRM_VERBOSE );
CU_basic_run_tests();
printf( "\n" );
CU_basic_show_failures( CU_get_failure_list() );
printf( "\n\n" );
rv = CU_get_number_of_tests_failed();
}
CU_cleanup_registry();
}
return rv;
}


0 comments on commit 51286b8

Please sign in to comment.