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