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