Skip to content

Commit

Permalink
Additional test cases for wdmp
Browse files Browse the repository at this point in the history
  • Loading branch information
suvidh authored and suvi-123 committed Dec 4, 2023
1 parent cc82bcf commit 7645616
Showing 1 changed file with 249 additions and 7 deletions.
256 changes: 249 additions & 7 deletions tests/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ void get_req_parse ()
}
}

void test_wdmp_parse_generic_request_negative()
{
WdmpInfo("\n***************************************************** \n\n");
char *payload = NULL;
req_struct *req = NULL;

wdmp_parse_request(payload,&req);
CU_ASSERT( NULL == req);
}



void get_attr_req_parse ()
{

Expand Down Expand Up @@ -99,6 +111,9 @@ void get_attr_req_parse ()
CU_ASSERT_EQUAL( 2, paramCount );
CU_ASSERT_STRING_EQUAL( "Device.WiFi.SSID.1.Enable", reqObj->u.getReq->paramNames[0] );
CU_ASSERT_STRING_EQUAL( "Device.WiFi.SSID.1.SSID", reqObj->u.getReq->paramNames[1] );

parse_get_request(request,&reqObj,WDMP_SNMP);
WdmpInfo("Request Type : %d\n",reqObj->reqType);

if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
Expand All @@ -110,6 +125,26 @@ void get_attr_req_parse ()
}
}

void test_parse_set_request ()
{
cJSON *request = NULL;
req_struct *reqObj = NULL;
char * payload= NULL;

WdmpInfo("\n***************************************************** \n\n");

payload = "{ \"names\":[\"Device.WiFi.SSID.1.Enable\",\"Device.WiFi.SSID.1.SSID\"],\"old-cid\": 42, \"attributes\":\"notify\",\"command\": \"SET\"}";
CU_ASSERT( NULL != payload);

request = cJSON_Parse(payload);

(reqObj) = (req_struct *) malloc(sizeof(req_struct));
memset( (reqObj), 0, sizeof( req_struct ) );

parse_set_request(request,&reqObj,WDMP_SNMP);

}

void set_req_parse ()
{

Expand Down Expand Up @@ -291,6 +326,13 @@ void test_and_set_req_parse ()
CU_ASSERT_STRING_EQUAL( "14cfe2142142", reqObj->u.testSetReq->param[1].value );
CU_ASSERT_EQUAL( WDMP_STRING, reqObj->u.testSetReq->param[0].type );
CU_ASSERT_EQUAL( WDMP_STRING, reqObj->u.testSetReq->param[1].type );

payload = "{ \"names\":[\"Device.WiFi.SSID.1.Enable\",\"Device.WiFi.SSID.1.SSID\"],\"old-cid\": 42, \"attributes\":\"notify\",\"command\": \"SET\"}";

CU_ASSERT( NULL != payload);

request = cJSON_Parse(payload);
parse_set_request(request, &reqObj, WDMP_SNMP);

if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
Expand Down Expand Up @@ -516,6 +558,80 @@ void get_req_empty_notify ()
}
}

void test_replace_rows ()
{
WdmpInfo("\n***************************************************** \n\n");
req_struct *reqObj = NULL;

char *request = "{\"rows\":{\"0\":{\"DeviceName\":\"Device1\",\"MacAddress\":\"12:2:3:5:11\"},\"1\":{\"DeviceName\":\"Device2\",\"MacAddress\":\"2:1:3:5:7\"} },\"table\" : \"Device.WiFi.AccessPoint.10001.X_CISCO_COM_MacFilterTable.\",\"command\":\"REPLACE_ROWS\"}";
wdmp_parse_request(request,&reqObj);

CU_ASSERT( NULL != reqObj);
if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
}
}

void test_add_row ()
{
WdmpInfo("\n***************************************************** \n\n");
req_struct *reqObj = NULL;

char *request = "{\"row\":{\"DeviceName\":\"Device1\",\"MacAddress\":\"12:2:3:5:11\"},\"table\":\"Device.WiFi.AccessPoint.10001.X_CISCO_COM_MacFilterTable.\",\"command\":\"ADD_ROW\"}";

wdmp_parse_request(request,&reqObj);

CU_ASSERT( NULL != reqObj);
if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
}
}

void test_delete_row ()
{
WdmpInfo("\n***************************************************** \n\n");
req_struct *reqObj = NULL;

char *request = "{\"row\":\"Device.WiFi.AccessPoint.10001.X_CISCO_COM_MacFilterTable.1.\",\"command\":\"DELETE_ROW\"}";

wdmp_parse_request(request,&reqObj);

CU_ASSERT( NULL != reqObj);
if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
}
}

/*void test__invalid_payload_type()
{
WdmpInfo("\n***************************************************** \n\n");
req_struct *reqObj = NULL;
char *request = "{\"row\":\"Device.WiFi.AccessPoint.10001.X_CISCO_COM_MacFilterTable.1.\",\"command\":\"WRONG\"}";
wdmp_parse_generic_request(request,WDMP_BLOB,&reqObj);
CU_ASSERT( NULL == reqObj);
if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
}
}*/

void test__invalid_payload_type()
{
WdmpInfo("\n***************************************************** \n\n");
req_struct *reqObj = NULL;

char *request = "{\"row\":\"Device.WiFi.AccessPoint.10001.X_CISCO_COM_MacFilterTable.1.\",\"command\":\"WRONG\"}";

wdmp_parse_generic_request(request,2,&reqObj);

CU_ASSERT( NULL == reqObj);
if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
}
}

void set_req_empty_notify ()
{
WdmpInfo("\n***************************************************** \n\n");
Expand Down Expand Up @@ -1045,6 +1161,10 @@ void get_wildcard_res_form()
resObj->retStatus = (WDMP_STATUS *) malloc(sizeof(WDMP_STATUS) * 2);
resObj->retStatus[0] = WDMP_SUCCESS;
resObj->retStatus[1] = WDMP_SUCCESS;

resObj->timeSpan = (money_trace_spans *)malloc(sizeof(money_trace_spans));
resObj->timeSpan->spans = (money_trace_span *)malloc(sizeof(money_trace_span));
resObj->timeSpan->spans->name = strdup("dummy");

wdmp_form_response(resObj,&payload);

Expand All @@ -1068,6 +1188,15 @@ void get_wildcard_res_form()
free(payload);
}

void test_wdmp_form_response_negative()
{
res_struct *res = NULL;
char *payload = NULL;

wdmp_form_response(res,&payload);
CU_ASSERT( NULL != payload);
}

void get_attr_res_form()
{
res_struct *resObj = NULL;
Expand Down Expand Up @@ -1475,12 +1604,118 @@ void test_map_wdmp_status()

mapWdmpStatusToStatusMessage(status, result);

CU_ASSERT( NULL != result );

CU_ASSERT_STRING_EQUAL( "SET of CMC or CID is not supported", result );

CU_ASSERT( NULL != result );
CU_ASSERT_STRING_EQUAL( "SET of CMC or CID is not supported", result );
WdmpInfo("result : %s\n",result);

status = WDMP_ERR_INVALID_PARAMETER_TYPE;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Invalid parameter type",result);

status = WDMP_ERR_NOT_EXIST;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Parameter does not exist",result);

status = WDMP_FAILURE;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Failure",result);

status = WDMP_ERR_TIMEOUT;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Error Timeout",result);

status = WDMP_ERR_SETATTRIBUTE_REJECTED;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("SetAttribute rejected",result);

status = WDMP_ERR_REQUEST_REJECTED;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Request rejected",result);

status = WDMP_ERR_NAMESPACE_OVERLAP;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Error namespace overlap",result);

status = WDMP_ERR_UNKNOWN_COMPONENT;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Error unkown component",result);

status = WDMP_ERR_NAMESPACE_MISMATCH;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Error namespace mismatch",result);

status = WDMP_ERR_DP_COMPONENT_VERSION_MISMATCH;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Error component version mismatch",result);

status = WDMP_ERR_INVALID_PARAM;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Invalid Param",result);

status = WDMP_ERR_UNSUPPORTED_DATATYPE;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Unsupported datatype",result);

status = WDMP_ERR_WIFI_BUSY;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("WiFi is busy",result);

status = WDMP_ERR_VALUE_IS_EMPTY;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Parameter value field is not available",result);

status = WDMP_ERR_VALUE_IS_NULL;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Parameter value is null",result);

status = WDMP_ERR_DATATYPE_IS_NULL;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Parameter dataType is null",result);

status = WDMP_ERR_ATTRIBUTES_IS_NULL;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("attributes is null",result);

status = WDMP_ERR_NOTIFY_IS_NULL;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("notify is null",result);

status = WDMP_ERR_CID_TEST_FAILED;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("CID test failed",result);

status = WDMP_ERR_ATOMIC_GET_SET_FAILED;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Atomic Set failed",result);

status = WDMP_ERR_INVALID_WIFI_INDEX;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Invalid WiFi index, valid range is between 10001-10008, 10101-10108 and 10201-10208",result);

status = WDMP_ERR_INVALID_RADIO_INDEX;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Invalid Radio index, valid indexes are 10000, 10100 and 10200",result);

status = WDMP_ERR_INVALID_INPUT_PARAMETER;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Invalid Input parameter - CID/CMC value cannot be set",result);

status = WDMP_ERR_METHOD_NOT_SUPPORTED;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Method is not supported",result);

status = WDMP_ERR_SESSION_IN_PROGRESS;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Previous request is in progress",result);

status = WDMP_ERR_MAX_REQUEST;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Max SET request limit reached",result);

status = 50;
mapWdmpStatusToStatusMessage(status, result);
CU_ASSERT_STRING_EQUAL("Unknown Error",result);

if(result)
{
free(result);
Expand Down Expand Up @@ -2206,19 +2441,26 @@ void add_request_parse_suites( CU_pSuite *suite )

/* positive scenario tests */
CU_add_test( *suite, "Test Get Request Parse", get_req_parse );
CU_add_test( *suite, "Test wdmp parse generic request negative", test_wdmp_parse_generic_request_negative );
CU_add_test( *suite, "Test Get attr Request Parse", get_attr_req_parse );
CU_add_test( *suite, "Test parse_set_request", test_parse_set_request );
CU_add_test( *suite, "Test Set Request Parse", set_req_parse );
CU_add_test( *suite, "Test Set Request Parse with both value and attributes field", set_req_parse_with_attributes );
CU_add_test( *suite, "Test Set attr Request Parse", set_attr_req_parse );
CU_add_test( *suite, "Test Test and set Request Parse", test_and_set_req_parse );
CU_add_test( *suite, "Test Replace row Request Parse", replace_rows_req_parse );
CU_add_test( *suite, "Test Add row Request Parse", add_row_req_parse );
CU_add_test( *suite, "Test Delete row Request Parse", delete_row_req_parse );

/* negative scenario tests */
CU_add_test( *suite, "Test Unknown command", test_unknown_command );
CU_add_test( *suite, "Test Get Empty names", get_req_empty_names );
CU_add_test( *suite, "Test Get Empty notify", get_req_empty_notify );
CU_add_test( *suite, "Test replace rows", test_replace_rows );
CU_add_test( *suite, "Test add rows", test_add_row );
CU_add_test( *suite, "Test delete rows", test_delete_row );
CU_add_test( *suite, "test invalid payload type", test__invalid_payload_type );

CU_add_test( *suite, "Test Set Empty notify", set_req_empty_notify );
CU_add_test( *suite, "Test and Set without cid", test_and_set_without_cid );
CU_add_test( *suite, "Test Empty Test and Set Request", empty_test_and_set );
Expand All @@ -2227,15 +2469,15 @@ void add_request_parse_suites( CU_pSuite *suite )
CU_add_test( *suite, "Test Get large parameter name Request", get_large_parameter_req_parse );
CU_add_test( *suite, "Test Set large parameter name and value Request", set_large_parameter_req_parse );
CU_add_test( *suite, "Test large parameter table Request", test_large_parameter_table_request );

}

void add_response_form_suites ( CU_pSuite *suite )
{
*suite = CU_add_suite( "wdmp-c Response forming tests", NULL, NULL );

CU_add_test( *suite, "Get Response Form", get_res_form );
CU_add_test( *suite, "Get wild card Response Form", get_wildcard_res_form );
CU_add_test( *suite, "test wdmp form response negative", get_wildcard_res_form );
CU_add_test( *suite, "Get wild card Response Form", test_wdmp_form_response_negative );
CU_add_test( *suite, "Get attributes Response Form", get_attr_res_form );
CU_add_test( *suite, "Set Response Form", set_res_form );
CU_add_test( *suite, "Set attributes Response Form", set_attr_res_form );
Expand Down

0 comments on commit 7645616

Please sign in to comment.