1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * *****************************************************************/
20 #include "gtest/gtest.h"
21 #include "ocprovisioningmanager.h"
23 static OicSecAcl_t acl1;
24 static OicSecAcl_t acl2;
25 static OCProvisionDev_t pDev1;
26 static OCProvisionDev_t pDev2;
27 static OicSecCredType_t credType = SYMMETRIC_PAIR_WISE_KEY;
28 static OicSecOxm_t oicSecDoxmJustWorks = OIC_JUST_WORKS;
29 static OicSecOxm_t oicSecDoxmRandomPin = OIC_RANDOM_DEVICE_PIN;
30 static OicSecDoxm_t defaultDoxm1 =
32 NULL, /* OicUrn_t *oxmType */
33 0, /* size_t oxmTypeLen */
34 &oicSecDoxmJustWorks, /* uint16_t *oxm */
35 1, /* size_t oxmLen */
36 OIC_JUST_WORKS, /* uint16_t oxmSel */
37 SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
38 false, /* bool owned */
39 {{0}}, /* OicUuid_t deviceID */
41 {{0}}, /* OicUuid_t owner */
45 static OicSecDoxm_t defaultDoxm2 =
47 NULL, /* OicUrn_t *oxmType */
48 0, /* size_t oxmTypeLen */
49 &oicSecDoxmRandomPin, /* uint16_t *oxm */
50 1, /* size_t oxmLen */
51 OIC_RANDOM_DEVICE_PIN, /* uint16_t oxmSel */
52 SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
53 false, /* bool owned */
54 {{0}}, /* OicUuid_t deviceID */
56 {{0}}, /* OicUuid_t owner */
60 static void provisioningCB (void* UNUSED1, size_t UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4)
69 static OCStackResult OTMLoadSecretCallback(OTMContext_t* otmCtx)
76 TEST(OCInitPMTest, NullPath)
78 EXPECT_EQ(OC_STACK_OK, OCInitPM(NULL));
81 TEST(OCProvisionPairwiseDevicesTest, NullDevice1)
83 pDev1.doxm = &defaultDoxm1;
84 uint8_t deviceId1[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64};
85 memcpy(pDev1.doxm->deviceID.id, deviceId1, sizeof(deviceId1));
87 pDev2.doxm = &defaultDoxm2;
88 uint8_t deviceId2[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x63};
89 memcpy(pDev2.doxm->deviceID.id, deviceId2, sizeof(deviceId2));
91 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
92 OWNER_PSK_LENGTH_128, NULL, &acl1,
93 &pDev2, &acl2, &provisioningCB));
96 TEST(OCProvisionPairwiseDevicesTest, NullDevice2)
98 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
99 OWNER_PSK_LENGTH_128, &pDev1, &acl1,
100 NULL, &acl2, &provisioningCB));
103 TEST(OCProvisionPairwiseDevicesTest, SamelDeviceId)
105 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
106 OWNER_PSK_LENGTH_128, &pDev1, &acl1,
107 &pDev1, &acl2, &provisioningCB));
110 TEST(OCProvisionPairwiseDevicesTest, NullCallback)
112 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCProvisionPairwiseDevices(NULL, credType,
113 OWNER_PSK_LENGTH_128, &pDev1, &acl1,
114 &pDev2, &acl2, NULL));
117 TEST(OCProvisionPairwiseDevicesTest, InvalidKeySize)
119 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
121 &pDev2, &acl2 ,&provisioningCB));
124 TEST(OCUnlinkDevicesTest, NullDevice1)
126 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, NULL, &pDev2, provisioningCB));
129 TEST(OCUnlinkDevicesTest, NullDevice2)
131 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, &pDev1, NULL, provisioningCB));
134 TEST(OCUnlinkDevicesTest, NullCallback)
136 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCUnlinkDevices(NULL, &pDev1, &pDev2, NULL));
139 TEST(OCUnlinkDevicesTest, SamelDeviceId)
141 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL,&pDev1, &pDev1, &provisioningCB));
144 TEST(OCRemoveDeviceTest, NullTargetDevice)
146 unsigned short waitTime = 10 ;
147 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, NULL, provisioningCB));
150 TEST(OCRemoveDeviceWithUuidTest, NullTargetDevice)
152 unsigned short waitTime = 10 ;
154 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDeviceWithUuid(NULL, waitTime, NULL, provisioningCB));
156 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDeviceWithUuid(NULL, waitTime, &uuid, NULL));
159 TEST(OCRemoveDeviceTest, NullResultCallback)
161 unsigned short waitTime = 10;
162 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDevice(NULL, waitTime, &pDev1, NULL));
165 TEST(OCRemoveDeviceTest, ZeroWaitTime)
167 unsigned short waitTime = 0;
168 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, &pDev1, provisioningCB));
171 TEST(OCGetDevInfoFromNetworkTest, NullUnOwnedDeviceInfo)
173 unsigned short waitTime = 10;
174 OCProvisionDev_t *ownedList = NULL;
175 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, NULL));
178 TEST(OCGetDevInfoFromNetworkTest, NullOwnedDeviceInfo)
180 unsigned short waitTime = 10;
181 OCProvisionDev_t *unownedList = NULL;
182 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, NULL, &unownedList));
185 TEST(OCGetDevInfoFromNetworkTest, ZeroWaitTime)
187 unsigned short waitTime = 0;
188 OCProvisionDev_t *ownedList = NULL;
189 OCProvisionDev_t *unownedList = NULL;
190 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, &unownedList));
193 TEST(OCGetLinkedStatusTest, NULLDeviceID)
195 OCUuidList_t *list = NULL;
196 size_t noOfDevices = 0;
197 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetLinkedStatus(NULL, &list, &noOfDevices));
200 TEST(OCDeleteUuidListTest, NullUuidList)
202 OCDeleteUuidList(NULL);
206 TEST(OCDeleteACLListTest, NullACLList)
208 OCDeleteACLList(NULL);
212 TEST(OCDeletePdAclListTest, NullPdACLList)
214 OCDeletePdAclList(NULL);
218 TEST(OCDeleteDiscoveredDevicesTest, NullProvisionDevList)
220 OCDeleteDiscoveredDevices(NULL);
224 TEST(OCSetOwnerTransferCallbackDataTest, NULLCallback)
226 OicSecOxm_t ownershipTransferMethod = OIC_JUST_WORKS;
227 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
231 TEST(OCSetOwnerTransferCallbackDataTest, InvalidOXMType)
233 OicSecOxm_t ownershipTransferMethod = OIC_OXM_COUNT;
234 OTMCallbackData_t stOTMCallbackData = { &OTMLoadSecretCallback, NULL, NULL, NULL};
235 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
236 &stOTMCallbackData));