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