a11d5653e541e00850a75b3fdc1803a7256812b4
[iotivity.git] / resource / csdk / security / provisioning / unittest / otmunittest.cpp
1 /* *****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * *****************************************************************/
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "gtest/gtest.h"
23 #include "ocstack.h"
24 #include "utlist.h"
25 #include "logger.h"
26 #include "oic_malloc.h"
27 #include "oic_string.h"
28 #include "ocprovisioningmanager.h"
29 #include "oxmjustworks.h"
30 #include "oxmrandompin.h"
31 #include "oxmmanufacturercert.h"
32 #include "securevirtualresourcetypes.h"
33 #include "provisioningdatabasemanager.h"
34 #ifdef MULTIPLE_OWNER
35 #include "multipleownershiptransfermanager.h"
36 #endif //MULTIPLE_OWNER
37 #include "srmutility.h"
38 #include "doxmresource.h"
39 #include "pmtypes.h"
40 #include "pmutility.h"
41 #include "ocrandom.h"
42
43 #define OTM_TIMEOUT 60
44 #define DISCOVERY_TIMEOUT 10
45
46 #define SVR_DB_FILE_NAME "oic_svr_db_client.dat"
47 #define PM_DB_FILE_NAME "test.db"
48
49 static OCPersistentStorage gPst;
50 static bool g_doneCB;
51 static bool g_callbackResult;
52 static const char* g_otmCtx = "Test User Context";
53 static OCProvisionDev_t* g_unownedDevices = NULL;
54 static OCProvisionDev_t* g_ownedDevices = NULL;
55 #ifdef MULTIPLE_OWNER
56 static OCProvisionDev_t* g_motEnabledDevices = NULL;
57 static OCProvisionDev_t* g_multiplOwnedDevices = NULL;
58 #endif //MULTIPLE_OWNER
59 static int gNumOfUnownDevice = 0;
60 static int gNumOfOwnDevice = 0;
61
62 using namespace std;
63
64 #define TAG "OTM_UNITTEST"
65
66 TEST(JustWorksOxMTest, NullParam)
67 {
68     OTMContext_t* otmCtx = NULL;
69     OCStackResult res = OC_STACK_ERROR;
70     uint8_t *payloadRes = NULL;
71     size_t size = 0;
72
73     //LoadSecretJustWorksCallback always returns OC_STACK_OK.
74     res = LoadSecretJustWorksCallback(otmCtx);
75     EXPECT_TRUE(OC_STACK_OK == res);
76
77     res = CreateSecureSessionJustWorksCallback(otmCtx);
78     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
79
80     res = CreateJustWorksSelectOxmPayload(otmCtx, &payloadRes, &size);
81     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
82
83     res = CreateJustWorksOwnerTransferPayload(otmCtx, &payloadRes, &size);
84     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
85
86     OTMContext_t otmCtx2;
87     otmCtx2.selectedDeviceInfo = NULL;
88
89     //LoadSecretJustWorksCallback always returns OC_STACK_OK.
90     res = LoadSecretJustWorksCallback(&otmCtx2);
91     EXPECT_TRUE(OC_STACK_OK == res);
92
93     res = CreateSecureSessionJustWorksCallback(&otmCtx2);
94     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
95
96     res = CreateJustWorksSelectOxmPayload(&otmCtx2, &payloadRes, &size);
97     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
98
99     res = CreateJustWorksOwnerTransferPayload(&otmCtx2, &payloadRes, &size);
100     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
101 }
102
103 TEST(RandomPinOxMTest, NullParam)
104 {
105     OTMContext_t* otmCtx = NULL;
106     OCStackResult res = OC_STACK_ERROR;
107     uint8_t *payloadRes = NULL;
108     size_t size = 0;
109
110     //LoadSecretJustWorksCallback always returns OC_STACK_OK.
111     res = InputPinCodeCallback(otmCtx);
112     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
113
114     res = CreateSecureSessionRandomPinCallback(otmCtx);
115     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
116
117     res = CreatePinBasedSelectOxmPayload(otmCtx, &payloadRes, &size);
118     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
119
120     res = CreatePinBasedOwnerTransferPayload(otmCtx, &payloadRes, &size);
121     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
122
123     OTMContext_t otmCtx2;
124     otmCtx2.selectedDeviceInfo = NULL;
125
126     //LoadSecretJustWorksCallback always returns OC_STACK_OK.
127     res = InputPinCodeCallback(&otmCtx2);
128     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
129
130     res = CreateSecureSessionRandomPinCallback(&otmCtx2);
131     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
132
133     res = CreatePinBasedSelectOxmPayload(&otmCtx2, &payloadRes, &size);
134     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
135
136     res = CreatePinBasedOwnerTransferPayload(&otmCtx2, &payloadRes, &size);
137     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
138 }
139
140 TEST(ManufacturerCertOxMTest, NullParam)
141 {
142     OTMContext_t* otmCtx = NULL;
143     OCStackResult res = OC_STACK_ERROR;
144     uint8_t *payloadRes = NULL;
145     size_t size = 0;
146
147     res = PrepareMCertificateCallback(otmCtx);
148     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
149
150     res = CreateSecureSessionMCertificateCallback(otmCtx);
151     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
152
153     res = CreateMCertificateBasedSelectOxmPayload(otmCtx, &payloadRes, &size);
154     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
155
156     res = CreateMCertificateBasedOwnerTransferPayload(otmCtx, &payloadRes, &size);
157     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
158
159     OTMContext_t otmCtx2;
160     otmCtx2.selectedDeviceInfo = NULL;
161
162     res = InputPinCodeCallback(&otmCtx2);
163     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
164
165     res = CreateSecureSessionMCertificateCallback(&otmCtx2);
166     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
167
168     res = CreateMCertificateBasedSelectOxmPayload(&otmCtx2, &payloadRes, &size);
169     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
170
171     res = CreateMCertificateBasedOwnerTransferPayload(&otmCtx2, &payloadRes, &size);
172     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
173 }
174
175 /****************************************
176  * Test the OTM modules with sample server
177  ****************************************/
178 static FILE* fopen_prvnMng(const char* path, const char* mode)
179 {
180     if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
181     {
182       return fopen(SVR_DB_FILE_NAME, mode);
183     }
184     OIC_LOG_V(DEBUG, TAG, "use db: %s", path);
185     return fopen(path, mode);
186 }
187
188 // callback function(s) for provisioning client using C-level provisioning API
189 static void ownershipTransferCB(void* ctx, size_t UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError)
190 {
191     OC_UNUSED(UNUSED1);
192     OC_UNUSED(UNUSED2);
193     OC_UNUSED(ctx);
194
195     if(!hasError)
196     {
197         OIC_LOG_V(DEBUG, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
198     }
199     else
200     {
201         OIC_LOG_V(FATAL, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
202     }
203     g_callbackResult = !hasError;
204     g_doneCB = true;
205
206     OIC_LOG_V(DEBUG, TAG, "%s: done(has erro: %s)", __func__, hasError ? "yes" : "no");
207 }
208
209 // callback function(s) for provisioning client using C-level provisioning API
210 static void removeDeviceCB(void* ctx, size_t UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError)
211 {
212     OC_UNUSED(UNUSED1);
213     OC_UNUSED(UNUSED2);
214     OC_UNUSED(ctx);
215
216     if(!hasError)
217     {
218         OIC_LOG_V(DEBUG, TAG, "Remove device request SUCCEEDED - ctx: %s", (char*) ctx);
219     }
220     else
221     {
222         OIC_LOG_V(FATAL, TAG, "Remove device request FAILED - ctx: %s", (char*) ctx);
223     }
224     g_callbackResult = !hasError;
225     g_doneCB = true;
226 }
227
228 static int waitCallbackRet(void)
229 {
230     for(int i = 0; !g_doneCB && OTM_TIMEOUT > i; ++i)
231     {
232         sleep(1);
233         if(OC_STACK_OK != OCProcess())
234         {
235             OIC_LOG(FATAL, TAG, "OCStack process error");
236             return -1;
237         }
238     }
239
240     return 0;
241 }
242
243 #define UUID_TEMPLATE "11111111-1234-1234-1234-12345678901"
244 #define UUID_TEMPLATE_LEN 35
245
246 static void RemoveUnknownDeviceFromDevList(OCProvisionDev_t* devList)
247 {
248     OCProvisionDev_t* unknowDev = NULL;
249     OCProvisionDev_t* tempDev1 = NULL;
250     OCProvisionDev_t* tempDev2 =NULL;
251
252     LL_FOREACH_SAFE(devList, tempDev1, tempDev2)
253     {
254         char *uuidString = NULL;
255         EXPECT_EQ(OC_STACK_OK, ConvertUuidToStr((const OicUuid_t*) &tempDev1->doxm->deviceID, &uuidString));
256
257         if (strncmp(UUID_TEMPLATE, uuidString, UUID_TEMPLATE_LEN) != 0)
258         {
259             OIC_LOG_V(DEBUG, TAG, "%s: delete from list id:%s ip:%s:%d",__func__,
260             uuidString ? uuidString :"unknow id",
261             tempDev1->endpoint.addr,tempDev1->endpoint.port);
262
263             LL_DELETE(devList, tempDev1);
264             LL_APPEND(unknowDev, tempDev1);
265         }
266         OICFree(uuidString);
267     }
268
269     OCDeleteDiscoveredDevices(unknowDev);
270 }
271
272 TEST(InitForOTM, NullParam)
273 {
274     OCStackResult result = OC_STACK_ERROR;
275
276     OTMCallbackData_t otmcb;
277     otmcb.loadSecretCB = LoadSecretJustWorksCallback;
278     otmcb.createSecureSessionCB = CreateSecureSessionJustWorksCallback;
279     otmcb.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
280     otmcb.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
281 #ifdef HAVE_UNISTD_H
282     EXPECT_EQ(0, access(SVR_DB_FILE_NAME, F_OK));
283 #endif // HAVE_UNISTD_H
284     gPst.open = fopen_prvnMng;
285     gPst.read = fread;
286     gPst.write = fwrite;
287     gPst.close = fclose;
288     gPst.unlink = unlink;
289
290     // register the persistent storage handler for SVR
291     result = OCRegisterPersistentStorageHandler(&gPst);
292     EXPECT_EQ(OC_STACK_OK, result);
293
294     // initialize OC stack and provisioning manager
295     result = OCInit(NULL, 0, OC_CLIENT_SERVER);
296     EXPECT_EQ(OC_STACK_OK, result);
297
298     //initialize Provisioning DB Manager
299     result = OCInitPM(PM_DB_FILE_NAME);
300     EXPECT_EQ(OC_STACK_OK, result);
301
302     // register callback function(s) for Justworks OxM
303     result = OCSetOwnerTransferCallbackData(OIC_JUST_WORKS, &otmcb);
304     EXPECT_EQ(OC_STACK_OK, result);
305
306     g_doneCB = false;
307     g_callbackResult = false;
308
309     gNumOfUnownDevice = 0;
310     gNumOfOwnDevice = 0;
311 }
312 /*
313 TEST(OCDiscoverSingleDeviceInUnicast, Simple)
314 {
315     OCProvisionDev_t* foundDevice = NULL;
316
317     OicUuid_t uuid = {0};
318     ConvertStrToUuid("11111111-1234-1234-1234-123456789011", &uuid);
319
320     EXPECT_EQ(OC_STACK_OK, OCDiscoverSingleDeviceInUnicast(DISCOVERY_TIMEOUT, &uuid, "::1", CT_ADAPTER_IP, &foundDevice));
321
322     int NumOfFoundDevice = 0;
323     OCProvisionDev_t* tempDev = foundDevice;
324     while(tempDev)
325     {
326         NumOfFoundDevice++;
327         tempDev = tempDev->next;
328     }
329
330     PMDeleteDeviceList(foundDevice);
331     OIC_LOG_V(DEBUG, TAG, "Discoveed: %d devices", NumOfFoundDevice);
332     //TODO fix after:
333     //54:22.622 INFO: OIC_SRM: Received error from remote device with result, 7 for request uri, /oic/sec/doxm
334     //EXPECT_EQ(true, NumOfFoundDevice > 0);
335 }
336 */
337 TEST(OCDiscoverUnownedDevices, Simple)
338 {
339     EXPECT_EQ(OC_STACK_OK, OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unownedDevices));
340
341     RemoveUnknownDeviceFromDevList(g_unownedDevices);
342
343     OCProvisionDev_t* tempDev = g_unownedDevices;
344     while(tempDev)
345     {
346         gNumOfUnownDevice++;
347
348         char *uuidString = NULL;
349         EXPECT_EQ(OC_STACK_OK, ConvertUuidToStr((const OicUuid_t*) &tempDev->doxm->deviceID, &uuidString));
350
351         OIC_LOG_V(DEBUG, TAG, "%d: id:%s ip:%s:%d", gNumOfUnownDevice,
352         uuidString ? uuidString :"unknow id",
353         tempDev->endpoint.addr,tempDev->endpoint.port);
354
355         OICFree(uuidString);
356
357         tempDev = tempDev->next;
358     }
359
360     EXPECT_EQ(true, gNumOfUnownDevice > 0);
361 }
362
363 TEST(OCDoOwnershipTransfer, Simple)
364 {
365     ASSERT_EQ(true, gNumOfUnownDevice > 0);
366
367     g_doneCB = false;
368     EXPECT_EQ(OC_STACK_OK, OCDoOwnershipTransfer((void*)g_otmCtx, g_unownedDevices, ownershipTransferCB));
369
370     if(waitCallbackRet())  // input |g_doneCB| flag implicitly
371     {
372         OIC_LOG(FATAL, TAG, "OCProvisionCredentials callback error");
373         return;
374     }
375
376     EXPECT_EQ(true, g_callbackResult);
377     EXPECT_EQ(true, g_doneCB);
378 }
379
380 TEST(OCDiscoverOwnedDevices, Simple)
381 {
382     OCStackResult result = OC_STACK_ERROR;
383     gNumOfOwnDevice = 0;
384
385     EXPECT_EQ(OC_STACK_OK, OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_ownedDevices));
386
387     RemoveUnknownDeviceFromDevList(g_ownedDevices);
388
389     OCProvisionDev_t* tempDev = g_ownedDevices;
390     while(tempDev)
391     {
392         gNumOfOwnDevice++;
393         tempDev = tempDev->next;
394     }
395
396     if (gNumOfUnownDevice > gNumOfOwnDevice)
397     {
398         OIC_LOG(DEBUG, TAG, "Discovering unowned devices on");
399
400         if(g_unownedDevices)
401         {
402             OCDeleteDiscoveredDevices(g_unownedDevices);
403             g_unownedDevices = NULL;
404         }
405
406         result = OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unownedDevices);
407         EXPECT_EQ(OC_STACK_OK, result);
408
409         RemoveUnknownDeviceFromDevList(g_unownedDevices);
410
411         tempDev = g_unownedDevices;
412         while(tempDev)
413         {
414             gNumOfUnownDevice++;
415             tempDev = tempDev->next;
416         }
417
418         if (gNumOfUnownDevice)
419         {
420             g_doneCB = false;
421             EXPECT_EQ(OC_STACK_OK, OCDoOwnershipTransfer((void*)g_otmCtx, g_unownedDevices, ownershipTransferCB));
422
423             if(waitCallbackRet())  // input |g_doneCB| flag implicitly
424             {
425                 OIC_LOG(FATAL, TAG, "OCProvisionCredentials callback error");
426                 return;
427             }
428
429             EXPECT_EQ(true, g_callbackResult);
430             EXPECT_EQ(true, g_doneCB);
431         }
432     }
433
434     EXPECT_EQ(true, gNumOfOwnDevice > 0);
435 }
436
437 TEST(PerformLinkDevices, NullParam)
438 {
439     if (gNumOfOwnDevice < 2)
440     {
441         OIC_LOG(WARNING, TAG, "Link can only pair owned devices");
442         OIC_LOG_V(DEBUG, TAG, "Number of owned devices: %d",gNumOfOwnDevice);
443         return;
444     }
445
446     OicUuid_t myUuid;
447     OCStackResult result = OC_STACK_ERROR;
448     result = GetDoxmDeviceID(&myUuid);
449     EXPECT_EQ(OC_STACK_OK, result);
450
451     //Extract target device except PT to perform link devices.
452     OCProvisionDev_t* dev1 = NULL;
453     OCProvisionDev_t* dev2 = NULL;
454     OCProvisionDev_t* tempDev = g_ownedDevices;
455
456     while(tempDev)
457     {
458         if(memcmp(tempDev->doxm->deviceID.id, myUuid.id, UUID_LENGTH) != 0)
459         {
460             if(NULL == dev1)
461             {
462                 dev1 = tempDev;
463             }
464             else if(NULL == dev2)
465             {
466                 dev2 = tempDev;
467                 break;
468             }
469         }
470         tempDev = tempDev->next;
471     }
472     EXPECT_TRUE(NULL != dev1);
473     EXPECT_TRUE(NULL != dev2);
474
475     // TODO: Pairwise provisioning (Cred & ACL)
476     // TODO: This part will be updated after ACL and credential data-structure is updated.
477
478     EXPECT_EQ(OC_STACK_OK, result);
479 }
480
481
482 TEST(PerformUnlinkDevices, NullParam)
483 {
484     OCStackResult result = OC_STACK_OK;
485
486     // TODO: Unlink devices
487     // TODO: This part will be updated after ACL and credential data-structure is updated.
488
489     EXPECT_EQ(OC_STACK_OK, result);
490 }
491
492 //TODO will fix after IOT-2106
493 #if 0
494 //#ifdef MULTIPLE_OWNER
495 static void updateDoxmForMOTCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError)
496 {
497     OC_UNUSED(nOfRes);
498     OC_UNUSED(arr);
499
500     if(!hasError)
501     {
502         OIC_LOG_V(DEBUG, TAG, "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
503     }
504     else
505     {
506         OIC_LOG_V(FATAL, TAG, "POST 'doxm'  FAILED - ctx: %s", (char*) ctx);
507     }
508     g_callbackResult = !hasError;
509     g_doneCB = true;
510 }
511
512 static void provisionPreconfiguredPinCB(void* ctx, size_t nOfRes, OCProvisionResult_t* arr, bool hasError)
513 {
514     OC_UNUSED(nOfRes);
515     OC_UNUSED(arr);
516
517     if(!hasError)
518     {
519         OIC_LOG_V(DEBUG, TAG, "Provision Preconfigured-PIN SUCCEEDED - ctx: %s", (char*) ctx);
520     }
521     else
522     {
523         OIC_LOG_V(FATAL, TAG, "Provision Preconfigured-PIN FAILED - ctx: %s", (char*) ctx);
524     }
525     g_callbackResult = !hasError;
526     g_doneCB = true;
527 }
528
529 TEST(EnableMOT, NullParam)
530 {
531     OCStackResult result = OC_STACK_OK;
532
533     if(NULL == g_ownedDevices)
534     {
535         OIC_LOG(DEBUG, TAG, "Discovering Only Owned Devices on Network..");
536         result = OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_ownedDevices);
537         EXPECT_EQ(OC_STACK_OK, result);
538         RemoveUnknownDeviceFromDevList(g_ownedDevices);
539     }
540
541     EXPECT_NE((OCProvisionDev_t*)NULL, g_ownedDevices);
542
543     g_doneCB = false;
544     ASSERT_EQ(OC_STACK_OK, OCChangeMOTMode(NULL, g_ownedDevices, OIC_MULTIPLE_OWNER_ENABLE, updateDoxmForMOTCB));
545     if(waitCallbackRet())  // input |g_doneCB| flag implicitly
546     {
547         OIC_LOG(FATAL, TAG, "OCChangeMOTMode callback error");
548         return;
549     }
550
551     EXPECT_TRUE(g_callbackResult);
552 }
553
554 TEST(DiscoverMOTEnabledDevices, NullParam)
555 {
556     if(g_motEnabledDevices)
557     {
558         PMDeleteDeviceList(g_motEnabledDevices);
559     }
560
561     ASSERT_EQ(OC_STACK_OK, OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_motEnabledDevices));
562
563     RemoveUnknownDeviceFromDevList(g_motEnabledDevices);
564
565     EXPECT_EQ(true, g_motEnabledDevices != NULL);
566 }
567
568 TEST(RegisterPreconfiguredPIN, NullParam)
569 {
570     OCStackResult result = SetPreconfigPin("12341234", strlen("12341234"));
571     EXPECT_EQ(OC_STACK_OK, result);
572 }
573
574 TEST(ProvisonPreconfiguredPIN, NullParam)
575 {
576     ASSERT_EQ(true, g_motEnabledDevices != NULL);
577     OCStackResult result = OC_STACK_OK;
578
579     g_doneCB = false;
580     result = OCProvisionPreconfigPin(NULL, g_motEnabledDevices, "12341234", strlen("12341234"), provisionPreconfiguredPinCB);
581     ASSERT_EQ(OC_STACK_OK, result);
582     if(waitCallbackRet())  // input |g_doneCB| flag implicitly
583     {
584         OIC_LOG(FATAL, TAG, "OCProvisionPreconfigPin callback error");
585         return;
586     }
587
588     EXPECT_EQ(true, g_callbackResult);
589 }
590
591 TEST(SelectMOTMethod, NullParam)
592 {
593     ASSERT_EQ(true, g_motEnabledDevices != NULL);
594     OCStackResult result = OC_STACK_OK;
595
596     g_doneCB = false;
597     result = OCSelectMOTMethod(NULL, g_motEnabledDevices, OIC_PRECONFIG_PIN, updateDoxmForMOTCB);
598     ASSERT_EQ(OC_STACK_OK, result);
599     if(waitCallbackRet())  // input |g_doneCB| flag implicitly
600     {
601         OIC_LOG(FATAL, TAG, "OCSelectMOTMethod callback error");
602         return;
603     }
604
605     EXPECT_EQ(true, g_callbackResult);
606 }
607
608 // TODO: Need to new server to perform MOT
609 TEST(PerformMOT, NullParam)
610 {
611     ASSERT_EQ(true, g_motEnabledDevices != NULL);
612     OCStackResult result = OC_STACK_OK;
613
614     g_doneCB = false;
615     result = OCDoMultipleOwnershipTransfer(NULL, g_motEnabledDevices, ownershipTransferCB);
616     ASSERT_EQ(OC_STACK_OK, result);
617     if(waitCallbackRet())  // input |g_doneCB| flag implicitly
618     {
619         OIC_LOG(FATAL, TAG, "OCDoMultipleOwnershipTransfer callback error");
620         return;
621     }
622     EXPECT_EQ(true, g_callbackResult);
623 }
624
625 TEST(DiscoverMultipleOwnedDevices, NullParam)
626 {
627     OCStackResult result = OC_STACK_OK;
628
629     if(g_multiplOwnedDevices)
630     {
631         PMDeleteDeviceList(g_multiplOwnedDevices);
632     }
633
634     OIC_LOG(DEBUG, TAG, "Discovering MOT Enabled Devices on Network..");
635     result = OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_multiplOwnedDevices);
636     ASSERT_EQ(OC_STACK_OK, result);
637     RemoveUnknownDeviceFromDevList(g_multiplOwnedDevices);
638     EXPECT_TRUE(NULL != g_multiplOwnedDevices);
639 }
640 #endif //MULTIPLE_OWNER
641
642 TEST(OCRemoveDevice, Simple)
643 {
644     ASSERT_EQ(true, gNumOfUnownDevice > 0);
645
646     OicUuid_t myUuid;
647     OCStackResult result = OC_STACK_ERROR;
648     result = GetDoxmDeviceID(&myUuid);
649     EXPECT_EQ(OC_STACK_OK, result);
650
651     //Extract target device except PT to perform remove device.
652     OCProvisionDev_t* removeDev = g_ownedDevices;
653     while(removeDev)
654     {
655         if(memcmp(removeDev->doxm->deviceID.id, myUuid.id, UUID_LENGTH) != 0)
656         {
657             break;
658         }
659         removeDev = removeDev->next;
660     }
661     EXPECT_TRUE(NULL != removeDev);
662
663     g_doneCB = false;
664     g_callbackResult = false;
665
666     result = OCRemoveDevice((void*)g_otmCtx, DISCOVERY_TIMEOUT, removeDev, removeDeviceCB);
667     EXPECT_EQ(OC_STACK_OK, result);
668     EXPECT_EQ(true, g_callbackResult);
669     EXPECT_EQ(true, g_doneCB);
670 }
671
672 TEST(FinalizeOTMTest, NullParam)
673 {
674     OCStackResult result = OCStop();
675     EXPECT_EQ(OC_STACK_OK, result);
676
677     PMDeleteDeviceList(g_unownedDevices);
678     PMDeleteDeviceList(g_ownedDevices);
679     result = PDMClose();
680     EXPECT_EQ(OC_STACK_OK, result);
681 }