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