1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include <OCPlatform.h>
23 #include <oic_malloc.h>
24 #include <gtest/gtest.h>
26 namespace OCPlatformTest
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;
37 //OCPersistent Storage Handlers
38 static FILE* client_open(const char * /*path*/, const char *mode)
40 std::cout << "<===Opening SVR DB file = './oic_svr_db_client.dat' with mode = '" << mode
42 return fopen(SVR_DB_FILE_NAME, mode);
44 OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
47 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request*/)
52 void foundResource(std::shared_ptr<OCResource> /*resource*/)
56 void receivedDeviceInfo(const OCRepresentation& /*rep*/)
60 void presenceHandler(OCStackResult /*result*/,
61 const unsigned int /*nonce*/, const std::string& /*hostAddress*/)
66 void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
71 void directPairHandler(std::shared_ptr<OCDirectPairing> /*dev*/, OCStackResult /*res*/)
75 void pairedHandler(const PairedDevices& /*list*/)
80 void DeleteStringLL(OCStringLL* ll)
87 DeleteStringLL(ll->next);
92 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
94 delete[] deviceInfo.deviceName;
95 DeleteStringLL(deviceInfo.types);
96 delete[] deviceInfo.specVersion;
97 DeleteStringLL(deviceInfo.dataModelVersions);
100 void DuplicateString(char ** targetString, std::string sourceString)
102 *targetString = new char[sourceString.length() + 1];
103 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
106 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
114 DuplicateString(&dup, value);
117 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
118 (*stringLL)->value = dup;
123 OCStringLL *temp = *stringLL;
128 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
129 temp->next->value = dup;
134 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
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;
146 OCResourceHandle RegisterResource(std::string uri, std::string type)
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;
158 OCResourceHandle RegisterResource(std::string uri)
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;
171 // Enable it when the stack throw an exception
172 // https://jira.iotivity.org/browse/IOT-428
173 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
176 OC::ServiceType::InProc,
180 OC::QualityOfService::LowQos
182 OCPlatform::Configure(cfg);
183 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
186 // Enable it when the stack throw an exception
187 // https://jira.iotivity.org/browse/IOT-428
188 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
192 OC::ModeType::Client,
195 OC::QualityOfService::LowQos
197 OCPlatform::Configure(cfg);
198 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
201 // Enable it when the stack throw an exception
202 // https://jira.iotivity.org/browse/IOT-428
203 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
206 OC::ServiceType::OutOfProc,
207 OC::ModeType::Client,
210 OC::QualityOfService::LowQos
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));
221 TEST(ConfigureTest, ConfigureServerOutProc)
225 OC::ServiceType::OutOfProc,
226 OC::ModeType::Server,
229 OC::QualityOfService::LowQos, &gps
231 std::string uri = "/a/light67";
232 std::string type = "core.light";
233 uint8_t gResourceProperty = 0;
234 OCPlatform::Configure(cfg);
236 EXPECT_ANY_THROW(OCPlatform::registerResource(
237 resourceHandle, uri, type,
238 gResourceInterface, entityHandler, gResourceProperty));
241 TEST(ConfigureTest, ConfigureDefault)
243 std::string uri = "/a/light68";
244 std::string type = "core.light";
245 uint8_t gResourceProperty = 0;
246 PlatformConfig cfg = {};
247 OCPlatform::Configure(cfg);
249 EXPECT_NO_THROW(OCPlatform::registerResource(
250 resourceHandle, uri, type,
251 gResourceInterface, entityHandler, gResourceProperty));
254 TEST(ConfigureTest, ConfigureServer)
256 std::string uri = "/a/light69";
257 std::string type = "core.light";
258 uint8_t gResourceProperty = 0;
260 OC::ServiceType::InProc,
261 OC::ModeType::Server,
264 OC::QualityOfService::LowQos, &gps
266 OCPlatform::Configure(cfg);
268 EXPECT_NO_THROW(OCPlatform::registerResource(
269 resourceHandle, uri, type,
270 gResourceInterface, entityHandler, gResourceProperty));
273 TEST(ConfigureTest, ConfigureClient)
275 std::string uri = "/a/light70";
276 std::string type = "core.light";
277 uint8_t gResourceProperty = 0;
280 OC::ServiceType::InProc,
281 OC::ModeType::Client,
284 OC::QualityOfService::LowQos,
288 EXPECT_NO_THROW(OCPlatform::registerResource(
289 resourceHandle, uri, type,
290 gResourceInterface, entityHandler, gResourceProperty));
292 //PersistentStorageTest
293 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
296 OC::ServiceType::InProc,
300 OC::QualityOfService::LowQos
302 OCPlatform::Configure(cfg);
303 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
306 //PersistentStorageTest
307 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
310 OC::ServiceType::InProc,
314 OC::QualityOfService::LowQos,
317 OCPlatform::Configure(cfg);
318 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
321 //PersistentStorageTest
322 TEST(ConfigureTest, ConfigurePersistentStorage)
325 OC::ServiceType::InProc,
329 OC::QualityOfService::LowQos,
332 OCPlatform::Configure(cfg);
333 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
336 //PersistentStorageTest
337 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
340 OC::ServiceType::InProc,
344 OC::QualityOfService::LowQos,
347 OCPlatform::Configure(cfg);
348 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
352 //RegisterResourceTest
353 TEST(RegisterResourceTest, RegisterSingleResource)
355 std::string uri = "/a/res2";
356 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
359 TEST(RegisterResourceTest, RegisterMultipleResources)
361 std::string uri = "/a/multi";
362 //Good enough for 5 resources.
363 for(int i=0; i< 5; i++)
365 uri +=std::to_string(i);
366 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
370 TEST(RegisterResourceTest, ReregisterResource)
372 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
373 std::string("core.light"));
374 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
376 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
377 std::string("core.light")));
381 TEST(RegisterResourceTest, RegisterEmptyResource)
383 // We should not allow empty URI.
384 std::string emptyStr = "";
385 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
386 emptyStr, entityHandler, gResourceProperty));
389 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
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));
400 TEST(UnregisterTest, UnregisterZeroHandleValue)
402 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
405 //UnbindResourcesTest
406 TEST(UnbindResourcesTest, UnbindResources)
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);
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));
422 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
424 OCResourceHandle resourceHandle1 = 0;
425 OCResourceHandle resourceHandle2 = 0;
426 OCResourceHandle resourceHandle3 = 0;
428 std::vector<OCResourceHandle> rList;
430 rList.push_back(resourceHandle2);
431 rList.push_back(resourceHandle3);
433 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
436 //BindInterfaceToResourceTest
437 TEST(BindInterfaceToResourceTest, BindResourceInterface)
439 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
440 std::string("core.light"));
441 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
443 EXPECT_EQ(OC_STACK_OK, result);
446 #if defined (_MSC_VER)
447 TEST(BindInterfaceToResourceTest, DISABLED_BindZeroResourceInterface)
449 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
452 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
453 std::string("core.light"));
454 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
457 //BindTypeToResourceTest
458 TEST(BindTypeToResourceTest, BindResourceType)
460 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
461 std::string("core.light"));
462 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
464 EXPECT_EQ(OC_STACK_OK, result);
467 #if defined (_MSC_VER)
468 TEST(BindTypeToResourceTest, DISABLED_BindZeroResourceType)
470 TEST(BindTypeToResourceTest, BindZeroResourceType)
473 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
474 std::string("core.light"));
475 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
479 TEST(UnbindResourceTest, BindAndUnbindResource)
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);
486 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
487 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
491 TEST(PresenceTest, DISABLED_StartAndStopPresence)
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());
499 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
501 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
504 //NotifyAllObserverTest
505 TEST(NotifyAllObserverTest, NotifyAllObservers)
507 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
508 std::string("core.obs"));
509 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
512 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
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));
520 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
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));
528 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
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));
536 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
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));
544 #if defined (_MSC_VER)
545 TEST(NotifyAllObserverTest, DISABLED_NotifyListOfObservers)
547 TEST(NotifyAllObserverTest, NotifyListOfObservers)
550 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
551 std::string("core.obs"));
553 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
554 ObservationIds interestedObservers;
555 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
556 interestedObservers, resourceResponse));
559 #if defined (_MSC_VER)
560 TEST(NotifyAllObserverTest, DISABLED_NotifyListOfObserversWithLowQos)
562 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
565 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
566 std::string("core.obs"));
568 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
569 ObservationIds interestedObservers;
570 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
571 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
574 #if defined (_MSC_VER)
575 TEST(NotifyAllObserverTest, DISABLED_NotifyListOfObserversWithMidQos)
577 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
580 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
581 std::string("core.obs"));
583 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
584 ObservationIds interestedObservers;
585 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
586 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
589 #if defined (_MSC_VER)
590 TEST(NotifyAllObserverTest, DISABLED_NotifyListOfObserversWithNaQos)
592 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
595 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
596 std::string("core.obs"));
598 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
599 ObservationIds interestedObservers;
600 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
601 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
604 #if defined (_MSC_VER)
605 TEST(NotifyAllObserverTest, DISABLED_NotifyListOfObserversWithHighQos)
607 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
610 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
611 std::string("core.obs"));
613 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
614 ObservationIds interestedObservers;
615 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
616 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
619 //DeviceEntityHandlerTest
620 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
622 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
623 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(nullptr));
628 TEST(FindResourceTest, DISABLED_FindResourceValid)
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));
636 #if defined (_MSC_VER)
637 TEST(FindResourceTest, DISABLED_FindResourceNullResourceURI)
639 TEST(FindResourceTest, FindResourceNullResourceURI)
642 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
643 CT_DEFAULT, &foundResource));
647 #if defined (_MSC_VER)
648 TEST(FindResourceTest, DISABLED_FindResourceNullResourceURI1)
650 TEST(FindResourceTest, FindResourceNullResourceURI1)
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));
659 #if defined (_MSC_VER)
660 TEST(FindResourceTest, DISABLED_FindResourceNullHost)
662 TEST(FindResourceTest, FindResourceNullHost)
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));
671 TEST(FindResourceTest, FindResourceNullresourceHandler)
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);
679 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
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));
688 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
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));
697 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
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));
706 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
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));
716 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
718 std::string deviceDiscoveryURI = "/oic/d";
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));
727 #if defined (_MSC_VER)
728 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoNullDeviceURI)
730 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
734 OCPlatform::Configure(cfg);
736 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
739 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
741 std::string deviceDiscoveryURI = "/oic/d";
743 OCPlatform::Configure(cfg);
744 std::ostringstream requestURI;
745 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
747 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, nullptr),
751 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
753 std::string deviceDiscoveryURI = "/oic/d";
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));
763 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
765 std::string deviceDiscoveryURI = "/oic/d";
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));
775 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
777 std::string deviceDiscoveryURI = "/oic/d";
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));
787 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
789 std::string deviceDiscoveryURI = "/oic/d";
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));
799 //RegisterDeviceInfo test
800 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
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));
817 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
819 OCDeviceInfo di = {0, 0, 0, 0};
820 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
823 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithSetPropertyValue)
825 std::string deviceName = "myDeviceName";
826 EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
828 std::string specVersion = "mySpecVersion";
829 EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
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,
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"));
843 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithGetPropertyValue)
845 EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
847 EXPECT_EQ(OC_STACK_OK, OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
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"));
856 EXPECT_EQ(OC_STACK_OK, OCPlatform::getPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
858 EXPECT_STREQ("myDeviceName", value.c_str());
859 EXPECT_EQ(OC_STACK_OK, OCPlatform::getPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
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,
865 EXPECT_STREQ("myDataModelVersions", dmv[0].c_str());
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));
871 //SubscribePresence Test
872 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
874 std::string hostAddress = "192.168.1.2:5000";
875 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
877 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
878 CT_DEFAULT, &presenceHandler));
881 #if defined (_MSC_VER)
882 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithNullHost)
884 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
887 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
889 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
890 CT_DEFAULT, &presenceHandler));
893 #if defined (_MSC_VER)
894 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithNullPresenceHandler)
896 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
899 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
901 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
902 CT_DEFAULT, nullptr));
905 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
907 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
909 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
910 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
913 #if defined (_MSC_VER)
914 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithNullResourceType)
916 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
919 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
921 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
922 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
925 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
927 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
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));
934 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
936 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
937 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
940 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
942 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
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));
950 // SubscribeDevicePresence Test
951 TEST(SubscribeDevicePresenceTest, DISABLED_SubscribeDevicePresenceWithValidParameters)
953 std::string hostAddress = "192.168.1.2:5000";
954 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
955 std::vector<std::string> di;
957 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
958 hostAddress, di, CT_DEFAULT, &onObserve));
961 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullHost)
963 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
964 std::vector<std::string> di;
966 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
967 nullptr, di, CT_DEFAULT, &onObserve));
970 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullOnObserve)
972 std::string hostAddress = "192.168.1.2:5000";
973 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
974 std::vector<std::string> di;
976 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
977 hostAddress, di, CT_DEFAULT, nullptr));
980 TEST(SubscribeDevicePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
982 std::string hostAddress = "192.168.1.2:5000";
983 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
984 std::vector<std::string> di;
986 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
987 hostAddress, di, CT_DEFAULT, &onObserve));
988 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
992 TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
994 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
997 TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
999 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
1002 TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
1004 EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
1007 TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
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));
1016 TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
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));
1025 TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
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));