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