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 DeleteStringLL(OCStringLL* ll)
73 DeleteStringLL(ll->next);
78 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
80 delete[] deviceInfo.deviceName;
81 DeleteStringLL(deviceInfo.types);
82 delete[] deviceInfo.specVersion;
83 delete[] deviceInfo.dataModleVersion;
86 void DuplicateString(char ** targetString, std::string sourceString)
88 *targetString = new char[sourceString.length() + 1];
89 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
92 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
95 DuplicateString(&dup, value);
98 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
99 (*stringLL)->value = dup;
104 OCStringLL *temp = *stringLL;
109 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
110 temp->next->value = dup;
116 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
119 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
120 OC::QualityOfService::LowQos, &gps };
121 OCPlatform::Configure(cfg);
122 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
123 resourceHandle, uri, type,
124 iface, entityHandler, gResourceProperty));
125 return resourceHandle;
128 OCResourceHandle RegisterResource(std::string uri, std::string type)
131 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
132 OC::QualityOfService::LowQos, &gps };
133 OCPlatform::Configure(cfg);
134 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
135 resourceHandle, uri, type,
136 gResourceInterface, entityHandler, gResourceProperty));
137 return resourceHandle;
140 OCResourceHandle RegisterResource(std::string uri)
143 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
144 OC::QualityOfService::LowQos, &gps };
145 OCPlatform::Configure(cfg);
146 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
147 resourceHandle, uri, gResourceTypeName,
148 gResourceInterface, entityHandler, gResourceProperty));
149 return resourceHandle;
153 // Enable it when the stack throw an exception
154 // https://jira.iotivity.org/browse/IOT-428
155 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
158 OC::ServiceType::InProc,
162 OC::QualityOfService::LowQos
164 OCPlatform::Configure(cfg);
165 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
168 // Enable it when the stack throw an exception
169 // https://jira.iotivity.org/browse/IOT-428
170 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
174 OC::ModeType::Client,
177 OC::QualityOfService::LowQos
179 OCPlatform::Configure(cfg);
180 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
183 // Enable it when the stack throw an exception
184 // https://jira.iotivity.org/browse/IOT-428
185 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
188 OC::ServiceType::OutOfProc,
189 OC::ModeType::Client,
192 OC::QualityOfService::LowQos
194 std::string uri = "/a/light66";
195 std::string type = "core.light";
196 uint8_t gResourceProperty = 0;
197 OCPlatform::Configure(cfg);
198 EXPECT_ANY_THROW(OCPlatform::registerResource(
199 resourceHandle, uri, type,
200 gResourceInterface, entityHandler, gResourceProperty));
203 TEST(ConfigureTest, ConfigureServerOutProc)
207 OC::ServiceType::OutOfProc,
208 OC::ModeType::Server,
211 OC::QualityOfService::LowQos, &gps
213 std::string uri = "/a/light67";
214 std::string type = "core.light";
215 uint8_t gResourceProperty = 0;
216 OCPlatform::Configure(cfg);
218 EXPECT_ANY_THROW(OCPlatform::registerResource(
219 resourceHandle, uri, type,
220 gResourceInterface, entityHandler, gResourceProperty));
223 TEST(ConfigureTest, ConfigureDefault)
225 std::string uri = "/a/light68";
226 std::string type = "core.light";
227 uint8_t gResourceProperty = 0;
228 PlatformConfig cfg = {};
229 OCPlatform::Configure(cfg);
231 EXPECT_NO_THROW(OCPlatform::registerResource(
232 resourceHandle, uri, type,
233 gResourceInterface, entityHandler, gResourceProperty));
236 TEST(ConfigureTest, ConfigureServer)
238 std::string uri = "/a/light69";
239 std::string type = "core.light";
240 uint8_t gResourceProperty = 0;
242 OC::ServiceType::InProc,
243 OC::ModeType::Server,
246 OC::QualityOfService::LowQos, &gps
248 OCPlatform::Configure(cfg);
250 EXPECT_NO_THROW(OCPlatform::registerResource(
251 resourceHandle, uri, type,
252 gResourceInterface, entityHandler, gResourceProperty));
255 TEST(ConfigureTest, ConfigureClient)
257 std::string uri = "/a/light70";
258 std::string type = "core.light";
259 uint8_t gResourceProperty = 0;
262 OC::ServiceType::InProc,
263 OC::ModeType::Client,
266 OC::QualityOfService::LowQos,
270 EXPECT_NO_THROW(OCPlatform::registerResource(
271 resourceHandle, uri, type,
272 gResourceInterface, entityHandler, gResourceProperty));
274 //PersistentStorageTest
275 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
278 OC::ServiceType::InProc,
282 OC::QualityOfService::LowQos
284 OCPlatform::Configure(cfg);
285 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
288 //PersistentStorageTest
289 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
292 OC::ServiceType::InProc,
296 OC::QualityOfService::LowQos,
299 OCPlatform::Configure(cfg);
300 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
303 //PersistentStorageTest
304 TEST(ConfigureTest, ConfigurePersistentStorage)
307 OC::ServiceType::InProc,
311 OC::QualityOfService::LowQos,
314 OCPlatform::Configure(cfg);
315 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
318 //PersistentStorageTest
319 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
322 OC::ServiceType::InProc,
326 OC::QualityOfService::LowQos,
329 OCPlatform::Configure(cfg);
330 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
334 //RegisterResourceTest
335 TEST(RegisterResourceTest, RegisterSingleResource)
337 std::string uri = "/a/res2";
338 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
341 TEST(RegisterResourceTest, RegisterMultipleResources)
343 std::string uri = "/a/multi";
344 //Good enough for 5 resources.
345 for(int i=0; i< 5; i++)
347 uri +=std::to_string(i);
348 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
352 TEST(RegisterResourceTest, ReregisterResource)
354 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
355 std::string("core.light"));
356 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
358 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
359 std::string("core.light")));
363 TEST(RegisterResourceTest, RegisterEmptyResource)
365 // We should not allow empty URI.
366 std::string emptyStr = "";
367 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
368 emptyStr, entityHandler, gResourceProperty));
371 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
373 std::string uri = "/a/light6";
374 std::string type = "core.light";
375 uint8_t gResourceProperty = 0;
376 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
377 resourceHandle, uri, type,
378 gResourceInterface, entityHandler, gResourceProperty));
382 TEST(UnregisterTest, UnregisterZeroHandleValue)
384 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
387 //UnbindResourcesTest
388 TEST(UnbindResourcesTest, UnbindResources)
390 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
391 std::string("core.home"));
392 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
393 std::string("core.kitchen"), LINK_INTERFACE);
394 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
395 std::string("core.office"), LINK_INTERFACE);
397 std::vector<OCResourceHandle> rList;
398 rList.push_back(resourceKitchen);
399 rList.push_back(resourceRoom);
400 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
401 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
404 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
406 OCResourceHandle resourceHandle1 = 0;
407 OCResourceHandle resourceHandle2 = 0;
408 OCResourceHandle resourceHandle3 = 0;
410 std::vector<OCResourceHandle> rList;
412 rList.push_back(resourceHandle2);
413 rList.push_back(resourceHandle3);
415 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
418 //BindInterfaceToResourceTest
419 TEST(BindInterfaceToResourceTest, BindResourceInterface)
421 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
422 std::string("core.light"));
423 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
425 EXPECT_EQ(OC_STACK_OK, result);
428 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
430 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
431 std::string("core.light"));
432 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
435 //BindTypeToResourceTest
436 TEST(BindTypeToResourceTest, BindResourceType)
438 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
439 std::string("core.light"));
440 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
442 EXPECT_EQ(OC_STACK_OK, result);
445 TEST(BindTypeToResourceTest, BindZeroResourceType)
447 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
448 std::string("core.light"));
449 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
453 TEST(UnbindResourceTest, BindAndUnbindResource)
455 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
456 std::string("core.unres"));
457 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
458 std::string("core.unres"), LINK_INTERFACE);
460 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
461 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
465 TEST(PresenceTest, DISABLED_StartAndStopPresence)
467 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
468 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
469 std::string("core.Presence")));
470 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
473 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
475 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
478 //NotifyAllObserverTest
479 TEST(NotifyAllObserverTest, NotifyAllObservers)
481 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
482 std::string("core.obs"));
483 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
486 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
488 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
489 std::string("core.obs"));
490 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
491 OC::QualityOfService::LowQos));
494 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
496 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
497 std::string("core.obs"));
498 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
499 OC::QualityOfService::MidQos));
502 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
504 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
505 std::string("core.obs"));
506 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
507 OC::QualityOfService::NaQos));
510 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
512 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
513 std::string("core.obs"));
514 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
515 OC::QualityOfService::HighQos));
518 TEST(NotifyAllObserverTest, NotifyListOfObservers)
520 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
521 std::string("core.obs"));
523 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
524 ObservationIds interestedObservers;
525 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
526 interestedObservers, resourceResponse));
529 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
531 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
532 std::string("core.obs"));
534 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
535 ObservationIds interestedObservers;
536 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
537 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
540 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
542 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
543 std::string("core.obs"));
545 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
546 ObservationIds interestedObservers;
547 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
548 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
551 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
553 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
554 std::string("core.obs"));
556 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
557 ObservationIds interestedObservers;
558 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
559 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
562 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
564 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
565 std::string("core.obs"));
567 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
568 ObservationIds interestedObservers;
569 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
570 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
573 //DeviceEntityHandlerTest
574 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
576 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
577 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
582 TEST(FindResourceTest, DISABLED_FindResourceValid)
584 std::ostringstream requestURI;
585 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
586 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
587 CT_DEFAULT, &foundResource));
590 TEST(FindResourceTest, FindResourceNullResourceURI)
592 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
593 CT_DEFAULT, &foundResource));
596 TEST(FindResourceTest, FindResourceNullResourceURI1)
598 std::ostringstream requestURI;
599 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
600 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
601 CT_DEFAULT, &foundResource));
604 TEST(FindResourceTest, FindResourceNullHost)
606 std::ostringstream requestURI;
607 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
608 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
609 CT_DEFAULT, &foundResource));
612 TEST(FindResourceTest, FindResourceNullresourceHandler)
614 std::ostringstream requestURI;
615 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
616 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
617 CT_DEFAULT, NULL), OC::OCException);
620 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
622 std::ostringstream requestURI;
623 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
624 EXPECT_EQ(OC_STACK_OK,
625 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
626 OC::QualityOfService::LowQos));
629 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
631 std::ostringstream requestURI;
632 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
633 EXPECT_EQ(OC_STACK_OK,
634 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
635 OC::QualityOfService::MidQos));
638 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
640 std::ostringstream requestURI;
641 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
642 EXPECT_EQ(OC_STACK_OK,
643 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
644 OC::QualityOfService::HighQos));
647 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
649 std::ostringstream requestURI;
650 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
651 EXPECT_EQ(OC_STACK_OK,
652 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
653 OC::QualityOfService::NaQos));
657 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
659 std::string deviceDiscoveryURI = "/oic/d";
661 OCPlatform::Configure(cfg);
662 std::ostringstream requestURI;
663 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
664 EXPECT_EQ(OC_STACK_OK,
665 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
668 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
671 OCPlatform::Configure(cfg);
673 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
676 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
678 std::string deviceDiscoveryURI = "/oic/d";
680 OCPlatform::Configure(cfg);
681 std::ostringstream requestURI;
682 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
684 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
688 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
690 std::string deviceDiscoveryURI = "/oic/d";
692 OCPlatform::Configure(cfg);
693 std::ostringstream requestURI;
694 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
695 EXPECT_EQ(OC_STACK_OK,
696 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
697 OC::QualityOfService::LowQos));
700 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
702 std::string deviceDiscoveryURI = "/oic/d";
704 OCPlatform::Configure(cfg);
705 std::ostringstream requestURI;
706 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
707 EXPECT_EQ(OC_STACK_OK,
708 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
709 OC::QualityOfService::MidQos));
712 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
714 std::string deviceDiscoveryURI = "/oic/d";
716 OCPlatform::Configure(cfg);
717 std::ostringstream requestURI;
718 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
719 EXPECT_EQ(OC_STACK_OK,
720 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
721 OC::QualityOfService::HighQos));
724 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
726 std::string deviceDiscoveryURI = "/oic/d";
728 OCPlatform::Configure(cfg);
729 std::ostringstream requestURI;
730 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
731 EXPECT_EQ(OC_STACK_OK,
732 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
733 OC::QualityOfService::NaQos));
736 //RegisterDeviceInfo test
737 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
739 OCDeviceInfo deviceInfo;
740 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
741 deviceInfo.types = NULL;
742 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
743 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
744 DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
745 DuplicateString(&deviceInfo.dataModleVersion, "myDataModleVersion");
746 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
747 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
750 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
752 OCDeviceInfo di = {0, 0, 0, 0};
753 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
756 //SubscribePresence Test
757 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
759 std::string hostAddress = "192.168.1.2:5000";
760 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
762 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
763 CT_DEFAULT, &presenceHandler));
766 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
768 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
770 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
771 CT_DEFAULT, &presenceHandler));
774 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
776 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
778 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
782 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
784 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
786 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
787 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
790 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
792 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
794 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
795 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
798 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
800 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
802 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
803 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
804 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
807 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
809 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
810 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
813 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
815 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
817 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
818 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
819 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));