1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include <OCPlatform.h>
23 #include <oic_malloc.h>
24 #include <gtest/gtest.h>
26 namespace OCPlatformTest
30 static const char* SVR_DB_FILE_NAME = "./oic_svr_db_server.dat";
31 const OCResourceHandle HANDLE_ZERO = 0;
32 const std::string gResourceTypeName = "core.res";
33 const std::string gResourceInterface = DEFAULT_INTERFACE;
34 const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
35 OCResourceHandle resourceHandle;
37 //OCPersistent Storage Handlers
38 static FILE* client_open(const char * /*path*/, const char *mode)
40 std::cout << "<===Opening SVR DB file = './oic_svr_db_client.dat' with mode = '" << mode
42 return fopen(SVR_DB_FILE_NAME, mode);
44 OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
47 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request*/)
52 void foundResource(std::shared_ptr<OCResource> /*resource*/)
56 void receivedDeviceInfo(const OCRepresentation& /*rep*/)
60 void presenceHandler(OCStackResult /*result*/,
61 const unsigned int /*nonce*/, const std::string& /*hostAddress*/)
65 void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
69 void directPairHandler(std::shared_ptr<OCDirectPairing> /*dev*/, OCStackResult /*res*/)
73 void pairedHandler(const PairedDevices& /*list*/)
77 void accountHandler(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
83 void DeleteStringLL(OCStringLL* ll)
90 DeleteStringLL(ll->next);
95 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
97 delete[] deviceInfo.deviceName;
98 DeleteStringLL(deviceInfo.types);
99 delete[] deviceInfo.specVersion;
100 DeleteStringLL(deviceInfo.dataModelVersions);
103 void DuplicateString(char ** targetString, std::string sourceString)
105 *targetString = new char[sourceString.length() + 1];
106 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
109 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
112 DuplicateString(&dup, value);
115 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
116 (*stringLL)->value = dup;
121 OCStringLL *temp = *stringLL;
126 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
127 temp->next->value = dup;
133 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
136 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
137 OC::QualityOfService::LowQos, &gps };
138 OCPlatform::Configure(cfg);
139 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
140 resourceHandle, uri, type,
141 iface, entityHandler, gResourceProperty));
142 return resourceHandle;
145 OCResourceHandle RegisterResource(std::string uri, std::string type)
148 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
149 OC::QualityOfService::LowQos, &gps };
150 OCPlatform::Configure(cfg);
151 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
152 resourceHandle, uri, type,
153 gResourceInterface, entityHandler, gResourceProperty));
154 return resourceHandle;
157 OCResourceHandle RegisterResource(std::string uri)
160 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
161 OC::QualityOfService::LowQos, &gps };
162 OCPlatform::Configure(cfg);
163 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
164 resourceHandle, uri, gResourceTypeName,
165 gResourceInterface, entityHandler, gResourceProperty));
166 return resourceHandle;
170 // Enable it when the stack throw an exception
171 // https://jira.iotivity.org/browse/IOT-428
172 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
175 OC::ServiceType::InProc,
179 OC::QualityOfService::LowQos
181 OCPlatform::Configure(cfg);
182 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
185 // Enable it when the stack throw an exception
186 // https://jira.iotivity.org/browse/IOT-428
187 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
191 OC::ModeType::Client,
194 OC::QualityOfService::LowQos
196 OCPlatform::Configure(cfg);
197 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
200 // Enable it when the stack throw an exception
201 // https://jira.iotivity.org/browse/IOT-428
202 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
205 OC::ServiceType::OutOfProc,
206 OC::ModeType::Client,
209 OC::QualityOfService::LowQos
211 std::string uri = "/a/light66";
212 std::string type = "core.light";
213 uint8_t gResourceProperty = 0;
214 OCPlatform::Configure(cfg);
215 EXPECT_ANY_THROW(OCPlatform::registerResource(
216 resourceHandle, uri, type,
217 gResourceInterface, entityHandler, gResourceProperty));
220 TEST(ConfigureTest, ConfigureServerOutProc)
224 OC::ServiceType::OutOfProc,
225 OC::ModeType::Server,
228 OC::QualityOfService::LowQos, &gps
230 std::string uri = "/a/light67";
231 std::string type = "core.light";
232 uint8_t gResourceProperty = 0;
233 OCPlatform::Configure(cfg);
235 EXPECT_ANY_THROW(OCPlatform::registerResource(
236 resourceHandle, uri, type,
237 gResourceInterface, entityHandler, gResourceProperty));
240 TEST(ConfigureTest, ConfigureDefault)
242 std::string uri = "/a/light68";
243 std::string type = "core.light";
244 uint8_t gResourceProperty = 0;
245 PlatformConfig cfg = {};
246 OCPlatform::Configure(cfg);
248 EXPECT_NO_THROW(OCPlatform::registerResource(
249 resourceHandle, uri, type,
250 gResourceInterface, entityHandler, gResourceProperty));
253 TEST(ConfigureTest, ConfigureServer)
255 std::string uri = "/a/light69";
256 std::string type = "core.light";
257 uint8_t gResourceProperty = 0;
259 OC::ServiceType::InProc,
260 OC::ModeType::Server,
263 OC::QualityOfService::LowQos, &gps
265 OCPlatform::Configure(cfg);
267 EXPECT_NO_THROW(OCPlatform::registerResource(
268 resourceHandle, uri, type,
269 gResourceInterface, entityHandler, gResourceProperty));
272 TEST(ConfigureTest, ConfigureClient)
274 std::string uri = "/a/light70";
275 std::string type = "core.light";
276 uint8_t gResourceProperty = 0;
279 OC::ServiceType::InProc,
280 OC::ModeType::Client,
283 OC::QualityOfService::LowQos,
287 EXPECT_NO_THROW(OCPlatform::registerResource(
288 resourceHandle, uri, type,
289 gResourceInterface, entityHandler, gResourceProperty));
291 //PersistentStorageTest
292 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
295 OC::ServiceType::InProc,
299 OC::QualityOfService::LowQos
301 OCPlatform::Configure(cfg);
302 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
305 //PersistentStorageTest
306 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
309 OC::ServiceType::InProc,
313 OC::QualityOfService::LowQos,
316 OCPlatform::Configure(cfg);
317 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
320 //PersistentStorageTest
321 TEST(ConfigureTest, ConfigurePersistentStorage)
324 OC::ServiceType::InProc,
328 OC::QualityOfService::LowQos,
331 OCPlatform::Configure(cfg);
332 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
335 //PersistentStorageTest
336 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
339 OC::ServiceType::InProc,
343 OC::QualityOfService::LowQos,
346 OCPlatform::Configure(cfg);
347 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
351 //RegisterResourceTest
352 TEST(RegisterResourceTest, RegisterSingleResource)
354 std::string uri = "/a/res2";
355 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
358 TEST(RegisterResourceTest, RegisterMultipleResources)
360 std::string uri = "/a/multi";
361 //Good enough for 5 resources.
362 for(int i=0; i< 5; i++)
364 uri +=std::to_string(i);
365 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
369 TEST(RegisterResourceTest, ReregisterResource)
371 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
372 std::string("core.light"));
373 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
375 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
376 std::string("core.light")));
380 TEST(RegisterResourceTest, RegisterEmptyResource)
382 // We should not allow empty URI.
383 std::string emptyStr = "";
384 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
385 emptyStr, entityHandler, gResourceProperty));
388 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
390 std::string uri = "/a/light6";
391 std::string type = "core.light";
392 uint8_t gResourceProperty = 0;
393 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
394 resourceHandle, uri, type,
395 gResourceInterface, entityHandler, gResourceProperty));
399 TEST(UnregisterTest, UnregisterZeroHandleValue)
401 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
404 //UnbindResourcesTest
405 TEST(UnbindResourcesTest, UnbindResources)
407 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
408 std::string("core.home"));
409 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
410 std::string("core.kitchen"), LINK_INTERFACE);
411 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
412 std::string("core.office"), LINK_INTERFACE);
414 std::vector<OCResourceHandle> rList;
415 rList.push_back(resourceKitchen);
416 rList.push_back(resourceRoom);
417 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
418 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
421 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
423 OCResourceHandle resourceHandle1 = 0;
424 OCResourceHandle resourceHandle2 = 0;
425 OCResourceHandle resourceHandle3 = 0;
427 std::vector<OCResourceHandle> rList;
429 rList.push_back(resourceHandle2);
430 rList.push_back(resourceHandle3);
432 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
435 //BindInterfaceToResourceTest
436 TEST(BindInterfaceToResourceTest, BindResourceInterface)
438 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
439 std::string("core.light"));
440 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
442 EXPECT_EQ(OC_STACK_OK, result);
445 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
447 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
448 std::string("core.light"));
449 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
452 //BindTypeToResourceTest
453 TEST(BindTypeToResourceTest, BindResourceType)
455 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
456 std::string("core.light"));
457 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
459 EXPECT_EQ(OC_STACK_OK, result);
462 TEST(BindTypeToResourceTest, BindZeroResourceType)
464 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
465 std::string("core.light"));
466 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
470 TEST(UnbindResourceTest, BindAndUnbindResource)
472 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
473 std::string("core.unres"));
474 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
475 std::string("core.unres"), LINK_INTERFACE);
477 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
478 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
482 TEST(PresenceTest, DISABLED_StartAndStopPresence)
484 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
485 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
486 std::string("core.Presence")));
487 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
490 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
492 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
495 //NotifyAllObserverTest
496 TEST(NotifyAllObserverTest, NotifyAllObservers)
498 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
499 std::string("core.obs"));
500 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
503 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
505 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
506 std::string("core.obs"));
507 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
508 OC::QualityOfService::LowQos));
511 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
513 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
514 std::string("core.obs"));
515 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
516 OC::QualityOfService::MidQos));
519 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
521 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
522 std::string("core.obs"));
523 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
524 OC::QualityOfService::NaQos));
527 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
529 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
530 std::string("core.obs"));
531 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
532 OC::QualityOfService::HighQos));
535 TEST(NotifyAllObserverTest, NotifyListOfObservers)
537 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
538 std::string("core.obs"));
540 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
541 ObservationIds interestedObservers;
542 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
543 interestedObservers, resourceResponse));
546 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
548 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
549 std::string("core.obs"));
551 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
552 ObservationIds interestedObservers;
553 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
554 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
557 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
559 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
560 std::string("core.obs"));
562 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
563 ObservationIds interestedObservers;
564 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
565 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
568 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
570 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
571 std::string("core.obs"));
573 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
574 ObservationIds interestedObservers;
575 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
576 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
579 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
581 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
582 std::string("core.obs"));
584 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
585 ObservationIds interestedObservers;
586 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
587 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
590 //DeviceEntityHandlerTest
591 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
593 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
594 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
599 TEST(FindResourceTest, DISABLED_FindResourceValid)
601 std::ostringstream requestURI;
602 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
603 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
604 CT_DEFAULT, &foundResource));
607 TEST(FindResourceTest, FindResourceNullResourceURI)
609 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
610 CT_DEFAULT, &foundResource));
613 TEST(FindResourceTest, FindResourceNullResourceURI1)
615 std::ostringstream requestURI;
616 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
617 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
618 CT_DEFAULT, &foundResource));
621 TEST(FindResourceTest, FindResourceNullHost)
623 std::ostringstream requestURI;
624 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
625 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
626 CT_DEFAULT, &foundResource));
629 TEST(FindResourceTest, FindResourceNullresourceHandler)
631 std::ostringstream requestURI;
632 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
633 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
634 CT_DEFAULT, NULL), OC::OCException);
637 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
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::LowQos));
646 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
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::MidQos));
655 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
657 std::ostringstream requestURI;
658 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
659 EXPECT_EQ(OC_STACK_OK,
660 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
661 OC::QualityOfService::HighQos));
664 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
666 std::ostringstream requestURI;
667 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
668 EXPECT_EQ(OC_STACK_OK,
669 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
670 OC::QualityOfService::NaQos));
674 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
676 std::string deviceDiscoveryURI = "/oic/d";
678 OCPlatform::Configure(cfg);
679 std::ostringstream requestURI;
680 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
681 EXPECT_EQ(OC_STACK_OK,
682 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
685 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
688 OCPlatform::Configure(cfg);
690 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
693 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
695 std::string deviceDiscoveryURI = "/oic/d";
697 OCPlatform::Configure(cfg);
698 std::ostringstream requestURI;
699 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
701 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
705 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
707 std::string deviceDiscoveryURI = "/oic/d";
709 OCPlatform::Configure(cfg);
710 std::ostringstream requestURI;
711 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
712 EXPECT_EQ(OC_STACK_OK,
713 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
714 OC::QualityOfService::LowQos));
717 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
719 std::string deviceDiscoveryURI = "/oic/d";
721 OCPlatform::Configure(cfg);
722 std::ostringstream requestURI;
723 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
724 EXPECT_EQ(OC_STACK_OK,
725 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
726 OC::QualityOfService::MidQos));
729 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
731 std::string deviceDiscoveryURI = "/oic/d";
733 OCPlatform::Configure(cfg);
734 std::ostringstream requestURI;
735 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
736 EXPECT_EQ(OC_STACK_OK,
737 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
738 OC::QualityOfService::HighQos));
741 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
743 std::string deviceDiscoveryURI = "/oic/d";
745 OCPlatform::Configure(cfg);
746 std::ostringstream requestURI;
747 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
748 EXPECT_EQ(OC_STACK_OK,
749 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
750 OC::QualityOfService::NaQos));
753 //RegisterDeviceInfo test
754 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
756 OCDeviceInfo deviceInfo;
757 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
758 deviceInfo.types = NULL;
759 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
760 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
761 DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
762 deviceInfo.dataModelVersions = nullptr;
763 OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions");
764 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
765 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
768 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
770 OCDeviceInfo di = {0, 0, 0, 0};
771 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
774 //SubscribePresence Test
775 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
777 std::string hostAddress = "192.168.1.2:5000";
778 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
780 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
781 CT_DEFAULT, &presenceHandler));
784 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
786 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
788 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
789 CT_DEFAULT, &presenceHandler));
792 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
794 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
796 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
800 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
802 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
804 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
805 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
808 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
810 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
812 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
813 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
816 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
818 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
820 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
821 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
822 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
825 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
827 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
828 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
831 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
833 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
835 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
836 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
837 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
840 //SubscribeDevicePresence Test
841 TEST(SubscribeDevicePresenceTest, DISABLED_SubscribeDevicePresenceWithValidParameters)
843 std::string hostAddress = "192.168.1.2:5000";
844 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
845 QueryParamsList queryParams = {};
847 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
848 hostAddress, queryParams, CT_DEFAULT, &onObserve));
851 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullHost)
853 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
854 QueryParamsList queryParams = {};
856 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
857 nullptr, queryParams, CT_DEFAULT, &onObserve));
860 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullOnObserve)
862 std::string hostAddress = "192.168.1.2:5000";
863 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
864 QueryParamsList queryParams = {};
866 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
867 hostAddress, queryParams, CT_DEFAULT, NULL));
870 TEST(SubscribeDevicePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
872 std::string hostAddress = "192.168.1.2:5000";
873 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
874 QueryParamsList queryParams = {};
876 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
877 hostAddress, queryParams, CT_DEFAULT, &onObserve));
878 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
881 TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
883 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
886 TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
888 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
891 TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
893 EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
896 TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
899 OCPrm_t pmSel = DP_PRE_CONFIGURED;
901 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
902 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(s_dp, pmSel, pin, nullptr));
905 TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
908 OCPrm_t pmSel = DP_PRE_CONFIGURED;
910 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
911 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, &directPairHandler));
914 TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
917 OCPrm_t pmSel = DP_PRE_CONFIGURED;
919 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
920 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));
924 TEST(SignUpTest, DISABLED_SignUpWithValidParameters)
926 std::string host("coap+tcp://192.168.1.2:5000");
927 std::string authProvider("AnyAuthProvider");
928 std::string authCode("AnyAuthCode");
929 EXPECT_EQ(OC_STACK_OK, OCPlatform::signUp(host, authProvider, authCode,
930 CT_DEFAULT, &accountHandler));
933 TEST(SignUpTest, SignUpWithNullCallback)
935 std::string host("coap+tcp://192.168.1.2:5000");
936 std::string authProvider("AnyAuthProvider");
937 std::string authCode("AnyAuthCode");
938 EXPECT_ANY_THROW(OCPlatform::signUp(host, authProvider, authCode, CT_DEFAULT, nullptr));
942 TEST(SignInTest, DISABLED_SignInWithValidParameters)
944 std::string host("coap+tcp://192.168.1.2:5000");
945 std::string accessToken("AnyAccessToken");
946 EXPECT_EQ(OC_STACK_OK, OCPlatform::signIn(host, accessToken, CT_DEFAULT, &accountHandler));
949 TEST(SignInTest, SignInWithNullCallback)
951 std::string host("coap+tcp://192.168.1.2:5000");
952 std::string accessToken("AnyAccessToken");
953 EXPECT_ANY_THROW(OCPlatform::signIn(host, accessToken, CT_DEFAULT, nullptr));
957 TEST(SignOutTest, DISABLED_SignOutWithValidParameters)
959 std::string host("coap+tcp://192.168.1.2:5000");
960 std::string accessToken("AnyAccessToken");
961 EXPECT_EQ(OC_STACK_OK, OCPlatform::signOut(host, accessToken,
962 CT_DEFAULT, &accountHandler));
965 TEST(SignOutTest, SignOutWithNullCallback)
967 std::string host("coap+tcp://192.168.1.2:5000");
968 std::string accessToken("AnyAccessToken");
969 EXPECT_ANY_THROW(OCPlatform::signOut(host, accessToken, CT_DEFAULT, nullptr));
972 //RefreshAccessToken Test
973 TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenWithValidParameters)
975 std::string host("coap+tcp://192.168.1.2:5000");
976 std::string refreshToken("AnyRefreshToken");
977 EXPECT_EQ(OC_STACK_OK, OCPlatform::refreshAccessToken(host, refreshToken,
978 CT_DEFAULT, &accountHandler));
981 TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
983 std::string host("coap+tcp://192.168.1.2:5000");
984 std::string refreshToken("AnyRefreshToken");
985 EXPECT_ANY_THROW(OCPlatform::refreshAccessToken(host, refreshToken, CT_DEFAULT, nullptr));