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 */
44 static OicSecDoxm_t defaultDoxm2 =
46 NULL, /* OicUrn_t *oxmType */
47 0, /* size_t oxmTypeLen */
48 &oicSecDoxmRandomPin, /* uint16_t *oxm */
49 1, /* size_t oxmLen */
50 OIC_RANDOM_DEVICE_PIN, /* uint16_t oxmSel */
51 SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
52 false, /* bool owned */
53 {{0}}, /* OicUuid_t deviceID */
55 {{0}}, /* OicUuid_t owner */
58 static void provisioningCB (void* UNUSED1, int UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4)
67 static OCStackResult OTMLoadSecretCallback(OTMContext_t* otmCtx)
74 TEST(OCInitPMTest, NullPath)
76 EXPECT_EQ(OC_STACK_OK, OCInitPM(NULL));
79 TEST(OCProvisionPairwiseDevicesTest, NullDevice1)
81 pDev1.doxm = &defaultDoxm1;
82 uint8_t deviceId1[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64};
83 memcpy(pDev1.doxm->deviceID.id, deviceId1, sizeof(deviceId1));
85 pDev2.doxm = &defaultDoxm2;
86 uint8_t deviceId2[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x63};
87 memcpy(pDev2.doxm->deviceID.id, deviceId2, sizeof(deviceId2));
89 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
90 OWNER_PSK_LENGTH_128, NULL, &acl1,
91 &pDev2, &acl2, &provisioningCB));
94 TEST(OCProvisionPairwiseDevicesTest, NullDevice2)
96 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
97 OWNER_PSK_LENGTH_128, &pDev1, &acl1,
98 NULL, &acl2, &provisioningCB));
101 TEST(OCProvisionPairwiseDevicesTest, SamelDeviceId)
103 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
104 OWNER_PSK_LENGTH_128, &pDev1, &acl1,
105 &pDev1, &acl2, &provisioningCB));
108 TEST(OCProvisionPairwiseDevicesTest, NullCallback)
110 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCProvisionPairwiseDevices(NULL, credType,
111 OWNER_PSK_LENGTH_128, &pDev1, &acl1,
112 &pDev2, &acl2, NULL));
115 TEST(OCProvisionPairwiseDevicesTest, InvalidKeySize)
117 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
119 &pDev2, &acl2 ,&provisioningCB));
122 TEST(OCUnlinkDevicesTest, NullDevice1)
124 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, NULL, &pDev2, provisioningCB));
127 TEST(OCUnlinkDevicesTest, NullDevice2)
129 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, &pDev1, NULL, provisioningCB));
132 TEST(OCUnlinkDevicesTest, NullCallback)
134 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCUnlinkDevices(NULL, &pDev1, &pDev2, NULL));
137 TEST(OCUnlinkDevicesTest, SamelDeviceId)
139 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL,&pDev1, &pDev1, &provisioningCB));
142 TEST(OCRemoveDeviceTest, NullTargetDevice)
144 unsigned short waitTime = 10 ;
145 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, NULL, provisioningCB));
148 TEST(OCRemoveDeviceWithUuidTest, NullTargetDevice)
150 unsigned short waitTime = 10 ;
152 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDeviceWithUuid(NULL, waitTime, NULL, provisioningCB));
154 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDeviceWithUuid(NULL, waitTime, &uuid, NULL));
157 TEST(OCRemoveDeviceTest, NullResultCallback)
159 unsigned short waitTime = 10;
160 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDevice(NULL, waitTime, &pDev1, NULL));
163 TEST(OCRemoveDeviceTest, ZeroWaitTime)
165 unsigned short waitTime = 0;
166 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, &pDev1, provisioningCB));
169 TEST(OCGetDevInfoFromNetworkTest, NullUnOwnedDeviceInfo)
171 unsigned short waitTime = 10;
172 OCProvisionDev_t *ownedList = NULL;
173 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, NULL));
176 TEST(OCGetDevInfoFromNetworkTest, NullOwnedDeviceInfo)
178 unsigned short waitTime = 10;
179 OCProvisionDev_t *unownedList = NULL;
180 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, NULL, &unownedList));
183 TEST(OCGetDevInfoFromNetworkTest, ZeroWaitTime)
185 unsigned short waitTime = 0;
186 OCProvisionDev_t *ownedList = NULL;
187 OCProvisionDev_t *unownedList = NULL;
188 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, &unownedList));
191 TEST(OCGetLinkedStatusTest, NULLDeviceID)
193 OCUuidList_t *list = NULL;
194 size_t noOfDevices = 0;
195 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetLinkedStatus(NULL, &list, &noOfDevices));
198 TEST(OCDeleteUuidListTest, NullUuidList)
200 OCDeleteUuidList(NULL);
204 TEST(OCDeleteACLListTest, NullACLList)
206 OCDeleteACLList(NULL);
210 TEST(OCDeletePdAclListTest, NullPdACLList)
212 OCDeletePdAclList(NULL);
216 TEST(OCDeleteDiscoveredDevicesTest, NullProvisionDevList)
218 OCDeleteDiscoveredDevices(NULL);
222 TEST(OCSetOwnerTransferCallbackDataTest, NULLCallback)
224 OicSecOxm_t ownershipTransferMethod = OIC_JUST_WORKS;
225 EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
229 TEST(OCSetOwnerTransferCallbackDataTest, InvalidOXMType)
231 OicSecOxm_t ownershipTransferMethod = OIC_OXM_COUNT;
232 OTMCallbackData_t stOTMCallbackData = { &OTMLoadSecretCallback, NULL, NULL, NULL};
233 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
234 &stOTMCallbackData));