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 <gtest/gtest.h>
25 namespace OCPlatformTest
29 const OCResourceHandle HANDLE_ZERO = 0;
30 const std::string gResourceTypeName = "core.res";
31 const std::string gResourceInterface = DEFAULT_INTERFACE;
32 const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
33 OCResourceHandle resourceHandle;
36 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
41 void foundResource(std::shared_ptr<OCResource> resource)
45 void receivedDeviceInfo(const OCRepresentation& rep)
49 void presenceHandler(OCStackResult result,
50 const unsigned int nonce, const std::string& hostAddress)
55 void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
57 delete[] deviceInfo.contentType;
58 delete[] deviceInfo.dateOfManufacture;
59 delete[] deviceInfo.deviceName;
60 delete[] deviceInfo.deviceUUID;
61 delete[] deviceInfo.firmwareVersion;
62 delete[] deviceInfo.hostName;
63 delete[] deviceInfo.manufacturerName;
64 delete[] deviceInfo.manufacturerUrl;
65 delete[] deviceInfo.modelNumber;
66 delete[] deviceInfo.platformVersion;
67 delete[] deviceInfo.supportUrl;
68 delete[] deviceInfo.version;
71 void DuplicateString(char ** targetString, std::string sourceString)
73 *targetString = new char[sourceString.length() + 1];
74 strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
77 OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
79 PlatformConfig cfg = {};
80 OCPlatform::Configure(cfg);
81 EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
82 resourceHandle, uri, type,
83 iface, entityHandler, gResourceProperty));
84 return resourceHandle;
87 OCResourceHandle RegisterResource(std::string uri, std::string type)
89 PlatformConfig cfg = {};
90 OCPlatform::Configure(cfg);
91 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
92 resourceHandle, uri, type,
93 gResourceInterface, entityHandler, gResourceProperty));
94 return resourceHandle;
97 OCResourceHandle RegisterResource(std::string uri)
99 PlatformConfig cfg = {};
100 OCPlatform::Configure(cfg);
101 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
102 resourceHandle, uri, gResourceTypeName,
103 gResourceInterface, entityHandler, gResourceProperty));
104 return resourceHandle;
108 // Enable it when the stack throw an exception
109 // https://jira.iotivity.org/browse/IOT-428
110 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
113 OC::ServiceType::InProc,
117 OC::QualityOfService::LowQos
119 OCPlatform::Configure(cfg);
120 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
123 // Enable it when the stack throw an exception
124 // https://jira.iotivity.org/browse/IOT-428
125 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
129 OC::ModeType::Client,
132 OC::QualityOfService::LowQos
134 OCPlatform::Configure(cfg);
135 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
138 // Enable it when the stack throw an exception
139 // https://jira.iotivity.org/browse/IOT-428
140 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
143 OC::ServiceType::OutOfProc,
144 OC::ModeType::Client,
147 OC::QualityOfService::LowQos
149 std::string uri = "/a/light66";
150 std::string type = "core.light";
151 uint8_t gResourceProperty = 0;
152 OCPlatform::Configure(cfg);
153 EXPECT_ANY_THROW(OCPlatform::registerResource(
154 resourceHandle, uri, type,
155 gResourceInterface, entityHandler, gResourceProperty));
158 TEST(ConfigureTest, ConfigureServerOutProc)
161 OC::ServiceType::OutOfProc,
162 OC::ModeType::Server,
165 OC::QualityOfService::LowQos
167 std::string uri = "/a/light67";
168 std::string type = "core.light";
169 uint8_t gResourceProperty = 0;
170 OCPlatform::Configure(cfg);
172 EXPECT_ANY_THROW(OCPlatform::registerResource(
173 resourceHandle, uri, type,
174 gResourceInterface, entityHandler, gResourceProperty));
177 TEST(ConfigureTest, ConfigureDefault)
179 std::string uri = "/a/light68";
180 std::string type = "core.light";
181 uint8_t gResourceProperty = 0;
182 PlatformConfig cfg = {};
183 OCPlatform::Configure(cfg);
185 EXPECT_NO_THROW(OCPlatform::registerResource(
186 resourceHandle, uri, type,
187 gResourceInterface, entityHandler, gResourceProperty));
190 TEST(ConfigureTest, ConfigureServer)
192 std::string uri = "/a/light69";
193 std::string type = "core.light";
194 uint8_t gResourceProperty = 0;
196 OC::ServiceType::InProc,
197 OC::ModeType::Server,
200 OC::QualityOfService::LowQos
202 OCPlatform::Configure(cfg);
204 EXPECT_NO_THROW(OCPlatform::registerResource(
205 resourceHandle, uri, type,
206 gResourceInterface, entityHandler, gResourceProperty));
209 TEST(ConfigureTest, ConfigureClient)
211 std::string uri = "/a/light70";
212 std::string type = "core.light";
213 uint8_t gResourceProperty = 0;
215 OC::ServiceType::InProc,
216 OC::ModeType::Client,
219 OC::QualityOfService::LowQos
221 OCPlatform::Configure(cfg);
223 EXPECT_NO_THROW(OCPlatform::registerResource(
224 resourceHandle, uri, type,
225 gResourceInterface, entityHandler, gResourceProperty));
228 //RegisterResourceTest
229 TEST(RegisterResourceTest, RegisterSingleResource)
231 std::string uri = "/a/res2";
232 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
235 TEST(RegisterResourceTest, RegisterMultipleResources)
237 std::string uri = "/a/multi";
238 //Good enough for 5 resources.
239 for(int i=0; i< 5; i++)
241 uri +=std::to_string(i);
242 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
246 TEST(RegisterResourceTest, ReregisterResource)
248 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
249 std::string("core.light"));
250 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
252 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
253 std::string("core.light")));
257 TEST(RegisterResourceTest, RegisterEmptyResource)
259 // We should not allow empty URI.
260 std::string emptyStr = "";
261 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
262 emptyStr, entityHandler, gResourceProperty));
265 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
267 std::string uri = "/a/light6";
268 std::string type = "core.light";
269 uint8_t gResourceProperty = 0;
270 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
271 resourceHandle, uri, type,
272 gResourceInterface, entityHandler, gResourceProperty));
276 TEST(UnregisterTest, UnregisterZeroHandleValue)
278 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
281 //UnbindResourcesTest
282 TEST(UnbindResourcesTest, UnbindResources)
284 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
285 std::string("core.home"));
286 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
287 std::string("core.kitchen"), LINK_INTERFACE);
288 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
289 std::string("core.office"), LINK_INTERFACE);
291 std::vector<OCResourceHandle> rList;
292 rList.push_back(resourceKitchen);
293 rList.push_back(resourceRoom);
294 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
295 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
298 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
300 OCResourceHandle resourceHandle1 = 0;
301 OCResourceHandle resourceHandle2 = 0;
302 OCResourceHandle resourceHandle3 = 0;
304 std::vector<OCResourceHandle> rList;
306 rList.push_back(resourceHandle2);
307 rList.push_back(resourceHandle3);
309 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
312 //BindInterfaceToResourceTest
313 TEST(BindInterfaceToResourceTest, BindResourceInterface)
315 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
316 std::string("core.light"));
317 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
319 EXPECT_EQ(OC_STACK_OK, result);
322 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
324 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
325 std::string("core.light"));
326 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
329 //BindTypeToResourceTest
330 TEST(BindTypeToResourceTest, BindResourceType)
332 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
333 std::string("core.light"));
334 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
336 EXPECT_EQ(OC_STACK_OK, result);
339 TEST(BindTypeToResourceTest, BindZeroResourceType)
341 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
342 std::string("core.light"));
343 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
347 TEST(UnbindResourceTest, BindAndUnbindResource)
349 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
350 std::string("core.unres"));
351 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
352 std::string("core.unres"), LINK_INTERFACE);
354 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
355 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
359 TEST(PresenceTest, DISABLED_StartAndStopPresence)
361 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
362 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
363 std::string("core.Presence")));
364 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
367 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
369 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
372 //NotifyAllObserverTest
373 TEST(NotifyAllObserverTest, NotifyAllObservers)
375 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
376 std::string("core.obs"));
377 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
380 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
382 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
383 std::string("core.obs"));
384 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
385 OC::QualityOfService::LowQos));
388 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
390 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
391 std::string("core.obs"));
392 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
393 OC::QualityOfService::MidQos));
396 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
398 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
399 std::string("core.obs"));
400 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
401 OC::QualityOfService::NaQos));
404 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
406 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
407 std::string("core.obs"));
408 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
409 OC::QualityOfService::HighQos));
412 TEST(NotifyAllObserverTest, NotifyListOfObservers)
414 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
415 std::string("core.obs"));
417 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
418 ObservationIds interestedObservers;
419 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
420 interestedObservers, resourceResponse));
423 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
425 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
426 std::string("core.obs"));
428 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
429 ObservationIds interestedObservers;
430 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
431 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
434 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
436 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
437 std::string("core.obs"));
439 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
440 ObservationIds interestedObservers;
441 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
442 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
445 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
447 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
448 std::string("core.obs"));
450 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
451 ObservationIds interestedObservers;
452 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
453 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
456 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
458 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
459 std::string("core.obs"));
461 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
462 ObservationIds interestedObservers;
463 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
464 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
467 //DeviceEntityHandlerTest
468 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
470 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
471 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
476 TEST(FindResourceTest, DISABLED_FindResourceValid)
478 std::ostringstream requestURI;
479 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
480 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
481 OC_IPV4, &foundResource));
484 TEST(FindResourceTest, FindResourceNullResourceURI)
486 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
487 OC_IPV4, &foundResource));
490 TEST(FindResourceTest, FindResourceNullResourceURI1)
492 std::ostringstream requestURI;
493 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
494 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
495 OC_IPV4, &foundResource));
498 TEST(FindResourceTest, FindResourceNullHost)
500 std::ostringstream requestURI;
501 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
502 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
503 OC_IPV4, &foundResource));
506 TEST(FindResourceTest, FindResourceNullresourceHandler)
508 std::ostringstream requestURI;
509 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
510 EXPECT_THROW(OCPlatform::findResource("", requestURI.str(),
511 OC_IPV4, NULL), OC::OCException);
514 TEST(FindResourceTest, DISABLED_FindResourceWithLowQoS)
516 std::ostringstream requestURI;
517 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
518 EXPECT_EQ(OC_STACK_OK,
519 OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
520 OC::QualityOfService::LowQos));
523 TEST(FindResourceTest, DISABLED_FindResourceWithMidQos)
525 std::ostringstream requestURI;
526 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
527 EXPECT_EQ(OC_STACK_OK,
528 OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
529 OC::QualityOfService::MidQos));
532 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
534 std::ostringstream requestURI;
535 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
536 EXPECT_EQ(OC_STACK_OK,
537 OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
538 OC::QualityOfService::HighQos));
541 TEST(FindResourceTest, DISABLED_FindResourceWithNaQos)
543 std::ostringstream requestURI;
544 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
545 EXPECT_EQ(OC_STACK_OK,
546 OCPlatform::findResource("", requestURI.str(), OC_IPV4, &foundResource,
547 OC::QualityOfService::NaQos));
551 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithValidParameters)
553 std::string deviceDiscoveryURI = "/oc/core/d";
555 OCPlatform::Configure(cfg);
556 std::ostringstream requestURI;
557 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
558 EXPECT_EQ(OC_STACK_OK,
559 OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo));
562 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
565 OCPlatform::Configure(cfg);
567 OCPlatform::getDeviceInfo("", nullptr, OC_IPV4, &receivedDeviceInfo));
570 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
572 std::string deviceDiscoveryURI = "/oc/core/d";
574 OCPlatform::Configure(cfg);
575 std::ostringstream requestURI;
576 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
578 OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, NULL),
582 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithLowQos)
584 std::string deviceDiscoveryURI = "/oc/core/d";
586 OCPlatform::Configure(cfg);
587 std::ostringstream requestURI;
588 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
589 EXPECT_EQ(OC_STACK_OK,
590 OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
591 OC::QualityOfService::LowQos));
594 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithMidQos)
596 std::string deviceDiscoveryURI = "/oc/core/d";
598 OCPlatform::Configure(cfg);
599 std::ostringstream requestURI;
600 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
601 EXPECT_EQ(OC_STACK_OK,
602 OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
603 OC::QualityOfService::MidQos));
606 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
608 std::string deviceDiscoveryURI = "/oc/core/d";
610 OCPlatform::Configure(cfg);
611 std::ostringstream requestURI;
612 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
613 EXPECT_EQ(OC_STACK_OK,
614 OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
615 OC::QualityOfService::HighQos));
618 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithNaQos)
620 std::string deviceDiscoveryURI = "/oc/core/d";
622 OCPlatform::Configure(cfg);
623 std::ostringstream requestURI;
624 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
625 EXPECT_EQ(OC_STACK_OK,
626 OCPlatform::getDeviceInfo("", requestURI.str(), OC_IPV4, &receivedDeviceInfo,
627 OC::QualityOfService::NaQos));
630 //RegisterDeviceInfo test
631 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
633 OCDeviceInfo deviceInfo;
635 DuplicateString(&deviceInfo.contentType, "myContentType");
636 DuplicateString(&deviceInfo.dateOfManufacture, "myDateOfManufacture");
637 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
638 DuplicateString(&deviceInfo.deviceUUID, "myDeviceUUID");
639 DuplicateString(&deviceInfo.firmwareVersion, "myFirmwareVersion");
640 DuplicateString(&deviceInfo.hostName, "myHostName");
641 DuplicateString(&deviceInfo.manufacturerName, "myManufacturerNa");
642 DuplicateString(&deviceInfo.manufacturerUrl, "myManufacturerUrl");
643 DuplicateString(&deviceInfo.modelNumber, "myModelNumber");
644 DuplicateString(&deviceInfo.platformVersion, "myPlatformVersion");
645 DuplicateString(&deviceInfo.supportUrl, "mySupportUrl");
646 DuplicateString(&deviceInfo.version, "myVersion");
648 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
649 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
652 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
654 OCDeviceInfo di = {};
655 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(di));
658 //SubscribePresence Test
659 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithValidParameters)
661 std::string hostAddress = "192.168.1.2:5000";
662 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
664 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
665 OC_IPV4, &presenceHandler));
668 TEST(SubscribePresenceTest, SubscribePresenceWithNullHost)
670 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
672 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
673 OC_IPV4, &presenceHandler));
676 TEST(SubscribePresenceTest, SubscribePresenceWithNullPresenceHandler)
678 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
680 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
684 TEST(SubscribePresenceTest, DISABLED_SubscribePresenceWithResourceType)
686 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
688 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
689 OC_MULTICAST_IP, "core.light", OC_IPV4, &presenceHandler));
692 TEST(SubscribePresenceTest, SubscribePresenceWithNullResourceType)
694 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
696 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
697 OC_MULTICAST_IP, nullptr, OC_IPV4, &presenceHandler));
700 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
702 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
704 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
705 OC_MULTICAST_IP, "core.light", OC_IPV4, &presenceHandler));
706 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
709 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
711 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
712 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
715 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandle)
717 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
719 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
720 OC_MULTICAST_IP, OC_IPV4, &presenceHandler));
721 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));