Support HighQoS and Cancel Observe in CA and RI
[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_THROW(OCPlatform::findResource("", requestURI.str(),
511               OC_WIFI, NULL), OC::OCException);
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     TEST(FindResourceTest, FindResourceWithHighQos)
533     {
534         std::ostringstream requestURI;
535         requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
536         EXPECT_EQ(OC_STACK_OK,
537                 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
538                         OC::QualityOfService::HighQos));
539     }
540
541     TEST(FindResourceTest, FindResourceWithNaQos)
542     {
543         std::ostringstream requestURI;
544         requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
545         EXPECT_EQ(OC_STACK_OK,
546                 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
547                         OC::QualityOfService::NaQos));
548     }
549
550     //GetDeviceInfo Test
551     TEST(GetDeviceInfoTest, GetDeviceInfoWithValidParameters)
552     {
553         std::string deviceDiscoveryURI = "/oc/core/d";
554         PlatformConfig cfg;
555         OCPlatform::Configure(cfg);
556         std::ostringstream requestURI;
557         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
558         EXPECT_EQ(OC_STACK_OK,
559                 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo));
560     }
561
562     TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
563     {
564         PlatformConfig cfg;
565         OCPlatform::Configure(cfg);
566         EXPECT_ANY_THROW(
567                 OCPlatform::getDeviceInfo("", nullptr, OC_WIFI, &receivedDeviceInfo));
568     }
569
570     TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
571     {
572         std::string deviceDiscoveryURI = "/oc/core/d";
573         PlatformConfig cfg;
574         OCPlatform::Configure(cfg);
575         std::ostringstream requestURI;
576         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
577         EXPECT_THROW(
578                 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, NULL),
579                 OC::OCException);
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     TEST(GetDeviceInfoTest, GetDeviceInfoWithHighQos)
607     {
608         std::string deviceDiscoveryURI = "/oc/core/d";
609         PlatformConfig cfg;
610         OCPlatform::Configure(cfg);
611         std::ostringstream requestURI;
612         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
613         EXPECT_EQ(OC_STACK_OK,
614                 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
615                         OC::QualityOfService::HighQos));
616     }
617
618     TEST(GetDeviceInfoTest, GetDeviceInfoWithNaQos)
619     {
620         std::string deviceDiscoveryURI = "/oc/core/d";
621         PlatformConfig cfg;
622         OCPlatform::Configure(cfg);
623         std::ostringstream requestURI;
624         requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
625         EXPECT_EQ(OC_STACK_OK,
626                 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
627                         OC::QualityOfService::NaQos));
628     }
629
630     //RegisterDeviceInfo test
631     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
632     {
633         OCDeviceInfo deviceInfo;
634
635         DuplicateString(&deviceInfo.contentType, "myContentType");
636         DuplicateString(&deviceInfo.dateOfManufacture, "myDateOfManufacture");
637         DuplicateString(&deviceInfo.deviceName, "myDeviceName");
638         DuplicateString(&deviceInfo.deviceUUID, "myDeviceUUID");
639         DuplicateString(&deviceInfo.firmwareVersion, "myFirmwareVersion");
640         DuplicateString(&deviceInfo.hostName, "myHostName");
641         DuplicateString(&deviceInfo.manufacturerName, "myManufacturerNa");
642         DuplicateString(&deviceInfo.manufacturerUrl, "myManufacturerUrl");
643         DuplicateString(&deviceInfo.modelNumber, "myModelNumber");
644         DuplicateString(&deviceInfo.platformVersion, "myPlatformVersion");
645         DuplicateString(&deviceInfo.supportUrl, "mySupportUrl");
646         DuplicateString(&deviceInfo.version, "myVersion");
647
648         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
649         EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
650     }
651
652     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
653     {
654         OCDeviceInfo di = {};
655         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(di));
656     }
657
658     //SubscribePresence Test
659     TEST(SubscribePresenceTest,SubscribePresenceWithValidParameters)
660     {
661         std::string hostAddress = "192.168.1.2:5000";
662         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
663
664         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
665                  OC_WIFI, &presenceHandler));
666     }
667
668     TEST(SubscribePresenceTest,SubscribePresenceWithNullHost)
669     {
670         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
671
672         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
673                  OC_WIFI, &presenceHandler));
674     }
675
676     TEST(SubscribePresenceTest,SubscribePresenceWithNullPresenceHandler)
677     {
678         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
679
680         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
681                  OC_WIFI, NULL));
682     }
683
684     TEST(SubscribePresenceTest,SubscribePresenceWithResourceType)
685     {
686         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
687
688         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
689                 OC_MULTICAST_IP, "core.light", OC_WIFI, &presenceHandler));
690     }
691
692     TEST(SubscribePresenceTest,SubscribePresenceWithNullResourceType)
693     {
694         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
695
696         EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
697                 OC_MULTICAST_IP, nullptr, OC_WIFI, &presenceHandler));
698     }
699
700     TEST(SubscribePresenceTest, UnsubscribePresenceWithValidHandleAndRT)
701     {
702         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
703
704         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
705                 OC_MULTICAST_IP, "core.light", OC_WIFI, &presenceHandler));
706         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
707     }
708
709     TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
710     {
711         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
712         EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
713     }
714
715     TEST(SubscribePresenceTest, UnsubscribePresenceWithValidHandle)
716     {
717         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
718
719         EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
720                 OC_MULTICAST_IP, OC_WIFI, &presenceHandler));
721         EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
722     }
723
724 }