[IOT-3022] 27/24527/22
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Fri, 30 Mar 2018 09:02:00 +0000 (12:02 +0300)
committerAleksey Volkov <a.volkov@samsung.com>
Wed, 18 Apr 2018 13:13:19 +0000 (13:13 +0000)
a) cloud resource unittests
b) amacl resource make cbor fix

Change-Id: Ib4d56f3105e060656d52f5b0b498ae188fe42c03
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
resource/csdk/security/provisioning/include/cloud/auth.h
resource/csdk/security/provisioning/include/cloud/occloudprovisioning.h
resource/csdk/security/provisioning/src/cloud/auth.c
resource/csdk/security/provisioning/src/cloud/cloudresource.c
resource/csdk/security/provisioning/src/cloud/config.c
resource/csdk/security/provisioning/unittest/SConscript
resource/csdk/security/provisioning/unittest/cloudresource.cpp
resource/csdk/security/src/amaclresource.c

index 26bb72a..45fe1b2 100644 (file)
@@ -115,8 +115,9 @@ OCStackResult OCCloudSignOut(OicCloud_t *cloud);
 /**
  * Session free function
  * @param[in] cloud
+ * @return  OicCloud_t * pointer to next
  */
-void FreeCloud(OicCloud_t *cloud);
+OicCloud_t * FreeCloud(OicCloud_t *cloud);
 
 /**
  * Cloud to CBOR
index 9b4cc9c..dc4df9d 100644 (file)
@@ -61,15 +61,15 @@ typedef struct {
 typedef struct CloudData
 {
     void *ctx;                                  /**< Pointer to user context.**/
-    const OCProvisionDev_t *targetDev;          /**< Pointer to OCProvisionDev_t.**/
+    OCProvisionDev_t *targetDev;          /**< Pointer to OCProvisionDev_t.**/
     OicSecCred_t *credInfo;                     /**< Array of pointers to OicSecCred_t.**/
     OCProvisionResultCB resultCallback;         /**< Pointer to result callback.**/
     OCProvisionResult_t *resArr;                /**< Result array.**/
     int numOfResults;                           /**< Number of results in result array.**/
-    const char* cloudURI;                       /**< Cloud URI.**/
-    const char* oauthProvider;                  /**< Authorisation provider name.**/
-    const char* accessToken;                    /**< Access token that can be validated by the Cloud.**/
-    const char* sid;                            /**< Cloud UUID.**/
+    char* cloudURI;                       /**< Cloud URI.**/
+    char* oauthProvider;                  /**< Authorisation provider name.**/
+    char* accessToken;                    /**< Access token that can be validated by the Cloud.**/
+    char* sid;                            /**< Cloud UUID.**/
 } CloudData_t;
 
 /**
index 73b7e73..4d60756 100644 (file)
@@ -75,27 +75,39 @@ void SessionFree(session_t *session)
         OIC_LOG_V(ERROR, TAG, "%s: session is NULL", __func__);
         return;
     }
-
-    OICFree(session->accessToken);
-    OICFree(session->refreshToken);
+    if (session->accessToken)
+    {
+        memset(session->accessToken, 0, strlen(session->accessToken));
+        OICFree(session->accessToken);
+        session->accessToken = NULL;
+    }
+    if (session->refreshToken)
+    {
+        memset(session->refreshToken, 0, strlen(session->refreshToken));
+        OICFree(session->refreshToken);
+        session->refreshToken = NULL;
+    }
     OICFree(session->uid);
+    session->uid = NULL;
 #if !defined(__MANDATORY__)
     OICFree(session->redirectUri);
+    session->redirectUri = NULL;
 #endif // __MANDATORY__
+    OICFree(session);
+    session = NULL;
 }
 
-void FreeCloud(OicCloud_t *cloud)
+OicCloud_t *FreeCloud(OicCloud_t *cloud)
 {
     if (!cloud)
     {
-        return;
+        return NULL;
     }
-
     cloud->stat = OC_CLOUD_PROV;
 
-
     if (cloud->pid)
     {
+        OIC_LOG_V(DEBUG, TAG, "oc_thread_waiting for cloud %s/%s", cloud->cis, cloud->apn);
         OCThreadResult_t res = oc_thread_wait(cloud->pid);
 
         if (OC_THREAD_SUCCESS != res)
@@ -109,24 +121,32 @@ void FreeCloud(OicCloud_t *cloud)
         {
             OIC_LOG_V(ERROR, TAG, "oc_thread_free failed - error %u", res);
         }
+        OIC_LOG_V(DEBUG, TAG, "thread for cloud %s/%s is stopped", cloud->cis, cloud->apn);
     }
+    cloud->pid = 0;
 
+    OicCloud_t *ret = cloud->next;
+    cloud->next = NULL;
     OICFree(cloud->apn);
+    cloud->apn = NULL;
     OICFree(cloud->cis);
+    cloud->cis = NULL;
     OICFree(cloud->at);
+    cloud->at = NULL;
     OICFree(cloud->sid);
+    cloud->sid = NULL;
 
-    if (cloud->session)
-    {
-        SessionFree(cloud->session);
-    }
+    SessionFree(cloud->session);
 
     OICFree(cloud);
+    cloud = NULL;
+
+    return ret;
 }
 
 bool CloudFind(OicCloud_t *list, const OicCloud_t *cloud)
 {
-    if (!list || !cloud)
+    if (!list || !cloud || !cloud->cis)
     {
         return false;
     }
@@ -134,7 +154,7 @@ bool CloudFind(OicCloud_t *list, const OicCloud_t *cloud)
     OicCloud_t *p1 = NULL, *p2 = NULL;
     LL_FOREACH_SAFE(list, p1, p2)
     {
-        if (0 == strcmp(p1->cis, cloud->cis))
+        if (p1 && p1->cis && 0 == strcmp(p1->cis, cloud->cis))
         {
             return true;
         }
@@ -406,6 +426,8 @@ OCStackResult CBORPayloadToCloud(const uint8_t *cborPayload, size_t size, OicClo
             continue;
         }
 
+        OICFree(mainSecName);
+
         CborValue cloudArray = { NULL, NULL, 0, 0, 0, 0 };
         cborError = cbor_value_enter_container(&rootMap, &cloudArray);
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborError, "Failed find cloud array");
@@ -603,10 +625,10 @@ OCStackResult OCCloudTokenRefresh(OicCloud_t *cloud)
     OCStackResult ret = OC_STACK_OK;
 
     VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_INVALID_PARAM);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_DELETE_TRANSACTION);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->uid, ERROR, OC_STACK_DELETE_TRANSACTION);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->refreshToken, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->uid, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->refreshToken, ERROR, OC_STACK_INVALID_PARAM);
 
     char *deviceId = getDeviceId();
     VERIFY_NON_NULL_RET(deviceId, TAG, "Can't get the device id", OC_STACK_ERROR);
@@ -620,6 +642,8 @@ OCStackResult OCCloudTokenRefresh(OicCloud_t *cloud)
     OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
     OCRepPayloadSetPropString(payload, OC_RSRVD_REFRESH_TOKEN, cloud->session->refreshToken);
 
+    OICFree(deviceId);
+
     OCCallbackData cbData =
     {
         .context = (void *)cloud,
@@ -627,10 +651,17 @@ OCStackResult OCCloudTokenRefresh(OicCloud_t *cloud)
         .cd = NULL
     };
 
-    ret = OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
-                       CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+    if (OC_CLOUD_TOKEN_REFRESH4 < cloud->stat)
+    {
+        OIC_LOG_V(DEBUG, TAG, "%s: token refresh cloud: %s break", __func__, cloud->apn);
+    }
+    else
+    {
+        ret = OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
+                           CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
+    }
 
-    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT: %d", __func__, (int)ret);
 
     return ret;
 }
@@ -640,7 +671,7 @@ static void *CloudTokenRefresh(void *data)
     OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
 
     OicCloud_t *cloud = (OicCloud_t *)data;
-    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, NULL);
+    VERIFY_NOT_NULL(TAG, cloud, ERROR);
 
     OIC_LOG_V(INFO, TAG, "%s: cloud(%s) refresh start", __func__, cloud->cis);
 
@@ -648,16 +679,20 @@ static void *CloudTokenRefresh(void *data)
 
     while (OC_CLOUD_TOKEN_REFRESH4 > cloud->stat)
     {
-        struct timespec timeout;
-        timeout.tv_sec  = cloud->session->expireSin - TIME_OUT_SHIFT;
-        timeout.tv_nsec = 0;
+
+        long ts_nsec = cloud->session->expireSin - TIME_OUT_SHIFT;
+        if (2 < ts_nsec)
+        {
+            ts_nsec = 1;
+        }
+        struct timespec timeout = {ts_nsec / 1000000000, ts_nsec % 1000000000};
 
         nanosleep(&timeout, NULL);
 
         if (OC_STACK_OK != OCCloudTokenRefresh(cloud))
         {
             OIC_LOG_V(ERROR, TAG, "%s: token refresh", __func__);
-            cloud->stat++;
+            cloud->stat = (CloudStatus)(cloud->stat + 1);
         }
     }
 
@@ -666,7 +701,7 @@ static void *CloudTokenRefresh(void *data)
         SessionFree(cloud->session);
         cloud->session = NULL;
     }
-
+exit:
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
     return NULL;
 }
@@ -790,25 +825,27 @@ static OCStackResult CloudSign(OicCloud_t *cloud, bool signIn)
     OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
 
     VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_INVALID_PARAM);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_DELETE_TRANSACTION);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->uid, ERROR, OC_STACK_DELETE_TRANSACTION);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->accessToken, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->uid, ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud->session->accessToken, ERROR, OC_STACK_INVALID_PARAM);
 
     OCStackResult ret = OC_STACK_OK;
     char uri[MAX_URI_QUERY] = { 0 };
 
     char *deviceId = getDeviceId();
-    VERIFY_NOT_NULL_RETURN(TAG, deviceId, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, deviceId, ERROR, OC_STACK_INVALID_PARAM);
 
     OCRepPayload *payload = OCRepPayloadCreate();
-    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, OC_STACK_INVALID_PARAM);
 
     OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, deviceId);
     OCRepPayloadSetPropString(payload, OC_RSRVD_USER_UUID, cloud->session->uid);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ACCESS_TOKEN, cloud->session->accessToken);
     OCRepPayloadSetPropBool(payload, OC_RSRVD_LOGIN, signIn);
 
+    OICFree(deviceId);
+
     snprintf(uri, MAX_URI_QUERY, "%s/%s", cloud->cis, OC_RSRVD_ACCOUNT_SESSION_URI);
 
     OCCallbackData cbData =
@@ -851,11 +888,12 @@ OCStackResult OCCloudSignOut(OicCloud_t *cloud)
  * @param[in] session session data
  * @return  OCStackResult application result
  */
-static bool SessionParsePayload(OCRepPayload *payload, session_t *session)
+static bool SessionParsePayload(const OCRepPayload *payload, session_t *session)
 {
     OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
     bool ret = true;
-    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, payload, ERROR, false);
+    VERIFY_NOT_NULL_RETURN(TAG, session, ERROR, false);
 
     if (!OCRepPayloadGetPropString(payload, OC_RSRVD_ACCESS_TOKEN,
                                    &session->accessToken))
@@ -932,8 +970,7 @@ static OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
 
     if (NULL != cloud->session)
     {
-        OIC_LOG_V(ERROR, TAG, "%s: session is run", __func__);
-        cloud->stat = OC_CLOUD_ERROR_CHECK_SESSION;
+        OIC_LOG_V(WARNING, TAG, "%s: session is running", __func__);
         goto exit;
     }
 
@@ -1004,6 +1041,8 @@ OCStackResult OCCloudSignUp(OicCloud_t *cloud)
 
     OIC_LOG_V(INFO, TAG, "%s: cloud(%s) sign in", __func__, cloud->cis);
 
+    OICFree(deviceId);
+
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
 
     return ret;
index deddff9..b6ae73b 100644 (file)
@@ -94,23 +94,21 @@ static bool ValidCloud(OicCloud_t *cloud)
 static void DeleteCloudList(OicCloud_t *clouds)
 {
     OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
-
     if (!clouds)
     {
         OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__);
-        return;
     }
-
-    OicCloud_t *p1 = NULL, *p2 = NULL;
-    oc_mutex_lock(gCloudMutex);
-    LL_FOREACH_SAFE(clouds, p1, p2)
+    else
     {
-        LL_DELETE(clouds, p1);
-        FreeCloud(p1);
-        p1 = NULL;
+        oc_mutex_lock(gCloudMutex);
+        OicCloud_t *p1 = clouds->next;
+        while(p1)
+        {
+            p1 = FreeCloud(p1);
+        }
+        FreeCloud(clouds);
+        oc_mutex_unlock(gCloudMutex);
     }
-    oc_mutex_unlock(gCloudMutex);
-
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
 }
 
@@ -288,7 +286,7 @@ static OCEntityHandlerResult HandleCloudGetRequest(OCEntityHandlerRequest *ehReq
 
     payload = (OCRepPayload *)ehRequest->payload;
 
-    if (!payload || !OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &cloud->cis))
+    if (!payload || !cloud->cis || !OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &cloud->cis))
     {
         OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_CIS);
         p1 = gCloud;
@@ -306,18 +304,16 @@ static OCEntityHandlerResult HandleCloudGetRequest(OCEntityHandlerRequest *ehReq
 
     LL_FOREACH_SAFE(gCloud, p1, p2)
     {
-        if (0 == strcmp(p1->cis, cloud->cis))
+        if (p1 && p1->cis && 0 == strcmp(p1->cis, cloud->cis))
         {
             ehRet = OC_EH_OK;
             break;
         }
     }
 exit:
-    payload = CreateCloudGetPayload(p1);
-
-    response.requestHandle = ehRequest->requestHandle;
+    response.requestHandle = ehRequest ? ehRequest->requestHandle : NULL;
     response.ehResult = payload ? ehRet : OC_EH_INTERNAL_SERVER_ERROR;
-    response.payload = (OCPayload *)payload;
+    response.payload = (OCPayload *)CreateCloudGetPayload(p1);
     response.payload->type = PAYLOAD_TYPE_REPRESENTATION;
     response.persistentBufferFlag = 0;
 
@@ -327,6 +323,7 @@ exit:
         ehRet = OC_EH_ERROR;
     }
 
+    OCPayloadDestroy((OCPayload *)response.payload);
     FreeCloud(cloud);
 
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
@@ -361,7 +358,7 @@ static OCEntityHandlerResult HandleCloudDeleteRequest(OCEntityHandlerRequest *eh
 
     payload = (OCRepPayload *)ehRequest->payload;
 
-    if (!OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &cloud->cis))
+    if (!cloud->cis || !OCRepPayloadGetPropString(payload, OC_CLOUD_PROVISIONING_CIS, &cloud->cis))
     {
         OIC_LOG_V(ERROR, TAG, "%s: Can't get: %s", __func__, OC_CLOUD_PROVISIONING_CIS);
         goto exit;
@@ -377,7 +374,7 @@ static OCEntityHandlerResult HandleCloudDeleteRequest(OCEntityHandlerRequest *eh
 
     LL_FOREACH_SAFE(gCloud, p1, p2)
     {
-        if (0 == strcmp(p1->cis, cloud->cis))
+        if (p1 && p1->cis && 0 == strcmp(p1->cis, cloud->cis))
         {
             OIC_LOG_V(INFO, TAG, "%s: delete cloud: %s", __func__, p1->cis);
             p1->stat = OC_CLOUD_EXIT;
@@ -388,7 +385,7 @@ static OCEntityHandlerResult HandleCloudDeleteRequest(OCEntityHandlerRequest *eh
         }
     }
 exit:
-    response.requestHandle = ehRequest->requestHandle;
+    response.requestHandle = ehRequest ? ehRequest->requestHandle : NULL;
     response.ehResult = ehRet;
     response.payload = (OCPayload *)OCRepPayloadCreate();
     response.payload->type = PAYLOAD_TYPE_REPRESENTATION;
index 2e99469..117d745 100644 (file)
@@ -49,6 +49,7 @@ OCStackResult OCProvisionCloudConfig(void *ctx,
     OIC_LOG_V(INFO, TAG, "IN %s", __func__);
     OCStackResult ret = OC_STACK_ERROR;
     char *query = NULL;
+    OCDoHandle lHandle = NULL;
 
     VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR,  OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, pDev, ERROR,  OC_STACK_INVALID_PARAM);
@@ -59,6 +60,8 @@ OCStackResult OCProvisionCloudConfig(void *ctx,
     VERIFY_NOT_NULL_RETURN(TAG, cloud->sid, ERROR,  OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR,  OC_STACK_INVALID_PARAM);
 
+    OCCallbackData cbData =  {.context = ctx, .cb = resultCallback, .cd = NULL};
+
     OCRepPayload *payload = OCRepPayloadCreate();
     VERIFY_NOT_NULL(TAG, payload, ERROR);
 
@@ -67,7 +70,7 @@ OCStackResult OCProvisionCloudConfig(void *ctx,
     OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_AT, cloud->at);
     OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_SID, cloud->sid);
 
-    query = OICCalloc(1, DEFAULT_URI_LENGTH);
+    query = (char *)OICCalloc(1, DEFAULT_URI_LENGTH);
     VERIFY_NOT_NULL(TAG, query, ERROR);
 
     VERIFY_SUCCESS(TAG, PMGenerateQuery(true,
@@ -76,8 +79,6 @@ OCStackResult OCProvisionCloudConfig(void *ctx,
                                         pDev->connType,
                                         query, DEFAULT_URI_LENGTH, OIC_RSRC_CLOUDCONF_URI), ERROR);
 
-    OCCallbackData cbData =  {.context = ctx, .cb = resultCallback, .cd = NULL};
-    OCDoHandle lHandle = NULL;
 
     ret = OCDoResource(&lHandle, OC_REST_POST, query,
                        &pDev->endpoint, (OCPayload *)payload,
@@ -172,6 +173,7 @@ OCStackResult OCGetCloudStatusRequest(void *ctx,
     OIC_LOG_V(INFO, TAG, "IN %s", __func__);
     OCStackResult ret = OC_STACK_ERROR;
     char *query = NULL;
+    OCDoHandle lHandle = NULL;
 
     VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR,  OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, pDev, ERROR,  OC_STACK_INVALID_PARAM);
@@ -179,7 +181,9 @@ OCStackResult OCGetCloudStatusRequest(void *ctx,
     VERIFY_NOT_NULL_RETURN(TAG, cloud->cis, ERROR,  OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR,  OC_STACK_INVALID_PARAM);
 
-    query = OICCalloc(1, DEFAULT_URI_LENGTH);
+    OCCallbackData cbData =  {.context = (void *)resultCallback, .cb = handleCloudStatusResponse, .cd = NULL};
+
+    query = (char *)OICCalloc(1, DEFAULT_URI_LENGTH);
     VERIFY_NOT_NULL(TAG, query, ERROR);
 
     VERIFY_SUCCESS(TAG, PMGenerateQuery(true,
@@ -188,9 +192,6 @@ OCStackResult OCGetCloudStatusRequest(void *ctx,
                                         pDev->connType,
                                         query, DEFAULT_URI_LENGTH, OIC_RSRC_CLOUDCONF_URI), ERROR);
 
-    OCCallbackData cbData =  {.context = resultCallback, .cb = handleCloudStatusResponse, .cd = NULL};
-    OCDoHandle lHandle = NULL;
-
     ret = OCDoResource(&lHandle, OC_REST_GET, query,
                        &pDev->endpoint, NULL,
                        pDev->connType, OC_HIGH_QOS, &cbData, NULL, 0);
@@ -218,15 +219,19 @@ static OCStackApplicationResult OCRemoveCloudConfigCB(void *ctx, OCDoHandle hand
     const OCProvisionDev_t *pDev = NULL;
     const char *sid = NULL;
     char *buf = NULL;
+    OCDoHandle lHandle = NULL;
+    int res = 0, bufLen = 0;
 
-    VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR,  OC_STACK_INVALID_PARAM);
-    VERIFY_NOT_NULL_RETURN(TAG, clientResponse, ERROR,  OC_STACK_INVALID_PARAM);
+    VERIFY_NOT_NULL_RETURN(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
+    VERIFY_NOT_NULL_RETURN(TAG, clientResponse, ERROR, OC_STACK_DELETE_TRANSACTION);
 
     VERIFY_SUCCESS_RETURN(TAG, (OC_STACK_RESOURCE_CHANGED == clientResponse->result), ERROR,
-                          OC_STACK_INVALID_PARAM);
+                          OC_STACK_DELETE_TRANSACTION);
 
     Data_t *data = (Data_t *) ctx;
-    VERIFY_SUCCESS_RETURN(TAG, (CLOUD_TYPE == data->type), ERROR, OC_STACK_INVALID_PARAM);
+    VERIFY_SUCCESS_RETURN(TAG, (CLOUD_TYPE == data->type), ERROR, OC_STACK_DELETE_TRANSACTION);
+
+    OCCallbackData cbData =  {.context = ctx, .cb = ProvisionCB, .cd = NULL};
 
     CloudData_t *cloudData = (CloudData_t *) (data->ctx);
     VERIFY_NOT_NULL(TAG, cloudData, ERROR);
@@ -235,14 +240,14 @@ static OCStackApplicationResult OCRemoveCloudConfigCB(void *ctx, OCDoHandle hand
     sid = cloudData->sid;
     VERIFY_NOT_NULL(TAG, sid, ERROR);
 
-    query = OICCalloc(1, DEFAULT_URI_LENGTH);
+    query = (char *)OICCalloc(1, DEFAULT_URI_LENGTH);
     VERIFY_NOT_NULL(TAG, query, ERROR);
 
-    int bufLen = strlen(OIC_RSRC_ACL2_URI) + strlen("?Subject=") + strlen(sid) + 1;
+    bufLen = strlen(OIC_RSRC_ACL2_URI) + strlen("?Subject=") + strlen(sid) + 1;
     buf = (char *)OICCalloc(1, bufLen);
     VERIFY_NOT_NULL(TAG, buf, ERROR);
 
-    int res = snprintf(buf, bufLen, "%s%s%s", OIC_RSRC_ACL2_URI, "?Subject=", sid);
+    res = snprintf(buf, bufLen, "%s%s%s", OIC_RSRC_ACL2_URI, "?Subject=", sid);
     if (res + 1 != bufLen)
     {
         OIC_LOG_V(ERROR, TAG, "%s: error assembling query", __func__);
@@ -255,20 +260,22 @@ static OCStackApplicationResult OCRemoveCloudConfigCB(void *ctx, OCDoHandle hand
                                         pDev->connType,
                                         query, DEFAULT_URI_LENGTH, buf), ERROR);
 
-    OCCallbackData cbData =  {.context = ctx, .cb = ProvisionCB, .cd = NULL};
-    OCDoHandle lHandle = NULL;
-
     ret = OCDoResource(&lHandle, OC_REST_DELETE, query,
                        &pDev->endpoint, NULL,
                        pDev->connType, OC_HIGH_QOS, &cbData, NULL, 0);
-    OIC_LOG_V(DEBUG, TAG, "DELETE:%s ret:%d", query, ret);
+    OIC_LOG_V(DEBUG, TAG, "%s:query: %s, do resource return: %d", __func__, query, (int)ret);
 exit:
+    if (ret == OC_STACK_ERROR)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s exit by error: %d", query, (int)ret);
+    }
+
     OICFree(query);
     OICFree(buf);
 
     OIC_LOG_V(INFO, TAG, "OUT %s", __func__);
 
-    return ret;
+    return OC_STACK_DELETE_TRANSACTION;
 }
 
 OCStackResult OCRemoveCloudConfig(void *ctx,
@@ -280,10 +287,11 @@ OCStackResult OCRemoveCloudConfig(void *ctx,
 
     VERIFY_NOT_NULL_RETURN(TAG, pDev, ERROR,  OC_STACK_INVALID_PARAM);
     VERIFY_NOT_NULL_RETURN(TAG, resultCallback, ERROR,  OC_STACK_INVALID_CALLBACK);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR,  OC_STACK_INVALID_CALLBACK);
+    VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR,  OC_STACK_INVALID_PARAM);
 
     OCStackResult ret = OC_STACK_ERROR;
     Data_t *data = NULL;
+    CloudData_t *cloudData =  NULL;
 
     OicUuid_t provTooldeviceID =   {{0,}};
     if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
@@ -296,11 +304,11 @@ OCStackResult OCRemoveCloudConfig(void *ctx,
     VERIFY_NOT_NULL(TAG, data, ERROR);
     data->type = CLOUD_TYPE;
 
-    CloudData_t *cloudData = (CloudData_t *)OICCalloc(1, sizeof(CloudData_t));
+    cloudData = (CloudData_t *)OICCalloc(1, sizeof(CloudData_t));
     VERIFY_NOT_NULL(TAG, cloudData, ERROR);
     data->ctx = cloudData;
     cloudData->ctx = ctx;
-    cloudData->targetDev = pDev;
+    cloudData->targetDev = (OCProvisionDev_t *)pDev;
     cloudData->resultCallback = resultCallback;
     cloudData->numOfResults = 0;
     cloudData->credInfo = NULL;
index eb550bb..cc74fb7 100644 (file)
@@ -171,6 +171,8 @@ sptest_env.PrependUnique(CPPPATH=[
     '../../../connectivity/inc/pkix',
     '../../../connectivity/common/inc',
     '../../../connectivity/api',
+    '#resource/csdk/security/include',
+    '#resource/csdk/security/include/experimental',
     '#resource/csdk/security/provisioning/src/cloud',
     '#resource/csdk/security/provisioning/include/cloud/'
 ])
index 69b9007..521df66 100644 (file)
 extern "C" {
 #include "octypes.h"
 #include "psinterface.h"
+
+#include "deviceonboardingstate.h"
+#include "srmutility.h"
+#include "experimental/logger.h"
+#include "srmresourcestrings.h"
+#include "aclresource.h"
+#include "amaclresource.h"
+#include "credresource.h"
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+#include "crlresource.h"
+#endif /* (__WITH_DTLS__) || (__WITH_TLS__) */
+#include "experimental/doxmresource.h"
+#include "pstatresource.h"
 }
 
 #include "../src/cloud/cloudresource.c"
@@ -31,14 +44,30 @@ extern "C" {
 #ifdef TAG
 #undef TAG
 #endif
+
+#include "../src/cloud/config.c"
+
+#ifdef TAG
+#undef TAG
+#endif
+
+#include "../src/cloud/auth.c"
+
+#ifdef TAG
+#undef TAG
+#endif
+
 #define TAG  "CLOUD_UNITTEST"
 
+#define SVR_DB_FILE_NAME "oic_svr_db_client.dat"
+#define PM_DB_FILE_NAME "test.db"
 #define STR_LEN 512
 static const char *sample =
     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!:/";
 
 void sessionInit(session_t *ses)
 {
+    ses->expireSin = 1;
     ses->accessToken = (char *)OICCalloc(STR_LEN, sizeof(char));
     ses->refreshToken = (char *)OICCalloc(STR_LEN, sizeof(char));
     ses->uid = (char *)OICCalloc(STR_LEN, sizeof(char));
@@ -76,25 +105,50 @@ OicCloud_t *getCloud()
         cloud->sid[i] = sample[rand() % STR_LEN];
     }
 
-    cloud->session = (session_t *)OICCalloc(STR_LEN, sizeof(session_t));
+    cloud->session = (session_t *)OICCalloc(1, sizeof(session_t));
     sessionInit(cloud->session);
 
+    cloud->stat = OC_CLOUD_OK;
+
+    cloud->pid = 0;
+
     return cloud;
 }
 
-TEST(CloudResourceTest, InitCloudResource)
+static FILE *fopen_prvnMng(const char *path, const char *mode)
 {
-    EXPECT_EQ(OC_STACK_OK, InitCloudResource());
+    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
+    {
+        return fopen(SVR_DB_FILE_NAME, mode);
+    }
+    OIC_LOG_V(DEBUG, TAG, "use db: %s", path);
+    return fopen(path, mode);
 }
 
-TEST(CloudResourceTest, DeInitCloudResource)
+TEST(CloudResourceTest, Init)
 {
-    EXPECT_EQ(OC_STACK_OK, DeInitCloudResource());
+    static OCPersistentStorage gPst;
+    OCStackResult result = OC_STACK_ERROR;
+
+#ifdef HAVE_UNISTD_H
+    EXPECT_EQ(0, access(SVR_DB_FILE_NAME, F_OK));
+#endif // HAVE_UNISTD_H
+    gPst.open = fopen_prvnMng;
+    gPst.read = fread;
+    gPst.write = fwrite;
+    gPst.close = fclose;
+    gPst.unlink = unlink;
+
+    result = OCRegisterPersistentStorageHandler(&gPst);
+    EXPECT_EQ(OC_STACK_OK, result);
+
+    result = OCInit(NULL, 0, OC_CLIENT_SERVER);
+    EXPECT_EQ(OC_STACK_OK, result);
 }
 
-TEST(CloudResourceTest, CreateCloudResource)
+TEST(CloudResourceTest, InitCloudResource)
 {
-    EXPECT_EQ(OC_STACK_OK, CreateCloudResource());
+    EXPECT_EQ(OC_STACK_OK, InitCloudResource());
 }
 
 TEST(CloudResourceTest, CloudToCBORPayloadNULL)
@@ -120,7 +174,7 @@ TEST(CloudResourceTest, CloudToCBORPayloadVALID)
     EXPECT_TRUE(payload != NULL);
 
     FreeCloud(cloud);
-    OICFree(payload);
+    OCPayloadDestroy((OCPayload *)payload);
 }
 
 TEST(CloudResourceTest, CloudToCBORPayloadResourceVALID)
@@ -133,7 +187,7 @@ TEST(CloudResourceTest, CloudToCBORPayloadResourceVALID)
     EXPECT_TRUE(payload != NULL);
 
     FreeCloud(cloud);
-    OICFree(payload);
+    OCPayloadDestroy((OCPayload *)payload);
 }
 
 TEST(CloudResourceTest, CBORPayloadToCloudNULL)
@@ -145,14 +199,22 @@ TEST(CloudResourceTest, CBORPayloadToCloudNULL)
     EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(NULL, 0, NULL));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(NULL, size, &cloud));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(cborPayload, size, NULL));
+    EXPECT_EQ(OC_STACK_ERROR, CBORPayloadToCloud(cborPayload, size, &cloud));
+    size = 0;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(cborPayload, size, &cloud));
+    size = 10;
+    cloud =  getCloud();
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CBORPayloadToCloud(cborPayload, size, &cloud));
+    FreeCloud(cloud);
     OICFree(cborPayload);
 }
 
 TEST(CloudResourceTest, CBORPayloadToCloudFULL)
 {
-    OicCloud_t *cloud =  getCloud();
+    OicCloud_t *cloud = NULL;
     uint8_t *payload = NULL;
     size_t size = 0;
+    cloud =  getCloud();
     EXPECT_EQ(OC_STACK_OK, CloudToCBORPayload(cloud, &payload, &size));
     EXPECT_TRUE(payload != NULL);
 
@@ -169,7 +231,6 @@ TEST(CloudResourceTest, CBORPayloadToCloudFULL)
         ASSERT_STREQ(cloudX->session->authProvider, cloud->session->authProvider);
         ASSERT_STREQ(cloudX->session->accessToken, cloud->session->accessToken);
         ASSERT_STREQ(cloudX->session->refreshToken, cloud->session->refreshToken);
-        ASSERT_EQ(cloudX->session->expireSin, cloud->session->expireSin);
         ASSERT_STREQ(cloudX->session->uid, cloud->session->uid);
 #if !defined(__MANDATORY__)
         ASSERT_STREQ(cloudX->session->redirectUri, cloud->session->redirectUri);
@@ -178,7 +239,7 @@ TEST(CloudResourceTest, CBORPayloadToCloudFULL)
 
     FreeCloud(cloudX);
     FreeCloud(cloud);
-    OICFree(payload);
+    OCPayloadDestroy((OCPayload *)payload);
 }
 
 TEST(CloudResourceTest, CBORPayloadToCloudResourceFULL)
@@ -198,14 +259,665 @@ TEST(CloudResourceTest, CBORPayloadToCloudResourceFULL)
 
     FreeCloud(cloudX);
     FreeCloud(cloud);
-    OICFree(payload);
+    OCPayloadDestroy((OCPayload *)payload);
 }
 
 TEST(CloudResourceTest, ValidCloudFULL)
 {
+    ASSERT_TRUE(false == ValidCloud(NULL));
     OicCloud_t *cloud =  getCloud();
     ASSERT_TRUE(false == ValidCloud(cloud));
     sprintf(cloud->cis, "coaps+tcp://");
     ASSERT_TRUE(true == ValidCloud(cloud));
+    OICFree(cloud->apn); cloud->apn = NULL;
+    OICFree(cloud->at); cloud->at = NULL;
+    ASSERT_TRUE(false == ValidCloud(cloud));
+    FreeCloud(cloud);
+}
+
+TEST(CloudResourceTest, DeleteCloudListFULL)
+{
+    DeleteCloudList(NULL);
+    OicCloud_t *cloud =  getCloud();
+    cloud->next =  getCloud();
+    cloud->next->next =  getCloud();
+    DeleteCloudList(cloud);
+}
+
+TEST(CloudResourceTest, CreateCloudGetPayloadFULL)
+{
+    OCRepPayload *payload = CreateCloudGetPayload(NULL);
+    ASSERT_TRUE(NULL != payload);
+
+    OicCloud_t *cloud =  getCloud();
+    ASSERT_TRUE(NULL != cloud);
+    OCPayloadDestroy((OCPayload *)payload);
+    payload = CreateCloudGetPayload(cloud);
+    ASSERT_TRUE(NULL != payload);
+
+    OICFree(cloud->apn);
+    cloud->apn = NULL;
+    OCPayloadDestroy((OCPayload *)payload);
+    payload = CreateCloudGetPayload(cloud);
+    ASSERT_TRUE(NULL != payload);
+
+    FreeCloud(cloud);
+    OCPayloadDestroy((OCPayload *)payload);
+}
+
+TEST(CloudResourceTest, StartCloudFULL)
+{
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RESET));
+    StartClouds();
+
+    OicUuid_t *uuid = (OicUuid_t *)OICCalloc(1, sizeof(OicUuid_t));
+    ASSERT_TRUE(OC_STACK_OK == ConvertStrToUuid("33333333-3333-3333-3333-333333333333", uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmDevOwnerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmIsOwned(true));
+    ASSERT_TRUE(OC_STACK_OK == SetAclRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetCredRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetPstatRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFPRO));
+    StartClouds();
+    OICFree(uuid);
+}
+
+TEST(CloudResourceTest, HandleCloudPostRequestFULL)
+{
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(NULL));
+
+    OCEntityHandlerRequest *ehRequest = (OCEntityHandlerRequest *)OICCalloc(1,
+                                        sizeof(OCEntityHandlerRequest));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+
+    ehRequest->payload = (OCPayload *)OCRepPayloadCreate();
+    ASSERT_TRUE(NULL != ehRequest->payload);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RESET));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    OicUuid_t *uuid = (OicUuid_t *)OICCalloc(1, sizeof(OicUuid_t));
+    ASSERT_TRUE(OC_STACK_OK == ConvertStrToUuid("33333333-3333-3333-3333-333333333333", uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmDevOwnerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmIsOwned(true));
+    ASSERT_TRUE(OC_STACK_OK == SetAclRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetCredRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetPstatRownerId(uuid));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFPRO));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmIsOwned(false));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmIsOwned(true));
+
+    OicCloud_t *cloud =  getCloud();
+    ASSERT_TRUE(NULL != cloud);
+
+    OCRepPayload *payload = NULL;
+    payload = OCRepPayloadCreate();
+    ASSERT_TRUE(NULL != payload);
+    ehRequest->payload = (OCPayload *)payload;
+
+    sprintf(cloud->cis, "coaps+tcp://");
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_APN, cloud->apn);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_CIS, cloud->cis);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_AT, cloud->at);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_SID, cloud->sid);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+    OCRepPayloadSetPropInt(payload, OIC_JSON_CLOUD_CLEC, (int64_t)cloud->stat);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
+
+    OICFree(uuid);
+    FreeCloud(cloud);
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFNOP));
+    OCPayloadDestroy(ehRequest->payload);
+    OICFree(ehRequest);
+}
+
+TEST(CloudResourceTest, HandleCloudGetRequestFULL)
+{
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(NULL));
+    OCRepPayload *payload = NULL;
+
+    OCEntityHandlerRequest *ehRequest = (OCEntityHandlerRequest *)OICCalloc(1,
+                                        sizeof(OCEntityHandlerRequest));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+
+    ehRequest->payload = (OCPayload *)OCRepPayloadCreate();
+    ASSERT_TRUE(NULL != ehRequest->payload);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RESET));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+
+    OicUuid_t *uuid = (OicUuid_t *)OICCalloc(1, sizeof(OicUuid_t));
+    ASSERT_TRUE(OC_STACK_OK == ConvertStrToUuid("33333333-3333-3333-3333-333333333333", uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmDevOwnerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmIsOwned(true));
+    ASSERT_TRUE(OC_STACK_OK == SetAclRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetCredRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetPstatRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFPRO));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+
+    OicCloud_t *cloud =  getCloud();
+    ASSERT_TRUE(NULL != cloud);
+    sprintf(cloud->cis, "coaps+tcp://");
+
+    OCPayloadDestroy(ehRequest->payload);
+    payload = OCRepPayloadCreate();
+    ASSERT_TRUE(NULL != payload);
+    ehRequest->payload = (OCPayload *)payload;
+
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_CIS, cloud->cis);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_APN, cloud->apn);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+    OCRepPayloadSetPropString(payload, OIC_JSON_CLOUD_AT, cloud->at);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(ehRequest));
+
+    OICFree(uuid);
+    FreeCloud(cloud);
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFNOP));
+    OCPayloadDestroy(ehRequest->payload);
+    OICFree(ehRequest);
+}
+
+TEST(CloudResourceTest, HandleCloudDeleteRequestFULL)
+{
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(NULL));
+
+    OCEntityHandlerRequest *ehRequest = (OCEntityHandlerRequest *)OICCalloc(1,
+                                        sizeof(OCEntityHandlerRequest));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(ehRequest));
+
+    ehRequest->payload = (OCPayload *)OCRepPayloadCreate();
+    ASSERT_TRUE(NULL != ehRequest->payload);
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(ehRequest));
+
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RESET));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(ehRequest));
+
+    OicUuid_t *uuid = (OicUuid_t *)OICCalloc(1, sizeof(OicUuid_t));
+    ASSERT_TRUE(OC_STACK_OK == ConvertStrToUuid("33333333-3333-3333-3333-333333333333", uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmDevOwnerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmIsOwned(true));
+    ASSERT_TRUE(OC_STACK_OK == SetAclRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetCredRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetPstatRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFPRO));
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(ehRequest));
+
+    OCPayloadDestroy(ehRequest->payload);
+    ASSERT_TRUE(NULL != ehRequest->payload);
+    OicCloud_t *cloud =  getCloud();
+    ASSERT_TRUE(NULL != cloud);
+    sprintf(cloud->cis, "coaps+tcp://");
+    ehRequest->payload = (OCPayload *)CreateCloudGetPayload(cloud);
+    ASSERT_TRUE(NULL != ehRequest->payload);
+    OCRepPayloadSetPropString((OCRepPayload *)ehRequest->payload, OIC_JSON_CLOUD_AT, "3453245234");
+    ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(ehRequest));
+
+    OICFree(uuid);
+    ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFNOP));
+    OCPayloadDestroy(ehRequest->payload);
+    FreeCloud(cloud);
+    OICFree(ehRequest);
+}
+
+TEST(CloudResourceTest, CloudEntityHandlerFULL)
+{
+    ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler((OCEntityHandlerFlag)0, NULL, NULL));
+    ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler(OC_OBSERVE_FLAG, NULL, NULL));
+    ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler(OC_REQUEST_FLAG, NULL, NULL));
+    OCEntityHandlerRequest *ehRequest = (OCEntityHandlerRequest *)OICCalloc(1,
+                                        sizeof(OCEntityHandlerRequest));
+    ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler(OC_REQUEST_FLAG, ehRequest, NULL));
+    ehRequest->method = OC_REST_POST;
+    ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler(OC_REQUEST_FLAG, ehRequest, NULL));
+    ehRequest->method = OC_REST_GET;
+    ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler(OC_REQUEST_FLAG, ehRequest, NULL));
+    ehRequest->method = OC_REST_DELETE;
+    ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler(OC_REQUEST_FLAG, ehRequest, NULL));
+    OICFree(ehRequest);
+}
+
+OCStackApplicationResult resultHandler(void *context, OCDoHandle handle,
+                                       OCClientResponse *clientResponse)
+{
+    OC_UNUSED(context);
+    OC_UNUSED(handle);
+    OC_UNUSED(clientResponse);
+
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+TEST(CloudResourceTest, OCProvisionCloudConfigFULL)
+{
+    void *ctx = NULL;
+    OCProvisionDev_t *pDev = NULL;
+    OicCloud_t *cloud = NULL;
+    OCClientResponseHandler resultCallback = NULL;
+
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
+    ctx = (void *)OICCalloc(1, 1024);
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
+    pDev = (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
+    FreeCloud(cloud);
+    cloud =  getCloud();
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
+    resultCallback = resultHandler;
+    ASSERT_TRUE(OC_STACK_ERROR == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
+    snprintf(pDev->endpoint.addr, sizeof(pDev->endpoint.addr), "127.0.0.1");
+    pDev->securePort = 1024;
+    pDev->connType = (OCConnectivityType)(CT_ADAPTER_IP | CT_FLAG_SECURE | CT_IP_USE_V4);
+    ASSERT_TRUE(OC_STACK_OK == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
+
+    FreeCloud(cloud);
+    OICFree(ctx);
+    OICFree(pDev);
+}
+
+static OCStackApplicationResult clientResponseHandler(void *context, OCDoHandle handle,
+        OCClientResponse *clientResponse)
+{
+    OC_UNUSED(context);
+    OC_UNUSED(handle);
+    OC_UNUSED(clientResponse);
+    OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
+    return ret;
+}
+
+TEST(CloudResourceTest, handleCloudStatusResponseFULL)
+{
+    void *ctx = NULL;
+    OCDoHandle handle = NULL;
+    OCClientResponse *response = NULL;
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudStatusResponse(ctx, handle, response));
+    ctx = (void *)&clientResponseHandler;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudStatusResponse(ctx, handle, response));
+    response = (OCClientResponse *)OICCalloc(1, sizeof(*response));
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    response->payload->type = PAYLOAD_TYPE_REPRESENTATION;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudStatusResponse(ctx, handle, response));
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OIC_JSON_CLOUD_APN, "github");
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OIC_JSON_CLOUD_CIS,
+                              "http://127.0.0.1:80");
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OIC_JSON_CLOUD_SID, "3453245234");
+    OCRepPayloadSetPropInt((OCRepPayload *)response->payload, OIC_JSON_CLOUD_CLEC, 23423);
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudStatusResponse(ctx, handle, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST(CloudResourceTest, OCRemoveCloudConfigCBFULL)
+{
+    void *ctx = NULL;
+    OCDoHandle handle = NULL;
+    OCClientResponse *response = NULL;
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == OCRemoveCloudConfigCB(ctx, handle, response));
+    ctx = (void *)OICCalloc(1, 1024);
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == OCRemoveCloudConfigCB(ctx, handle, response));
+    response = (OCClientResponse *)OICCalloc(1, sizeof(*response));
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    response->payload->type = PAYLOAD_TYPE_REPRESENTATION;
+    response->result = OC_STACK_RESOURCE_CHANGED;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == OCRemoveCloudConfigCB(ctx, handle, response));
+
+    Data_t *data = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ASSERT_TRUE(NULL != data);
+    data->type = CLOUD_TYPE;
+    CloudData_t *cloudData = (CloudData_t *)OICCalloc(1, sizeof(CloudData_t));
+    OICFree(ctx);
+    data->ctx = (void *)cloudData;
+    ASSERT_TRUE(NULL != data->ctx);
+    cloudData->ctx = (void *)OICCalloc(1, 1024);
+    cloudData->targetDev = (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+    cloudData->numOfResults = 0;
+    cloudData->credInfo = NULL;
+    cloudData->resArr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+    ASSERT_TRUE(NULL != cloudData->resArr);
+    cloudData->sid = (char *)OICCalloc(1, 1024);
+    ASSERT_TRUE(NULL != cloudData->sid);
+    ctx = (void *)data;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == OCRemoveCloudConfigCB(ctx, handle, response));
+
+    OICFree(cloudData->ctx);
+    OICFree(cloudData->targetDev);
+    OICFree(cloudData->resArr);
+    OICFree(cloudData->sid);
+    OICFree(cloudData);
+
+    OICFree(data);
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST(CloudResourceTest, OCGetCloudStatusRequestFULL)
+{
+    void *ctx = NULL;
+    OCProvisionDev_t *pDev = NULL;
+    OicCloud_t *cloud = NULL;
+    OCClientResponseHandler resultCallback = NULL;
+
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCGetCloudStatusRequest(ctx, pDev, cloud, resultCallback));
+    ctx = (void *)OICCalloc(1, 1024);
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCGetCloudStatusRequest(ctx, pDev, cloud, resultCallback));
+    pDev = (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCGetCloudStatusRequest(ctx, pDev, cloud, resultCallback));
+    cloud =  getCloud();
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCGetCloudStatusRequest(ctx, pDev, cloud, resultCallback));
+    resultCallback = resultHandler;
+    ASSERT_TRUE(OC_STACK_ERROR == OCGetCloudStatusRequest(ctx, pDev, cloud, resultCallback));
+    snprintf(pDev->endpoint.addr, sizeof(pDev->endpoint.addr), "127.0.0.1");
+    pDev->securePort = 1024;
+    pDev->connType = (OCConnectivityType)(CT_ADAPTER_IP | CT_FLAG_SECURE | CT_IP_USE_V4);
+    ASSERT_TRUE(OC_STACK_OK == OCGetCloudStatusRequest(ctx, pDev, cloud, resultCallback));
+
+    FreeCloud(cloud);
+    OICFree(ctx);
+    OICFree(pDev);
+}
+
+
+void resultCB(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+
+    return;
+}
+
+TEST(CloudResourceTest, OCRemoveCloudConfigFULL)
+{
+    void *ctx = NULL;
+    OCProvisionDev_t *pDev = NULL;
+    OicCloud_t *cloud = NULL;
+    OCProvisionResultCB resultCallback = NULL;
+
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCRemoveCloudConfig(ctx, pDev, cloud, resultCallback));
+    ctx = (void *)OICCalloc(1, 1024);
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCRemoveCloudConfig(ctx, pDev, cloud, resultCallback));
+    pDev = (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+    ASSERT_TRUE(OC_STACK_INVALID_CALLBACK == OCRemoveCloudConfig(ctx, pDev, cloud, resultCallback));
+    resultCallback = resultCB;
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCRemoveCloudConfig(ctx, pDev, cloud, resultCallback));
+    FreeCloud(cloud);
+    cloud =  getCloud();
+    ASSERT_TRUE(OC_STACK_ERROR == OCRemoveCloudConfig(ctx, pDev, cloud, resultCallback));
+    snprintf(pDev->endpoint.addr, sizeof(pDev->endpoint.addr), "127.0.0.1");
+    pDev->securePort = 1024;
+    pDev->connType = (OCConnectivityType)(CT_ADAPTER_IP | CT_FLAG_SECURE | CT_IP_USE_V4);
+    ASSERT_TRUE(OC_STACK_OK == OCRemoveCloudConfig(ctx, pDev, cloud, resultCallback));
+
+    FreeCloud(cloud);
+    OICFree(ctx);
+    OICFree(pDev);
+}
+
+TEST(CloudResourceTest, GetCloudStatusFULL)
+{
+    gCloud = getCloud();
+    ASSERT_TRUE(NULL != gCloud);
+
+    for ( CloudStatus i = OC_CLOUD_OK; i <= OC_CLOUD_EXIT; i = (CloudStatus)(i + 1))
+    {
+        gCloud->stat = i;
+        const char *mes = GetCloudStatus(gCloud);
+        ASSERT_TRUE(NULL != mes);
+    }
+
+    FreeCloud(gCloud);
+    gCloud = NULL;
+}
+
+TEST(CloudResourceTest, handleCloudTokenRefreshResponseFULL)
+{
+    void *ctx = NULL;
+    OCDoHandle handle = NULL;
+    OCClientResponse *response = NULL;
+    OicCloud_t *cloud = getCloud();
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudTokenRefreshResponse(ctx, handle, response));
+    ctx = (void *)cloud;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudTokenRefreshResponse(ctx, handle, response));
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+//    response->result = (OCStackResult)LOGIN_OK;
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    response->payload->type = PAYLOAD_TYPE_REPRESENTATION;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudTokenRefreshResponse(ctx, handle, response));
+
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_REFRESH_TOKEN,
+                              cloud->session->refreshToken);
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_ACCESS_TOKEN,
+                              cloud->session->accessToken);
+    OCRepPayloadSetPropInt((OCRepPayload *)response->payload, OC_RSRVD_EXPIRES_IN,
+                           cloud->session->expireSin);
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudTokenRefreshResponse(ctx, handle, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+    FreeCloud(cloud);
+}
+
+TEST(CloudResourceTest, OCCloudTokenRefreshFULL)
+{
+    OicCloud_t *cloud = NULL;
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCCloudTokenRefresh(cloud));
+
+    cloud = getCloud();
+    ASSERT_TRUE(OC_STACK_OK == OCCloudTokenRefresh(cloud));
+    sprintf(cloud->cis, "coaps+tcp://127.0.0.1:5683");
+    ASSERT_TRUE(OC_STACK_OK == OCCloudTokenRefresh(cloud));
+
+    OicUuid_t *uuid = (OicUuid_t *)OICCalloc(1, sizeof(OicUuid_t));
+    ASSERT_TRUE(OC_STACK_OK == ConvertStrToUuid("33333333-3333-3333-3333-333333333333", uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmDevOwnerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmRownerId(uuid));
+    ASSERT_TRUE(OC_STACK_OK == SetDoxmIsOwned(true));
+    ASSERT_TRUE(OC_STACK_OK == OCCloudTokenRefresh(cloud));
+
+    OICFree(uuid);
+    FreeCloud(cloud);
+}
+
+TEST(CloudResourceTest, handleCloudSignUpResponseFULL)
+{
+    void *ctx = NULL;
+    OCDoHandle handle = NULL;
+    OCClientResponse *response = NULL;
+    OicCloud_t *cloud = getCloud();
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignUpResponse(ctx, handle, response));
+    ctx = (void *)&clientResponseHandler;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignUpResponse(ctx, handle, response));
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    response->result = (OCStackResult)LOGIN_OK;
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    response->payload->type = PAYLOAD_TYPE_REPRESENTATION;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignUpResponse(ctx, handle, response));
+
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_ACCESS_TOKEN,
+                              cloud->session->accessToken);
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_REFRESH_TOKEN,
+                              cloud->session->refreshToken);
+    OCRepPayloadSetPropInt((OCRepPayload *)response->payload, OC_RSRVD_EXPIRES_IN,
+                           cloud->session->expireSin);
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_USER_UUID,
+                              cloud->session->uid);
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_REDIRECT_URI,
+                              cloud->session->redirectUri);
+    SessionFree(cloud->session);
+    cloud->session = NULL;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignUpResponse(ctx, handle, response));
+
+    SessionFree(NULL);
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    FreeCloud(cloud);
+    OICFree(response);
+}
+
+/*
+TEST(CloudResourceTest, CloudTokenRefreshFULL)
+{
+    OicCloud_t *cloud = NULL;
+
+    ASSERT_TRUE(NULL == CloudTokenRefresh(cloud));
+    cloud = getCloud();
+    ASSERT_TRUE(OC_THREAD_SUCCESS == oc_thread_new(&cloud->pid, CloudTokenRefresh, cloud));
+    cloud->stat = OC_CLOUD_EXIT;
+    sleep(2);
+    FreeCloud(cloud);
+}
+*/
+
+TEST(CloudResourceTest, handleCloudSignInResponseFULL)
+{
+    void *ctx = NULL;
+    OCDoHandle handle = NULL;
+    OCClientResponse *response = NULL;
+    OicCloud_t *cloud = getCloud();
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignInResponse(ctx, handle, response));
+    ctx = (void *)cloud;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignInResponse(ctx, handle, response));
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    response->result = OC_STACK_OK;
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    response->payload->type = PAYLOAD_TYPE_REPRESENTATION;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignInResponse(ctx, handle, response));
+    response->result = (OCStackResult)LOGIN_OK;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignInResponse(ctx, handle, response));
+
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_ACCESS_TOKEN,
+                              cloud->session->accessToken);
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_REFRESH_TOKEN,
+                              cloud->session->refreshToken);
+    OCRepPayloadSetPropInt((OCRepPayload *)response->payload, OC_RSRVD_EXPIRES_IN,
+                           cloud->session->expireSin);
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_USER_UUID,
+                              cloud->session->uid);
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_REDIRECT_URI,
+                              cloud->session->redirectUri);
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignInResponse(ctx, handle, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+    FreeCloud(cloud);
+}
+
+TEST(CloudResourceTest, CloudSignFULL)
+{
+    OicCloud_t *cloud = NULL;
+
+    ASSERT_TRUE(OC_STACK_INVALID_PARAM == CloudSign(cloud, true));
+    cloud = getCloud();
+    ASSERT_TRUE(OC_STACK_ERROR == CloudSign(cloud, true));
+    cloud->stat = OC_CLOUD_SIGNUP;
+    ASSERT_TRUE(OC_STACK_OK == CloudSign(cloud, true));
+    ASSERT_TRUE(OC_STACK_OK == CloudSign(cloud, false));
+
     FreeCloud(cloud);
 }
+
+
+TEST(CloudResourceTest, SessionParsePayloadFULL)
+{
+    OicCloud_t *cloud = getCloud();
+    session_t *session = NULL;
+    OCRepPayload *payload = OCRepPayloadCreate();
+    ASSERT_TRUE(!SessionParsePayload(payload, session));
+    session = (session_t *)OICCalloc(1, sizeof(session_t));
+    ASSERT_TRUE(NULL != session);
+
+    ASSERT_TRUE(!SessionParsePayload(payload, session));
+    SessionFree(session);
+    session = (session_t *)OICCalloc(1, sizeof(session_t));
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ACCESS_TOKEN,
+                              cloud->session->accessToken);
+    ASSERT_TRUE(!SessionParsePayload(payload, session));
+    SessionFree(session);
+    session = (session_t *)OICCalloc(1, sizeof(session_t));
+    OCRepPayloadSetPropString(payload, OC_RSRVD_REFRESH_TOKEN,
+                              cloud->session->refreshToken);
+    ASSERT_TRUE(!SessionParsePayload(payload, session));
+    SessionFree(session);
+    session = (session_t *)OICCalloc(1, sizeof(session_t));
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_EXPIRES_IN,
+                           cloud->session->expireSin);
+    ASSERT_TRUE(!SessionParsePayload(payload, session));
+    SessionFree(session);
+    session = (session_t *)OICCalloc(1, sizeof(session_t));
+    OCRepPayloadSetPropString(payload, OC_RSRVD_USER_UUID,
+                              cloud->session->uid);
+    ASSERT_TRUE(SessionParsePayload(payload, session));
+    SessionFree(session);
+    session = (session_t *)OICCalloc(1, sizeof(session_t));
+    OCRepPayloadSetPropString(payload, OC_RSRVD_REDIRECT_URI,
+                              cloud->session->redirectUri);
+
+    ASSERT_TRUE(SessionParsePayload(payload, session));
+    SessionFree(session);
+    session = (session_t *)OICCalloc(1, sizeof(session_t));
+
+    SessionFree(session);
+    OCPayloadDestroy((OCPayload *)payload);
+    FreeCloud(cloud);
+}
+
+
+TEST(CloudResourceTest, handleCloudSignOutResponseFULL)
+{
+    void *ctx = NULL;
+    OCDoHandle handle = NULL;
+    OCClientResponse *response = NULL;
+    OicCloud_t *cloud = getCloud();
+
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignOutResponse(ctx, handle, response));
+    ctx = (void *)cloud;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignOutResponse(ctx, handle, response));
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    response->result = (OCStackResult)LOGIN_OK;
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    response->payload->type = PAYLOAD_TYPE_REPRESENTATION;
+    ASSERT_TRUE(OC_STACK_DELETE_TRANSACTION == handleCloudSignOutResponse(ctx, handle, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+    FreeCloud(cloud);
+}
+
+TEST(CloudResourceTest, UpdateCloudPersistentStorageFULL)
+{
+    DeleteCloudList(gCloud);
+    ASSERT_TRUE(false == UpdateCloudPersistentStorage());
+    OicCloud_t *cloud = getCloud();
+    LL_APPEND(gCloud, cloud);
+    ASSERT_TRUE(true == UpdateCloudPersistentStorage());
+    DeleteCloudList(gCloud);
+    gCloud = NULL;
+}
+
+TEST(CloudResourceTest, DeInitCloudResource)
+{
+    EXPECT_EQ(OC_STACK_OK, DeInitCloudResource());
+}
index 1a14143..adb2dc0 100644 (file)
@@ -42,14 +42,14 @@ static const uint16_t CBOR_SIZE = 1024;
 static const uint16_t CBOR_MAX_SIZE = 4400;
 
 /** AMACL Map size - Number of mandatory items. */
-static const uint8_t AMACL_MAP_SIZE = 3;
+static const uint8_t AMACL_MAP_SIZE = 1;
 static const uint8_t AMACL_RSRC_MAP_SIZE = 1;
 static const uint8_t AMACL_RLIST_MAP_SIZE = 3;
 
 static OicSecAmacl_t *gAmacl = NULL;
 static OCResourceHandle gAmaclHandle = NULL;
 
-void DeleteAmaclList(OicSecAmacl_tamacl)
+void DeleteAmaclList(OicSecAmacl_t *amacl)
 {
     if (amacl)
     {
@@ -71,7 +71,8 @@ void DeleteAmaclList(OicSecAmacl_t* amacl)
     }
 }
 
-OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayload, size_t *cborSize)
+OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayload,
+                                 size_t *cborSize)
 {
     if (NULL == amaclS || NULL == cborPayload || NULL != *cborPayload || NULL == cborSize)
     {
@@ -106,7 +107,7 @@ OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayl
 
     // resources -- Mandatory
     cborEncoderResult = cbor_encode_text_string(&amaclMap, OIC_JSON_RESOURCES_NAME,
-                strlen(OIC_JSON_RESOURCES_NAME));
+                        strlen(OIC_JSON_RESOURCES_NAME));
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding Resource Name Tag.");
 
     cborEncoderResult = cbor_encoder_create_map(&amaclMap, &rsrcMap, AMACL_RSRC_MAP_SIZE);
@@ -114,7 +115,7 @@ OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayl
 
 
     cborEncoderResult = cbor_encode_text_string(&rsrcMap, OIC_JSON_RLIST_NAME,
-                strlen(OIC_JSON_RLIST_NAME));
+                        strlen(OIC_JSON_RLIST_NAME));
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding RLIST Name Tag.");
 
     // TODO : Need to input array length by OicSecAmacl_t->resources->rlistLen based on spec.
@@ -130,28 +131,28 @@ OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayl
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding RLIST Map.");
 
         cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_HREF_NAME,
-                strlen(OIC_JSON_HREF_NAME));
+                            strlen(OIC_JSON_HREF_NAME));
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding HREF Name Tag.");
         cborEncoderResult = cbor_encode_text_string(&rMap, amacl->resources[i],
-                strlen(amacl->resources[i]));
+                            strlen(amacl->resources[i]));
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding HREF Value in Map.");
 
         cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_RT_NAME,
-                strlen(OIC_JSON_RT_NAME));
+                            strlen(OIC_JSON_RT_NAME));
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding RT Name Tag.");
 
         // TODO : Need to assign real value of RT
         cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_EMPTY_STRING,
-                strlen(OIC_JSON_EMPTY_STRING));
+                            strlen(OIC_JSON_EMPTY_STRING));
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding RT Value.");
 
         cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_IF_NAME,
-                strlen(OIC_JSON_IF_NAME));
+                            strlen(OIC_JSON_IF_NAME));
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding IF Name Tag.");
 
         // TODO : Need to assign real value of IF
         cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_EMPTY_STRING,
-                strlen(OIC_JSON_EMPTY_STRING));
+                            strlen(OIC_JSON_EMPTY_STRING));
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding IF Value.");
 
         cborEncoderResult = cbor_encoder_close_container(&rlistArray, &rMap);
@@ -178,27 +179,27 @@ OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayl
 exit:
     if ((CborErrorOutOfMemory == cborEncoderResult) && (cborLen < CBOR_MAX_SIZE))
     {
-       // reallocate and try again!
-       OICFree(outPayload);
-       outPayload = NULL;
-       // Since the allocated initial memory failed, double the memory.
-       cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
-       cborEncoderResult = CborNoError;
-       ret = AmaclToCBORPayload(amaclS, cborPayload, &cborLen);
-       if (OC_STACK_OK == ret)
-       {
-           *cborSize = cborLen;
-           ret = OC_STACK_OK;
-       }
+        // reallocate and try again!
+        OICFree(outPayload);
+        outPayload = NULL;
+        // Since the allocated initial memory failed, double the memory.
+        cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
+        cborEncoderResult = CborNoError;
+        ret = AmaclToCBORPayload(amaclS, cborPayload, &cborLen);
+        if (OC_STACK_OK == ret)
+        {
+            *cborSize = cborLen;
+            ret = OC_STACK_OK;
+        }
     }
 
     if (CborNoError != cborEncoderResult || ret != OC_STACK_OK)
     {
-       OICFree(outPayload);
-       outPayload = NULL;
-       *cborSize = 0;
-       *cborPayload = NULL;
-       ret = OC_STACK_ERROR;
+        OICFree(outPayload);
+        outPayload = NULL;
+        *cborSize = 0;
+        *cborPayload = NULL;
+        ret = OC_STACK_ERROR;
     }
 
     return ret;
@@ -228,7 +229,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
     cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Amacl Map.");
 
-    while(cbor_value_is_valid(&amaclMap) && cbor_value_is_text_string(&amaclMap))
+    while (cbor_value_is_valid(&amaclMap) && cbor_value_is_text_string(&amaclMap))
     {
         char *name = NULL;
         size_t len = 0;
@@ -247,7 +248,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
             cborFindResult = cbor_value_enter_container(&amaclMap, &rsrcMap);
             VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Resource Map");
 
-            while(cbor_value_is_valid(&rsrcMap) && cbor_value_is_text_string(&rsrcMap))
+            while (cbor_value_is_valid(&rsrcMap) && cbor_value_is_text_string(&rsrcMap))
             {
                 // resource name
                 char *rsrcName = NULL;
@@ -282,7 +283,7 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
                         cborFindResult = cbor_value_enter_container(&rsrcArray, &rMap);
                         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborFindResult, "Failed Entering Rlist Map");
 
-                        while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
+                        while (cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
                         {
                             char *rMapName = NULL;
                             size_t rMapNameLen = 0;
@@ -361,7 +362,7 @@ exit:
     return ret;
 }
 
-static OCEntityHandlerResult HandleAmaclGetRequest (const OCEntityHandlerRequest * ehRequest)
+static OCEntityHandlerResult HandleAmaclGetRequest (const OCEntityHandlerRequest *ehRequest)
 {
     // Convert Amacl data into JSON for transmission
     size_t size = 0;
@@ -372,15 +373,15 @@ static OCEntityHandlerResult HandleAmaclGetRequest (const OCEntityHandlerRequest
 
     // Send response payload to request originator
     ehRet = ((SendSRMResponse(ehRequest, ehRet, cborPayload, size)) == OC_STACK_OK) ?
-                   OC_EH_OK : OC_EH_ERROR;
+            OC_EH_OK : OC_EH_ERROR;
 
     OICFree(cborPayload);
 
-    OIC_LOG_V (DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
+    OIC_LOG_V (DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
     return ehRet;
 }
 
-static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerRequest * ehRequest)
+static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerRequest *ehRequest)
 {
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
 
@@ -416,7 +417,7 @@ static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerReques
         OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleAmaclPostRequest");
     }
 
-    OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
+    OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
     return ehRet;
 }
 
@@ -425,8 +426,8 @@ static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerReques
  * will handle REST request (GET/PUT/POST/DEL) for them.
  */
 static OCEntityHandlerResult AmaclEntityHandler (OCEntityHandlerFlag flag,
-                                                 OCEntityHandlerRequest * ehRequest,
-                                                 void* callbackParameter)
+        OCEntityHandlerRequest *ehRequest,
+        void *callbackParameter)
 {
     (void) callbackParameter;
     OCEntityHandlerResult ehRet = OC_EH_ERROR;