Merge "Merge 'security-basecamp' branch into master with CBOR"
[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 <gtest/gtest.h>
24
25 namespace OCPlatformTest
26 {
27     using namespace OC;
28
29     const OCResourceHandle HANDLE_ZERO = 0;
30     const std::string gResourceTypeName = "core.res";
31     const std::string gResourceInterface = DEFAULT_INTERFACE;
32     const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
33     OCResourceHandle resourceHandle;
34   //OCPersistent Storage Handlers
35
36    static FILE* client_open(const char *path, const char *mode)
37    {
38        std::cout << "<===Opening SVR DB file = './oic_svr_db_client.json' with mode = '"<< mode<<"' "<<std::endl;
39                return fopen("./oic_svr_db_client.json", mode);
40    }
41     // Callbacks
42     OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
43     {
44         return OC_EH_OK;
45     }
46
47     void foundResource(std::shared_ptr<OCResource> resource)
48     {
49     }
50
51     void receivedDeviceInfo(const OCRepresentation& rep)
52     {
53     }
54
55     void presenceHandler(OCStackResult result,
56             const unsigned int nonce, const std::string& hostAddress)
57     {
58     }
59
60     //Helper methods
61     void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
62     {
63         delete[] deviceInfo.deviceName;
64
65     }
66
67     void DuplicateString(char ** targetString, std::string sourceString)
68     {
69         *targetString = new char[sourceString.length() + 1];
70         strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
71     }
72
73     OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
74     {
75         PlatformConfig cfg = {};
76         OCPlatform::Configure(cfg);
77         EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
78                                         resourceHandle, uri, type,
79                                         iface, entityHandler, gResourceProperty));
80         return resourceHandle;
81     }
82
83     OCResourceHandle RegisterResource(std::string uri, std::string type)
84     {
85         PlatformConfig cfg = {};
86         OCPlatform::Configure(cfg);
87         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
88                                         resourceHandle, uri, type,
89                                         gResourceInterface, entityHandler, gResourceProperty));
90         return resourceHandle;
91     }
92
93     OCResourceHandle RegisterResource(std::string uri)
94     {
95         PlatformConfig cfg = {};
96         OCPlatform::Configure(cfg);
97         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
98                                         resourceHandle, uri, gResourceTypeName,
99                                         gResourceInterface, entityHandler, gResourceProperty));
100         return resourceHandle;
101     }
102
103     //Configure
104     // Enable it when the stack throw an exception
105     // https://jira.iotivity.org/browse/IOT-428
106     TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
107     {
108         PlatformConfig cfg {
109              OC::ServiceType::InProc,
110             (OC::ModeType)99,
111              "0.0.0.0",
112              0,
113              OC::QualityOfService::LowQos
114          };
115          OCPlatform::Configure(cfg);
116          EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
117      }
118
119     // Enable it when the stack throw an exception
120     // https://jira.iotivity.org/browse/IOT-428
121     TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
122     {
123         PlatformConfig cfg {
124              (OC::ServiceType)99,
125             OC::ModeType::Client,
126              "0.0.0.0",
127              0,
128              OC::QualityOfService::LowQos
129          };
130          OCPlatform::Configure(cfg);
131          EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
132      }
133
134     // Enable it when the stack throw an exception
135     // https://jira.iotivity.org/browse/IOT-428
136     TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
137     {
138         PlatformConfig cfg {
139             OC::ServiceType::OutOfProc,
140             OC::ModeType::Client,
141             "0.0.0.0",
142             0,
143             OC::QualityOfService::LowQos
144         };
145         std::string uri = "/a/light66";
146         std::string type = "core.light";
147         uint8_t gResourceProperty = 0;
148         OCPlatform::Configure(cfg);
149         EXPECT_ANY_THROW(OCPlatform::registerResource(
150              resourceHandle, uri, type,
151              gResourceInterface, entityHandler, gResourceProperty));
152     }
153
154     TEST(ConfigureTest, ConfigureServerOutProc)
155     {
156         PlatformConfig cfg {
157             OC::ServiceType::OutOfProc,
158             OC::ModeType::Server,
159             "0.0.0.0",
160             0,
161             OC::QualityOfService::LowQos
162         };
163         std::string uri = "/a/light67";
164         std::string type = "core.light";
165         uint8_t gResourceProperty = 0;
166         OCPlatform::Configure(cfg);
167
168         EXPECT_ANY_THROW(OCPlatform::registerResource(
169              resourceHandle, uri, type,
170              gResourceInterface, entityHandler, gResourceProperty));
171     }
172
173     TEST(ConfigureTest, ConfigureDefault)
174     {
175         std::string uri = "/a/light68";
176         std::string type = "core.light";
177         uint8_t gResourceProperty = 0;
178         PlatformConfig cfg = {};
179         OCPlatform::Configure(cfg);
180
181         EXPECT_NO_THROW(OCPlatform::registerResource(
182                  resourceHandle, uri, type,
183                  gResourceInterface, entityHandler, gResourceProperty));
184     }
185
186     TEST(ConfigureTest, ConfigureServer)
187     {
188         std::string uri = "/a/light69";
189         std::string type = "core.light";
190         uint8_t gResourceProperty = 0;
191         PlatformConfig cfg {
192             OC::ServiceType::InProc,
193             OC::ModeType::Server,
194             "0.0.0.0",
195             0,
196             OC::QualityOfService::LowQos
197         };
198         OCPlatform::Configure(cfg);
199
200         EXPECT_NO_THROW(OCPlatform::registerResource(
201                  resourceHandle, uri, type,
202                  gResourceInterface, entityHandler, gResourceProperty));
203     }
204
205     TEST(ConfigureTest, ConfigureClient)
206     {
207         std::string uri = "/a/light70";
208         std::string type = "core.light";
209         uint8_t gResourceProperty = 0;
210         PlatformConfig cfg {
211             OC::ServiceType::InProc,
212             OC::ModeType::Client,
213             "0.0.0.0",
214             0,
215             OC::QualityOfService::LowQos
216         };
217         OCPlatform::Configure(cfg);
218
219         EXPECT_NO_THROW(OCPlatform::registerResource(
220                  resourceHandle, uri, type,
221                  gResourceInterface, entityHandler, gResourceProperty));
222     }
223     //PersistentStorageTest
224     TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
225     {
226         PlatformConfig cfg {
227              OC::ServiceType::InProc,
228              OC::ModeType::Both,
229              "0.0.0.0",
230              0,
231              OC::QualityOfService::LowQos
232          };
233          OCPlatform::Configure(cfg);
234          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
235      }
236
237     //PersistentStorageTest
238     TEST(ConfigureTest, ConfigureNULLPersistentStorage)
239     {
240         PlatformConfig cfg {
241              OC::ServiceType::InProc,
242              OC::ModeType::Both,
243              "0.0.0.0",
244              0,
245              OC::QualityOfService::LowQos,
246              nullptr
247          };
248          OCPlatform::Configure(cfg);
249          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
250      }
251
252     //PersistentStorageTest
253     TEST(ConfigureTest, ConfigurePersistentStorage)
254     {
255         OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
256         PlatformConfig cfg {
257              OC::ServiceType::InProc,
258              OC::ModeType::Both,
259              "0.0.0.0",
260              0,
261              OC::QualityOfService::LowQos,
262              &ps
263          };
264          OCPlatform::Configure(cfg);
265          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
266      }
267
268     //PersistentStorageTest
269     TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
270     {
271         OCPersistentStorage ps {client_open, nullptr, nullptr, nullptr, nullptr };
272         PlatformConfig cfg {
273              OC::ServiceType::InProc,
274              OC::ModeType::Both,
275              "0.0.0.0",
276              0,
277              OC::QualityOfService::LowQos,
278              &ps
279          };
280          OCPlatform::Configure(cfg);
281          EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
282      }
283
284
285     //RegisterResourceTest
286     TEST(RegisterResourceTest, RegisterSingleResource)
287     {
288         std::string uri = "/a/res2";
289         EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
290     }
291
292     TEST(RegisterResourceTest, RegisterMultipleResources)
293     {
294         std::string uri = "/a/multi";
295         //Good enough for 5 resources.
296         for(int i=0; i< 5; i++)
297         {
298             uri +=std::to_string(i);
299             EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
300         }
301     }
302
303     TEST(RegisterResourceTest, ReregisterResource)
304     {
305         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
306             std::string("core.light"));
307         EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
308
309         EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
310             std::string("core.light")));
311
312     }
313
314     TEST(RegisterResourceTest, RegisterEmptyResource)
315     {
316         // We should not allow empty URI.
317         std::string emptyStr = "";
318         EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
319                                         emptyStr, entityHandler, gResourceProperty));
320     }
321
322     TEST(RegisterResourceTest, RegisterZeroResourceProperty)
323     {
324         std::string uri = "/a/light6";
325         std::string type = "core.light";
326         uint8_t gResourceProperty = 0;
327         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
328                 resourceHandle, uri, type,
329                 gResourceInterface, entityHandler, gResourceProperty));
330     }
331
332     //UnregisterTest
333     TEST(UnregisterTest, UnregisterZeroHandleValue)
334     {
335         EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
336     }
337
338     //UnbindResourcesTest
339     TEST(UnbindResourcesTest, UnbindResources)
340     {
341         OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
342             std::string("core.home"));
343         OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
344             std::string("core.kitchen"), LINK_INTERFACE);
345         OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
346             std::string("core.office"), LINK_INTERFACE);
347
348         std::vector<OCResourceHandle> rList;
349         rList.push_back(resourceKitchen);
350         rList.push_back(resourceRoom);
351         EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
352         EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
353     }
354
355     TEST(UnbindResourcesTest, UnbindResourcesWithZero)
356     {
357         OCResourceHandle resourceHandle1 = 0;
358         OCResourceHandle resourceHandle2 = 0;
359         OCResourceHandle resourceHandle3 = 0;
360
361         std::vector<OCResourceHandle> rList;
362
363         rList.push_back(resourceHandle2);
364         rList.push_back(resourceHandle3);
365
366         EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
367     }
368
369     //BindInterfaceToResourceTest
370     TEST(BindInterfaceToResourceTest, BindResourceInterface)
371     {
372         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
373             std::string("core.light"));
374         OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
375             BATCH_INTERFACE);
376         EXPECT_EQ(OC_STACK_OK, result);
377     }
378
379     TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
380     {
381         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
382             std::string("core.light"));
383         EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
384     }
385
386     //BindTypeToResourceTest
387     TEST(BindTypeToResourceTest, BindResourceType)
388     {
389         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
390             std::string("core.light"));
391         OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
392             "core.brightlight");
393         EXPECT_EQ(OC_STACK_OK, result);
394     }
395
396     TEST(BindTypeToResourceTest, BindZeroResourceType)
397     {
398         OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
399             std::string("core.light"));
400         EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
401     }
402
403     //UnbindResourceTest
404     TEST(UnbindResourceTest, BindAndUnbindResource)
405     {
406         OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
407             std::string("core.unres"));
408         OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
409             std::string("core.unres"), LINK_INTERFACE);
410
411         EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
412         EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
413     }
414
415     //PresenceTest
416     TEST(PresenceTest, DISABLED_StartAndStopPresence)
417     {
418         EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
419         EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
420             std::string("core.Presence")));
421         EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
422     }
423
424     TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
425     {
426         EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
427     }
428
429     //NotifyAllObserverTest
430     TEST(NotifyAllObserverTest, NotifyAllObservers)
431     {
432         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
433             std::string("core.obs"));
434         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
435     }
436
437     TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
438     {
439         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
440             std::string("core.obs"));
441         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
442                 OC::QualityOfService::LowQos));
443     }
444
445     TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
446     {
447         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
448             std::string("core.obs"));
449         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
450                 OC::QualityOfService::MidQos));
451     }
452
453     TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
454     {
455         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
456             std::string("core.obs"));
457         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
458                 OC::QualityOfService::NaQos));
459     }
460
461     TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
462     {
463         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
464             std::string("core.obs"));
465         EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
466                 OC::QualityOfService::HighQos));
467     }
468
469     TEST(NotifyAllObserverTest, NotifyListOfObservers)
470     {
471         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
472             std::string("core.obs"));
473
474         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
475         ObservationIds interestedObservers;
476         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
477             interestedObservers, resourceResponse));
478     }
479
480     TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
481     {
482         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
483             std::string("core.obs"));
484
485         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
486         ObservationIds interestedObservers;
487         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
488             interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
489     }
490
491     TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
492     {
493         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
494             std::string("core.obs"));
495
496         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
497         ObservationIds interestedObservers;
498         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
499             interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
500     }
501
502     TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
503     {
504         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
505             std::string("core.obs"));
506
507         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
508         ObservationIds interestedObservers;
509         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
510             interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
511     }
512
513     TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
514     {
515         OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
516             std::string("core.obs"));
517
518         std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
519         ObservationIds interestedObservers;
520         EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
521             interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
522     }
523
524     //DeviceEntityHandlerTest
525     TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
526     {
527         EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
528         EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
529     }
530
531
532     //FindResource test
533     TEST(FindResourceTest, DISABLED_FindResourceValid)
534     {
535       std::ostringstream requestURI;
536       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
537       EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
538               CT_DEFAULT, &foundResource));
539     }
540
541     TEST(FindResourceTest, FindResourceNullResourceURI)
542     {
543       EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
544               CT_DEFAULT, &foundResource));
545     }
546
547     TEST(FindResourceTest, FindResourceNullResourceURI1)
548     {
549       std::ostringstream requestURI;
550       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
551       EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
552               CT_DEFAULT, &foundResource));
553     }
554
555     TEST(FindResourceTest, FindResourceNullHost)
556     {
557       std::ostringstream requestURI;
558       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
559       EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
560               CT_DEFAULT, &foundResource));
561     }
562
563     TEST(FindResourceTest, FindResourceNullresourceHandler)
564     {
565       std::ostringstream requestURI;
566       requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
567       EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
568               CT_DEFAULT, NULL), OC::OCException);
569     }
570
571     TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
572     {
573         std::ostringstream requestURI;
574         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
575         EXPECT_EQ(OC_STACK_OK,
576                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
577                         OC::QualityOfService::LowQos));
578     }
579
580     TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
581     {
582         std::ostringstream requestURI;
583         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
584         EXPECT_EQ(OC_STACK_OK,
585                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
586                         OC::QualityOfService::MidQos));
587     }
588
589     TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
590     {
591         std::ostringstream requestURI;
592         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
593         EXPECT_EQ(OC_STACK_OK,
594                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
595                         OC::QualityOfService::HighQos));
596     }
597
598     TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
599     {
600         std::ostringstream requestURI;
601         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
602         EXPECT_EQ(OC_STACK_OK,
603                 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
604                         OC::QualityOfService::NaQos));
605     }
606
607     //GetDeviceInfo Test
608     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
609     {
610         std::string deviceDiscoveryURI = "/oic/d";
611         PlatformConfig cfg;
612         OCPlatform::Configure(cfg);
613         std::ostringstream requestURI;
614         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
615         EXPECT_EQ(OC_STACK_OK,
616                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
617     }
618
619     TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
620     {
621         PlatformConfig cfg;
622         OCPlatform::Configure(cfg);
623         EXPECT_ANY_THROW(
624                 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
625     }
626
627     TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
628     {
629         std::string deviceDiscoveryURI = "/oic/d";
630         PlatformConfig cfg;
631         OCPlatform::Configure(cfg);
632         std::ostringstream requestURI;
633         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
634         EXPECT_THROW(
635                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
636                 OC::OCException);
637     }
638
639     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
640     {
641         std::string deviceDiscoveryURI = "/oic/d";
642         PlatformConfig cfg;
643         OCPlatform::Configure(cfg);
644         std::ostringstream requestURI;
645         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
646         EXPECT_EQ(OC_STACK_OK,
647                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
648                         OC::QualityOfService::LowQos));
649     }
650
651     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
652     {
653         std::string deviceDiscoveryURI = "/oic/d";
654         PlatformConfig cfg;
655         OCPlatform::Configure(cfg);
656         std::ostringstream requestURI;
657         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
658         EXPECT_EQ(OC_STACK_OK,
659                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
660                         OC::QualityOfService::MidQos));
661     }
662
663     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
664     {
665         std::string deviceDiscoveryURI = "/oic/d";
666         PlatformConfig cfg;
667         OCPlatform::Configure(cfg);
668         std::ostringstream requestURI;
669         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
670         EXPECT_EQ(OC_STACK_OK,
671                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
672                         OC::QualityOfService::HighQos));
673     }
674
675     TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
676     {
677         std::string deviceDiscoveryURI = "/oic/d";
678         PlatformConfig cfg;
679         OCPlatform::Configure(cfg);
680         std::ostringstream requestURI;
681         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
682         EXPECT_EQ(OC_STACK_OK,
683                 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
684                         OC::QualityOfService::NaQos));
685     }
686
687     //RegisterDeviceInfo test
688     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
689     {
690         OCDeviceInfo deviceInfo;
691
692         DuplicateString(&deviceInfo.deviceName, "myDeviceName");
693
694         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
695         EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
696     }
697
698     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
699     {
700         OCDeviceInfo di = {};
701         EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
702     }
703
704     //SubscribePresence Test
705     TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
706     {
707         std::string hostAddress = "192.168.1.2:5000";
708         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
709
710         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
711                  CT_DEFAULT, &presenceHandler));
712     }
713
714     TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
715     {
716         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
717
718         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
719                  CT_DEFAULT, &presenceHandler));
720     }
721
722     TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
723     {
724         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
725
726         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
727                  CT_DEFAULT, NULL));
728     }
729
730     TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
731     {
732         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
733
734         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
735                 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
736     }
737
738     TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
739     {
740         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
741
742         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
743                 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
744     }
745
746     TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
747     {
748         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
749
750         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
751                 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
752         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
753     }
754
755     TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
756     {
757         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
758         EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
759     }
760
761     TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
762     {
763         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
764
765         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
766                 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
767         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
768     }
769 }