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;
34 //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<<"' "<<std::endl;
39 return fopen("./oic_svr_db_client.json", mode);
42 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
47 void foundResource(std::shared_ptr<OCResource> resource)
51 void receivedDeviceInfo(const OCRepresentation& rep)
55 void presenceHandler(OCStackResult result,
56 const unsigned int nonce, const std::string& hostAddress)
61 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
63 delete[] deviceInfo.deviceName;
67 void DuplicateString(char ** targetString, std::string sourceString)
69 *targetString = new char[sourceString.length() + 1];
70 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
73 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
75 PlatformConfig cfg = {};
76 OCPlatform::Configure(cfg);
77 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
78 resourceHandle, uri, type,
79 iface, entityHandler, gResourceProperty));
80 return resourceHandle;
83 OCResourceHandle RegisterResource(std::string uri, std::string type)
85 PlatformConfig cfg = {};
86 OCPlatform::Configure(cfg);
87 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
88 resourceHandle, uri, type,
89 gResourceInterface, entityHandler, gResourceProperty));
90 return resourceHandle;
93 OCResourceHandle RegisterResource(std::string uri)
95 PlatformConfig cfg = {};
96 OCPlatform::Configure(cfg);
97 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
98 resourceHandle, uri, gResourceTypeName,
99 gResourceInterface, entityHandler, gResourceProperty));
100 return resourceHandle;
104 // Enable it when the stack throw an exception
105 // https://jira.iotivity.org/browse/IOT-428
106 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
109 OC::ServiceType::InProc,
113 OC::QualityOfService::LowQos
115 OCPlatform::Configure(cfg);
116 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
119 // Enable it when the stack throw an exception
120 // https://jira.iotivity.org/browse/IOT-428
121 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
125 OC::ModeType::Client,
128 OC::QualityOfService::LowQos
130 OCPlatform::Configure(cfg);
131 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
134 // Enable it when the stack throw an exception
135 // https://jira.iotivity.org/browse/IOT-428
136 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
139 OC::ServiceType::OutOfProc,
140 OC::ModeType::Client,
143 OC::QualityOfService::LowQos
145 std::string uri = "/a/light66";
146 std::string type = "core.light";
147 uint8_t gResourceProperty = 0;
148 OCPlatform::Configure(cfg);
149 EXPECT_ANY_THROW(OCPlatform::registerResource(
150 resourceHandle, uri, type,
151 gResourceInterface, entityHandler, gResourceProperty));
154 TEST(ConfigureTest, ConfigureServerOutProc)
157 OC::ServiceType::OutOfProc,
158 OC::ModeType::Server,
161 OC::QualityOfService::LowQos
163 std::string uri = "/a/light67";
164 std::string type = "core.light";
165 uint8_t gResourceProperty = 0;
166 OCPlatform::Configure(cfg);
168 EXPECT_ANY_THROW(OCPlatform::registerResource(
169 resourceHandle, uri, type,
170 gResourceInterface, entityHandler, gResourceProperty));
173 TEST(ConfigureTest, ConfigureDefault)
175 std::string uri = "/a/light68";
176 std::string type = "core.light";
177 uint8_t gResourceProperty = 0;
178 PlatformConfig cfg = {};
179 OCPlatform::Configure(cfg);
181 EXPECT_NO_THROW(OCPlatform::registerResource(
182 resourceHandle, uri, type,
183 gResourceInterface, entityHandler, gResourceProperty));
186 TEST(ConfigureTest, ConfigureServer)
188 std::string uri = "/a/light69";
189 std::string type = "core.light";
190 uint8_t gResourceProperty = 0;
192 OC::ServiceType::InProc,
193 OC::ModeType::Server,
196 OC::QualityOfService::LowQos
198 OCPlatform::Configure(cfg);
200 EXPECT_NO_THROW(OCPlatform::registerResource(
201 resourceHandle, uri, type,
202 gResourceInterface, entityHandler, gResourceProperty));
205 TEST(ConfigureTest, ConfigureClient)
207 std::string uri = "/a/light70";
208 std::string type = "core.light";
209 uint8_t gResourceProperty = 0;
211 OC::ServiceType::InProc,
212 OC::ModeType::Client,
215 OC::QualityOfService::LowQos
217 OCPlatform::Configure(cfg);
219 EXPECT_NO_THROW(OCPlatform::registerResource(
220 resourceHandle, uri, type,
221 gResourceInterface, entityHandler, gResourceProperty));
223 //PersistentStorageTest
224 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
227 OC::ServiceType::InProc,
231 OC::QualityOfService::LowQos
233 OCPlatform::Configure(cfg);
234 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
237 //PersistentStorageTest
238 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
241 OC::ServiceType::InProc,
245 OC::QualityOfService::LowQos,
248 OCPlatform::Configure(cfg);
249 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
252 //PersistentStorageTest
253 TEST(ConfigureTest, ConfigurePersistentStorage)
255 OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
257 OC::ServiceType::InProc,
261 OC::QualityOfService::LowQos,
264 OCPlatform::Configure(cfg);
265 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
268 //PersistentStorageTest
269 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
271 OCPersistentStorage ps {client_open, nullptr, nullptr, nullptr, nullptr };
273 OC::ServiceType::InProc,
277 OC::QualityOfService::LowQos,
280 OCPlatform::Configure(cfg);
281 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
285 //RegisterResourceTest
286 TEST(RegisterResourceTest, RegisterSingleResource)
288 std::string uri = "/a/res2";
289 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
292 TEST(RegisterResourceTest, RegisterMultipleResources)
294 std::string uri = "/a/multi";
295 //Good enough for 5 resources.
296 for(int i=0; i< 5; i++)
298 uri +=std::to_string(i);
299 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
303 TEST(RegisterResourceTest, ReregisterResource)
305 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
306 std::string("core.light"));
307 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
309 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
310 std::string("core.light")));
314 TEST(RegisterResourceTest, RegisterEmptyResource)
316 // We should not allow empty URI.
317 std::string emptyStr = "";
318 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
319 emptyStr, entityHandler, gResourceProperty));
322 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
324 std::string uri = "/a/light6";
325 std::string type = "core.light";
326 uint8_t gResourceProperty = 0;
327 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
328 resourceHandle, uri, type,
329 gResourceInterface, entityHandler, gResourceProperty));
333 TEST(UnregisterTest, UnregisterZeroHandleValue)
335 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
338 //UnbindResourcesTest
339 TEST(UnbindResourcesTest, UnbindResources)
341 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
342 std::string("core.home"));
343 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
344 std::string("core.kitchen"), LINK_INTERFACE);
345 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
346 std::string("core.office"), LINK_INTERFACE);
348 std::vector<OCResourceHandle> rList;
349 rList.push_back(resourceKitchen);
350 rList.push_back(resourceRoom);
351 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
352 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
355 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
357 OCResourceHandle resourceHandle1 = 0;
358 OCResourceHandle resourceHandle2 = 0;
359 OCResourceHandle resourceHandle3 = 0;
361 std::vector<OCResourceHandle> rList;
363 rList.push_back(resourceHandle2);
364 rList.push_back(resourceHandle3);
366 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
369 //BindInterfaceToResourceTest
370 TEST(BindInterfaceToResourceTest, BindResourceInterface)
372 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
373 std::string("core.light"));
374 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
376 EXPECT_EQ(OC_STACK_OK, result);
379 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
381 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
382 std::string("core.light"));
383 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
386 //BindTypeToResourceTest
387 TEST(BindTypeToResourceTest, BindResourceType)
389 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
390 std::string("core.light"));
391 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
393 EXPECT_EQ(OC_STACK_OK, result);
396 TEST(BindTypeToResourceTest, BindZeroResourceType)
398 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
399 std::string("core.light"));
400 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
404 TEST(UnbindResourceTest, BindAndUnbindResource)
406 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
407 std::string("core.unres"));
408 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
409 std::string("core.unres"), LINK_INTERFACE);
411 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
412 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
416 TEST(PresenceTest, DISABLED_StartAndStopPresence)
418 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
419 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
420 std::string("core.Presence")));
421 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
424 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
426 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
429 //NotifyAllObserverTest
430 TEST(NotifyAllObserverTest, NotifyAllObservers)
432 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
433 std::string("core.obs"));
434 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
437 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
439 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
440 std::string("core.obs"));
441 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
442 OC::QualityOfService::LowQos));
445 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
447 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
448 std::string("core.obs"));
449 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
450 OC::QualityOfService::MidQos));
453 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
455 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
456 std::string("core.obs"));
457 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
458 OC::QualityOfService::NaQos));
461 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
463 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
464 std::string("core.obs"));
465 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
466 OC::QualityOfService::HighQos));
469 TEST(NotifyAllObserverTest, NotifyListOfObservers)
471 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
472 std::string("core.obs"));
474 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
475 ObservationIds interestedObservers;
476 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
477 interestedObservers, resourceResponse));
480 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
482 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
483 std::string("core.obs"));
485 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
486 ObservationIds interestedObservers;
487 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
488 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
491 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
493 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
494 std::string("core.obs"));
496 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
497 ObservationIds interestedObservers;
498 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
499 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
502 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
504 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
505 std::string("core.obs"));
507 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
508 ObservationIds interestedObservers;
509 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
510 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
513 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
515 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
516 std::string("core.obs"));
518 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
519 ObservationIds interestedObservers;
520 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
521 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
524 //DeviceEntityHandlerTest
525 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
527 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
528 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
533 TEST(FindResourceTest, DISABLED_FindResourceValid)
535 std::ostringstream requestURI;
536 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
537 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
538 CT_DEFAULT, &foundResource));
541 TEST(FindResourceTest, FindResourceNullResourceURI)
543 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
544 CT_DEFAULT, &foundResource));
547 TEST(FindResourceTest, FindResourceNullResourceURI1)
549 std::ostringstream requestURI;
550 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
551 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
552 CT_DEFAULT, &foundResource));
555 TEST(FindResourceTest, FindResourceNullHost)
557 std::ostringstream requestURI;
558 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
559 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
560 CT_DEFAULT, &foundResource));
563 TEST(FindResourceTest, FindResourceNullresourceHandler)
565 std::ostringstream requestURI;
566 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
567 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
568 CT_DEFAULT, NULL), OC::OCException);
571 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
573 std::ostringstream requestURI;
574 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
575 EXPECT_EQ(OC_STACK_OK,
576 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
577 OC::QualityOfService::LowQos));
580 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
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::MidQos));
589 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
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::HighQos));
598 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
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::NaQos));
608 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
610 std::string deviceDiscoveryURI = "/oic/d";
612 OCPlatform::Configure(cfg);
613 std::ostringstream requestURI;
614 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
615 EXPECT_EQ(OC_STACK_OK,
616 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
619 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
622 OCPlatform::Configure(cfg);
624 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
627 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
629 std::string deviceDiscoveryURI = "/oic/d";
631 OCPlatform::Configure(cfg);
632 std::ostringstream requestURI;
633 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
635 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
639 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
641 std::string deviceDiscoveryURI = "/oic/d";
643 OCPlatform::Configure(cfg);
644 std::ostringstream requestURI;
645 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
646 EXPECT_EQ(OC_STACK_OK,
647 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
648 OC::QualityOfService::LowQos));
651 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
653 std::string deviceDiscoveryURI = "/oic/d";
655 OCPlatform::Configure(cfg);
656 std::ostringstream requestURI;
657 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
658 EXPECT_EQ(OC_STACK_OK,
659 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
660 OC::QualityOfService::MidQos));
663 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
665 std::string deviceDiscoveryURI = "/oic/d";
667 OCPlatform::Configure(cfg);
668 std::ostringstream requestURI;
669 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
670 EXPECT_EQ(OC_STACK_OK,
671 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
672 OC::QualityOfService::HighQos));
675 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
677 std::string deviceDiscoveryURI = "/oic/d";
679 OCPlatform::Configure(cfg);
680 std::ostringstream requestURI;
681 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
682 EXPECT_EQ(OC_STACK_OK,
683 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
684 OC::QualityOfService::NaQos));
687 //RegisterDeviceInfo test
688 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
690 OCDeviceInfo deviceInfo;
692 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
694 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
695 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
698 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
700 OCDeviceInfo di = {};
701 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
704 //SubscribePresence Test
705 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
707 std::string hostAddress = "192.168.1.2:5000";
708 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
710 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
711 CT_DEFAULT, &presenceHandler));
714 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
716 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
718 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
719 CT_DEFAULT, &presenceHandler));
722 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
724 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
726 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
730 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
732 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
734 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
735 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
738 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
740 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
742 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
743 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
746 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
748 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
750 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
751 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
752 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
755 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
757 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
758 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
761 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
763 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
765 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
766 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
767 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));