diff --git a/distributedschedule_lite/samgr_hal/src/sendrequest_func_test.c b/distributedschedule_lite/samgr_hal/src/sendrequest_func_test.c index 7808784c9f57c8a876a1386224bb6620ed32d000..8b1d16e6bd212b5c7888f41847991f525f4bdae8 100755 --- a/distributedschedule_lite/samgr_hal/src/sendrequest_func_test.c +++ b/distributedschedule_lite/samgr_hal/src/sendrequest_func_test.c @@ -150,7 +150,24 @@ static BOOL FEATURE_OnMessage(Feature *feature, Request *request) int32 returnCode = 0;; DemoFeature *demoFeature = (DemoFeature *)feature; demoFeature->featureCalledCount++; - demoFeature->latestRequest = (char *)request->data; + + if (demoFeature->latestRequest != NULL) { + free(demoFeature->latestRequest); + } + int requestLen; + if (request->len > 0) { + requestLen = request->len; + } else { + requestLen = strlen((char *)request->data) + 1; + } + demoFeature->latestRequest = (char *)malloc(requestLen * sizeof(char)); + if (demoFeature->latestRequest == NULL) { + TEST_FAIL(); + } + errno_t error = strcpy_s(demoFeature->latestRequest, requestLen, (char *)request->data); + if (error != EOK) { + TEST_FAIL(); + } switch (request->msgId) { case MSG_NO: @@ -180,7 +197,24 @@ static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) int32 returnCode = 0; DemoFeature *demoFeature = (DemoFeature *)feature; demoFeature->featureCalledCount++; - demoFeature->latestRequest = (char *)request->data; + + if (demoFeature->latestRequest != NULL) { + free(demoFeature->latestRequest); + } + int requestLen; + if (request->len > 0) { + requestLen = request->len; + } else { + requestLen = strlen((char *)request->data) + 1; + } + demoFeature->latestRequest = (char *)malloc(requestLen * sizeof(char)); + if (demoFeature->latestRequest == NULL) { + TEST_FAIL(); + } + errno_t error = strcpy_s(demoFeature->latestRequest, requestLen, (char *)request->data); + if (error != EOK) { + TEST_FAIL(); + } switch (request->msgId) { case MSG_NO: @@ -210,7 +244,24 @@ static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) int32 returnCode = 0; DemoFeature *demoFeature = (DemoFeature *)feature; demoFeature->featureCalledCount++; - demoFeature->latestRequest = (char *)request->data; + + if (demoFeature->latestRequest != NULL) { + free(demoFeature->latestRequest); + } + int requestLen; + if (request->len > 0) { + requestLen = request->len; + } else { + requestLen = strlen((char *)request->data) + 1; + } + demoFeature->latestRequest = (char *)malloc(requestLen * sizeof(char)); + if (demoFeature->latestRequest == NULL) { + TEST_FAIL(); + } + errno_t error = strcpy_s(demoFeature->latestRequest, requestLen, (char *)request->data); + if (error != EOK) { + TEST_FAIL(); + } switch (request->msgId) { case MSG_NO: @@ -513,7 +564,7 @@ LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0040, LEVEL2) } Request request = {.msgId = MSG_RT, .msgValue = 0}; request.len = 0; - request.data = NULL; + request.data = "I wanna async call good result!"; IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); @@ -582,7 +633,7 @@ LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0060, LEVEL2) Request request = {.msgId = MSG_NO, .msgValue = 0}; char *body = "I wanna async call good result!"; request.len = 0; - request.data = NULL; + request.data = "I wanna async call good result!"; IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); if (iUnknown == NULL) { TEST_FAIL(); diff --git a/distributedschedule_lite/samgr_hal/src/sendsharerequest_func_test.c b/distributedschedule_lite/samgr_hal/src/sendsharerequest_func_test.c index d7e1b29f1942b8cac3a04444b0450c32caf66683..daca2bd4f60ad8eb3e152cae8aaf71ee2c23a9eb 100755 --- a/distributedschedule_lite/samgr_hal/src/sendsharerequest_func_test.c +++ b/distributedschedule_lite/samgr_hal/src/sendsharerequest_func_test.c @@ -158,7 +158,24 @@ static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) int32 returnCode = 0; DemoFeature *demoFeature = (DemoFeature *)feature; demoFeature->featureCalledCount++; - demoFeature->latestRequest = (char *)request->data; + + if (demoFeature->latestRequest != NULL) { + free(demoFeature->latestRequest); + } + int requestLen; + if (request->len > 0) { + requestLen = request->len; + } else { + requestLen = strlen((char *)request->data) + 1; + } + demoFeature->latestRequest = (char *)malloc(requestLen * sizeof(char)); + if (demoFeature->latestRequest == NULL) { + TEST_FAIL(); + } + errno_t error = strcpy_s(demoFeature->latestRequest, requestLen, (char *)request->data); + if (error != EOK) { + TEST_FAIL(); + } switch (request->msgId) { case MSG_NO: @@ -188,7 +205,24 @@ static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) int32 returnCode = 0; DemoFeature *demoFeature = (DemoFeature *)feature; demoFeature->featureCalledCount++; - demoFeature->latestRequest = (char *)request->data; + + if (demoFeature->latestRequest != NULL) { + free(demoFeature->latestRequest); + } + int requestLen; + if (request->len > 0) { + requestLen = request->len; + } else { + requestLen = strlen((char *)request->data) + 1; + } + demoFeature->latestRequest = (char *)malloc(requestLen * sizeof(char)); + if (demoFeature->latestRequest == NULL) { + TEST_FAIL(); + } + errno_t error = strcpy_s(demoFeature->latestRequest, requestLen, (char *)request->data); + if (error != EOK) { + TEST_FAIL(); + } switch (request->msgId) { case MSG_NO: