Merge branch 'master' into notification-service
[platform/upstream/iotivity.git] / resource / unittests / OCPlatformTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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
21 #include <OCPlatform.h>
22 #include <OCApi.h>
23 #include <oic_malloc.h>
24 #include <gtest/gtest.h>
25
26 namespace OCPlatformTest
27 {
28     using namespace OC;
29
30     static const char* SVR_DB_FILE_NAME = "./oic_svr_db_server.dat";
31     const OCResourceHandle HANDLE_ZERO = 0;
32     const std::string gResourceTypeName = "core.res";
33     const std::string gResourceInterface = DEFAULT_INTERFACE;
34     const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
35     OCResourceHandle resourceHandle;
36
37     //OCPersistent Storage Handlers
38     static FILE* client_open(const char * /*path*/, const char *mode)
39     {
40         std::cout << "<===Opening SVR DB file = './oic_svr_db_client.dat' with mode = '" << mode
41                 << "' " << std::endl;
42         return fopen(SVR_DB_FILE_NAME, mode);
43     }
44     OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
45
46     // Callbacks
47     OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request*/)
48     {
49         return OC_EH_OK;
50     }
51
52     void foundResource(std::shared_ptr<OCResource> /*resource*/)
53     {
54     }
55
56     void receivedDeviceInfo(const OCRepresentation& /*rep*/)
57     {
58     }
59
60     void presenceHandler(OCStackResult /*result*/,
61             const unsigned int /*nonce*/, const std::string& /*hostAddress*/)
62     {
63     }
64
65 #ifdef WITH_CLOUD
66     void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
67     {
68     }
69 #endif
70
71     void directPairHandler(std::shared_ptr<OCDirectPairing> /*dev*/, OCStackResult /*res*/)
72     {
73     }
74
75     void pairedHandler(const PairedDevices& /*list*/)
76     {
77     }
78 #ifdef WITH_CLOUD
79     void accountHandler(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
80             const int /*eCode*/)
81     {
82     }
83 #endif
84     //Helper methods
85     void DeleteStringLL(OCStringLL* ll)
86     {
87         if (!ll)
88         {
89             return;
90         }
91
92         DeleteStringLL(ll->next);
93         delete[] ll->value;
94         OICFree(ll);
95     }
96
97     void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
98     {
99         delete[] deviceInfo.deviceName;
100         DeleteStringLL(deviceInfo.types);
101         delete[] deviceInfo.specVersion;
102         DeleteStringLL(deviceInfo.dataModelVersions);
103     }
104
105     void DuplicateString(char ** targetString, std::string sourceString)
106     {
107         *targetString = new char[sourceString.length() + 1];
108         strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
109     }
110
111     bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
112     {
113         char *dup = NULL;
114         DuplicateString(&dup, value);
115         if (!*stringLL)
116         {
117             *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
118             (*stringLL)->value = dup;
119             return true;
120         }
121         else
122         {
123             OCStringLL *temp = *stringLL;
124             while(temp->next)
125             {
126                 temp = temp->next;
127             }
128             temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
129             temp->next->value = dup;
130             return true;
131         }
132         return false;
133     }
134
135     OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
136     {
137         PlatformConfig cfg
138         { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
139                 OC::QualityOfService::LowQos, &gps };
140         OCPlatform::Configure(cfg);
141         EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
142                                         resourceHandle, uri, type,
143                                         iface, entityHandler, gResourceProperty));
144         return resourceHandle;
145     }
146
147     OCResourceHandle RegisterResource(std::string uri, std::string type)
148     {
149         PlatformConfig cfg
150         { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
151                 OC::QualityOfService::LowQos, &gps };
152         OCPlatform::Configure(cfg);
153         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
154                                         resourceHandle, uri, type,
155                                         gResourceInterface, entityHandler, gResourceProperty));
156         return resourceHandle;
157     }
158
159     OCResourceHandle RegisterResource(std::string uri)
160     {
161         PlatformConfig cfg
162         { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
163                 OC::QualityOfService::LowQos, &gps };
164         OCPlatform::Configure(cfg);
165         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
166                                         resourceHandle, uri, gResourceTypeName,
167                                         gResourceInterface, entityHandler, gResourceProperty));
168         return resourceHandle;
169     }
170
171     //Configure
172     // Enable it when the stack throw an exception
173     // https://jira.iotivity.org/browse/IOT-428
174     TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
175     {
176         PlatformConfig cfg {
177              OC::ServiceType::InProc,
178             (OC::ModeType)99,
179              "0.0.0.0",
180              0,
181              OC::QualityOfService::LowQos
182          };
183          OCPlatform::Configure(cfg);
184          EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
185      }
186
187     // Enable it when the stack throw an exception
188     // https://jira.iotivity.org/browse/IOT-428
189     TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
190     {
191         PlatformConfig cfg {
192              (OC::ServiceType)99,
193             OC::ModeType::Client,
194              "0.0.0.0",
195              0,
196              OC::QualityOfService::LowQos
197          };
198          OCPlatform::Configure(cfg);
199          EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
200      }
201
202     // Enable it when the stack throw an exception
203     // https://jira.iotivity.org/browse/IOT-428
204     TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
205     {
206         PlatformConfig cfg {
207             OC::ServiceType::OutOfProc,
208             OC::ModeType::Client,
209             "0.0.0.0",
210             0,
211             OC::QualityOfService::LowQos
212         };
213         std::string uri = "/a/light66";
214         std::string type = "core.light";
215         uint8_t gResourceProperty = 0;
216         OCPlatform::Configure(cfg);
217         EXPECT_ANY_THROW(OCPlatform::registerResource(
218              resourceHandle, uri, type,
219              gResourceInterface, entityHandler, gResourceProperty));
220     }
221
222     TEST(ConfigureTest, ConfigureServerOutProc)
223     {
224         PlatformConfig cfg
225         {
226             OC::ServiceType::OutOfProc,
227             OC::ModeType::Server,
228             "0.0.0.0",
229             0,
230             OC::QualityOfService::LowQos, &gps
231         };
232         std::string uri = "/a/light67";
233         std::string type = "core.light";
234         uint8_t gResourceProperty = 0;
235         OCPlatform::Configure(cfg);
236
237         EXPECT_ANY_THROW(OCPlatform::registerResource(
238              resourceHandle, uri, type,
239              gResourceInterface, entityHandler, gResourceProperty));
240     }
241
242     TEST(ConfigureTest, ConfigureDefault)
243     {
244         std::string uri = "/a/light68";
245         std::string type = "core.light";
246         uint8_t gResourceProperty = 0;
247         PlatformConfig cfg = {};
248         OCPlatform::Configure(cfg);
249
250         EXPECT_NO_THROW(OCPlatform::registerResource(
251                  resourceHandle, uri, type,
252                  gResourceInterface, entityHandler, gResourceProperty));
253     }
254
255     TEST(ConfigureTest, ConfigureServer)
256     {
257         std::string uri = "/a/light69";
258         std::string type = "core.light";
259         uint8_t gResourceProperty = 0;
260         PlatformConfig cfg {
261             OC::ServiceType::InProc,
262             OC::ModeType::Server,
263             "0.0.0.0",
264             0,
265             OC::QualityOfService::LowQos, &gps
266         };
267         OCPlatform::Configure(cfg);
268
269         EXPECT_NO_THROW(OCPlatform::registerResource(
270                  resourceHandle, uri, type,
271                  gResourceInterface, entityHandler, gResourceProperty));
272     }
273
274     TEST(ConfigureTest, ConfigureClient)
275     {
276         std::string uri = "/a/light70";
277         std::string type = "core.light";
278         uint8_t gResourceProperty = 0;
279         PlatformConfig cfg
280         {
281             OC::ServiceType::InProc,
282             OC::ModeType::Client,
283             "0.0.0.0",
284             0,
285             OC::QualityOfService::LowQos,
286             &gps
287         };
288
289         EXPECT_NO_THROW(OCPlatform::registerResource(
290                  resourceHandle, uri, type,
291                  gResourceInterface, entityHandler, gResourceProperty));
292     }
293     //PersistentStorageTest
294     TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
295     {
296         PlatformConfig cfg {
297              OC::ServiceType::InProc,
298              OC::ModeType::Both,
299              "0.0.0.0",
300              0,
301              OC::QualityOfService::LowQos
302          };
303          OCPlatform::Configure(cfg);
304          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
305      }
306
307     //PersistentStorageTest
308     TEST(ConfigureTest, ConfigureNULLPersistentStorage)
309     {
310         PlatformConfig cfg {
311              OC::ServiceType::InProc,
312              OC::ModeType::Both,
313              "0.0.0.0",
314              0,
315              OC::QualityOfService::LowQos,
316              nullptr
317          };
318          OCPlatform::Configure(cfg);
319          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
320      }
321
322     //PersistentStorageTest
323     TEST(ConfigureTest, ConfigurePersistentStorage)
324     {
325          PlatformConfig cfg {
326              OC::ServiceType::InProc,
327              OC::ModeType::Both,
328              "0.0.0.0",
329              0,
330              OC::QualityOfService::LowQos,
331              &gps
332          };
333          OCPlatform::Configure(cfg);
334          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
335      }
336
337     //PersistentStorageTest
338     TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
339     {
340         PlatformConfig cfg {
341              OC::ServiceType::InProc,
342              OC::ModeType::Both,
343              "0.0.0.0",
344              0,
345              OC::QualityOfService::LowQos,
346              &gps
347          };
348          OCPlatform::Configure(cfg);
349          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
350      }
351
352
353     //RegisterResourceTest
354     TEST(RegisterResourceTest, RegisterSingleResource)
355     {
356         std::string uri = "/a/res2";
357         EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
358     }
359
360     TEST(RegisterResourceTest, RegisterMultipleResources)
361     {
362         std::string uri = "/a/multi";
363         //Good enough for 5 resources.
364         for(int i=0; i< 5; i++)
365         {
366             uri +=std::to_string(i);
367             EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
368         }
369     }
370
371     TEST(RegisterResourceTest, ReregisterResource)
372     {
373         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
374             std::string("core.light"));
375         EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
376
377         EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
378             std::string("core.light")));
379
380     }
381
382     TEST(RegisterResourceTest, RegisterEmptyResource)
383     {
384         // We should not allow empty URI.
385         std::string emptyStr = "";
386         EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
387                                         emptyStr, entityHandler, gResourceProperty));
388     }
389
390     TEST(RegisterResourceTest, RegisterZeroResourceProperty)
391     {
392         std::string uri = "/a/light6";
393         std::string type = "core.light";
394         uint8_t gResourceProperty = 0;
395         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
396                 resourceHandle, uri, type,
397                 gResourceInterface, entityHandler, gResourceProperty));
398     }
399
400     //UnregisterTest
401     TEST(UnregisterTest, UnregisterZeroHandleValue)
402     {
403         EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
404     }
405
406     //UnbindResourcesTest
407     TEST(UnbindResourcesTest, UnbindResources)
408     {
409         OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
410             std::string("core.home"));
411         OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
412             std::string("core.kitchen"), LINK_INTERFACE);
413         OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
414             std::string("core.office"), LINK_INTERFACE);
415
416         std::vector<OCResourceHandle> rList;
417         rList.push_back(resourceKitchen);
418         rList.push_back(resourceRoom);
419         EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
420         EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
421     }
422
423     TEST(UnbindResourcesTest, UnbindResourcesWithZero)
424     {
425         OCResourceHandle resourceHandle1 = 0;
426         OCResourceHandle resourceHandle2 = 0;
427         OCResourceHandle resourceHandle3 = 0;
428
429         std::vector<OCResourceHandle> rList;
430
431         rList.push_back(resourceHandle2);
432         rList.push_back(resourceHandle3);
433
434         EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
435     }
436
437     //BindInterfaceToResourceTest
438     TEST(BindInterfaceToResourceTest, BindResourceInterface)
439     {
440         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
441             std::string("core.light"));
442         OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
443             BATCH_INTERFACE);
444         EXPECT_EQ(OC_STACK_OK, result);
445     }
446
447     TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
448     {
449         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
450             std::string("core.light"));
451         EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
452     }
453
454     //BindTypeToResourceTest
455     TEST(BindTypeToResourceTest, BindResourceType)
456     {
457         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
458             std::string("core.light"));
459         OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
460             "core.brightlight");
461         EXPECT_EQ(OC_STACK_OK, result);
462     }
463
464     TEST(BindTypeToResourceTest, BindZeroResourceType)
465     {
466         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
467             std::string("core.light"));
468         EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
469     }
470
471     //UnbindResourceTest
472     TEST(UnbindResourceTest, BindAndUnbindResource)
473     {
474         OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
475             std::string("core.unres"));
476         OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
477             std::string("core.unres"), LINK_INTERFACE);
478
479         EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
480         EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
481     }
482
483     //PresenceTest
484     TEST(PresenceTest, DISABLED_StartAndStopPresence)
485     {
486         EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
487         EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
488             std::string("core.Presence")));
489         EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
490     }
491
492     TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
493     {
494         EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
495     }
496
497     //NotifyAllObserverTest
498     TEST(NotifyAllObserverTest, NotifyAllObservers)
499     {
500         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
501             std::string("core.obs"));
502         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
503     }
504
505     TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
506     {
507         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
508             std::string("core.obs"));
509         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
510                 OC::QualityOfService::LowQos));
511     }
512
513     TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
514     {
515         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
516             std::string("core.obs"));
517         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
518                 OC::QualityOfService::MidQos));
519     }
520
521     TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
522     {
523         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
524             std::string("core.obs"));
525         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
526                 OC::QualityOfService::NaQos));
527     }
528
529     TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
530     {
531         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
532             std::string("core.obs"));
533         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
534                 OC::QualityOfService::HighQos));
535     }
536
537     TEST(NotifyAllObserverTest, NotifyListOfObservers)
538     {
539         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
540             std::string("core.obs"));
541
542         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
543         ObservationIds interestedObservers;
544         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
545             interestedObservers, resourceResponse));
546     }
547
548     TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
549     {
550         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
551             std::string("core.obs"));
552
553         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
554         ObservationIds interestedObservers;
555         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
556             interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
557     }
558
559     TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
560     {
561         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
562             std::string("core.obs"));
563
564         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
565         ObservationIds interestedObservers;
566         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
567             interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
568     }
569
570     TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
571     {
572         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
573             std::string("core.obs"));
574
575         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
576         ObservationIds interestedObservers;
577         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
578             interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
579     }
580
581     TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
582     {
583         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
584             std::string("core.obs"));
585
586         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
587         ObservationIds interestedObservers;
588         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
589             interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
590     }
591
592     //DeviceEntityHandlerTest
593     TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
594     {
595         EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
596         EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
597     }
598
599
600     //FindResource test
601     TEST(FindResourceTest, DISABLED_FindResourceValid)
602     {
603       std::ostringstream requestURI;
604       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
605       EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
606               CT_DEFAULT, &foundResource));
607     }
608
609     TEST(FindResourceTest, FindResourceNullResourceURI)
610     {
611       EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
612               CT_DEFAULT, &foundResource));
613     }
614
615     TEST(FindResourceTest, FindResourceNullResourceURI1)
616     {
617       std::ostringstream requestURI;
618       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
619       EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
620               CT_DEFAULT, &foundResource));
621     }
622
623     TEST(FindResourceTest, FindResourceNullHost)
624     {
625       std::ostringstream requestURI;
626       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
627       EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
628               CT_DEFAULT, &foundResource));
629     }
630
631     TEST(FindResourceTest, FindResourceNullresourceHandler)
632     {
633       std::ostringstream requestURI;
634       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
635       EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
636               CT_DEFAULT, NULL), OC::OCException);
637     }
638
639     TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
640     {
641         std::ostringstream requestURI;
642         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
643         EXPECT_EQ(OC_STACK_OK,
644                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
645                         OC::QualityOfService::LowQos));
646     }
647
648     TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
649     {
650         std::ostringstream requestURI;
651         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
652         EXPECT_EQ(OC_STACK_OK,
653                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
654                         OC::QualityOfService::MidQos));
655     }
656
657     TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
658     {
659         std::ostringstream requestURI;
660         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
661         EXPECT_EQ(OC_STACK_OK,
662                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
663                         OC::QualityOfService::HighQos));
664     }
665
666     TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
667     {
668         std::ostringstream requestURI;
669         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
670         EXPECT_EQ(OC_STACK_OK,
671                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
672                         OC::QualityOfService::NaQos));
673     }
674
675     //GetDeviceInfo Test
676     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
677     {
678         std::string deviceDiscoveryURI = "/oic/d";
679         PlatformConfig cfg;
680         OCPlatform::Configure(cfg);
681         std::ostringstream requestURI;
682         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
683         EXPECT_EQ(OC_STACK_OK,
684                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
685     }
686
687     TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
688     {
689         PlatformConfig cfg;
690         OCPlatform::Configure(cfg);
691         EXPECT_ANY_THROW(
692                 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
693     }
694
695     TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
696     {
697         std::string deviceDiscoveryURI = "/oic/d";
698         PlatformConfig cfg;
699         OCPlatform::Configure(cfg);
700         std::ostringstream requestURI;
701         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
702         EXPECT_THROW(
703                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
704                 OC::OCException);
705     }
706
707     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
708     {
709         std::string deviceDiscoveryURI = "/oic/d";
710         PlatformConfig cfg;
711         OCPlatform::Configure(cfg);
712         std::ostringstream requestURI;
713         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
714         EXPECT_EQ(OC_STACK_OK,
715                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
716                         OC::QualityOfService::LowQos));
717     }
718
719     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
720     {
721         std::string deviceDiscoveryURI = "/oic/d";
722         PlatformConfig cfg;
723         OCPlatform::Configure(cfg);
724         std::ostringstream requestURI;
725         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
726         EXPECT_EQ(OC_STACK_OK,
727                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
728                         OC::QualityOfService::MidQos));
729     }
730
731     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
732     {
733         std::string deviceDiscoveryURI = "/oic/d";
734         PlatformConfig cfg;
735         OCPlatform::Configure(cfg);
736         std::ostringstream requestURI;
737         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
738         EXPECT_EQ(OC_STACK_OK,
739                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
740                         OC::QualityOfService::HighQos));
741     }
742
743     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
744     {
745         std::string deviceDiscoveryURI = "/oic/d";
746         PlatformConfig cfg;
747         OCPlatform::Configure(cfg);
748         std::ostringstream requestURI;
749         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
750         EXPECT_EQ(OC_STACK_OK,
751                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
752                         OC::QualityOfService::NaQos));
753     }
754
755     //RegisterDeviceInfo test
756     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
757     {
758         OCDeviceInfo deviceInfo;
759         DuplicateString(&deviceInfo.deviceName, "myDeviceName");
760         deviceInfo.types = NULL;
761         OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
762         OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
763         DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
764         deviceInfo.dataModelVersions = nullptr;
765         OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions");
766         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
767         EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
768     }
769
770     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
771     {
772         OCDeviceInfo di = {0, 0, 0, 0};
773         EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
774     }
775
776     //SubscribePresence Test
777     TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
778     {
779         std::string hostAddress = "192.168.1.2:5000";
780         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
781
782         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
783                  CT_DEFAULT, &presenceHandler));
784     }
785
786     TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
787     {
788         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
789
790         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
791                  CT_DEFAULT, &presenceHandler));
792     }
793
794     TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
795     {
796         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
797
798         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
799                  CT_DEFAULT, NULL));
800     }
801
802     TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
803     {
804         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
805
806         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
807                 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
808     }
809
810     TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
811     {
812         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
813
814         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
815                 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
816     }
817
818     TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
819     {
820         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
821
822         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
823                 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
824         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
825     }
826
827     TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
828     {
829         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
830         EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
831     }
832
833     TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
834     {
835         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
836
837         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
838                 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
839         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
840     }
841
842 #ifdef WITH_CLOUD
843     //SubscribeDevicePresence Test
844     TEST(SubscribeDevicePresenceTest, DISABLED_SubscribeDevicePresenceWithValidParameters)
845     {
846         std::string hostAddress = "192.168.1.2:5000";
847         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
848         QueryParamsList queryParams = {};
849
850         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
851                 hostAddress, queryParams, CT_DEFAULT, &onObserve));
852     }
853
854     TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullHost)
855     {
856         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
857         QueryParamsList queryParams = {};
858
859         EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
860                         nullptr, queryParams, CT_DEFAULT, &onObserve));
861     }
862
863     TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullOnObserve)
864     {
865         std::string hostAddress = "192.168.1.2:5000";
866         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
867         QueryParamsList queryParams = {};
868
869         EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
870                         hostAddress, queryParams, CT_DEFAULT, NULL));
871     }
872
873     TEST(SubscribeDevicePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
874     {
875         std::string hostAddress = "192.168.1.2:5000";
876         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
877         QueryParamsList queryParams = {};
878
879         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
880                 hostAddress, queryParams, CT_DEFAULT, &onObserve));
881         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
882     }
883 #endif
884
885     TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
886     {
887         EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
888     }
889
890     TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
891     {
892         EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
893     }
894
895     TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
896     {
897         EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
898     }
899
900     TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
901     {
902         OCDPDev_t peer;
903         OCPrm_t pmSel = DP_PRE_CONFIGURED;
904         std::string pin("");
905         std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
906         EXPECT_ANY_THROW(OCPlatform::doDirectPairing(s_dp, pmSel, pin, nullptr));
907     }
908
909     TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
910     {
911         OCDPDev_t peer;
912         OCPrm_t pmSel = DP_PRE_CONFIGURED;
913         std::string pin("");
914         std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
915         EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, &directPairHandler));
916     }
917
918     TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
919     {
920         OCDPDev_t peer;
921         OCPrm_t pmSel = DP_PRE_CONFIGURED;
922         std::string pin("");
923         std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
924         EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));
925     }
926 #ifdef WITH_CLOUD
927     //SignUp Test
928     TEST(SignUpTest, DISABLED_SignUpWithValidParameters)
929     {
930         std::string host("coap+tcp://192.168.1.2:5000");
931         std::string authProvider("AnyAuthProvider");
932         std::string authCode("AnyAuthCode");
933         EXPECT_EQ(OC_STACK_OK, OCPlatform::signUp(host, authProvider, authCode,
934                                                   CT_DEFAULT, &accountHandler));
935     }
936
937     TEST(SignUpTest, SignUpWithNullCallback)
938     {
939         std::string host("coap+tcp://192.168.1.2:5000");
940         std::string authProvider("AnyAuthProvider");
941         std::string authCode("AnyAuthCode");
942         EXPECT_ANY_THROW(OCPlatform::signUp(host, authProvider, authCode, CT_DEFAULT, nullptr));
943     }
944
945     //SignIn Test
946     TEST(SignInTest, DISABLED_SignInWithValidParameters)
947     {
948         std::string host("coap+tcp://192.168.1.2:5000");
949         std::string accessToken("AnyAccessToken");
950         EXPECT_EQ(OC_STACK_OK, OCPlatform::signIn(host, accessToken, CT_DEFAULT, &accountHandler));
951     }
952
953     TEST(SignInTest, SignInWithNullCallback)
954     {
955         std::string host("coap+tcp://192.168.1.2:5000");
956         std::string accessToken("AnyAccessToken");
957         EXPECT_ANY_THROW(OCPlatform::signIn(host, accessToken, CT_DEFAULT, nullptr));
958     }
959
960     //SignOut Test
961     TEST(SignOutTest, DISABLED_SignOutWithValidParameters)
962     {
963         std::string host("coap+tcp://192.168.1.2:5000");
964         std::string accessToken("AnyAccessToken");
965         EXPECT_EQ(OC_STACK_OK, OCPlatform::signOut(host, accessToken,
966                                                    CT_DEFAULT, &accountHandler));
967     }
968
969     TEST(SignOutTest, SignOutWithNullCallback)
970     {
971         std::string host("coap+tcp://192.168.1.2:5000");
972         std::string accessToken("AnyAccessToken");
973         EXPECT_ANY_THROW(OCPlatform::signOut(host, accessToken, CT_DEFAULT, nullptr));
974     }
975
976     //RefreshAccessToken Test
977     TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenWithValidParameters)
978     {
979         std::string host("coap+tcp://192.168.1.2:5000");
980         std::string refreshToken("AnyRefreshToken");
981         EXPECT_EQ(OC_STACK_OK, OCPlatform::refreshAccessToken(host, refreshToken,
982                                                               CT_DEFAULT, &accountHandler));
983     }
984
985     TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
986     {
987         std::string host("coap+tcp://192.168.1.2:5000");
988         std::string refreshToken("AnyRefreshToken");
989         EXPECT_ANY_THROW(OCPlatform::refreshAccessToken(host, refreshToken, CT_DEFAULT, nullptr));
990     }
991 #endif // WITH_CLOUD
992 }