TEST(PDMIsDuplicateDeviceTest, ValidUUID) { OicUuid_t uid1 = {{0,}}; memcpy(&uid1.id, ID_1, sizeof(uid1.id)); PDMAddDevice(&uid1); OicUuid_t uid2 = {{0,}}; memcpy(&uid2.id, ID_2, sizeof(uid2.id)); PDMAddDevice(&uid2); OicUuid_t uid3 = {{0,}}; memcpy(&uid3.id, ID_3, sizeof(uid3.id)); bool isDuplicate = true; EXPECT_EQ(OC_STACK_OK, PDMIsDuplicateDevice(&uid1,&isDuplicate)); EXPECT_TRUE(isDuplicate); EXPECT_EQ(OC_STACK_OK, PDMIsDuplicateDevice(&uid3, &isDuplicate)); EXPECT_FALSE(isDuplicate); }
TEST(CallPDMAPIbeforeInit, BeforeInit) { EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMAddDevice(NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsDuplicateDevice(NULL,NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMLinkDevices(NULL, NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMUnlinkDevices(NULL, NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMDeleteDevice(NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetOwnedDevices(NULL, NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetLinkedDevices(NULL, NULL, NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMSetLinkStale(NULL, NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetToBeUnlinkedDevices(NULL, NULL)); EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsLinkExists(NULL, NULL, NULL)); }
/** * NOTE : Unowned discovery should be done before performing OTMDoOwnershipTransfer */ OCStackResult OTMDoOwnershipTransfer(void* ctx, OCProvisionDev_t *selectedDevicelist, OCProvisionResultCB resultCallback) { OC_LOG(DEBUG, TAG, "IN OTMDoOwnershipTransfer"); if (NULL == selectedDevicelist || NULL == resultCallback ) { return OC_STACK_INVALID_PARAM; } OTMContext_t* otmCtx = (OTMContext_t*)OICCalloc(1,sizeof(OTMContext_t)); if(!otmCtx) { OC_LOG(ERROR, TAG, "Failed to create OTM Context"); return OC_STACK_NO_MEMORY; } otmCtx->ctxResultCallback = resultCallback; otmCtx->ctxHasError = false; otmCtx->userCtx = ctx; OCProvisionDev_t* pCurDev = selectedDevicelist; //Counting number of selected devices. otmCtx->ctxResultArraySize = 0; while(NULL != pCurDev) { otmCtx->ctxResultArraySize++; pCurDev = pCurDev->next; } otmCtx->ctxResultArray = (OCProvisionResult_t*)OICCalloc(otmCtx->ctxResultArraySize, sizeof(OCProvisionResult_t)); if(NULL == otmCtx->ctxResultArray) { OC_LOG(ERROR, TAG, "OTMDoOwnershipTransfer : Failed to memory allocation"); OICFree(otmCtx); return OC_STACK_NO_MEMORY; } pCurDev = selectedDevicelist; //Fill the device UUID for result array. for(size_t devIdx = 0; devIdx < otmCtx->ctxResultArraySize; devIdx++) { //Checking duplication of Device ID. bool isDuplicate = true; OCStackResult res = PDMIsDuplicateDevice(&pCurDev->doxm->deviceID, &isDuplicate); if (OC_STACK_OK != res) { OICFree(otmCtx->ctxResultArray); OICFree(otmCtx); return res; } if (isDuplicate) { OC_LOG(ERROR, TAG, "OTMDoOwnershipTransfer : Device ID is duplicated"); OICFree(otmCtx->ctxResultArray); OICFree(otmCtx); return OC_STACK_INVALID_PARAM; } memcpy(otmCtx->ctxResultArray[devIdx].deviceId.id, pCurDev->doxm->deviceID.id, UUID_LENGTH); otmCtx->ctxResultArray[devIdx].res = OC_STACK_CONTINUE; pCurDev = pCurDev->next; } StartOwnershipTransfer(otmCtx, selectedDevicelist); OC_LOG(DEBUG, TAG, "OUT OTMDoOwnershipTransfer"); return OC_STACK_OK; }
TEST(PDMIsDuplicateDeviceTest, NullUUID) { EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMIsDuplicateDevice(NULL,NULL)); }