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