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