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 DeleteStringLL(OCStringLL* ll)
73 DeleteStringLL(ll->next);
78 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
80 delete[] deviceInfo.deviceName;
81 DeleteStringLL(deviceInfo.types);
85 void DuplicateString(char ** targetString, std::string sourceString)
87 *targetString = new char[sourceString.length() + 1];
88 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
91 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
94 DuplicateString(&dup, value);
97 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
98 (*stringLL)->value = dup;
103 OCStringLL *temp = *stringLL;
108 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
109 temp->next->value = dup;
115 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
118 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
119 OC::QualityOfService::LowQos, &gps };
120 OCPlatform::Configure(cfg);
121 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
122 resourceHandle, uri, type,
123 iface, entityHandler, gResourceProperty));
124 return resourceHandle;
127 OCResourceHandle RegisterResource(std::string uri, std::string type)
130 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
131 OC::QualityOfService::LowQos, &gps };
132 OCPlatform::Configure(cfg);
133 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
134 resourceHandle, uri, type,
135 gResourceInterface, entityHandler, gResourceProperty));
136 return resourceHandle;
139 OCResourceHandle RegisterResource(std::string uri)
142 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
143 OC::QualityOfService::LowQos, &gps };
144 OCPlatform::Configure(cfg);
145 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
146 resourceHandle, uri, gResourceTypeName,
147 gResourceInterface, entityHandler, gResourceProperty));
148 return resourceHandle;
152 // Enable it when the stack throw an exception
153 // https://jira.iotivity.org/browse/IOT-428
154 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
157 OC::ServiceType::InProc,
161 OC::QualityOfService::LowQos
163 OCPlatform::Configure(cfg);
164 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
167 // Enable it when the stack throw an exception
168 // https://jira.iotivity.org/browse/IOT-428
169 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
173 OC::ModeType::Client,
176 OC::QualityOfService::LowQos
178 OCPlatform::Configure(cfg);
179 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
182 // Enable it when the stack throw an exception
183 // https://jira.iotivity.org/browse/IOT-428
184 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
187 OC::ServiceType::OutOfProc,
188 OC::ModeType::Client,
191 OC::QualityOfService::LowQos
193 std::string uri = "/a/light66";
194 std::string type = "core.light";
195 uint8_t gResourceProperty = 0;
196 OCPlatform::Configure(cfg);
197 EXPECT_ANY_THROW(OCPlatform::registerResource(
198 resourceHandle, uri, type,
199 gResourceInterface, entityHandler, gResourceProperty));
202 TEST(ConfigureTest, ConfigureServerOutProc)
206 OC::ServiceType::OutOfProc,
207 OC::ModeType::Server,
210 OC::QualityOfService::LowQos, &gps
212 std::string uri = "/a/light67";
213 std::string type = "core.light";
214 uint8_t gResourceProperty = 0;
215 OCPlatform::Configure(cfg);
217 EXPECT_ANY_THROW(OCPlatform::registerResource(
218 resourceHandle, uri, type,
219 gResourceInterface, entityHandler, gResourceProperty));
222 TEST(ConfigureTest, ConfigureDefault)
224 std::string uri = "/a/light68";
225 std::string type = "core.light";
226 uint8_t gResourceProperty = 0;
227 PlatformConfig cfg = {};
228 OCPlatform::Configure(cfg);
230 EXPECT_NO_THROW(OCPlatform::registerResource(
231 resourceHandle, uri, type,
232 gResourceInterface, entityHandler, gResourceProperty));
235 TEST(ConfigureTest, ConfigureServer)
237 std::string uri = "/a/light69";
238 std::string type = "core.light";
239 uint8_t gResourceProperty = 0;
241 OC::ServiceType::InProc,
242 OC::ModeType::Server,
245 OC::QualityOfService::LowQos, &gps
247 OCPlatform::Configure(cfg);
249 EXPECT_NO_THROW(OCPlatform::registerResource(
250 resourceHandle, uri, type,
251 gResourceInterface, entityHandler, gResourceProperty));
254 TEST(ConfigureTest, ConfigureClient)
256 std::string uri = "/a/light70";
257 std::string type = "core.light";
258 uint8_t gResourceProperty = 0;
261 OC::ServiceType::InProc,
262 OC::ModeType::Client,
265 OC::QualityOfService::LowQos,
269 EXPECT_NO_THROW(OCPlatform::registerResource(
270 resourceHandle, uri, type,
271 gResourceInterface, entityHandler, gResourceProperty));
273 //PersistentStorageTest
274 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
277 OC::ServiceType::InProc,
281 OC::QualityOfService::LowQos
283 OCPlatform::Configure(cfg);
284 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
287 //PersistentStorageTest
288 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
291 OC::ServiceType::InProc,
295 OC::QualityOfService::LowQos,
298 OCPlatform::Configure(cfg);
299 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
302 //PersistentStorageTest
303 TEST(ConfigureTest, ConfigurePersistentStorage)
306 OC::ServiceType::InProc,
310 OC::QualityOfService::LowQos,
313 OCPlatform::Configure(cfg);
314 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
317 //PersistentStorageTest
318 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
321 OC::ServiceType::InProc,
325 OC::QualityOfService::LowQos,
328 OCPlatform::Configure(cfg);
329 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
333 //RegisterResourceTest
334 TEST(RegisterResourceTest, RegisterSingleResource)
336 std::string uri = "/a/res2";
337 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
340 TEST(RegisterResourceTest, RegisterMultipleResources)
342 std::string uri = "/a/multi";
343 //Good enough for 5 resources.
344 for(int i=0; i< 5; i++)
346 uri +=std::to_string(i);
347 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
351 TEST(RegisterResourceTest, ReregisterResource)
353 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
354 std::string("core.light"));
355 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
357 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
358 std::string("core.light")));
362 TEST(RegisterResourceTest, RegisterEmptyResource)
364 // We should not allow empty URI.
365 std::string emptyStr = "";
366 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
367 emptyStr, entityHandler, gResourceProperty));
370 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
372 std::string uri = "/a/light6";
373 std::string type = "core.light";
374 uint8_t gResourceProperty = 0;
375 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
376 resourceHandle, uri, type,
377 gResourceInterface, entityHandler, gResourceProperty));
381 TEST(UnregisterTest, UnregisterZeroHandleValue)
383 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
386 //UnbindResourcesTest
387 TEST(UnbindResourcesTest, UnbindResources)
389 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
390 std::string("core.home"));
391 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
392 std::string("core.kitchen"), LINK_INTERFACE);
393 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
394 std::string("core.office"), LINK_INTERFACE);
396 std::vector<OCResourceHandle> rList;
397 rList.push_back(resourceKitchen);
398 rList.push_back(resourceRoom);
399 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
400 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
403 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
405 OCResourceHandle resourceHandle1 = 0;
406 OCResourceHandle resourceHandle2 = 0;
407 OCResourceHandle resourceHandle3 = 0;
409 std::vector<OCResourceHandle> rList;
411 rList.push_back(resourceHandle2);
412 rList.push_back(resourceHandle3);
414 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
417 //BindInterfaceToResourceTest
418 TEST(BindInterfaceToResourceTest, BindResourceInterface)
420 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
421 std::string("core.light"));
422 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
424 EXPECT_EQ(OC_STACK_OK, result);
427 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
429 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
430 std::string("core.light"));
431 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
434 //BindTypeToResourceTest
435 TEST(BindTypeToResourceTest, BindResourceType)
437 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
438 std::string("core.light"));
439 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
441 EXPECT_EQ(OC_STACK_OK, result);
444 TEST(BindTypeToResourceTest, BindZeroResourceType)
446 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
447 std::string("core.light"));
448 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
452 TEST(UnbindResourceTest, BindAndUnbindResource)
454 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
455 std::string("core.unres"));
456 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
457 std::string("core.unres"), LINK_INTERFACE);
459 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
460 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
464 TEST(PresenceTest, DISABLED_StartAndStopPresence)
466 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
467 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
468 std::string("core.Presence")));
469 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
472 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
474 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
477 //NotifyAllObserverTest
478 TEST(NotifyAllObserverTest, NotifyAllObservers)
480 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
481 std::string("core.obs"));
482 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
485 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
487 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
488 std::string("core.obs"));
489 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
490 OC::QualityOfService::LowQos));
493 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
495 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
496 std::string("core.obs"));
497 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
498 OC::QualityOfService::MidQos));
501 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
503 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
504 std::string("core.obs"));
505 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
506 OC::QualityOfService::NaQos));
509 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
511 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
512 std::string("core.obs"));
513 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
514 OC::QualityOfService::HighQos));
517 TEST(NotifyAllObserverTest, NotifyListOfObservers)
519 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
520 std::string("core.obs"));
522 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
523 ObservationIds interestedObservers;
524 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
525 interestedObservers, resourceResponse));
528 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
530 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
531 std::string("core.obs"));
533 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
534 ObservationIds interestedObservers;
535 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
536 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
539 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
541 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
542 std::string("core.obs"));
544 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
545 ObservationIds interestedObservers;
546 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
547 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
550 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
552 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
553 std::string("core.obs"));
555 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
556 ObservationIds interestedObservers;
557 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
558 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
561 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
563 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
564 std::string("core.obs"));
566 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
567 ObservationIds interestedObservers;
568 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
569 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
572 //DeviceEntityHandlerTest
573 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
575 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
576 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
581 TEST(FindResourceTest, DISABLED_FindResourceValid)
583 std::ostringstream requestURI;
584 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
585 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
586 CT_DEFAULT, &foundResource));
589 TEST(FindResourceTest, FindResourceNullResourceURI)
591 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
592 CT_DEFAULT, &foundResource));
595 TEST(FindResourceTest, FindResourceNullResourceURI1)
597 std::ostringstream requestURI;
598 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
599 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
600 CT_DEFAULT, &foundResource));
603 TEST(FindResourceTest, FindResourceNullHost)
605 std::ostringstream requestURI;
606 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
607 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
608 CT_DEFAULT, &foundResource));
611 TEST(FindResourceTest, FindResourceNullresourceHandler)
613 std::ostringstream requestURI;
614 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
615 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
616 CT_DEFAULT, NULL), OC::OCException);
619 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
621 std::ostringstream requestURI;
622 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
623 EXPECT_EQ(OC_STACK_OK,
624 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
625 OC::QualityOfService::LowQos));
628 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
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::MidQos));
637 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
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::HighQos));
646 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
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::NaQos));
656 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
658 std::string deviceDiscoveryURI = "/oic/d";
660 OCPlatform::Configure(cfg);
661 std::ostringstream requestURI;
662 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
663 EXPECT_EQ(OC_STACK_OK,
664 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
667 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
670 OCPlatform::Configure(cfg);
672 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
675 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
677 std::string deviceDiscoveryURI = "/oic/d";
679 OCPlatform::Configure(cfg);
680 std::ostringstream requestURI;
681 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
683 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
687 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
689 std::string deviceDiscoveryURI = "/oic/d";
691 OCPlatform::Configure(cfg);
692 std::ostringstream requestURI;
693 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
694 EXPECT_EQ(OC_STACK_OK,
695 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
696 OC::QualityOfService::LowQos));
699 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
701 std::string deviceDiscoveryURI = "/oic/d";
703 OCPlatform::Configure(cfg);
704 std::ostringstream requestURI;
705 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
706 EXPECT_EQ(OC_STACK_OK,
707 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
708 OC::QualityOfService::MidQos));
711 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
713 std::string deviceDiscoveryURI = "/oic/d";
715 OCPlatform::Configure(cfg);
716 std::ostringstream requestURI;
717 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
718 EXPECT_EQ(OC_STACK_OK,
719 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
720 OC::QualityOfService::HighQos));
723 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
725 std::string deviceDiscoveryURI = "/oic/d";
727 OCPlatform::Configure(cfg);
728 std::ostringstream requestURI;
729 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
730 EXPECT_EQ(OC_STACK_OK,
731 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
732 OC::QualityOfService::NaQos));
735 //RegisterDeviceInfo test
736 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
738 OCDeviceInfo deviceInfo;
739 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
740 deviceInfo.types = NULL;
741 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
742 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
743 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
744 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
747 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
749 OCDeviceInfo di = {0, 0};
750 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
753 //SubscribePresence Test
754 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
756 std::string hostAddress = "192.168.1.2:5000";
757 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
759 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
760 CT_DEFAULT, &presenceHandler));
763 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
765 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
767 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
768 CT_DEFAULT, &presenceHandler));
771 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
773 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
775 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
779 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
781 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
783 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
784 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
787 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
789 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
791 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
792 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
795 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
797 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
799 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
800 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
801 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
804 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
806 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
807 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
810 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
812 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
814 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
815 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
816 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));