1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include <OCPlatform.h>
23 #include <oic_malloc.h>
24 #include <gtest/gtest.h>
26 namespace OCPlatformTest
30 static const char* SVR_DB_FILE_NAME = "./oic_svr_db_server.dat";
31 const OCResourceHandle HANDLE_ZERO = 0;
32 const std::string gResourceTypeName = "core.res";
33 const std::string gResourceInterface = DEFAULT_INTERFACE;
34 const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
35 OCResourceHandle resourceHandle;
37 //OCPersistent Storage Handlers
38 static FILE* client_open(const char * /*path*/, const char *mode)
40 std::cout << "<===Opening SVR DB file = './oic_svr_db_client.dat' with mode = '" << mode
42 return fopen(SVR_DB_FILE_NAME, mode);
44 OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
47 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request*/)
52 void foundResource(std::shared_ptr<OCResource> /*resource*/)
56 void receivedDeviceInfo(const OCRepresentation& /*rep*/)
60 void presenceHandler(OCStackResult /*result*/,
61 const unsigned int /*nonce*/, const std::string& /*hostAddress*/)
66 void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
71 void directPairHandler(std::shared_ptr<OCDirectPairing> /*dev*/, OCStackResult /*res*/)
75 void pairedHandler(const PairedDevices& /*list*/)
80 void DeleteStringLL(OCStringLL* ll)
87 DeleteStringLL(ll->next);
92 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
94 delete[] deviceInfo.deviceName;
95 DeleteStringLL(deviceInfo.types);
96 delete[] deviceInfo.specVersion;
97 DeleteStringLL(deviceInfo.dataModelVersions);
100 void DuplicateString(char ** targetString, std::string sourceString)
102 *targetString = new char[sourceString.length() + 1];
103 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
106 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
109 DuplicateString(&dup, value);
112 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
113 (*stringLL)->value = dup;
118 OCStringLL *temp = *stringLL;
123 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
124 temp->next->value = dup;
130 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
133 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
134 OC::QualityOfService::LowQos, &gps };
135 OCPlatform::Configure(cfg);
136 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
137 resourceHandle, uri, type,
138 iface, entityHandler, gResourceProperty));
139 return resourceHandle;
142 OCResourceHandle RegisterResource(std::string uri, std::string type)
145 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
146 OC::QualityOfService::LowQos, &gps };
147 OCPlatform::Configure(cfg);
148 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
149 resourceHandle, uri, type,
150 gResourceInterface, entityHandler, gResourceProperty));
151 return resourceHandle;
154 OCResourceHandle RegisterResource(std::string uri)
157 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
158 OC::QualityOfService::LowQos, &gps };
159 OCPlatform::Configure(cfg);
160 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
161 resourceHandle, uri, gResourceTypeName,
162 gResourceInterface, entityHandler, gResourceProperty));
163 return resourceHandle;
166 TEST(ConfigureTest, ConfigureInvalidModeType)
169 OC::ServiceType::InProc,
173 OC::QualityOfService::LowQos
175 OCPlatform::Configure(cfg);
176 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
179 TEST(ConfigureTest, ConfigureInvalidServiceType)
183 OC::ModeType::Client,
186 OC::QualityOfService::LowQos
188 OCPlatform::Configure(cfg);
189 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
192 TEST(ConfigureTest, ConfigureClientOutProc)
195 OC::ServiceType::OutOfProc,
196 OC::ModeType::Client,
199 OC::QualityOfService::LowQos
201 std::string uri = "/a/light66";
202 std::string type = "core.light";
203 uint8_t gResourceProperty = 0;
204 OCPlatform::Configure(cfg);
205 EXPECT_ANY_THROW(OCPlatform::registerResource(
206 resourceHandle, uri, type,
207 gResourceInterface, entityHandler, gResourceProperty));
210 TEST(ConfigureTest, ConfigureServerOutProc)
214 OC::ServiceType::OutOfProc,
215 OC::ModeType::Server,
218 OC::QualityOfService::LowQos, &gps
220 std::string uri = "/a/light67";
221 std::string type = "core.light";
222 uint8_t gResourceProperty = 0;
223 OCPlatform::Configure(cfg);
225 EXPECT_ANY_THROW(OCPlatform::registerResource(
226 resourceHandle, uri, type,
227 gResourceInterface, entityHandler, gResourceProperty));
230 TEST(ConfigureTest, ConfigureDefault)
232 std::string uri = "/a/light68";
233 std::string type = "core.light";
234 uint8_t gResourceProperty = 0;
235 PlatformConfig cfg = {};
236 OCPlatform::Configure(cfg);
238 EXPECT_NO_THROW(OCPlatform::registerResource(
239 resourceHandle, uri, type,
240 gResourceInterface, entityHandler, gResourceProperty));
243 TEST(ConfigureTest, ConfigureServer)
245 std::string uri = "/a/light69";
246 std::string type = "core.light";
247 uint8_t gResourceProperty = 0;
249 OC::ServiceType::InProc,
250 OC::ModeType::Server,
253 OC::QualityOfService::LowQos, &gps
255 OCPlatform::Configure(cfg);
257 EXPECT_NO_THROW(OCPlatform::registerResource(
258 resourceHandle, uri, type,
259 gResourceInterface, entityHandler, gResourceProperty));
262 TEST(ConfigureTest, ConfigureClient)
264 std::string uri = "/a/light70";
265 std::string type = "core.light";
266 uint8_t gResourceProperty = 0;
269 OC::ServiceType::InProc,
270 OC::ModeType::Client,
273 OC::QualityOfService::LowQos,
277 EXPECT_NO_THROW(OCPlatform::registerResource(
278 resourceHandle, uri, type,
279 gResourceInterface, entityHandler, gResourceProperty));
281 //PersistentStorageTest
282 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
285 OC::ServiceType::InProc,
289 OC::QualityOfService::LowQos
291 OCPlatform::Configure(cfg);
292 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
295 //PersistentStorageTest
296 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
299 OC::ServiceType::InProc,
303 OC::QualityOfService::LowQos,
306 OCPlatform::Configure(cfg);
307 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
310 //PersistentStorageTest
311 TEST(ConfigureTest, ConfigurePersistentStorage)
314 OC::ServiceType::InProc,
318 OC::QualityOfService::LowQos,
321 OCPlatform::Configure(cfg);
322 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
325 //PersistentStorageTest
326 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
329 OC::ServiceType::InProc,
333 OC::QualityOfService::LowQos,
336 OCPlatform::Configure(cfg);
337 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
341 //RegisterResourceTest
342 TEST(RegisterResourceTest, RegisterSingleResource)
344 std::string uri = "/a/res2";
345 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
348 TEST(RegisterResourceTest, RegisterMultipleResources)
350 std::string uri = "/a/multi";
351 //Good enough for 5 resources.
352 for(int i=0; i< 5; i++)
354 uri +=std::to_string(i);
355 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
359 TEST(RegisterResourceTest, ReregisterResource)
361 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
362 std::string("core.light"));
363 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
365 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
366 std::string("core.light")));
370 TEST(RegisterResourceTest, RegisterEmptyResource)
372 // We should not allow empty URI.
373 std::string emptyStr = "";
374 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
375 emptyStr, entityHandler, gResourceProperty));
378 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
380 std::string uri = "/a/light6";
381 std::string type = "core.light";
382 uint8_t gResourceProperty = 0;
383 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
384 resourceHandle, uri, type,
385 gResourceInterface, entityHandler, gResourceProperty));
389 TEST(UnregisterTest, UnregisterZeroHandleValue)
391 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
394 //UnbindResourcesTest
395 TEST(UnbindResourcesTest, UnbindResources)
397 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
398 std::string("core.home"));
399 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
400 std::string("core.kitchen"), LINK_INTERFACE);
401 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
402 std::string("core.office"), LINK_INTERFACE);
404 std::vector<OCResourceHandle> rList;
405 rList.push_back(resourceKitchen);
406 rList.push_back(resourceRoom);
407 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
408 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
411 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
413 OCResourceHandle resourceHandle1 = 0;
414 OCResourceHandle resourceHandle2 = 0;
415 OCResourceHandle resourceHandle3 = 0;
417 std::vector<OCResourceHandle> rList;
419 rList.push_back(resourceHandle2);
420 rList.push_back(resourceHandle3);
422 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
425 //BindInterfaceToResourceTest
426 TEST(BindInterfaceToResourceTest, BindResourceInterface)
428 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
429 std::string("core.light"));
430 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
432 EXPECT_EQ(OC_STACK_OK, result);
435 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
437 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
438 std::string("core.light"));
439 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
442 //BindTypeToResourceTest
443 TEST(BindTypeToResourceTest, BindResourceType)
445 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
446 std::string("core.light"));
447 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
449 EXPECT_EQ(OC_STACK_OK, result);
452 TEST(BindTypeToResourceTest, BindZeroResourceType)
454 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
455 std::string("core.light"));
456 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
460 TEST(UnbindResourceTest, BindAndUnbindResource)
462 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
463 std::string("core.unres"));
464 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
465 std::string("core.unres"), LINK_INTERFACE);
467 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
468 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
472 TEST(PresenceTest, DISABLED_StartAndStopPresence)
474 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
475 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
476 std::string("core.Presence")));
477 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
480 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
482 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
485 //NotifyAllObserverTest
486 TEST(NotifyAllObserverTest, NotifyAllObservers)
488 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
489 std::string("core.obs"));
490 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
493 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
495 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
496 std::string("core.obs"));
497 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
498 OC::QualityOfService::LowQos));
501 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
503 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
504 std::string("core.obs"));
505 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
506 OC::QualityOfService::MidQos));
509 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
511 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
512 std::string("core.obs"));
513 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
514 OC::QualityOfService::NaQos));
517 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
519 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
520 std::string("core.obs"));
521 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
522 OC::QualityOfService::HighQos));
525 TEST(NotifyAllObserverTest, NotifyListOfObservers)
527 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
528 std::string("core.obs"));
530 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
531 ObservationIds interestedObservers;
532 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
533 interestedObservers, resourceResponse));
536 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
538 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
539 std::string("core.obs"));
541 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
542 ObservationIds interestedObservers;
543 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
544 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
547 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
549 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
550 std::string("core.obs"));
552 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
553 ObservationIds interestedObservers;
554 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
555 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
558 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
560 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
561 std::string("core.obs"));
563 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
564 ObservationIds interestedObservers;
565 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
566 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
569 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
571 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
572 std::string("core.obs"));
574 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
575 ObservationIds interestedObservers;
576 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
577 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
580 //DeviceEntityHandlerTest
581 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
583 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
584 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
589 TEST(FindResourceTest, DISABLED_FindResourceValid)
591 std::ostringstream requestURI;
592 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
593 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
594 CT_DEFAULT, &foundResource));
597 TEST(FindResourceTest, FindResourceNullResourceURI)
599 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
600 CT_DEFAULT, &foundResource));
603 TEST(FindResourceTest, FindResourceNullResourceURI1)
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, FindResourceNullHost)
613 std::ostringstream requestURI;
614 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
615 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
616 CT_DEFAULT, &foundResource));
619 TEST(FindResourceTest, FindResourceNullresourceHandler)
621 std::ostringstream requestURI;
622 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
623 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
624 CT_DEFAULT, NULL), OC::OCException);
627 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
629 std::ostringstream requestURI;
630 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
631 EXPECT_EQ(OC_STACK_OK,
632 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
633 OC::QualityOfService::LowQos));
636 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
638 std::ostringstream requestURI;
639 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
640 EXPECT_EQ(OC_STACK_OK,
641 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
642 OC::QualityOfService::MidQos));
645 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
647 std::ostringstream requestURI;
648 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
649 EXPECT_EQ(OC_STACK_OK,
650 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
651 OC::QualityOfService::HighQos));
654 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
656 std::ostringstream requestURI;
657 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
658 EXPECT_EQ(OC_STACK_OK,
659 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
660 OC::QualityOfService::NaQos));
664 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
666 std::string deviceDiscoveryURI = "/oic/d";
668 OCPlatform::Configure(cfg);
669 std::ostringstream requestURI;
670 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
671 EXPECT_EQ(OC_STACK_OK,
672 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
675 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
678 OCPlatform::Configure(cfg);
680 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
683 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
685 std::string deviceDiscoveryURI = "/oic/d";
687 OCPlatform::Configure(cfg);
688 std::ostringstream requestURI;
689 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
691 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
695 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
697 std::string deviceDiscoveryURI = "/oic/d";
699 OCPlatform::Configure(cfg);
700 std::ostringstream requestURI;
701 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
702 EXPECT_EQ(OC_STACK_OK,
703 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
704 OC::QualityOfService::LowQos));
707 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
709 std::string deviceDiscoveryURI = "/oic/d";
711 OCPlatform::Configure(cfg);
712 std::ostringstream requestURI;
713 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
714 EXPECT_EQ(OC_STACK_OK,
715 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
716 OC::QualityOfService::MidQos));
719 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
721 std::string deviceDiscoveryURI = "/oic/d";
723 OCPlatform::Configure(cfg);
724 std::ostringstream requestURI;
725 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
726 EXPECT_EQ(OC_STACK_OK,
727 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
728 OC::QualityOfService::HighQos));
731 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
733 std::string deviceDiscoveryURI = "/oic/d";
735 OCPlatform::Configure(cfg);
736 std::ostringstream requestURI;
737 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
738 EXPECT_EQ(OC_STACK_OK,
739 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
740 OC::QualityOfService::NaQos));
743 //RegisterDeviceInfo test
744 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
746 OCDeviceInfo deviceInfo;
747 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
748 deviceInfo.types = NULL;
749 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
750 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
751 DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
752 deviceInfo.dataModelVersions = nullptr;
753 OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions");
754 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
755 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
758 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
760 OCDeviceInfo di = {0, 0, 0, 0};
761 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
764 //SubscribePresence Test
765 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
767 std::string hostAddress = "192.168.1.2:5000";
768 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
770 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
771 CT_DEFAULT, &presenceHandler));
774 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
776 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
778 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
779 CT_DEFAULT, &presenceHandler));
782 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
784 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
786 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
790 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
792 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
794 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
795 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
798 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
800 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
802 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
803 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
806 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
808 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
810 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
811 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
812 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
815 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
817 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
818 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
821 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
823 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
825 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
826 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
827 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
831 // SubscribeDevicePresence Test
832 TEST(SubscribeDevicePresenceTest, DISABLED_SubscribeDevicePresenceWithValidParameters)
834 std::string hostAddress = "192.168.1.2:5000";
835 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
836 std::vector<std::string> di;
838 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
839 hostAddress, di, CT_DEFAULT, &onObserve));
842 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullHost)
844 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
845 std::vector<std::string> di;
847 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
848 nullptr, di, CT_DEFAULT, &onObserve));
851 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullOnObserve)
853 std::string hostAddress = "192.168.1.2:5000";
854 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
855 std::vector<std::string> di;
857 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
858 hostAddress, di, CT_DEFAULT, NULL));
861 TEST(SubscribeDevicePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
863 std::string hostAddress = "192.168.1.2:5000";
864 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
865 std::vector<std::string> di;
867 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
868 hostAddress, di, CT_DEFAULT, &onObserve));
869 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
873 TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
875 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
878 TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
880 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
883 TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
885 EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
888 TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
891 OCPrm_t pmSel = DP_PRE_CONFIGURED;
893 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
894 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(s_dp, pmSel, pin, nullptr));
897 TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
900 OCPrm_t pmSel = DP_PRE_CONFIGURED;
902 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
903 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, &directPairHandler));
906 TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
909 OCPrm_t pmSel = DP_PRE_CONFIGURED;
911 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
912 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));