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*/)
65 void directPairHandler(std::shared_ptr<OCDirectPairing> /*dev*/, OCStackResult /*res*/)
69 void pairedHandler(const PairedDevices& /*list*/)
74 void DeleteStringLL(OCStringLL* ll)
81 DeleteStringLL(ll->next);
86 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
88 delete[] deviceInfo.deviceName;
89 DeleteStringLL(deviceInfo.types);
90 delete[] deviceInfo.specVersion;
91 DeleteStringLL(deviceInfo.dataModelVersions);
94 void DuplicateString(char ** targetString, std::string sourceString)
96 *targetString = new char[sourceString.length() + 1];
97 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
100 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
103 DuplicateString(&dup, value);
106 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
107 (*stringLL)->value = dup;
112 OCStringLL *temp = *stringLL;
117 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
118 temp->next->value = dup;
124 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
127 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
128 OC::QualityOfService::LowQos, &gps };
129 OCPlatform::Configure(cfg);
130 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
131 resourceHandle, uri, type,
132 iface, entityHandler, gResourceProperty));
133 return resourceHandle;
136 OCResourceHandle RegisterResource(std::string uri, std::string type)
139 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
140 OC::QualityOfService::LowQos, &gps };
141 OCPlatform::Configure(cfg);
142 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
143 resourceHandle, uri, type,
144 gResourceInterface, entityHandler, gResourceProperty));
145 return resourceHandle;
148 OCResourceHandle RegisterResource(std::string uri)
151 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
152 OC::QualityOfService::LowQos, &gps };
153 OCPlatform::Configure(cfg);
154 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
155 resourceHandle, uri, gResourceTypeName,
156 gResourceInterface, entityHandler, gResourceProperty));
157 return resourceHandle;
161 // Enable it when the stack throw an exception
162 // https://jira.iotivity.org/browse/IOT-428
163 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
166 OC::ServiceType::InProc,
170 OC::QualityOfService::LowQos
172 OCPlatform::Configure(cfg);
173 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
176 // Enable it when the stack throw an exception
177 // https://jira.iotivity.org/browse/IOT-428
178 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
182 OC::ModeType::Client,
185 OC::QualityOfService::LowQos
187 OCPlatform::Configure(cfg);
188 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
191 // Enable it when the stack throw an exception
192 // https://jira.iotivity.org/browse/IOT-428
193 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
196 OC::ServiceType::OutOfProc,
197 OC::ModeType::Client,
200 OC::QualityOfService::LowQos
202 std::string uri = "/a/light66";
203 std::string type = "core.light";
204 uint8_t gResourceProperty = 0;
205 OCPlatform::Configure(cfg);
206 EXPECT_ANY_THROW(OCPlatform::registerResource(
207 resourceHandle, uri, type,
208 gResourceInterface, entityHandler, gResourceProperty));
211 TEST(ConfigureTest, ConfigureServerOutProc)
215 OC::ServiceType::OutOfProc,
216 OC::ModeType::Server,
219 OC::QualityOfService::LowQos, &gps
221 std::string uri = "/a/light67";
222 std::string type = "core.light";
223 uint8_t gResourceProperty = 0;
224 OCPlatform::Configure(cfg);
226 EXPECT_ANY_THROW(OCPlatform::registerResource(
227 resourceHandle, uri, type,
228 gResourceInterface, entityHandler, gResourceProperty));
231 TEST(ConfigureTest, ConfigureDefault)
233 std::string uri = "/a/light68";
234 std::string type = "core.light";
235 uint8_t gResourceProperty = 0;
236 PlatformConfig cfg = {};
237 OCPlatform::Configure(cfg);
239 EXPECT_NO_THROW(OCPlatform::registerResource(
240 resourceHandle, uri, type,
241 gResourceInterface, entityHandler, gResourceProperty));
244 TEST(ConfigureTest, ConfigureServer)
246 std::string uri = "/a/light69";
247 std::string type = "core.light";
248 uint8_t gResourceProperty = 0;
250 OC::ServiceType::InProc,
251 OC::ModeType::Server,
254 OC::QualityOfService::LowQos, &gps
256 OCPlatform::Configure(cfg);
258 EXPECT_NO_THROW(OCPlatform::registerResource(
259 resourceHandle, uri, type,
260 gResourceInterface, entityHandler, gResourceProperty));
263 TEST(ConfigureTest, ConfigureClient)
265 std::string uri = "/a/light70";
266 std::string type = "core.light";
267 uint8_t gResourceProperty = 0;
270 OC::ServiceType::InProc,
271 OC::ModeType::Client,
274 OC::QualityOfService::LowQos,
278 EXPECT_NO_THROW(OCPlatform::registerResource(
279 resourceHandle, uri, type,
280 gResourceInterface, entityHandler, gResourceProperty));
282 //PersistentStorageTest
283 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
286 OC::ServiceType::InProc,
290 OC::QualityOfService::LowQos
292 OCPlatform::Configure(cfg);
293 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
296 //PersistentStorageTest
297 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
300 OC::ServiceType::InProc,
304 OC::QualityOfService::LowQos,
307 OCPlatform::Configure(cfg);
308 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
311 //PersistentStorageTest
312 TEST(ConfigureTest, ConfigurePersistentStorage)
315 OC::ServiceType::InProc,
319 OC::QualityOfService::LowQos,
322 OCPlatform::Configure(cfg);
323 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
326 //PersistentStorageTest
327 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
330 OC::ServiceType::InProc,
334 OC::QualityOfService::LowQos,
337 OCPlatform::Configure(cfg);
338 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
342 //RegisterResourceTest
343 TEST(RegisterResourceTest, RegisterSingleResource)
345 std::string uri = "/a/res2";
346 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
349 TEST(RegisterResourceTest, RegisterMultipleResources)
351 std::string uri = "/a/multi";
352 //Good enough for 5 resources.
353 for(int i=0; i< 5; i++)
355 uri +=std::to_string(i);
356 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
360 TEST(RegisterResourceTest, ReregisterResource)
362 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
363 std::string("core.light"));
364 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
366 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
367 std::string("core.light")));
371 TEST(RegisterResourceTest, RegisterEmptyResource)
373 // We should not allow empty URI.
374 std::string emptyStr = "";
375 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
376 emptyStr, entityHandler, gResourceProperty));
379 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
381 std::string uri = "/a/light6";
382 std::string type = "core.light";
383 uint8_t gResourceProperty = 0;
384 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
385 resourceHandle, uri, type,
386 gResourceInterface, entityHandler, gResourceProperty));
390 TEST(UnregisterTest, UnregisterZeroHandleValue)
392 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
395 //UnbindResourcesTest
396 TEST(UnbindResourcesTest, UnbindResources)
398 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
399 std::string("core.home"));
400 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
401 std::string("core.kitchen"), LINK_INTERFACE);
402 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
403 std::string("core.office"), LINK_INTERFACE);
405 std::vector<OCResourceHandle> rList;
406 rList.push_back(resourceKitchen);
407 rList.push_back(resourceRoom);
408 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
409 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
412 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
414 OCResourceHandle resourceHandle1 = 0;
415 OCResourceHandle resourceHandle2 = 0;
416 OCResourceHandle resourceHandle3 = 0;
418 std::vector<OCResourceHandle> rList;
420 rList.push_back(resourceHandle2);
421 rList.push_back(resourceHandle3);
423 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
426 //BindInterfaceToResourceTest
427 TEST(BindInterfaceToResourceTest, BindResourceInterface)
429 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
430 std::string("core.light"));
431 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
433 EXPECT_EQ(OC_STACK_OK, result);
436 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
438 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
439 std::string("core.light"));
440 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
443 //BindTypeToResourceTest
444 TEST(BindTypeToResourceTest, BindResourceType)
446 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
447 std::string("core.light"));
448 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
450 EXPECT_EQ(OC_STACK_OK, result);
453 TEST(BindTypeToResourceTest, BindZeroResourceType)
455 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
456 std::string("core.light"));
457 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
461 TEST(UnbindResourceTest, BindAndUnbindResource)
463 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
464 std::string("core.unres"));
465 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
466 std::string("core.unres"), LINK_INTERFACE);
468 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
469 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
473 TEST(PresenceTest, DISABLED_StartAndStopPresence)
475 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
476 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
477 std::string("core.Presence")));
478 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
481 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
483 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
486 //NotifyAllObserverTest
487 TEST(NotifyAllObserverTest, NotifyAllObservers)
489 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
490 std::string("core.obs"));
491 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
494 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
496 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
497 std::string("core.obs"));
498 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
499 OC::QualityOfService::LowQos));
502 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
504 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
505 std::string("core.obs"));
506 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
507 OC::QualityOfService::MidQos));
510 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
512 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
513 std::string("core.obs"));
514 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
515 OC::QualityOfService::NaQos));
518 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
520 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
521 std::string("core.obs"));
522 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
523 OC::QualityOfService::HighQos));
526 TEST(NotifyAllObserverTest, NotifyListOfObservers)
528 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
529 std::string("core.obs"));
531 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
532 ObservationIds interestedObservers;
533 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
534 interestedObservers, resourceResponse));
537 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
539 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
540 std::string("core.obs"));
542 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
543 ObservationIds interestedObservers;
544 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
545 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
548 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
550 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
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,OC::QualityOfService::MidQos));
559 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
561 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
562 std::string("core.obs"));
564 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
565 ObservationIds interestedObservers;
566 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
567 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
570 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
572 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
573 std::string("core.obs"));
575 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
576 ObservationIds interestedObservers;
577 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
578 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
581 //DeviceEntityHandlerTest
582 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
584 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
585 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
590 TEST(FindResourceTest, DISABLED_FindResourceValid)
592 std::ostringstream requestURI;
593 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
594 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
595 CT_DEFAULT, &foundResource));
598 TEST(FindResourceTest, FindResourceNullResourceURI)
600 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
601 CT_DEFAULT, &foundResource));
604 TEST(FindResourceTest, FindResourceNullResourceURI1)
606 std::ostringstream requestURI;
607 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
608 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
609 CT_DEFAULT, &foundResource));
612 TEST(FindResourceTest, FindResourceNullHost)
614 std::ostringstream requestURI;
615 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
616 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
617 CT_DEFAULT, &foundResource));
620 TEST(FindResourceTest, FindResourceNullresourceHandler)
622 std::ostringstream requestURI;
623 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
624 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
625 CT_DEFAULT, NULL), OC::OCException);
628 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
630 std::ostringstream requestURI;
631 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
632 EXPECT_EQ(OC_STACK_OK,
633 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
634 OC::QualityOfService::LowQos));
637 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
639 std::ostringstream requestURI;
640 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
641 EXPECT_EQ(OC_STACK_OK,
642 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
643 OC::QualityOfService::MidQos));
646 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
648 std::ostringstream requestURI;
649 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
650 EXPECT_EQ(OC_STACK_OK,
651 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
652 OC::QualityOfService::HighQos));
655 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
657 std::ostringstream requestURI;
658 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
659 EXPECT_EQ(OC_STACK_OK,
660 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
661 OC::QualityOfService::NaQos));
665 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
667 std::string deviceDiscoveryURI = "/oic/d";
669 OCPlatform::Configure(cfg);
670 std::ostringstream requestURI;
671 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
672 EXPECT_EQ(OC_STACK_OK,
673 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
676 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
679 OCPlatform::Configure(cfg);
681 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
684 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
686 std::string deviceDiscoveryURI = "/oic/d";
688 OCPlatform::Configure(cfg);
689 std::ostringstream requestURI;
690 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
692 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
696 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
698 std::string deviceDiscoveryURI = "/oic/d";
700 OCPlatform::Configure(cfg);
701 std::ostringstream requestURI;
702 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
703 EXPECT_EQ(OC_STACK_OK,
704 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
705 OC::QualityOfService::LowQos));
708 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
710 std::string deviceDiscoveryURI = "/oic/d";
712 OCPlatform::Configure(cfg);
713 std::ostringstream requestURI;
714 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
715 EXPECT_EQ(OC_STACK_OK,
716 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
717 OC::QualityOfService::MidQos));
720 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
722 std::string deviceDiscoveryURI = "/oic/d";
724 OCPlatform::Configure(cfg);
725 std::ostringstream requestURI;
726 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
727 EXPECT_EQ(OC_STACK_OK,
728 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
729 OC::QualityOfService::HighQos));
732 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
734 std::string deviceDiscoveryURI = "/oic/d";
736 OCPlatform::Configure(cfg);
737 std::ostringstream requestURI;
738 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
739 EXPECT_EQ(OC_STACK_OK,
740 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
741 OC::QualityOfService::NaQos));
744 //RegisterDeviceInfo test
745 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
747 OCDeviceInfo deviceInfo;
748 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
749 deviceInfo.types = NULL;
750 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
751 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
752 DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
753 deviceInfo.dataModelVersions = nullptr;
754 OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions");
755 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
756 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
759 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
761 OCDeviceInfo di = {0, 0, 0, 0};
762 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
765 //SubscribePresence Test
766 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
768 std::string hostAddress = "192.168.1.2:5000";
769 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
771 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
772 CT_DEFAULT, &presenceHandler));
775 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
777 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
779 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
780 CT_DEFAULT, &presenceHandler));
783 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
785 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
787 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
791 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
793 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
795 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
796 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
799 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
801 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
803 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
804 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
807 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
809 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
811 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
812 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
813 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
816 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
818 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
819 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
822 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
824 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
826 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
827 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
828 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
831 TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
833 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
836 TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
838 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
841 TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
843 EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
846 TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
849 OCPrm_t pmSel = DP_PRE_CONFIGURED;
851 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
852 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(s_dp, pmSel, pin, nullptr));
855 TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
858 OCPrm_t pmSel = DP_PRE_CONFIGURED;
860 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
861 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, &directPairHandler));
864 TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
867 OCPrm_t pmSel = DP_PRE_CONFIGURED;
869 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
870 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));