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 directPairHandler(std::shared_ptr<OCDirectPairing> /*dev*/, OCStackResult /*res*/)
69 void pairedHandler(const PairedDevices& /*list*/)
73 void accountHandler(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
79 void DeleteStringLL(OCStringLL* ll)
86 DeleteStringLL(ll->next);
91 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
93 delete[] deviceInfo.deviceName;
94 DeleteStringLL(deviceInfo.types);
95 delete[] deviceInfo.specVersion;
96 DeleteStringLL(deviceInfo.dataModelVersions);
99 void DuplicateString(char ** targetString, std::string sourceString)
101 *targetString = new char[sourceString.length() + 1];
102 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
105 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
108 DuplicateString(&dup, value);
111 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
112 (*stringLL)->value = dup;
117 OCStringLL *temp = *stringLL;
122 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
123 temp->next->value = dup;
129 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
132 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
133 OC::QualityOfService::LowQos, &gps };
134 OCPlatform::Configure(cfg);
135 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
136 resourceHandle, uri, type,
137 iface, entityHandler, gResourceProperty));
138 return resourceHandle;
141 OCResourceHandle RegisterResource(std::string uri, std::string type)
144 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
145 OC::QualityOfService::LowQos, &gps };
146 OCPlatform::Configure(cfg);
147 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
148 resourceHandle, uri, type,
149 gResourceInterface, entityHandler, gResourceProperty));
150 return resourceHandle;
153 OCResourceHandle RegisterResource(std::string uri)
156 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
157 OC::QualityOfService::LowQos, &gps };
158 OCPlatform::Configure(cfg);
159 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
160 resourceHandle, uri, gResourceTypeName,
161 gResourceInterface, entityHandler, gResourceProperty));
162 return resourceHandle;
166 // Enable it when the stack throw an exception
167 // https://jira.iotivity.org/browse/IOT-428
168 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
171 OC::ServiceType::InProc,
175 OC::QualityOfService::LowQos
177 OCPlatform::Configure(cfg);
178 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
181 // Enable it when the stack throw an exception
182 // https://jira.iotivity.org/browse/IOT-428
183 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
187 OC::ModeType::Client,
190 OC::QualityOfService::LowQos
192 OCPlatform::Configure(cfg);
193 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
196 // Enable it when the stack throw an exception
197 // https://jira.iotivity.org/browse/IOT-428
198 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
201 OC::ServiceType::OutOfProc,
202 OC::ModeType::Client,
205 OC::QualityOfService::LowQos
207 std::string uri = "/a/light66";
208 std::string type = "core.light";
209 uint8_t gResourceProperty = 0;
210 OCPlatform::Configure(cfg);
211 EXPECT_ANY_THROW(OCPlatform::registerResource(
212 resourceHandle, uri, type,
213 gResourceInterface, entityHandler, gResourceProperty));
216 TEST(ConfigureTest, ConfigureServerOutProc)
220 OC::ServiceType::OutOfProc,
221 OC::ModeType::Server,
224 OC::QualityOfService::LowQos, &gps
226 std::string uri = "/a/light67";
227 std::string type = "core.light";
228 uint8_t gResourceProperty = 0;
229 OCPlatform::Configure(cfg);
231 EXPECT_ANY_THROW(OCPlatform::registerResource(
232 resourceHandle, uri, type,
233 gResourceInterface, entityHandler, gResourceProperty));
236 TEST(ConfigureTest, ConfigureDefault)
238 std::string uri = "/a/light68";
239 std::string type = "core.light";
240 uint8_t gResourceProperty = 0;
241 PlatformConfig cfg = {};
242 OCPlatform::Configure(cfg);
244 EXPECT_NO_THROW(OCPlatform::registerResource(
245 resourceHandle, uri, type,
246 gResourceInterface, entityHandler, gResourceProperty));
249 TEST(ConfigureTest, ConfigureServer)
251 std::string uri = "/a/light69";
252 std::string type = "core.light";
253 uint8_t gResourceProperty = 0;
255 OC::ServiceType::InProc,
256 OC::ModeType::Server,
259 OC::QualityOfService::LowQos, &gps
261 OCPlatform::Configure(cfg);
263 EXPECT_NO_THROW(OCPlatform::registerResource(
264 resourceHandle, uri, type,
265 gResourceInterface, entityHandler, gResourceProperty));
268 TEST(ConfigureTest, ConfigureClient)
270 std::string uri = "/a/light70";
271 std::string type = "core.light";
272 uint8_t gResourceProperty = 0;
275 OC::ServiceType::InProc,
276 OC::ModeType::Client,
279 OC::QualityOfService::LowQos,
283 EXPECT_NO_THROW(OCPlatform::registerResource(
284 resourceHandle, uri, type,
285 gResourceInterface, entityHandler, gResourceProperty));
287 //PersistentStorageTest
288 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
291 OC::ServiceType::InProc,
295 OC::QualityOfService::LowQos
297 OCPlatform::Configure(cfg);
298 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
301 //PersistentStorageTest
302 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
305 OC::ServiceType::InProc,
309 OC::QualityOfService::LowQos,
312 OCPlatform::Configure(cfg);
313 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
316 //PersistentStorageTest
317 TEST(ConfigureTest, ConfigurePersistentStorage)
320 OC::ServiceType::InProc,
324 OC::QualityOfService::LowQos,
327 OCPlatform::Configure(cfg);
328 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
331 //PersistentStorageTest
332 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
335 OC::ServiceType::InProc,
339 OC::QualityOfService::LowQos,
342 OCPlatform::Configure(cfg);
343 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
347 //RegisterResourceTest
348 TEST(RegisterResourceTest, RegisterSingleResource)
350 std::string uri = "/a/res2";
351 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
354 TEST(RegisterResourceTest, RegisterMultipleResources)
356 std::string uri = "/a/multi";
357 //Good enough for 5 resources.
358 for(int i=0; i< 5; i++)
360 uri +=std::to_string(i);
361 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
365 TEST(RegisterResourceTest, ReregisterResource)
367 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
368 std::string("core.light"));
369 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
371 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
372 std::string("core.light")));
376 TEST(RegisterResourceTest, RegisterEmptyResource)
378 // We should not allow empty URI.
379 std::string emptyStr = "";
380 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
381 emptyStr, entityHandler, gResourceProperty));
384 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
386 std::string uri = "/a/light6";
387 std::string type = "core.light";
388 uint8_t gResourceProperty = 0;
389 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
390 resourceHandle, uri, type,
391 gResourceInterface, entityHandler, gResourceProperty));
395 TEST(UnregisterTest, UnregisterZeroHandleValue)
397 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
400 //UnbindResourcesTest
401 TEST(UnbindResourcesTest, UnbindResources)
403 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
404 std::string("core.home"));
405 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
406 std::string("core.kitchen"), LINK_INTERFACE);
407 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
408 std::string("core.office"), LINK_INTERFACE);
410 std::vector<OCResourceHandle> rList;
411 rList.push_back(resourceKitchen);
412 rList.push_back(resourceRoom);
413 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
414 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
417 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
419 OCResourceHandle resourceHandle1 = 0;
420 OCResourceHandle resourceHandle2 = 0;
421 OCResourceHandle resourceHandle3 = 0;
423 std::vector<OCResourceHandle> rList;
425 rList.push_back(resourceHandle2);
426 rList.push_back(resourceHandle3);
428 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
431 //BindInterfaceToResourceTest
432 TEST(BindInterfaceToResourceTest, BindResourceInterface)
434 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
435 std::string("core.light"));
436 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
438 EXPECT_EQ(OC_STACK_OK, result);
441 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
443 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
444 std::string("core.light"));
445 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
448 //BindTypeToResourceTest
449 TEST(BindTypeToResourceTest, BindResourceType)
451 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
452 std::string("core.light"));
453 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
455 EXPECT_EQ(OC_STACK_OK, result);
458 TEST(BindTypeToResourceTest, BindZeroResourceType)
460 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
461 std::string("core.light"));
462 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
466 TEST(UnbindResourceTest, BindAndUnbindResource)
468 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
469 std::string("core.unres"));
470 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
471 std::string("core.unres"), LINK_INTERFACE);
473 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
474 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
478 TEST(PresenceTest, DISABLED_StartAndStopPresence)
480 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
481 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
482 std::string("core.Presence")));
483 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
486 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
488 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
491 //NotifyAllObserverTest
492 TEST(NotifyAllObserverTest, NotifyAllObservers)
494 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
495 std::string("core.obs"));
496 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
499 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
501 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
502 std::string("core.obs"));
503 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
504 OC::QualityOfService::LowQos));
507 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
509 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
510 std::string("core.obs"));
511 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
512 OC::QualityOfService::MidQos));
515 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
517 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
518 std::string("core.obs"));
519 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
520 OC::QualityOfService::NaQos));
523 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
525 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
526 std::string("core.obs"));
527 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
528 OC::QualityOfService::HighQos));
531 TEST(NotifyAllObserverTest, NotifyListOfObservers)
533 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
534 std::string("core.obs"));
536 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
537 ObservationIds interestedObservers;
538 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
539 interestedObservers, resourceResponse));
542 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
544 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
545 std::string("core.obs"));
547 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
548 ObservationIds interestedObservers;
549 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
550 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
553 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
555 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
556 std::string("core.obs"));
558 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
559 ObservationIds interestedObservers;
560 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
561 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
564 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
566 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
567 std::string("core.obs"));
569 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
570 ObservationIds interestedObservers;
571 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
572 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
575 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
577 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
578 std::string("core.obs"));
580 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
581 ObservationIds interestedObservers;
582 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
583 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
586 //DeviceEntityHandlerTest
587 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
589 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
590 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
595 TEST(FindResourceTest, DISABLED_FindResourceValid)
597 std::ostringstream requestURI;
598 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
599 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
600 CT_DEFAULT, &foundResource));
603 TEST(FindResourceTest, FindResourceNullResourceURI)
605 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
606 CT_DEFAULT, &foundResource));
609 TEST(FindResourceTest, FindResourceNullResourceURI1)
611 std::ostringstream requestURI;
612 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
613 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
614 CT_DEFAULT, &foundResource));
617 TEST(FindResourceTest, FindResourceNullHost)
619 std::ostringstream requestURI;
620 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
621 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
622 CT_DEFAULT, &foundResource));
625 TEST(FindResourceTest, FindResourceNullresourceHandler)
627 std::ostringstream requestURI;
628 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
629 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
630 CT_DEFAULT, NULL), OC::OCException);
633 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
635 std::ostringstream requestURI;
636 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
637 EXPECT_EQ(OC_STACK_OK,
638 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
639 OC::QualityOfService::LowQos));
642 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
644 std::ostringstream requestURI;
645 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
646 EXPECT_EQ(OC_STACK_OK,
647 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
648 OC::QualityOfService::MidQos));
651 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
653 std::ostringstream requestURI;
654 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
655 EXPECT_EQ(OC_STACK_OK,
656 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
657 OC::QualityOfService::HighQos));
660 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
662 std::ostringstream requestURI;
663 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
664 EXPECT_EQ(OC_STACK_OK,
665 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
666 OC::QualityOfService::NaQos));
670 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
672 std::string deviceDiscoveryURI = "/oic/d";
674 OCPlatform::Configure(cfg);
675 std::ostringstream requestURI;
676 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
677 EXPECT_EQ(OC_STACK_OK,
678 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
681 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
684 OCPlatform::Configure(cfg);
686 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
689 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
691 std::string deviceDiscoveryURI = "/oic/d";
693 OCPlatform::Configure(cfg);
694 std::ostringstream requestURI;
695 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
697 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
701 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
703 std::string deviceDiscoveryURI = "/oic/d";
705 OCPlatform::Configure(cfg);
706 std::ostringstream requestURI;
707 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
708 EXPECT_EQ(OC_STACK_OK,
709 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
710 OC::QualityOfService::LowQos));
713 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
715 std::string deviceDiscoveryURI = "/oic/d";
717 OCPlatform::Configure(cfg);
718 std::ostringstream requestURI;
719 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
720 EXPECT_EQ(OC_STACK_OK,
721 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
722 OC::QualityOfService::MidQos));
725 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
727 std::string deviceDiscoveryURI = "/oic/d";
729 OCPlatform::Configure(cfg);
730 std::ostringstream requestURI;
731 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
732 EXPECT_EQ(OC_STACK_OK,
733 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
734 OC::QualityOfService::HighQos));
737 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
739 std::string deviceDiscoveryURI = "/oic/d";
741 OCPlatform::Configure(cfg);
742 std::ostringstream requestURI;
743 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
744 EXPECT_EQ(OC_STACK_OK,
745 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
746 OC::QualityOfService::NaQos));
749 //RegisterDeviceInfo test
750 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
752 OCDeviceInfo deviceInfo;
753 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
754 deviceInfo.types = NULL;
755 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
756 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
757 DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
758 deviceInfo.dataModelVersions = nullptr;
759 OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions");
760 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
761 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
764 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
766 OCDeviceInfo di = {0, 0, 0, 0};
767 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
770 //SubscribePresence Test
771 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
773 std::string hostAddress = "192.168.1.2:5000";
774 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
776 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
777 CT_DEFAULT, &presenceHandler));
780 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
782 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
784 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
785 CT_DEFAULT, &presenceHandler));
788 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
790 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
792 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
796 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
798 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
800 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
801 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
804 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
806 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
808 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
809 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
812 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
814 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
816 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
817 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
818 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
821 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
823 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
824 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
827 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
829 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
831 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
832 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
833 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
836 TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
838 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
841 TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
843 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
846 TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
848 EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
851 TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
854 OCPrm_t pmSel = DP_PRE_CONFIGURED;
856 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
857 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(s_dp, pmSel, pin, nullptr));
860 TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
863 OCPrm_t pmSel = DP_PRE_CONFIGURED;
865 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
866 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, &directPairHandler));
869 TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
872 OCPrm_t pmSel = DP_PRE_CONFIGURED;
874 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
875 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));
879 TEST(SignUpTest, DISABLED_SignUpWithValidParameters)
881 std::string host("coap+tcp://192.168.1.2:5000");
882 std::string authProvider("AnyAuthProvider");
883 std::string authCode("AnyAuthCode");
884 EXPECT_EQ(OC_STACK_OK, OCPlatform::signUp(host, authProvider, authCode,
885 CT_DEFAULT, &accountHandler));
888 TEST(SignUpTest, SignUpWithNullCallback)
890 std::string host("coap+tcp://192.168.1.2:5000");
891 std::string authProvider("AnyAuthProvider");
892 std::string authCode("AnyAuthCode");
893 EXPECT_ANY_THROW(OCPlatform::signUp(host, authProvider, authCode, CT_DEFAULT, nullptr));
897 TEST(SignInTest, DISABLED_SignInWithValidParameters)
899 std::string host("coap+tcp://192.168.1.2:5000");
900 std::string accessToken("AnyAccessToken");
901 EXPECT_EQ(OC_STACK_OK, OCPlatform::signIn(host, accessToken, CT_DEFAULT, &accountHandler));
904 TEST(SignInTest, SignInWithNullCallback)
906 std::string host("coap+tcp://192.168.1.2:5000");
907 std::string accessToken("AnyAccessToken");
908 EXPECT_ANY_THROW(OCPlatform::signIn(host, accessToken, CT_DEFAULT, nullptr));
912 TEST(SignOutTest, DISABLED_SignOutWithValidParameters)
914 std::string host("coap+tcp://192.168.1.2:5000");
915 std::string accessToken("AnyAccessToken");
916 EXPECT_EQ(OC_STACK_OK, OCPlatform::signOut(host, accessToken,
917 CT_DEFAULT, &accountHandler));
920 TEST(SignOutTest, SignOutWithNullCallback)
922 std::string host("coap+tcp://192.168.1.2:5000");
923 std::string accessToken("AnyAccessToken");
924 EXPECT_ANY_THROW(OCPlatform::signOut(host, accessToken, CT_DEFAULT, nullptr));
927 //RefreshAccessToken Test
928 TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenWithValidParameters)
930 std::string host("coap+tcp://192.168.1.2:5000");
931 std::string refreshToken("AnyRefreshToken");
932 EXPECT_EQ(OC_STACK_OK, OCPlatform::refreshAccessToken(host, refreshToken,
933 CT_DEFAULT, &accountHandler));
936 TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
938 std::string host("coap+tcp://192.168.1.2:5000");
939 std::string refreshToken("AnyRefreshToken");
940 EXPECT_ANY_THROW(OCPlatform::refreshAccessToken(host, refreshToken, CT_DEFAULT, nullptr));