X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Funittest%2Fdoxmresource.cpp;h=f2de1ddd0e90fde7c03a73e4724a415b2452b31d;hb=17c68b2fd1e74586f85e552eeab4e32dc121f8a0;hp=0b32cd97c3c6bd8bbcc6af228070c770cb969512;hpb=8c01dff2c5bc5496f7dc1632c498943ec6ecb015;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/security/unittest/doxmresource.cpp b/resource/csdk/security/unittest/doxmresource.cpp index 0b32cd9..f2de1dd 100644 --- a/resource/csdk/security/unittest/doxmresource.cpp +++ b/resource/csdk/security/unittest/doxmresource.cpp @@ -23,12 +23,17 @@ #include "srmresourcestrings.h" #include "doxmresource.h" #include "ocserverrequest.h" +#include "oic_string.h" #include "oic_malloc.h" +#include "logger.h" + +#define TAG "SRM-DOXM" #ifdef __cplusplus extern "C" { #endif + //Declare Doxm resource methods for testing OCStackResult CreateDoxmResource(); OCEntityHandlerResult DoxmEntityHandler (OCEntityHandlerFlag flag, @@ -43,17 +48,43 @@ OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest * ehReq } #endif + OicSecDoxm_t * getBinDoxm() { OicSecDoxm_t * doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t)); + if(!doxm) + { + return NULL; + } doxm->oxmTypeLen = 1; doxm->oxmType = (OicUrn_t *)OICCalloc(doxm->oxmTypeLen, sizeof(char *)); + if(!doxm->oxmType) + { + OICFree(doxm); + return NULL; + } doxm->oxmType[0] = (char*)OICMalloc(strlen(OXM_JUST_WORKS) + 1); + if(!doxm->oxmType[0]) + { + OICFree(doxm->oxmType); + OICFree(doxm); + return NULL; + } + strcpy(doxm->oxmType[0], OXM_JUST_WORKS); doxm->oxmLen = 1; - doxm->oxm = (OicSecOxm_t *)OICCalloc(doxm->oxmLen, sizeof(short)); + doxm->oxm = (OicSecOxm_t *)OICCalloc(doxm->oxmLen, sizeof(OicSecOxm_t)); + if(!doxm->oxm) + { + OICFree(doxm->oxmType[0]); + OICFree(doxm->oxmType); + OICFree(doxm); + return NULL; + } + doxm->oxm[0] = OIC_JUST_WORKS; doxm->oxmSel = OIC_JUST_WORKS; + doxm->sct = SYMMETRIC_PAIR_WISE_KEY; doxm->owned = true; //TODO: Need more clarification on deviceIDFormat field type. //doxm.deviceIDFormat = URN; @@ -101,11 +132,22 @@ TEST(DoxmEntityHandlerTest, DoxmEntityHandlerInvalidFlag) TEST(DoxmEntityHandlerTest, DoxmEntityHandlerValidRequest) { EXPECT_EQ(OC_STACK_INVALID_PARAM, InitDoxmResource()); - char query[] = "oxm=0&owned=false&owner=owner1"; - OCEntityHandlerRequest req = {}; + char query[] = "oxm=0;owned=false;owner=owner1"; + OCEntityHandlerRequest req = OCEntityHandlerRequest(); + req.method = OC_REST_GET; + req.query = OICStrdup(query); + EXPECT_EQ(OC_EH_ERROR, DoxmEntityHandler(OCEntityHandlerFlag::OC_REQUEST_FLAG, &req)); + + OICFree(req.query); +} + +TEST(DoxmEntityHandlerTest, DoxmEntityHandlerDeviceIdQuery) +{ + EXPECT_EQ(OC_STACK_INVALID_PARAM, InitDoxmResource()); + char query[] = "deviceid=MjIyMjIyMjIyMjIyMjIyMg=="; + OCEntityHandlerRequest req = OCEntityHandlerRequest(); req.method = OC_REST_GET; - req.query = (char*)OICMalloc(strlen(query) + 1); - strcpy((char *)req.query, query); + req.query = OICStrdup(query); EXPECT_EQ(OC_EH_ERROR, DoxmEntityHandler(OCEntityHandlerFlag::OC_REQUEST_FLAG, &req)); OICFree(req.query); @@ -123,7 +165,7 @@ TEST(BinToDoxmJSONTest, BinToDoxmJSONValidDoxm) OicSecDoxm_t * doxm = getBinDoxm(); char * json = BinToDoxmJSON(doxm); - printf("BinToDoxmJSON:%s\n", json); + OC_LOG_V(INFO, TAG, "BinToDoxmJSON:%s", json); EXPECT_TRUE(json != NULL); DeleteDoxmBinData(doxm); @@ -141,6 +183,7 @@ TEST(JSONToDoxmBinTest, JSONToDoxmBinValidJSON) EXPECT_TRUE(doxm2 != NULL); DeleteDoxmBinData(doxm1); + DeleteDoxmBinData(doxm2); OICFree(json); }