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