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*/)
79 void accountHandler(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
85 void DeleteStringLL(OCStringLL* ll)
92 DeleteStringLL(ll->next);
97 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
99 delete[] deviceInfo.deviceName;
100 DeleteStringLL(deviceInfo.types);
101 delete[] deviceInfo.specVersion;
102 DeleteStringLL(deviceInfo.dataModelVersions);
105 void DuplicateString(char ** targetString, std::string sourceString)
107 *targetString = new char[sourceString.length() + 1];
108 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
111 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
114 DuplicateString(&dup, value);
117 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
118 (*stringLL)->value = dup;
123 OCStringLL *temp = *stringLL;
128 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
129 temp->next->value = dup;
135 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
138 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
139 OC::QualityOfService::LowQos, &gps };
140 OCPlatform::Configure(cfg);
141 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
142 resourceHandle, uri, type,
143 iface, entityHandler, gResourceProperty));
144 return resourceHandle;
147 OCResourceHandle RegisterResource(std::string uri, std::string type)
150 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
151 OC::QualityOfService::LowQos, &gps };
152 OCPlatform::Configure(cfg);
153 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
154 resourceHandle, uri, type,
155 gResourceInterface, entityHandler, gResourceProperty));
156 return resourceHandle;
159 OCResourceHandle RegisterResource(std::string uri)
162 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
163 OC::QualityOfService::LowQos, &gps };
164 OCPlatform::Configure(cfg);
165 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
166 resourceHandle, uri, gResourceTypeName,
167 gResourceInterface, entityHandler, gResourceProperty));
168 return resourceHandle;
172 // Enable it when the stack throw an exception
173 // https://jira.iotivity.org/browse/IOT-428
174 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
177 OC::ServiceType::InProc,
181 OC::QualityOfService::LowQos
183 OCPlatform::Configure(cfg);
184 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
187 // Enable it when the stack throw an exception
188 // https://jira.iotivity.org/browse/IOT-428
189 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
193 OC::ModeType::Client,
196 OC::QualityOfService::LowQos
198 OCPlatform::Configure(cfg);
199 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
202 // Enable it when the stack throw an exception
203 // https://jira.iotivity.org/browse/IOT-428
204 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
207 OC::ServiceType::OutOfProc,
208 OC::ModeType::Client,
211 OC::QualityOfService::LowQos
213 std::string uri = "/a/light66";
214 std::string type = "core.light";
215 uint8_t gResourceProperty = 0;
216 OCPlatform::Configure(cfg);
217 EXPECT_ANY_THROW(OCPlatform::registerResource(
218 resourceHandle, uri, type,
219 gResourceInterface, entityHandler, gResourceProperty));
222 TEST(ConfigureTest, ConfigureServerOutProc)
226 OC::ServiceType::OutOfProc,
227 OC::ModeType::Server,
230 OC::QualityOfService::LowQos, &gps
232 std::string uri = "/a/light67";
233 std::string type = "core.light";
234 uint8_t gResourceProperty = 0;
235 OCPlatform::Configure(cfg);
237 EXPECT_ANY_THROW(OCPlatform::registerResource(
238 resourceHandle, uri, type,
239 gResourceInterface, entityHandler, gResourceProperty));
242 TEST(ConfigureTest, ConfigureDefault)
244 std::string uri = "/a/light68";
245 std::string type = "core.light";
246 uint8_t gResourceProperty = 0;
247 PlatformConfig cfg = {};
248 OCPlatform::Configure(cfg);
250 EXPECT_NO_THROW(OCPlatform::registerResource(
251 resourceHandle, uri, type,
252 gResourceInterface, entityHandler, gResourceProperty));
255 TEST(ConfigureTest, ConfigureServer)
257 std::string uri = "/a/light69";
258 std::string type = "core.light";
259 uint8_t gResourceProperty = 0;
261 OC::ServiceType::InProc,
262 OC::ModeType::Server,
265 OC::QualityOfService::LowQos, &gps
267 OCPlatform::Configure(cfg);
269 EXPECT_NO_THROW(OCPlatform::registerResource(
270 resourceHandle, uri, type,
271 gResourceInterface, entityHandler, gResourceProperty));
274 TEST(ConfigureTest, ConfigureClient)
276 std::string uri = "/a/light70";
277 std::string type = "core.light";
278 uint8_t gResourceProperty = 0;
281 OC::ServiceType::InProc,
282 OC::ModeType::Client,
285 OC::QualityOfService::LowQos,
289 EXPECT_NO_THROW(OCPlatform::registerResource(
290 resourceHandle, uri, type,
291 gResourceInterface, entityHandler, gResourceProperty));
293 //PersistentStorageTest
294 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
297 OC::ServiceType::InProc,
301 OC::QualityOfService::LowQos
303 OCPlatform::Configure(cfg);
304 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
307 //PersistentStorageTest
308 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
311 OC::ServiceType::InProc,
315 OC::QualityOfService::LowQos,
318 OCPlatform::Configure(cfg);
319 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
322 //PersistentStorageTest
323 TEST(ConfigureTest, ConfigurePersistentStorage)
326 OC::ServiceType::InProc,
330 OC::QualityOfService::LowQos,
333 OCPlatform::Configure(cfg);
334 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
337 //PersistentStorageTest
338 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
341 OC::ServiceType::InProc,
345 OC::QualityOfService::LowQos,
348 OCPlatform::Configure(cfg);
349 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
353 //RegisterResourceTest
354 TEST(RegisterResourceTest, RegisterSingleResource)
356 std::string uri = "/a/res2";
357 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
360 TEST(RegisterResourceTest, RegisterMultipleResources)
362 std::string uri = "/a/multi";
363 //Good enough for 5 resources.
364 for(int i=0; i< 5; i++)
366 uri +=std::to_string(i);
367 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
371 TEST(RegisterResourceTest, ReregisterResource)
373 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
374 std::string("core.light"));
375 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
377 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
378 std::string("core.light")));
382 TEST(RegisterResourceTest, RegisterEmptyResource)
384 // We should not allow empty URI.
385 std::string emptyStr = "";
386 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
387 emptyStr, entityHandler, gResourceProperty));
390 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
392 std::string uri = "/a/light6";
393 std::string type = "core.light";
394 uint8_t gResourceProperty = 0;
395 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
396 resourceHandle, uri, type,
397 gResourceInterface, entityHandler, gResourceProperty));
401 TEST(UnregisterTest, UnregisterZeroHandleValue)
403 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
406 //UnbindResourcesTest
407 TEST(UnbindResourcesTest, UnbindResources)
409 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
410 std::string("core.home"));
411 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
412 std::string("core.kitchen"), LINK_INTERFACE);
413 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
414 std::string("core.office"), LINK_INTERFACE);
416 std::vector<OCResourceHandle> rList;
417 rList.push_back(resourceKitchen);
418 rList.push_back(resourceRoom);
419 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
420 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
423 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
425 OCResourceHandle resourceHandle1 = 0;
426 OCResourceHandle resourceHandle2 = 0;
427 OCResourceHandle resourceHandle3 = 0;
429 std::vector<OCResourceHandle> rList;
431 rList.push_back(resourceHandle2);
432 rList.push_back(resourceHandle3);
434 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
437 //BindInterfaceToResourceTest
438 TEST(BindInterfaceToResourceTest, BindResourceInterface)
440 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
441 std::string("core.light"));
442 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
444 EXPECT_EQ(OC_STACK_OK, result);
447 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
449 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
450 std::string("core.light"));
451 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
454 //BindTypeToResourceTest
455 TEST(BindTypeToResourceTest, BindResourceType)
457 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
458 std::string("core.light"));
459 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
461 EXPECT_EQ(OC_STACK_OK, result);
464 TEST(BindTypeToResourceTest, BindZeroResourceType)
466 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
467 std::string("core.light"));
468 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
472 TEST(UnbindResourceTest, BindAndUnbindResource)
474 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
475 std::string("core.unres"));
476 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
477 std::string("core.unres"), LINK_INTERFACE);
479 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
480 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
484 TEST(PresenceTest, DISABLED_StartAndStopPresence)
486 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
487 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
488 std::string("core.Presence")));
489 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
492 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
494 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
497 //NotifyAllObserverTest
498 TEST(NotifyAllObserverTest, NotifyAllObservers)
500 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
501 std::string("core.obs"));
502 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
505 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
507 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
508 std::string("core.obs"));
509 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
510 OC::QualityOfService::LowQos));
513 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
515 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
516 std::string("core.obs"));
517 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
518 OC::QualityOfService::MidQos));
521 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
523 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
524 std::string("core.obs"));
525 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
526 OC::QualityOfService::NaQos));
529 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
531 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
532 std::string("core.obs"));
533 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
534 OC::QualityOfService::HighQos));
537 TEST(NotifyAllObserverTest, NotifyListOfObservers)
539 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
540 std::string("core.obs"));
542 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
543 ObservationIds interestedObservers;
544 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
545 interestedObservers, resourceResponse));
548 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
550 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
551 std::string("core.obs"));
553 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
554 ObservationIds interestedObservers;
555 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
556 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
559 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
561 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
562 std::string("core.obs"));
564 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
565 ObservationIds interestedObservers;
566 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
567 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
570 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
572 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
573 std::string("core.obs"));
575 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
576 ObservationIds interestedObservers;
577 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
578 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
581 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
583 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
584 std::string("core.obs"));
586 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
587 ObservationIds interestedObservers;
588 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
589 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
592 //DeviceEntityHandlerTest
593 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
595 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
596 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
601 TEST(FindResourceTest, DISABLED_FindResourceValid)
603 std::ostringstream requestURI;
604 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
605 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
606 CT_DEFAULT, &foundResource));
609 TEST(FindResourceTest, FindResourceNullResourceURI)
611 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
612 CT_DEFAULT, &foundResource));
615 TEST(FindResourceTest, FindResourceNullResourceURI1)
617 std::ostringstream requestURI;
618 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
619 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
620 CT_DEFAULT, &foundResource));
623 TEST(FindResourceTest, FindResourceNullHost)
625 std::ostringstream requestURI;
626 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
627 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
628 CT_DEFAULT, &foundResource));
631 TEST(FindResourceTest, FindResourceNullresourceHandler)
633 std::ostringstream requestURI;
634 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
635 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
636 CT_DEFAULT, NULL), OC::OCException);
639 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
641 std::ostringstream requestURI;
642 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
643 EXPECT_EQ(OC_STACK_OK,
644 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
645 OC::QualityOfService::LowQos));
648 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
650 std::ostringstream requestURI;
651 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
652 EXPECT_EQ(OC_STACK_OK,
653 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
654 OC::QualityOfService::MidQos));
657 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
659 std::ostringstream requestURI;
660 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
661 EXPECT_EQ(OC_STACK_OK,
662 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
663 OC::QualityOfService::HighQos));
666 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
668 std::ostringstream requestURI;
669 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
670 EXPECT_EQ(OC_STACK_OK,
671 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
672 OC::QualityOfService::NaQos));
676 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
678 std::string deviceDiscoveryURI = "/oic/d";
680 OCPlatform::Configure(cfg);
681 std::ostringstream requestURI;
682 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
683 EXPECT_EQ(OC_STACK_OK,
684 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
687 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
690 OCPlatform::Configure(cfg);
692 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
695 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
697 std::string deviceDiscoveryURI = "/oic/d";
699 OCPlatform::Configure(cfg);
700 std::ostringstream requestURI;
701 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
703 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
707 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
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::LowQos));
719 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
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::MidQos));
731 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
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::HighQos));
743 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
745 std::string deviceDiscoveryURI = "/oic/d";
747 OCPlatform::Configure(cfg);
748 std::ostringstream requestURI;
749 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
750 EXPECT_EQ(OC_STACK_OK,
751 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
752 OC::QualityOfService::NaQos));
755 //RegisterDeviceInfo test
756 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
758 OCDeviceInfo deviceInfo;
759 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
760 deviceInfo.types = NULL;
761 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
762 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
763 DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
764 deviceInfo.dataModelVersions = nullptr;
765 OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions");
766 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
767 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
770 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
772 OCDeviceInfo di = {0, 0, 0, 0};
773 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
776 //SubscribePresence Test
777 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
779 std::string hostAddress = "192.168.1.2:5000";
780 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
782 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
783 CT_DEFAULT, &presenceHandler));
786 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
788 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
790 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
791 CT_DEFAULT, &presenceHandler));
794 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
796 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
798 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
802 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
804 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
806 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
807 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
810 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
812 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
814 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
815 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
818 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
820 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
822 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
823 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
824 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
827 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
829 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
830 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
833 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
835 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
837 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
838 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
839 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
843 //SubscribeDevicePresence Test
844 TEST(SubscribeDevicePresenceTest, DISABLED_SubscribeDevicePresenceWithValidParameters)
846 std::string hostAddress = "192.168.1.2:5000";
847 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
848 QueryParamsList queryParams = {};
850 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
851 hostAddress, queryParams, CT_DEFAULT, &onObserve));
854 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullHost)
856 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
857 QueryParamsList queryParams = {};
859 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
860 nullptr, queryParams, CT_DEFAULT, &onObserve));
863 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullOnObserve)
865 std::string hostAddress = "192.168.1.2:5000";
866 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
867 QueryParamsList queryParams = {};
869 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
870 hostAddress, queryParams, CT_DEFAULT, NULL));
873 TEST(SubscribeDevicePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
875 std::string hostAddress = "192.168.1.2:5000";
876 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
877 QueryParamsList queryParams = {};
879 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
880 hostAddress, queryParams, CT_DEFAULT, &onObserve));
881 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
885 TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
887 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
890 TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
892 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
895 TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
897 EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
900 TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
903 OCPrm_t pmSel = DP_PRE_CONFIGURED;
905 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
906 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(s_dp, pmSel, pin, nullptr));
909 TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
912 OCPrm_t pmSel = DP_PRE_CONFIGURED;
914 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
915 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, &directPairHandler));
918 TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
921 OCPrm_t pmSel = DP_PRE_CONFIGURED;
923 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
924 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));
928 TEST(SignUpTest, DISABLED_SignUpWithValidParameters)
930 std::string host("coap+tcp://192.168.1.2:5000");
931 std::string authProvider("AnyAuthProvider");
932 std::string authCode("AnyAuthCode");
933 EXPECT_EQ(OC_STACK_OK, OCPlatform::signUp(host, authProvider, authCode,
934 CT_DEFAULT, &accountHandler));
937 TEST(SignUpTest, SignUpWithNullCallback)
939 std::string host("coap+tcp://192.168.1.2:5000");
940 std::string authProvider("AnyAuthProvider");
941 std::string authCode("AnyAuthCode");
942 EXPECT_ANY_THROW(OCPlatform::signUp(host, authProvider, authCode, CT_DEFAULT, nullptr));
946 TEST(SignInTest, DISABLED_SignInWithValidParameters)
948 std::string host("coap+tcp://192.168.1.2:5000");
949 std::string accessToken("AnyAccessToken");
950 EXPECT_EQ(OC_STACK_OK, OCPlatform::signIn(host, accessToken, CT_DEFAULT, &accountHandler));
953 TEST(SignInTest, SignInWithNullCallback)
955 std::string host("coap+tcp://192.168.1.2:5000");
956 std::string accessToken("AnyAccessToken");
957 EXPECT_ANY_THROW(OCPlatform::signIn(host, accessToken, CT_DEFAULT, nullptr));
961 TEST(SignOutTest, DISABLED_SignOutWithValidParameters)
963 std::string host("coap+tcp://192.168.1.2:5000");
964 std::string accessToken("AnyAccessToken");
965 EXPECT_EQ(OC_STACK_OK, OCPlatform::signOut(host, accessToken,
966 CT_DEFAULT, &accountHandler));
969 TEST(SignOutTest, SignOutWithNullCallback)
971 std::string host("coap+tcp://192.168.1.2:5000");
972 std::string accessToken("AnyAccessToken");
973 EXPECT_ANY_THROW(OCPlatform::signOut(host, accessToken, CT_DEFAULT, nullptr));
976 //RefreshAccessToken Test
977 TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenWithValidParameters)
979 std::string host("coap+tcp://192.168.1.2:5000");
980 std::string refreshToken("AnyRefreshToken");
981 EXPECT_EQ(OC_STACK_OK, OCPlatform::refreshAccessToken(host, refreshToken,
982 CT_DEFAULT, &accountHandler));
985 TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
987 std::string host("coap+tcp://192.168.1.2:5000");
988 std::string refreshToken("AnyRefreshToken");
989 EXPECT_ANY_THROW(OCPlatform::refreshAccessToken(host, refreshToken, CT_DEFAULT, nullptr));