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