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