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