From 73076ecbcb744f529e82bd178a3118ca55a9e762 Mon Sep 17 00:00:00 2001 From: suvidh Date: Thu, 30 Nov 2023 18:45:58 +0530 Subject: [PATCH] Additional test cases for wdmp --- tests/simple.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 5 deletions(-) diff --git a/tests/simple.c b/tests/simple.c index 1740420..1e253af 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -99,6 +99,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 ); @@ -110,6 +113,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 () { @@ -291,6 +314,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 ); @@ -1475,12 +1505,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); @@ -2207,6 +2343,7 @@ 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 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 ); @@ -2227,7 +2364,6 @@ 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 )