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;
167 // Enable it when the stack throw an exception
168 // https://jira.iotivity.org/browse/IOT-428
169 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
172 OC::ServiceType::InProc,
176 OC::QualityOfService::LowQos
178 OCPlatform::Configure(cfg);
179 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
182 // Enable it when the stack throw an exception
183 // https://jira.iotivity.org/browse/IOT-428
184 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
188 OC::ModeType::Client,
191 OC::QualityOfService::LowQos
193 OCPlatform::Configure(cfg);
194 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
197 // Enable it when the stack throw an exception
198 // https://jira.iotivity.org/browse/IOT-428
199 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
202 OC::ServiceType::OutOfProc,
203 OC::ModeType::Client,
206 OC::QualityOfService::LowQos
208 std::string uri = "/a/light66";
209 std::string type = "core.light";
210 uint8_t gResourceProperty = 0;
211 OCPlatform::Configure(cfg);
212 EXPECT_ANY_THROW(OCPlatform::registerResource(
213 resourceHandle, uri, type,
214 gResourceInterface, entityHandler, gResourceProperty));
217 TEST(ConfigureTest, ConfigureServerOutProc)
221 OC::ServiceType::OutOfProc,
222 OC::ModeType::Server,
225 OC::QualityOfService::LowQos, &gps
227 std::string uri = "/a/light67";
228 std::string type = "core.light";
229 uint8_t gResourceProperty = 0;
230 OCPlatform::Configure(cfg);
232 EXPECT_ANY_THROW(OCPlatform::registerResource(
233 resourceHandle, uri, type,
234 gResourceInterface, entityHandler, gResourceProperty));
237 TEST(ConfigureTest, ConfigureDefault)
239 std::string uri = "/a/light68";
240 std::string type = "core.light";
241 uint8_t gResourceProperty = 0;
242 PlatformConfig cfg = {};
243 OCPlatform::Configure(cfg);
245 EXPECT_NO_THROW(OCPlatform::registerResource(
246 resourceHandle, uri, type,
247 gResourceInterface, entityHandler, gResourceProperty));
250 TEST(ConfigureTest, ConfigureServer)
252 std::string uri = "/a/light69";
253 std::string type = "core.light";
254 uint8_t gResourceProperty = 0;
256 OC::ServiceType::InProc,
257 OC::ModeType::Server,
260 OC::QualityOfService::LowQos, &gps
262 OCPlatform::Configure(cfg);
264 EXPECT_NO_THROW(OCPlatform::registerResource(
265 resourceHandle, uri, type,
266 gResourceInterface, entityHandler, gResourceProperty));
269 TEST(ConfigureTest, ConfigureClient)
271 std::string uri = "/a/light70";
272 std::string type = "core.light";
273 uint8_t gResourceProperty = 0;
276 OC::ServiceType::InProc,
277 OC::ModeType::Client,
280 OC::QualityOfService::LowQos,
284 EXPECT_NO_THROW(OCPlatform::registerResource(
285 resourceHandle, uri, type,
286 gResourceInterface, entityHandler, gResourceProperty));
288 //PersistentStorageTest
289 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
292 OC::ServiceType::InProc,
296 OC::QualityOfService::LowQos
298 OCPlatform::Configure(cfg);
299 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
302 //PersistentStorageTest
303 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
306 OC::ServiceType::InProc,
310 OC::QualityOfService::LowQos,
313 OCPlatform::Configure(cfg);
314 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
317 //PersistentStorageTest
318 TEST(ConfigureTest, ConfigurePersistentStorage)
321 OC::ServiceType::InProc,
325 OC::QualityOfService::LowQos,
328 OCPlatform::Configure(cfg);
329 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
332 //PersistentStorageTest
333 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
336 OC::ServiceType::InProc,
340 OC::QualityOfService::LowQos,
343 OCPlatform::Configure(cfg);
344 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
348 //RegisterResourceTest
349 TEST(RegisterResourceTest, RegisterSingleResource)
351 std::string uri = "/a/res2";
352 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
355 TEST(RegisterResourceTest, RegisterMultipleResources)
357 std::string uri = "/a/multi";
358 //Good enough for 5 resources.
359 for(int i=0; i< 5; i++)
361 uri +=std::to_string(i);
362 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
366 TEST(RegisterResourceTest, ReregisterResource)
368 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
369 std::string("core.light"));
370 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
372 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
373 std::string("core.light")));
377 TEST(RegisterResourceTest, RegisterEmptyResource)
379 // We should not allow empty URI.
380 std::string emptyStr = "";
381 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
382 emptyStr, entityHandler, gResourceProperty));
385 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
387 std::string uri = "/a/light6";
388 std::string type = "core.light";
389 uint8_t gResourceProperty = 0;
390 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
391 resourceHandle, uri, type,
392 gResourceInterface, entityHandler, gResourceProperty));
396 TEST(UnregisterTest, UnregisterZeroHandleValue)
398 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
401 //UnbindResourcesTest
402 TEST(UnbindResourcesTest, UnbindResources)
404 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
405 std::string("core.home"));
406 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
407 std::string("core.kitchen"), LINK_INTERFACE);
408 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
409 std::string("core.office"), LINK_INTERFACE);
411 std::vector<OCResourceHandle> rList;
412 rList.push_back(resourceKitchen);
413 rList.push_back(resourceRoom);
414 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
415 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
418 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
420 OCResourceHandle resourceHandle1 = 0;
421 OCResourceHandle resourceHandle2 = 0;
422 OCResourceHandle resourceHandle3 = 0;
424 std::vector<OCResourceHandle> rList;
426 rList.push_back(resourceHandle2);
427 rList.push_back(resourceHandle3);
429 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
432 //BindInterfaceToResourceTest
433 TEST(BindInterfaceToResourceTest, BindResourceInterface)
435 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
436 std::string("core.light"));
437 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
439 EXPECT_EQ(OC_STACK_OK, result);
442 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
444 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
445 std::string("core.light"));
446 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
449 //BindTypeToResourceTest
450 TEST(BindTypeToResourceTest, BindResourceType)
452 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
453 std::string("core.light"));
454 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
456 EXPECT_EQ(OC_STACK_OK, result);
459 TEST(BindTypeToResourceTest, BindZeroResourceType)
461 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
462 std::string("core.light"));
463 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
467 TEST(UnbindResourceTest, BindAndUnbindResource)
469 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
470 std::string("core.unres"));
471 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
472 std::string("core.unres"), LINK_INTERFACE);
474 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
475 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
479 TEST(PresenceTest, DISABLED_StartAndStopPresence)
481 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
482 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
483 std::string("core.Presence")));
484 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
487 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
489 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
492 //NotifyAllObserverTest
493 TEST(NotifyAllObserverTest, NotifyAllObservers)
495 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
496 std::string("core.obs"));
497 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
500 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
502 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
503 std::string("core.obs"));
504 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
505 OC::QualityOfService::LowQos));
508 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
510 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
511 std::string("core.obs"));
512 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
513 OC::QualityOfService::MidQos));
516 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
518 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
519 std::string("core.obs"));
520 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
521 OC::QualityOfService::NaQos));
524 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
526 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
527 std::string("core.obs"));
528 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
529 OC::QualityOfService::HighQos));
532 TEST(NotifyAllObserverTest, NotifyListOfObservers)
534 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
535 std::string("core.obs"));
537 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
538 ObservationIds interestedObservers;
539 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
540 interestedObservers, resourceResponse));
543 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
545 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
546 std::string("core.obs"));
548 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
549 ObservationIds interestedObservers;
550 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
551 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
554 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
556 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
557 std::string("core.obs"));
559 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
560 ObservationIds interestedObservers;
561 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
562 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
565 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
567 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
568 std::string("core.obs"));
570 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
571 ObservationIds interestedObservers;
572 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
573 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
576 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
578 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
579 std::string("core.obs"));
581 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
582 ObservationIds interestedObservers;
583 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
584 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
587 //DeviceEntityHandlerTest
588 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
590 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
591 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
596 TEST(FindResourceTest, DISABLED_FindResourceValid)
598 std::ostringstream requestURI;
599 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
600 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
601 CT_DEFAULT, &foundResource));
604 TEST(FindResourceTest, FindResourceNullResourceURI)
606 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
607 CT_DEFAULT, &foundResource));
610 TEST(FindResourceTest, FindResourceNullResourceURI1)
612 std::ostringstream requestURI;
613 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
614 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
615 CT_DEFAULT, &foundResource));
618 TEST(FindResourceTest, FindResourceNullHost)
620 std::ostringstream requestURI;
621 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
622 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
623 CT_DEFAULT, &foundResource));
626 TEST(FindResourceTest, FindResourceNullresourceHandler)
628 std::ostringstream requestURI;
629 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
630 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
631 CT_DEFAULT, NULL), OC::OCException);
634 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
636 std::ostringstream requestURI;
637 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
638 EXPECT_EQ(OC_STACK_OK,
639 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
640 OC::QualityOfService::LowQos));
643 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
645 std::ostringstream requestURI;
646 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
647 EXPECT_EQ(OC_STACK_OK,
648 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
649 OC::QualityOfService::MidQos));
652 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
654 std::ostringstream requestURI;
655 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
656 EXPECT_EQ(OC_STACK_OK,
657 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
658 OC::QualityOfService::HighQos));
661 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
663 std::ostringstream requestURI;
664 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
665 EXPECT_EQ(OC_STACK_OK,
666 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
667 OC::QualityOfService::NaQos));
671 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
673 std::string deviceDiscoveryURI = "/oic/d";
675 OCPlatform::Configure(cfg);
676 std::ostringstream requestURI;
677 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
678 EXPECT_EQ(OC_STACK_OK,
679 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
682 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
685 OCPlatform::Configure(cfg);
687 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
690 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
692 std::string deviceDiscoveryURI = "/oic/d";
694 OCPlatform::Configure(cfg);
695 std::ostringstream requestURI;
696 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
698 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
702 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
704 std::string deviceDiscoveryURI = "/oic/d";
706 OCPlatform::Configure(cfg);
707 std::ostringstream requestURI;
708 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
709 EXPECT_EQ(OC_STACK_OK,
710 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
711 OC::QualityOfService::LowQos));
714 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
716 std::string deviceDiscoveryURI = "/oic/d";
718 OCPlatform::Configure(cfg);
719 std::ostringstream requestURI;
720 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
721 EXPECT_EQ(OC_STACK_OK,
722 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
723 OC::QualityOfService::MidQos));
726 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
728 std::string deviceDiscoveryURI = "/oic/d";
730 OCPlatform::Configure(cfg);
731 std::ostringstream requestURI;
732 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
733 EXPECT_EQ(OC_STACK_OK,
734 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
735 OC::QualityOfService::HighQos));
738 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
740 std::string deviceDiscoveryURI = "/oic/d";
742 OCPlatform::Configure(cfg);
743 std::ostringstream requestURI;
744 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
745 EXPECT_EQ(OC_STACK_OK,
746 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
747 OC::QualityOfService::NaQos));
750 //RegisterDeviceInfo test
751 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
753 OCDeviceInfo deviceInfo;
754 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
755 deviceInfo.types = NULL;
756 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
757 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
758 DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
759 deviceInfo.dataModelVersions = nullptr;
760 OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, "myDataModelVersions");
761 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
762 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
765 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
767 OCDeviceInfo di = {0, 0, 0, 0};
768 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
771 //SubscribePresence Test
772 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
774 std::string hostAddress = "192.168.1.2:5000";
775 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
777 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
778 CT_DEFAULT, &presenceHandler));
781 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
783 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
785 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
786 CT_DEFAULT, &presenceHandler));
789 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
791 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
793 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
797 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
799 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
801 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
802 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
805 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
807 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
809 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
810 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
813 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
815 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
817 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
818 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
819 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
822 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
824 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
825 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
828 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
830 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
832 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
833 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
834 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
838 // SubscribeDevicePresence Test
839 TEST(SubscribeDevicePresenceTest, DISABLED_SubscribeDevicePresenceWithValidParameters)
841 std::string hostAddress = "192.168.1.2:5000";
842 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
843 std::vector<std::string> di;
845 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
846 hostAddress, di, CT_DEFAULT, &onObserve));
849 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullHost)
851 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
852 std::vector<std::string> di;
854 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
855 nullptr, di, CT_DEFAULT, &onObserve));
858 TEST(SubscribeDevicePresenceTest, SubscribeDevicePresenceWithNullOnObserve)
860 std::string hostAddress = "192.168.1.2:5000";
861 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
862 std::vector<std::string> di;
864 EXPECT_ANY_THROW(OCPlatform::subscribeDevicePresence(presenceHandle,
865 hostAddress, di, CT_DEFAULT, NULL));
868 TEST(SubscribeDevicePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
870 std::string hostAddress = "192.168.1.2:5000";
871 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
872 std::vector<std::string> di;
874 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribeDevicePresence(presenceHandle,
875 hostAddress, di, CT_DEFAULT, &onObserve));
876 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
880 TEST(FindDirectPairingTest, FindDirectPairingNullCallback)
882 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(1, nullptr));
885 TEST(FindDirectPairingTest, FindDirectPairingZeroTimeout)
887 EXPECT_ANY_THROW(OCPlatform::findDirectPairingDevices(0, &pairedHandler));
890 TEST(GetDirectPairedTest, GetDirectPairedNullCallback)
892 EXPECT_ANY_THROW(OCPlatform::getDirectPairedDevices(nullptr));
895 TEST(DoDirectPairingTest, DoDirectPairingNullCallback)
898 OCPrm_t pmSel = DP_PRE_CONFIGURED;
900 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
901 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(s_dp, pmSel, pin, nullptr));
904 TEST(DoDirectPairingTest, DoDirectPairingNullPeer)
907 OCPrm_t pmSel = DP_PRE_CONFIGURED;
909 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
910 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, &directPairHandler));
913 TEST(DoDirectPairingTest, DoDirectPairingNullPeerNullCallback)
916 OCPrm_t pmSel = DP_PRE_CONFIGURED;
918 std::shared_ptr<OCDirectPairing> s_dp(new OCDirectPairing(&peer));
919 EXPECT_ANY_THROW(OCPlatform::doDirectPairing(nullptr, pmSel, pin, nullptr));