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 865e448
Showing 1 changed file with 223 additions and 16 deletions.
239 changes: 223 additions & 16 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()

Check warning on line 67 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L67

Added line #L67 was not covered by tests
{
WdmpInfo("\n***************************************************** \n\n");
char *payload = NULL;
req_struct *req = NULL;

Check warning on line 71 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L70-L71

Added lines #L70 - L71 were not covered by tests

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

Check warning on line 74 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L73-L74

Added lines #L73 - L74 were not covered by tests
}



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);

Check warning on line 116 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L115-L116

Added lines #L115 - L116 were not covered by tests

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

void test_parse_set_request ()

Check warning on line 128 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L128

Added line #L128 was not covered by tests
{
cJSON *request = NULL;
req_struct *reqObj = NULL;
char * payload= NULL;

Check warning on line 132 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L130-L132

Added lines #L130 - L132 were not covered by tests

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

Check warning on line 134 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L134

Added line #L134 was not covered by tests

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

Check warning on line 137 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L136-L137

Added lines #L136 - L137 were not covered by tests

request = cJSON_Parse(payload);

Check warning on line 139 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L139

Added line #L139 was not covered by tests

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

Check warning on line 142 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L141-L142

Added lines #L141 - L142 were not covered by tests

parse_set_request(request,&reqObj,WDMP_SNMP);

Check warning on line 144 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L144

Added line #L144 was not covered by tests

}

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\"}";

Check warning on line 330 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L330

Added line #L330 was not covered by tests

CU_ASSERT( NULL != payload);

Check warning on line 332 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L332

Added line #L332 was not covered by tests

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

Check warning on line 335 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L334-L335

Added lines #L334 - L335 were not covered by tests

if (NULL != reqObj) {
wdmp_free_req_struct(reqObj );
Expand Down Expand Up @@ -516,6 +558,50 @@ 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 set_req_empty_notify ()
{
WdmpInfo("\n***************************************************** \n\n");
Expand Down Expand Up @@ -1068,6 +1154,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 +1570,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 );

Check warning on line 1574 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1573-L1574

Added lines #L1573 - L1574 were not covered by tests
WdmpInfo("result : %s\n",result);

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

Check warning on line 1579 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1577-L1579

Added lines #L1577 - L1579 were not covered by tests

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

Check warning on line 1583 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1581-L1583

Added lines #L1581 - L1583 were not covered by tests

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

Check warning on line 1587 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1585-L1587

Added lines #L1585 - L1587 were not covered by tests

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

Check warning on line 1591 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1589-L1591

Added lines #L1589 - L1591 were not covered by tests

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

Check warning on line 1595 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1593-L1595

Added lines #L1593 - L1595 were not covered by tests

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

Check warning on line 1599 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1597-L1599

Added lines #L1597 - L1599 were not covered by tests

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

Check warning on line 1603 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1601-L1603

Added lines #L1601 - L1603 were not covered by tests

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

Check warning on line 1607 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1605-L1607

Added lines #L1605 - L1607 were not covered by tests

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

Check warning on line 1611 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1609-L1611

Added lines #L1609 - L1611 were not covered by tests

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

Check warning on line 1615 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1613-L1615

Added lines #L1613 - L1615 were not covered by tests

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

Check warning on line 1619 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1617-L1619

Added lines #L1617 - L1619 were not covered by tests

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

Check warning on line 1623 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1621-L1623

Added lines #L1621 - L1623 were not covered by tests

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

Check warning on line 1627 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1625-L1627

Added lines #L1625 - L1627 were not covered by tests

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

Check warning on line 1631 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1629-L1631

Added lines #L1629 - L1631 were not covered by tests

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

Check warning on line 1635 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1633-L1635

Added lines #L1633 - L1635 were not covered by tests

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

Check warning on line 1639 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1637-L1639

Added lines #L1637 - L1639 were not covered by tests

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

Check warning on line 1643 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1641-L1643

Added lines #L1641 - L1643 were not covered by tests

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

Check warning on line 1647 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1645-L1647

Added lines #L1645 - L1647 were not covered by tests

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

Check warning on line 1651 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1649-L1651

Added lines #L1649 - L1651 were not covered by tests

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

Check warning on line 1655 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1653-L1655

Added lines #L1653 - L1655 were not covered by tests

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);

Check warning on line 1659 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1657-L1659

Added lines #L1657 - L1659 were not covered by tests

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

Check warning on line 1663 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1661-L1663

Added lines #L1661 - L1663 were not covered by tests

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

Check warning on line 1667 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1665-L1667

Added lines #L1665 - L1667 were not covered by tests

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

Check warning on line 1671 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1669-L1671

Added lines #L1669 - L1671 were not covered by tests

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

Check warning on line 1675 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1673-L1675

Added lines #L1673 - L1675 were not covered by tests

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

Check warning on line 1679 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1677-L1679

Added lines #L1677 - L1679 were not covered by tests

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

Check warning on line 1683 in tests/simple.c

View check run for this annotation

Codecov / codecov/patch

tests/simple.c#L1681-L1683

Added lines #L1681 - L1683 were not covered by tests

if(result)
{
free(result);
Expand Down Expand Up @@ -2205,38 +2406,44 @@ void add_request_parse_suites( CU_pSuite *suite )
*suite = CU_add_suite( "wdmp-c request parsing tests", NULL, NULL );

/* positive scenario tests */
CU_add_test( *suite, "Test Get Request Parse", get_req_parse );
/*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 Set Empty notify", set_req_empty_notify );
// 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 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 );
CU_add_test( *suite, "Test Set Req NULL Param value", set_req_null_param_value );
CU_add_test( *suite, "Test Set Req empty value field", set_req_value_field_empty );
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, "Get attributes Response Form", get_attr_res_form );
/*CU_add_test( *suite, "Get Response Form", get_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 );
CU_add_test( *suite, "Test and Set Response Form", test_and_set_res_form );
Expand All @@ -2259,7 +2466,7 @@ void add_response_form_suites ( CU_pSuite *suite )
CU_add_test( *suite, "Negative Replace rows Response Form", neg_replace_rows_res_form );
CU_add_test( *suite, "Negative Delete row Response Form", neg_delete_row_res_form );
CU_add_test( *suite, "Test unknown request type", test_unknown_req_type);
}
*/}

/*----------------------------------------------------------------------------*/
/* External Functions */
Expand Down

0 comments on commit 865e448

Please sign in to comment.