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