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, 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, 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_WIFI, &foundResource));
484 TEST(FindResourceTest, FindResourceNullResourceURI)
486 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
487 OC_WIFI, &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_WIFI, &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_WIFI, &foundResource));
506 TEST(FindResourceTest, FindResourceNullresourceHandler)
508 std::ostringstream requestURI;
509 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
510 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
514 TEST(FindResourceTest, 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_WIFI, &foundResource,
520 OC::QualityOfService::LowQos));
523 TEST(FindResourceTest, 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_WIFI, &foundResource,
529 OC::QualityOfService::MidQos));
532 //We will enable it when CON is supported in the stack
533 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
535 std::ostringstream requestURI;
536 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
537 EXPECT_EQ(OC_STACK_OK,
538 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
539 OC::QualityOfService::HighQos));
542 TEST(FindResourceTest, FindResourceWithNaQos)
544 std::ostringstream requestURI;
545 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
546 EXPECT_EQ(OC_STACK_OK,
547 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
548 OC::QualityOfService::NaQos));
552 TEST(GetDeviceInfoTest, GetDeviceInfoWithValidParameters)
554 std::string deviceDiscoveryURI = "/oc/core/d";
556 OCPlatform::Configure(cfg);
557 std::ostringstream requestURI;
558 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
559 EXPECT_EQ(OC_STACK_OK,
560 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo));
563 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
566 OCPlatform::Configure(cfg);
568 OCPlatform::getDeviceInfo("", nullptr, OC_WIFI, &receivedDeviceInfo));
571 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
573 std::string deviceDiscoveryURI = "/oc/core/d";
575 OCPlatform::Configure(cfg);
576 std::ostringstream requestURI;
577 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
578 EXPECT_EQ(OC_STACK_OK,
579 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, NULL));
582 TEST(GetDeviceInfoTest, 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_WIFI, &receivedDeviceInfo,
591 OC::QualityOfService::LowQos));
594 TEST(GetDeviceInfoTest, 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_WIFI, &receivedDeviceInfo,
603 OC::QualityOfService::MidQos));
606 //We will enable it when CON is supported in the stack
607 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
609 std::string deviceDiscoveryURI = "/oc/core/d";
611 OCPlatform::Configure(cfg);
612 std::ostringstream requestURI;
613 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
614 EXPECT_EQ(OC_STACK_OK,
615 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
616 OC::QualityOfService::HighQos));
619 TEST(GetDeviceInfoTest, GetDeviceInfoWithNaQos)
621 std::string deviceDiscoveryURI = "/oc/core/d";
623 OCPlatform::Configure(cfg);
624 std::ostringstream requestURI;
625 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
626 EXPECT_EQ(OC_STACK_OK,
627 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
628 OC::QualityOfService::NaQos));
631 //RegisterDeviceInfo test
632 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
634 OCDeviceInfo deviceInfo;
636 DuplicateString(&deviceInfo.contentType, "myContentType");
637 DuplicateString(&deviceInfo.dateOfManufacture, "myDateOfManufacture");
638 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
639 DuplicateString(&deviceInfo.deviceUUID, "myDeviceUUID");
640 DuplicateString(&deviceInfo.firmwareVersion, "myFirmwareVersion");
641 DuplicateString(&deviceInfo.hostName, "myHostName");
642 DuplicateString(&deviceInfo.manufacturerName, "myManufacturerNa");
643 DuplicateString(&deviceInfo.manufacturerUrl, "myManufacturerUrl");
644 DuplicateString(&deviceInfo.modelNumber, "myModelNumber");
645 DuplicateString(&deviceInfo.platformVersion, "myPlatformVersion");
646 DuplicateString(&deviceInfo.supportUrl, "mySupportUrl");
647 DuplicateString(&deviceInfo.version, "myVersion");
649 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
650 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
653 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
655 OCDeviceInfo di = {};
656 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(di));
659 //SubscribePresence Test
660 TEST(SubscribePresenceTest,SubscribePresenceWithValidParameters)
662 std::string hostAddress = "192.168.1.2:5000";
663 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
665 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
666 OC_WIFI, &presenceHandler));
669 TEST(SubscribePresenceTest,SubscribePresenceWithNullHost)
671 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
673 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
674 OC_WIFI, &presenceHandler));
677 TEST(SubscribePresenceTest,SubscribePresenceWithNullPresenceHandler)
679 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
681 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
685 TEST(SubscribePresenceTest,SubscribePresenceWithResourceType)
687 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
689 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
690 OC_MULTICAST_IP, "core.light", OC_WIFI, &presenceHandler));
693 TEST(SubscribePresenceTest,SubscribePresenceWithNullResourceType)
695 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
697 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
698 OC_MULTICAST_IP, nullptr, OC_WIFI, &presenceHandler));
701 //UnsubscribePresence Test
702 //We will enable it after fixing double free or corruption
703 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
705 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
707 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
708 OC_MULTICAST_IP, "core.light", OC_WIFI, &presenceHandler));
709 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
712 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
714 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
715 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
718 TEST(SubscribePresenceTest, UnsubscribePresenceWithValidHandle)
720 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
722 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
723 OC_MULTICAST_IP, OC_WIFI, &presenceHandler));
724 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));