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));
143 TEST(OCRemoveDeviceTest, NullTargetDevice)
145 unsigned short waitTime = 10 ;
146 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, NULL, provisioningCB));
149 TEST(OCRemoveDeviceWithUuidTest, NullTargetDevice)
151 unsigned short waitTime = 10 ;
153 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDeviceWithUuid(NULL, waitTime, NULL, provisioningCB));
155 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));