예제 #1
0
TEST(BinToDoxmJSONTest, BinToDoxmJSONValidDoxm)
{
    OicSecDoxm_t * doxm =  getBinDoxm();

    char * json = BinToDoxmJSON(doxm);
    EXPECT_TRUE(json != NULL);

    DeleteDoxmBinData(doxm);
    OICFree(json);
}
예제 #2
0
//JSONToDoxmBin Tests
TEST(JSONToDoxmBinTest, JSONToDoxmBinValidJSON)
{
    OicSecDoxm_t * doxm1 =  getBinDoxm();
    char * json = BinToDoxmJSON(doxm1);
    EXPECT_TRUE(json != NULL);

    OicSecDoxm_t *doxm2 = JSONToDoxmBin(json);
    EXPECT_TRUE(doxm2 != NULL);

    DeleteDoxmBinData(doxm1);
    DeleteDoxmBinData(doxm2);
    OICFree(json);
}
예제 #3
0
//HandleDoxmPostRequest Test
TEST(HandleDoxmPostRequestTest, HandleDoxmPostRequestValidInput)
{
    OCEntityHandlerRequest ehRequest = {};
    OCServerRequest svRequest = {};

    OicSecDoxm_t * doxm =  getBinDoxm();

    strcpy(svRequest.addressInfo.IP.ipAddress, "10.10.10.10");
    svRequest.addressInfo.IP.port = 2345;
    svRequest.connectivityType = CA_ETHERNET;

    ehRequest.reqJSONPayload = (unsigned char *) BinToDoxmJSON(doxm);
    ehRequest.requestHandle = (OCRequestHandle) &svRequest;

    EXPECT_EQ(OC_EH_ERROR, HandleDoxmPostRequest(&ehRequest));
    DeleteDoxmBinData(doxm);
    OICFree(ehRequest.reqJSONPayload);
}
예제 #4
0
static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest * ehRequest)
{
    char* jsonStr = NULL;
    OCEntityHandlerResult ehRet = OC_EH_OK;

    OIC_LOG (DEBUG, TAG, "Doxm EntityHandle processing GET request");

    //Checking if Get request is a query.
    if(ehRequest->query)
    {
        OIC_LOG (DEBUG, TAG, "HandleDoxmGetRequest processing query");
        if(!ValidateQuery(ehRequest->query))
        {
            ehRet = OC_EH_ERROR;
        }
    }

    /*
     * For GET or Valid Query request return doxm resource json payload.
     * For non-valid query return NULL json payload.
     * A device will 'always' have a default Doxm, so BinToDoxmJSON will
     * return valid doxm resource json.
     */

    jsonStr = (ehRet == OC_EH_OK) ? BinToDoxmJSON(gDoxm) : NULL;

    // Send response payload to request originator
    if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, jsonStr))
    {
        OIC_LOG (ERROR, TAG, "SendSRMResponse failed in HandleDoxmGetRequest");
    }

    OICFree(jsonStr);

    return ehRet;
}
예제 #5
0
/**
 * @todo document this function including why code might need to call this.
 * The current suspicion is that it's not being called as much as it should.
 */
static bool UpdatePersistentStorage(OicSecDoxm_t * doxm)
{
    bool bRet = false;

    if (NULL != doxm)
    {
        // Convert Doxm data into JSON for update to persistent storage
        char *jsonStr = BinToDoxmJSON(doxm);
        if (jsonStr)
        {
            cJSON *jsonDoxm = cJSON_Parse(jsonStr);
            OICFree(jsonStr);

            if (jsonDoxm &&
                    (OC_STACK_OK == UpdateSVRDatabase(OIC_JSON_DOXM_NAME, jsonDoxm)))
            {
                bRet = true;
            }
            cJSON_Delete(jsonDoxm);
        }
    }

    return bRet;
}
예제 #6
0
//BinToDoxmJSON Tests
TEST(BinToDoxmJSONTest, BinToDoxmJSONNullDoxm)
{
    char* value = BinToDoxmJSON(NULL);
    EXPECT_TRUE(value == NULL);
}