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 const OCResourceHandle HANDLE_ZERO = 0;
31 const std::string gResourceTypeName = "core.res";
32 const std::string gResourceInterface = DEFAULT_INTERFACE;
33 const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
34 OCResourceHandle resourceHandle;
36 //OCPersistent Storage Handlers
37 static FILE* client_open(const char * /*path*/, const char *mode)
39 std::cout << "<===Opening SVR DB file = './oic_svr_db_client.json' with mode = '" << mode
41 return fopen("./oic_svr_db_client.json", mode);
43 OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
46 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request*/)
51 void foundResource(std::shared_ptr<OCResource> /*resource*/)
55 void receivedDeviceInfo(const OCRepresentation& /*rep*/)
59 void presenceHandler(OCStackResult /*result*/,
60 const unsigned int /*nonce*/, const std::string& /*hostAddress*/)
65 void DeleteStringLL(OCStringLL* ll)
72 DeleteStringLL(ll->next);
77 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
79 delete[] deviceInfo.deviceName;
80 DeleteStringLL(deviceInfo.types);
84 void DuplicateString(char ** targetString, std::string sourceString)
86 *targetString = new char[sourceString.length() + 1];
87 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
90 bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value)
93 DuplicateString(&dup, value);
96 *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
97 (*stringLL)->value = dup;
102 OCStringLL *temp = *stringLL;
107 temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
108 temp->next->value = dup;
114 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
117 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
118 OC::QualityOfService::LowQos, &gps };
119 OCPlatform::Configure(cfg);
120 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
121 resourceHandle, uri, type,
122 iface, entityHandler, gResourceProperty));
123 return resourceHandle;
126 OCResourceHandle RegisterResource(std::string uri, std::string type)
129 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
130 OC::QualityOfService::LowQos, &gps };
131 OCPlatform::Configure(cfg);
132 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
133 resourceHandle, uri, type,
134 gResourceInterface, entityHandler, gResourceProperty));
135 return resourceHandle;
138 OCResourceHandle RegisterResource(std::string uri)
141 { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
142 OC::QualityOfService::LowQos, &gps };
143 OCPlatform::Configure(cfg);
144 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
145 resourceHandle, uri, gResourceTypeName,
146 gResourceInterface, entityHandler, gResourceProperty));
147 return resourceHandle;
151 // Enable it when the stack throw an exception
152 // https://jira.iotivity.org/browse/IOT-428
153 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
156 OC::ServiceType::InProc,
160 OC::QualityOfService::LowQos
162 OCPlatform::Configure(cfg);
163 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
166 // Enable it when the stack throw an exception
167 // https://jira.iotivity.org/browse/IOT-428
168 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
172 OC::ModeType::Client,
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_ConfigureClientOutProc)
186 OC::ServiceType::OutOfProc,
187 OC::ModeType::Client,
190 OC::QualityOfService::LowQos
192 std::string uri = "/a/light66";
193 std::string type = "core.light";
194 uint8_t gResourceProperty = 0;
195 OCPlatform::Configure(cfg);
196 EXPECT_ANY_THROW(OCPlatform::registerResource(
197 resourceHandle, uri, type,
198 gResourceInterface, entityHandler, gResourceProperty));
201 TEST(ConfigureTest, ConfigureServerOutProc)
205 OC::ServiceType::OutOfProc,
206 OC::ModeType::Server,
209 OC::QualityOfService::LowQos, &gps
211 std::string uri = "/a/light67";
212 std::string type = "core.light";
213 uint8_t gResourceProperty = 0;
214 OCPlatform::Configure(cfg);
216 EXPECT_ANY_THROW(OCPlatform::registerResource(
217 resourceHandle, uri, type,
218 gResourceInterface, entityHandler, gResourceProperty));
221 TEST(ConfigureTest, ConfigureDefault)
223 std::string uri = "/a/light68";
224 std::string type = "core.light";
225 uint8_t gResourceProperty = 0;
226 PlatformConfig cfg = {};
227 OCPlatform::Configure(cfg);
229 EXPECT_NO_THROW(OCPlatform::registerResource(
230 resourceHandle, uri, type,
231 gResourceInterface, entityHandler, gResourceProperty));
234 TEST(ConfigureTest, ConfigureServer)
236 std::string uri = "/a/light69";
237 std::string type = "core.light";
238 uint8_t gResourceProperty = 0;
240 OC::ServiceType::InProc,
241 OC::ModeType::Server,
244 OC::QualityOfService::LowQos, &gps
246 OCPlatform::Configure(cfg);
248 EXPECT_NO_THROW(OCPlatform::registerResource(
249 resourceHandle, uri, type,
250 gResourceInterface, entityHandler, gResourceProperty));
253 TEST(ConfigureTest, ConfigureClient)
255 std::string uri = "/a/light70";
256 std::string type = "core.light";
257 uint8_t gResourceProperty = 0;
260 OC::ServiceType::InProc,
261 OC::ModeType::Client,
264 OC::QualityOfService::LowQos,
268 EXPECT_NO_THROW(OCPlatform::registerResource(
269 resourceHandle, uri, type,
270 gResourceInterface, entityHandler, gResourceProperty));
272 //PersistentStorageTest
273 TEST(ConfigureTest, ConfigureDefaultNULLPersistentStorage)
276 OC::ServiceType::InProc,
280 OC::QualityOfService::LowQos
282 OCPlatform::Configure(cfg);
283 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
286 //PersistentStorageTest
287 TEST(ConfigureTest, ConfigureNULLPersistentStorage)
290 OC::ServiceType::InProc,
294 OC::QualityOfService::LowQos,
297 OCPlatform::Configure(cfg);
298 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
301 //PersistentStorageTest
302 TEST(ConfigureTest, ConfigurePersistentStorage)
305 OC::ServiceType::InProc,
309 OC::QualityOfService::LowQos,
312 OCPlatform::Configure(cfg);
313 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
316 //PersistentStorageTest
317 TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
320 OC::ServiceType::InProc,
324 OC::QualityOfService::LowQos,
327 OCPlatform::Configure(cfg);
328 EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
332 //RegisterResourceTest
333 TEST(RegisterResourceTest, RegisterSingleResource)
335 std::string uri = "/a/res2";
336 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
339 TEST(RegisterResourceTest, RegisterMultipleResources)
341 std::string uri = "/a/multi";
342 //Good enough for 5 resources.
343 for(int i=0; i< 5; i++)
345 uri +=std::to_string(i);
346 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
350 TEST(RegisterResourceTest, ReregisterResource)
352 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
353 std::string("core.light"));
354 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
356 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
357 std::string("core.light")));
361 TEST(RegisterResourceTest, RegisterEmptyResource)
363 // We should not allow empty URI.
364 std::string emptyStr = "";
365 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
366 emptyStr, entityHandler, gResourceProperty));
369 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
371 std::string uri = "/a/light6";
372 std::string type = "core.light";
373 uint8_t gResourceProperty = 0;
374 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
375 resourceHandle, uri, type,
376 gResourceInterface, entityHandler, gResourceProperty));
380 TEST(UnregisterTest, UnregisterZeroHandleValue)
382 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
385 //UnbindResourcesTest
386 TEST(UnbindResourcesTest, UnbindResources)
388 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
389 std::string("core.home"));
390 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
391 std::string("core.kitchen"), LINK_INTERFACE);
392 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
393 std::string("core.office"), LINK_INTERFACE);
395 std::vector<OCResourceHandle> rList;
396 rList.push_back(resourceKitchen);
397 rList.push_back(resourceRoom);
398 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
399 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
402 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
404 OCResourceHandle resourceHandle1 = 0;
405 OCResourceHandle resourceHandle2 = 0;
406 OCResourceHandle resourceHandle3 = 0;
408 std::vector<OCResourceHandle> rList;
410 rList.push_back(resourceHandle2);
411 rList.push_back(resourceHandle3);
413 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
416 //BindInterfaceToResourceTest
417 TEST(BindInterfaceToResourceTest, BindResourceInterface)
419 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
420 std::string("core.light"));
421 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
423 EXPECT_EQ(OC_STACK_OK, result);
426 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
428 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
429 std::string("core.light"));
430 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
433 //BindTypeToResourceTest
434 TEST(BindTypeToResourceTest, BindResourceType)
436 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
437 std::string("core.light"));
438 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
440 EXPECT_EQ(OC_STACK_OK, result);
443 TEST(BindTypeToResourceTest, BindZeroResourceType)
445 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
446 std::string("core.light"));
447 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
451 TEST(UnbindResourceTest, BindAndUnbindResource)
453 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
454 std::string("core.unres"));
455 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
456 std::string("core.unres"), LINK_INTERFACE);
458 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
459 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
463 TEST(PresenceTest, DISABLED_StartAndStopPresence)
465 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
466 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
467 std::string("core.Presence")));
468 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
471 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
473 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
476 //NotifyAllObserverTest
477 TEST(NotifyAllObserverTest, NotifyAllObservers)
479 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
480 std::string("core.obs"));
481 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
484 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
486 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
487 std::string("core.obs"));
488 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
489 OC::QualityOfService::LowQos));
492 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
494 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
495 std::string("core.obs"));
496 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
497 OC::QualityOfService::MidQos));
500 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
502 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
503 std::string("core.obs"));
504 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
505 OC::QualityOfService::NaQos));
508 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
510 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
511 std::string("core.obs"));
512 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
513 OC::QualityOfService::HighQos));
516 TEST(NotifyAllObserverTest, NotifyListOfObservers)
518 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
519 std::string("core.obs"));
521 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
522 ObservationIds interestedObservers;
523 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
524 interestedObservers, resourceResponse));
527 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
529 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
530 std::string("core.obs"));
532 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
533 ObservationIds interestedObservers;
534 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
535 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
538 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
540 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
541 std::string("core.obs"));
543 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
544 ObservationIds interestedObservers;
545 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
546 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
549 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
551 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
552 std::string("core.obs"));
554 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
555 ObservationIds interestedObservers;
556 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
557 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
560 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
562 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
563 std::string("core.obs"));
565 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
566 ObservationIds interestedObservers;
567 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
568 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
571 //DeviceEntityHandlerTest
572 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
574 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
575 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
580 TEST(FindResourceTest, DISABLED_FindResourceValid)
582 std::ostringstream requestURI;
583 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
584 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
585 CT_DEFAULT, &foundResource));
588 TEST(FindResourceTest, FindResourceNullResourceURI)
590 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
591 CT_DEFAULT, &foundResource));
594 TEST(FindResourceTest, FindResourceNullResourceURI1)
596 std::ostringstream requestURI;
597 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
598 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
599 CT_DEFAULT, &foundResource));
602 TEST(FindResourceTest, FindResourceNullHost)
604 std::ostringstream requestURI;
605 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
606 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
607 CT_DEFAULT, &foundResource));
610 TEST(FindResourceTest, FindResourceNullresourceHandler)
612 std::ostringstream requestURI;
613 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
614 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
615 CT_DEFAULT, NULL), OC::OCException);
618 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
620 std::ostringstream requestURI;
621 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
622 EXPECT_EQ(OC_STACK_OK,
623 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
624 OC::QualityOfService::LowQos));
627 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
629 std::ostringstream requestURI;
630 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
631 EXPECT_EQ(OC_STACK_OK,
632 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
633 OC::QualityOfService::MidQos));
636 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
638 std::ostringstream requestURI;
639 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
640 EXPECT_EQ(OC_STACK_OK,
641 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
642 OC::QualityOfService::HighQos));
645 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
647 std::ostringstream requestURI;
648 requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
649 EXPECT_EQ(OC_STACK_OK,
650 OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource,
651 OC::QualityOfService::NaQos));
655 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
657 std::string deviceDiscoveryURI = "/oic/d";
659 OCPlatform::Configure(cfg);
660 std::ostringstream requestURI;
661 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
662 EXPECT_EQ(OC_STACK_OK,
663 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo));
666 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
669 OCPlatform::Configure(cfg);
671 OCPlatform::getDeviceInfo("", nullptr, CT_DEFAULT, &receivedDeviceInfo));
674 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
676 std::string deviceDiscoveryURI = "/oic/d";
678 OCPlatform::Configure(cfg);
679 std::ostringstream requestURI;
680 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
682 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, NULL),
686 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
688 std::string deviceDiscoveryURI = "/oic/d";
690 OCPlatform::Configure(cfg);
691 std::ostringstream requestURI;
692 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
693 EXPECT_EQ(OC_STACK_OK,
694 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
695 OC::QualityOfService::LowQos));
698 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
700 std::string deviceDiscoveryURI = "/oic/d";
702 OCPlatform::Configure(cfg);
703 std::ostringstream requestURI;
704 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
705 EXPECT_EQ(OC_STACK_OK,
706 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
707 OC::QualityOfService::MidQos));
710 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
712 std::string deviceDiscoveryURI = "/oic/d";
714 OCPlatform::Configure(cfg);
715 std::ostringstream requestURI;
716 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
717 EXPECT_EQ(OC_STACK_OK,
718 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
719 OC::QualityOfService::HighQos));
722 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
724 std::string deviceDiscoveryURI = "/oic/d";
726 OCPlatform::Configure(cfg);
727 std::ostringstream requestURI;
728 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
729 EXPECT_EQ(OC_STACK_OK,
730 OCPlatform::getDeviceInfo("", requestURI.str(), CT_DEFAULT, &receivedDeviceInfo,
731 OC::QualityOfService::NaQos));
734 //RegisterDeviceInfo test
735 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
737 OCDeviceInfo deviceInfo;
738 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
739 deviceInfo.types = NULL;
740 OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
741 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
742 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
745 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
747 OCDeviceInfo di = {0, 0};
748 EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
751 //SubscribePresence Test
752 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
754 std::string hostAddress = "192.168.1.2:5000";
755 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
757 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
758 CT_DEFAULT, &presenceHandler));
761 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
763 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
765 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
766 CT_DEFAULT, &presenceHandler));
769 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
771 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
773 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
777 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
779 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
781 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
782 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
785 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
787 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
789 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
790 OC_MULTICAST_IP, nullptr, CT_DEFAULT, &presenceHandler));
793 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
795 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
797 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
798 OC_MULTICAST_IP, "core.light", CT_DEFAULT, &presenceHandler));
799 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
802 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
804 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
805 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
808 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
810 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
812 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
813 OC_MULTICAST_IP, CT_DEFAULT, &presenceHandler));
814 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));