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 <gtest/gtest.h>
25 namespace OCPlatformTest
29 const OCResourceHandle HANDLE_ZERO = 0;
30 const std::string gResourceTypeName = "core.res";
31 const std::string gResourceInterface = DEFAULT_INTERFACE;
32 const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
33 OCResourceHandle resourceHandle;
35 //OCPersistent Storage Handlers
36 static FILE* client_open(const char * /*path*/, const char *mode)
38 std::cout << "<===Opening SVR DB file = './oic_svr_db_client.json' with mode = '" << mode
40 return fopen("./oic_svr_db_client.json", mode);
42 OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
45 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request*/)
50 void foundResource(std::shared_ptr<OCResource> /*resource*/)
54 void receivedDeviceInfo(const OCRepresentation& /*rep*/)
58 void presenceHandler(OCStackResult /*result*/,
59 const unsigned int /*nonce*/, const std::string& /*hostAddress*/)
64 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
66 delete[] deviceInfo.deviceName;
70 void DuplicateString(char ** targetString, std::string sourceString)
72 *targetString = new char[sourceString.length() + 1];
73 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
76 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
79 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
80 OC::QualityOfService::LowQos, &gps };
81 OCPlatform::Configure(cfg);
82 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
83 resourceHandle, uri, type,
84 iface, entityHandler, gResourceProperty));
85 return resourceHandle;
88 OCResourceHandle RegisterResource(std::string uri, std::string type)
91 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
92 OC::QualityOfService::LowQos, &gps };
93 OCPlatform::Configure(cfg);
94 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
95 resourceHandle, uri, type,
96 gResourceInterface, entityHandler, gResourceProperty));
97 return resourceHandle;
100 OCResourceHandle RegisterResource(std::string uri)
103 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
104 OC::QualityOfService::LowQos, &gps };
105 OCPlatform::Configure(cfg);
106 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
107 resourceHandle, uri, gResourceTypeName,
108 gResourceInterface, entityHandler, gResourceProperty));
109 return resourceHandle;
113 // Enable it when the stack throw an exception
114 // https://jira.iotivity.org/browse/IOT-428
115 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
118 OC::ServiceType::InProc,
122 OC::QualityOfService::LowQos
124 OCPlatform::Configure(cfg);
125 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
128 // Enable it when the stack throw an exception
129 // https://jira.iotivity.org/browse/IOT-428
130 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
134 OC::ModeType::Client,
137 OC::QualityOfService::LowQos
139 OCPlatform::Configure(cfg);
140 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
143 // Enable it when the stack throw an exception
144 // https://jira.iotivity.org/browse/IOT-428
145 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
148 OC::ServiceType::OutOfProc,
149 OC::ModeType::Client,
152 OC::QualityOfService::LowQos
154 std::string uri = "/a/light66";
155 std::string type = "core.light";
156 uint8_t gResourceProperty = 0;
157 OCPlatform::Configure(cfg);
158 EXPECT_ANY_THROW(OCPlatform::registerResource(
159 resourceHandle, uri, type,
160 gResourceInterface, entityHandler, gResourceProperty));
163 TEST(ConfigureTest, ConfigureServerOutProc)
167 OC::ServiceType::OutOfProc,
168 OC::ModeType::Server,
171 OC::QualityOfService::LowQos, &gps
173 std::string uri = "/a/light67";
174 std::string type = "core.light";
175 uint8_t gResourceProperty = 0;
176 OCPlatform::Configure(cfg);
178 EXPECT_ANY_THROW(OCPlatform::registerResource(
179 resourceHandle, uri, type,
180 gResourceInterface, entityHandler, gResourceProperty));
183 TEST(ConfigureTest, ConfigureDefault)
185 std::string uri = "/a/light68";
186 std::string type = "core.light";
187 uint8_t gResourceProperty = 0;
188 PlatformConfig cfg = {};
189 OCPlatform::Configure(cfg);
191 EXPECT_NO_THROW(OCPlatform::registerResource(
192 resourceHandle, uri, type,
193 gResourceInterface, entityHandler, gResourceProperty));
196 TEST(ConfigureTest, ConfigureServer)
198 std::string uri = "/a/light69";
199 std::string type = "core.light";
200 uint8_t gResourceProperty = 0;
202 OC::ServiceType::InProc,
203 OC::ModeType::Server,
206 OC::QualityOfService::LowQos, &gps
208 OCPlatform::Configure(cfg);
210 EXPECT_NO_THROW(OCPlatform::registerResource(
211 resourceHandle, uri, type,
212 gResourceInterface, entityHandler, gResourceProperty));
215 TEST(ConfigureTest, ConfigureClient)
217 std::string uri = "/a/light70";
218 std::string type = "core.light";
219 uint8_t gResourceProperty = 0;
222 OC::ServiceType::InProc,
223 OC::ModeType::Client,
226 OC::QualityOfService::LowQos,
230 EXPECT_NO_THROW(OCPlatform::registerResource(
231 resourceHandle, uri, type,
232 gResourceInterface, entityHandler, gResourceProperty));
234 //PersistentStorageTest
235 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
238 OC::ServiceType::InProc,
242 OC::QualityOfService::LowQos
244 OCPlatform::Configure(cfg);
245 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
248 //PersistentStorageTest
249 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
252 OC::ServiceType::InProc,
256 OC::QualityOfService::LowQos,
259 OCPlatform::Configure(cfg);
260 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
263 //PersistentStorageTest
264 TEST(ConfigureTest, ConfigurePersistentStorage)
267 OC::ServiceType::InProc,
271 OC::QualityOfService::LowQos,
274 OCPlatform::Configure(cfg);
275 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
278 //PersistentStorageTest
279 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
282 OC::ServiceType::InProc,
286 OC::QualityOfService::LowQos,
289 OCPlatform::Configure(cfg);
290 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
294 //RegisterResourceTest
295 TEST(RegisterResourceTest, RegisterSingleResource)
297 std::string uri = "/a/res2";
298 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
301 TEST(RegisterResourceTest, RegisterMultipleResources)
303 std::string uri = "/a/multi";
304 //Good enough for 5 resources.
305 for(int i=0; i< 5; i++)
307 uri +=std::to_string(i);
308 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
312 TEST(RegisterResourceTest, ReregisterResource)
314 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
315 std::string("core.light"));
316 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
318 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
319 std::string("core.light")));
323 TEST(RegisterResourceTest, RegisterEmptyResource)
325 // We should not allow empty URI.
326 std::string emptyStr = "";
327 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
328 emptyStr, entityHandler, gResourceProperty));
331 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
333 std::string uri = "/a/light6";
334 std::string type = "core.light";
335 uint8_t gResourceProperty = 0;
336 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
337 resourceHandle, uri, type,
338 gResourceInterface, entityHandler, gResourceProperty));
342 TEST(UnregisterTest, UnregisterZeroHandleValue)
344 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
347 //UnbindResourcesTest
348 TEST(UnbindResourcesTest, UnbindResources)
350 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
351 std::string("core.home"));
352 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
353 std::string("core.kitchen"), LINK_INTERFACE);
354 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
355 std::string("core.office"), LINK_INTERFACE);
357 std::vector<OCResourceHandle> rList;
358 rList.push_back(resourceKitchen);
359 rList.push_back(resourceRoom);
360 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
361 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
364 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
366 OCResourceHandle resourceHandle1 = 0;
367 OCResourceHandle resourceHandle2 = 0;
368 OCResourceHandle resourceHandle3 = 0;
370 std::vector<OCResourceHandle> rList;
372 rList.push_back(resourceHandle2);
373 rList.push_back(resourceHandle3);
375 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
378 //BindInterfaceToResourceTest
379 TEST(BindInterfaceToResourceTest, BindResourceInterface)
381 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
382 std::string("core.light"));
383 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
385 EXPECT_EQ(OC_STACK_OK, result);
388 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
390 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
391 std::string("core.light"));
392 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
395 //BindTypeToResourceTest
396 TEST(BindTypeToResourceTest, BindResourceType)
398 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
399 std::string("core.light"));
400 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
402 EXPECT_EQ(OC_STACK_OK, result);
405 TEST(BindTypeToResourceTest, BindZeroResourceType)
407 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
408 std::string("core.light"));
409 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
413 TEST(UnbindResourceTest, BindAndUnbindResource)
415 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
416 std::string("core.unres"));
417 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
418 std::string("core.unres"), LINK_INTERFACE);
420 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
421 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
425 TEST(PresenceTest, DISABLED_StartAndStopPresence)
427 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
428 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
429 std::string("core.Presence")));
430 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
433 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
435 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
438 //NotifyAllObserverTest
439 TEST(NotifyAllObserverTest, NotifyAllObservers)
441 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
442 std::string("core.obs"));
443 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
446 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
448 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
449 std::string("core.obs"));
450 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
451 OC::QualityOfService::LowQos));
454 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
456 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
457 std::string("core.obs"));
458 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
459 OC::QualityOfService::MidQos));
462 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
464 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
465 std::string("core.obs"));
466 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
467 OC::QualityOfService::NaQos));
470 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
472 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
473 std::string("core.obs"));
474 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
475 OC::QualityOfService::HighQos));
478 TEST(NotifyAllObserverTest, NotifyListOfObservers)
480 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
481 std::string("core.obs"));
483 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
484 ObservationIds interestedObservers;
485 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
486 interestedObservers, resourceResponse));
489 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
491 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
492 std::string("core.obs"));
494 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
495 ObservationIds interestedObservers;
496 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
497 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
500 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
502 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
503 std::string("core.obs"));
505 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
506 ObservationIds interestedObservers;
507 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
508 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
511 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
513 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
514 std::string("core.obs"));
516 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
517 ObservationIds interestedObservers;
518 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
519 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
522 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
524 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
525 std::string("core.obs"));
527 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
528 ObservationIds interestedObservers;
529 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
530 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
533 //DeviceEntityHandlerTest
534 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
536 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
537 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
542 TEST(FindResourceTest, DISABLED_FindResourceValid)
544 std::ostringstream requestURI;
545 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
546 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
547 CT_DEFAULT, &foundResource));
550 TEST(FindResourceTest, FindResourceNullResourceURI)
552 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
553 CT_DEFAULT, &foundResource));
556 TEST(FindResourceTest, FindResourceNullResourceURI1)
558 std::ostringstream requestURI;
559 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
560 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
561 CT_DEFAULT, &foundResource));
564 TEST(FindResourceTest, FindResourceNullHost)
566 std::ostringstream requestURI;
567 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
568 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
569 CT_DEFAULT, &foundResource));
572 TEST(FindResourceTest, FindResourceNullresourceHandler)
574 std::ostringstream requestURI;
575 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
576 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
577 CT_DEFAULT, NULL), OC::OCException);
580 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
582 std::ostringstream requestURI;
583 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
584 EXPECT_EQ(OC_STACK_OK,
585 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
586 OC::QualityOfService::LowQos));
589 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
591 std::ostringstream requestURI;
592 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
593 EXPECT_EQ(OC_STACK_OK,
594 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
595 OC::QualityOfService::MidQos));
598 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
600 std::ostringstream requestURI;
601 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
602 EXPECT_EQ(OC_STACK_OK,
603 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
604 OC::QualityOfService::HighQos));
607 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
609 std::ostringstream requestURI;
610 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
611 EXPECT_EQ(OC_STACK_OK,
612 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
613 OC::QualityOfService::NaQos));
617 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
619 std::string deviceDiscoveryURI = "/oic/d";
621 OCPlatform::Configure(cfg);
622 std::ostringstream requestURI;
623 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
624 EXPECT_EQ(OC_STACK_OK,
625 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
628 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
631 OCPlatform::Configure(cfg);
633 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
636 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
638 std::string deviceDiscoveryURI = "/oic/d";
640 OCPlatform::Configure(cfg);
641 std::ostringstream requestURI;
642 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
644 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
648 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
650 std::string deviceDiscoveryURI = "/oic/d";
652 OCPlatform::Configure(cfg);
653 std::ostringstream requestURI;
654 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
655 EXPECT_EQ(OC_STACK_OK,
656 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
657 OC::QualityOfService::LowQos));
660 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
662 std::string deviceDiscoveryURI = "/oic/d";
664 OCPlatform::Configure(cfg);
665 std::ostringstream requestURI;
666 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
667 EXPECT_EQ(OC_STACK_OK,
668 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
669 OC::QualityOfService::MidQos));
672 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
674 std::string deviceDiscoveryURI = "/oic/d";
676 OCPlatform::Configure(cfg);
677 std::ostringstream requestURI;
678 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
679 EXPECT_EQ(OC_STACK_OK,
680 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
681 OC::QualityOfService::HighQos));
684 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
686 std::string deviceDiscoveryURI = "/oic/d";
688 OCPlatform::Configure(cfg);
689 std::ostringstream requestURI;
690 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
691 EXPECT_EQ(OC_STACK_OK,
692 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
693 OC::QualityOfService::NaQos));
696 //RegisterDeviceInfo test
697 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
699 OCDeviceInfo deviceInfo;
701 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
702 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
703 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
706 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
708 OCDeviceInfo di = {0};
709 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
712 //SubscribePresence Test
713 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
715 std::string hostAddress = "192.168.1.2:5000";
716 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
718 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
719 CT_DEFAULT, &presenceHandler));
722 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
724 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
726 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
727 CT_DEFAULT, &presenceHandler));
730 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
732 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
734 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
738 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
740 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
742 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
743 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
746 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
748 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
750 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
751 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
754 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
756 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
758 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
759 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
760 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
763 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
765 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
766 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
769 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
771 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
773 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
774 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
775 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));