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 TEST(ConfigureTest, DISABLED_ConfigureInvalidModeType)
112 OC::ServiceType::InProc,
116 OC::QualityOfService::LowQos
119 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
122 // Enable it when the stack throw an exception
123 TEST(ConfigureTest, DISABLED_ConfigureInvalidServiceType)
127 OC::ModeType::Client,
130 OC::QualityOfService::LowQos
133 EXPECT_ANY_THROW(OCPlatform::setDefaultDeviceEntityHandler(NULL));
136 // Enable it when the stack throw an exception
137 TEST(ConfigureTest, DISABLED_ConfigureClientOutProc)
140 OC::ServiceType::OutOfProc,
141 OC::ModeType::Client,
144 OC::QualityOfService::LowQos
146 std::string uri = "/a/light66";
147 std::string type = "core.light";
148 uint8_t gResourceProperty = 0;
149 OCPlatform::Configure(cfg);
151 EXPECT_ANY_THROW(OCPlatform::registerResource(
152 resourceHandle, uri, type,
153 gResourceInterface, entityHandler, gResourceProperty));
156 TEST(ConfigureTest, ConfigureServerOutProc)
159 OC::ServiceType::OutOfProc,
160 OC::ModeType::Server,
163 OC::QualityOfService::LowQos
165 std::string uri = "/a/light67";
166 std::string type = "core.light";
167 uint8_t gResourceProperty = 0;
168 OCPlatform::Configure(cfg);
170 EXPECT_ANY_THROW(OCPlatform::registerResource(
171 resourceHandle, uri, type,
172 gResourceInterface, entityHandler, gResourceProperty));
175 TEST(ConfigureTest, ConfigureDefault)
177 std::string uri = "/a/light68";
178 std::string type = "core.light";
179 uint8_t gResourceProperty = 0;
180 PlatformConfig cfg = {};
181 OCPlatform::Configure(cfg);
183 EXPECT_NO_THROW(OCPlatform::registerResource(
184 resourceHandle, uri, type,
185 gResourceInterface, entityHandler, gResourceProperty));
188 TEST(ConfigureTest, ConfigureServer)
190 std::string uri = "/a/light69";
191 std::string type = "core.light";
192 uint8_t gResourceProperty = 0;
194 OC::ServiceType::InProc,
195 OC::ModeType::Server,
198 OC::QualityOfService::LowQos
200 OCPlatform::Configure(cfg);
202 EXPECT_NO_THROW(OCPlatform::registerResource(
203 resourceHandle, uri, type,
204 gResourceInterface, entityHandler, gResourceProperty));
207 TEST(ConfigureTest, ConfigureClient)
209 std::string uri = "/a/light70";
210 std::string type = "core.light";
211 uint8_t gResourceProperty = 0;
213 OC::ServiceType::InProc,
214 OC::ModeType::Client,
217 OC::QualityOfService::LowQos
219 OCPlatform::Configure(cfg);
221 EXPECT_NO_THROW(OCPlatform::registerResource(
222 resourceHandle, uri, type,
223 gResourceInterface, entityHandler, gResourceProperty));
226 //RegisterResourceTest
227 TEST(RegisterResourceTest, RegisterSingleResource)
229 std::string uri = "/a/res2";
230 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
233 TEST(RegisterResourceTest, RegisterMultipleResources)
235 std::string uri = "/a/multi";
236 //Good enough for 5 resources.
237 for(int i=0; i< 5; i++)
239 uri +=std::to_string(i);
240 EXPECT_NE(HANDLE_ZERO, RegisterResource(uri));
244 TEST(RegisterResourceTest, ReregisterResource)
246 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light5"),
247 std::string("core.light"));
248 EXPECT_EQ(OC_STACK_OK, OC::OCPlatform::unregisterResource(resourceHandle));
250 EXPECT_NE(HANDLE_ZERO, RegisterResource(std::string("/a/light5"),
251 std::string("core.light")));
255 TEST(RegisterResourceTest, RegisterEmptyResource)
257 // We should not allow empty URI.
258 std::string emptyStr = "";
259 EXPECT_ANY_THROW(OCPlatform::registerResource(resourceHandle, emptyStr, emptyStr,
260 emptyStr, entityHandler, gResourceProperty));
263 TEST(RegisterResourceTest, RegisterZeroResourceProperty)
265 std::string uri = "/a/light6";
266 std::string type = "core.light";
267 uint8_t gResourceProperty = 0;
268 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
269 resourceHandle, uri, type,
270 gResourceInterface, entityHandler, gResourceProperty));
274 TEST(UnregisterTest, UnregisterZeroHandleValue)
276 EXPECT_ANY_THROW(OC::OCPlatform::unregisterResource(HANDLE_ZERO));
279 //UnbindResourcesTest
280 TEST(UnbindResourcesTest, UnbindResources)
282 OCResourceHandle resourceHome = RegisterResource(std::string("a/home"),
283 std::string("core.home"));
284 OCResourceHandle resourceKitchen = RegisterResource(std::string("a/kitchen"),
285 std::string("core.kitchen"), LINK_INTERFACE);
286 OCResourceHandle resourceRoom = RegisterResource(std::string("a/office"),
287 std::string("core.office"), LINK_INTERFACE);
289 std::vector<OCResourceHandle> rList;
290 rList.push_back(resourceKitchen);
291 rList.push_back(resourceRoom);
292 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResources(resourceHome, rList));
293 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResources(resourceHome, rList));
296 TEST(UnbindResourcesTest, UnbindResourcesWithZero)
298 OCResourceHandle resourceHandle1 = 0;
299 OCResourceHandle resourceHandle2 = 0;
300 OCResourceHandle resourceHandle3 = 0;
302 std::vector<OCResourceHandle> rList;
304 rList.push_back(resourceHandle2);
305 rList.push_back(resourceHandle3);
307 EXPECT_ANY_THROW(OCPlatform::unbindResources(resourceHandle1, rList));
310 //BindInterfaceToResourceTest
311 TEST(BindInterfaceToResourceTest, BindResourceInterface)
313 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light"),
314 std::string("core.light"));
315 OCStackResult result = OC::OCPlatform::bindInterfaceToResource(resourceHandle,
317 EXPECT_EQ(OC_STACK_OK, result);
320 TEST(BindInterfaceToResourceTest, BindZeroResourceInterface)
322 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light1"),
323 std::string("core.light"));
324 EXPECT_ANY_THROW(OC::OCPlatform::bindInterfaceToResource(resourceHandle, 0));
327 //BindTypeToResourceTest
328 TEST(BindTypeToResourceTest, BindResourceType)
330 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light3"),
331 std::string("core.light"));
332 OCStackResult result = OC::OCPlatform::bindTypeToResource(resourceHandle,
334 EXPECT_EQ(OC_STACK_OK, result);
337 TEST(BindTypeToResourceTest, BindZeroResourceType)
339 OCResourceHandle resourceHandle = RegisterResource(std::string("/a/light4"),
340 std::string("core.light"));
341 EXPECT_ANY_THROW(OC::OCPlatform::bindTypeToResource(resourceHandle, 0));
345 TEST(UnbindResourceTest, BindAndUnbindResource)
347 OCResourceHandle resourceHandle1 = RegisterResource(std::string("a/unres"),
348 std::string("core.unres"));
349 OCResourceHandle resourceHandle2 = RegisterResource(std::string("a/unres2"),
350 std::string("core.unres"), LINK_INTERFACE);
352 EXPECT_EQ(OC_STACK_OK, OCPlatform::bindResource(resourceHandle1, resourceHandle2));
353 EXPECT_EQ(OC_STACK_OK, OCPlatform::unbindResource(resourceHandle1, resourceHandle2));
357 TEST(PresenceTest, StartAndStopPresence)
359 EXPECT_EQ(OC_STACK_OK, OCPlatform::startPresence(30));
360 EXPECT_NE(HANDLE_ZERO, RegisterResource( std::string("/a/Presence"),
361 std::string("core.Presence")));
362 EXPECT_EQ(OC_STACK_OK, OCPlatform::stopPresence());
365 TEST(OCPlatformTest, UnbindZeroRsourceHandleValue)
367 EXPECT_ANY_THROW(OCPlatform::unbindResource(HANDLE_ZERO, HANDLE_ZERO));
370 //NotifyAllObserverTest
371 TEST(NotifyAllObserverTest, NotifyAllObservers)
373 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs1"),
374 std::string("core.obs"));
375 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome));
378 TEST(NotifyAllObserverTest, NotifyAllObserversWithLowQos)
380 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs2"),
381 std::string("core.obs"));
382 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
383 OC::QualityOfService::LowQos));
386 TEST(NotifyAllObserverTest, NotifyAllObserversWithMidQos)
388 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs3"),
389 std::string("core.obs"));
390 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
391 OC::QualityOfService::MidQos));
394 TEST(NotifyAllObserverTest, NotifyAllObserversWithNaQos)
396 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs4"),
397 std::string("core.obs"));
398 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
399 OC::QualityOfService::NaQos));
402 TEST(NotifyAllObserverTest, NotifyAllObserversWithHighQos)
404 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs5"),
405 std::string("core.obs"));
406 EXPECT_EQ(OC_STACK_NO_OBSERVERS, OCPlatform::notifyAllObservers(resourceHome,
407 OC::QualityOfService::HighQos));
410 TEST(NotifyAllObserverTest, NotifyListOfObservers)
412 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs6"),
413 std::string("core.obs"));
415 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
416 ObservationIds interestedObservers;
417 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
418 interestedObservers, resourceResponse));
421 TEST(NotifyAllObserverTest, NotifyListOfObserversWithLowQos)
423 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs7"),
424 std::string("core.obs"));
426 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
427 ObservationIds interestedObservers;
428 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
429 interestedObservers, resourceResponse,OC::QualityOfService::LowQos));
432 TEST(NotifyAllObserverTest, NotifyListOfObserversWithMidQos)
434 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs8"),
435 std::string("core.obs"));
437 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
438 ObservationIds interestedObservers;
439 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
440 interestedObservers, resourceResponse,OC::QualityOfService::MidQos));
443 TEST(NotifyAllObserverTest, NotifyListOfObserversWithNaQos)
445 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs9"),
446 std::string("core.obs"));
448 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
449 ObservationIds interestedObservers;
450 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
451 interestedObservers, resourceResponse,OC::QualityOfService::NaQos));
454 TEST(NotifyAllObserverTest, NotifyListOfObserversWithHighQos)
456 OCResourceHandle resourceHome = RegisterResource(std::string("/a/obs10"),
457 std::string("core.obs"));
459 std::shared_ptr<OCResourceResponse> resourceResponse(new OCResourceResponse());
460 ObservationIds interestedObservers;
461 EXPECT_ANY_THROW(OCPlatform::notifyListOfObservers(resourceHome,
462 interestedObservers, resourceResponse,OC::QualityOfService::HighQos));
465 //DeviceEntityHandlerTest
466 TEST(DeviceEntityHandlerTest, SetDefaultDeviceEntityHandler)
468 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(entityHandler));
469 EXPECT_EQ(OC_STACK_OK, OCPlatform::setDefaultDeviceEntityHandler(NULL));
474 TEST(FindResourceTest, FindResourceValid)
476 std::ostringstream requestURI;
477 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
478 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
479 OC_WIFI, &foundResource));
482 TEST(FindResourceTest, FindResourceNullResourceURI)
484 EXPECT_ANY_THROW(OCPlatform::findResource("", nullptr,
485 OC_WIFI, &foundResource));
488 TEST(FindResourceTest, FindResourceNullResourceURI1)
490 std::ostringstream requestURI;
491 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
492 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
493 OC_WIFI, &foundResource));
496 TEST(FindResourceTest, FindResourceNullHost)
498 std::ostringstream requestURI;
499 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
500 EXPECT_ANY_THROW(OCPlatform::findResource(nullptr, requestURI.str(),
501 OC_WIFI, &foundResource));
504 TEST(FindResourceTest, FindResourceNullresourceHandler)
506 std::ostringstream requestURI;
507 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
508 EXPECT_EQ(OC_STACK_OK, OCPlatform::findResource("", requestURI.str(),
512 TEST(FindResourceTest, FindResourceWithLowQoS)
514 std::ostringstream requestURI;
515 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
516 EXPECT_EQ(OC_STACK_OK,
517 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
518 OC::QualityOfService::LowQos));
521 TEST(FindResourceTest, FindResourceWithMidQos)
523 std::ostringstream requestURI;
524 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
525 EXPECT_EQ(OC_STACK_OK,
526 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
527 OC::QualityOfService::MidQos));
530 //We will enable it when CON is supported in the stack
531 TEST(FindResourceTest, DISABLED_FindResourceWithHighQos)
533 std::ostringstream requestURI;
534 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
535 EXPECT_EQ(OC_STACK_OK,
536 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
537 OC::QualityOfService::HighQos));
540 TEST(FindResourceTest, FindResourceWithNaQos)
542 std::ostringstream requestURI;
543 requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
544 EXPECT_EQ(OC_STACK_OK,
545 OCPlatform::findResource("", requestURI.str(), OC_WIFI, &foundResource,
546 OC::QualityOfService::NaQos));
550 TEST(GetDeviceInfoTest, GetDeviceInfoWithValidParameters)
552 std::string deviceDiscoveryURI = "/oc/core/d";
554 OCPlatform::Configure(cfg);
555 std::ostringstream requestURI;
556 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
557 EXPECT_EQ(OC_STACK_OK,
558 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo));
561 TEST(GetDeviceInfoTest, GetDeviceInfoNullDeviceURI)
564 OCPlatform::Configure(cfg);
566 OCPlatform::getDeviceInfo("", nullptr, OC_WIFI, &receivedDeviceInfo));
569 TEST(GetDeviceInfoTest, GetDeviceInfoWithNullDeviceInfoHandler)
571 std::string deviceDiscoveryURI = "/oc/core/d";
573 OCPlatform::Configure(cfg);
574 std::ostringstream requestURI;
575 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
576 EXPECT_EQ(OC_STACK_OK,
577 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, NULL));
580 TEST(GetDeviceInfoTest, GetDeviceInfoWithLowQos)
582 std::string deviceDiscoveryURI = "/oc/core/d";
584 OCPlatform::Configure(cfg);
585 std::ostringstream requestURI;
586 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
587 EXPECT_EQ(OC_STACK_OK,
588 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
589 OC::QualityOfService::LowQos));
592 TEST(GetDeviceInfoTest, GetDeviceInfoWithMidQos)
594 std::string deviceDiscoveryURI = "/oc/core/d";
596 OCPlatform::Configure(cfg);
597 std::ostringstream requestURI;
598 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
599 EXPECT_EQ(OC_STACK_OK,
600 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
601 OC::QualityOfService::MidQos));
604 //We will enable it when CON is supported in the stack
605 TEST(GetDeviceInfoTest, DISABLED_GetDeviceInfoWithHighQos)
607 std::string deviceDiscoveryURI = "/oc/core/d";
609 OCPlatform::Configure(cfg);
610 std::ostringstream requestURI;
611 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
612 EXPECT_EQ(OC_STACK_OK,
613 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
614 OC::QualityOfService::HighQos));
617 TEST(GetDeviceInfoTest, GetDeviceInfoWithNaQos)
619 std::string deviceDiscoveryURI = "/oc/core/d";
621 OCPlatform::Configure(cfg);
622 std::ostringstream requestURI;
623 requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
624 EXPECT_EQ(OC_STACK_OK,
625 OCPlatform::getDeviceInfo("", requestURI.str(), OC_WIFI, &receivedDeviceInfo,
626 OC::QualityOfService::NaQos));
629 //RegisterDeviceInfo test
630 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters)
632 OCDeviceInfo deviceInfo;
634 DuplicateString(&deviceInfo.contentType, "myContentType");
635 DuplicateString(&deviceInfo.dateOfManufacture, "myDateOfManufacture");
636 DuplicateString(&deviceInfo.deviceName, "myDeviceName");
637 DuplicateString(&deviceInfo.deviceUUID, "myDeviceUUID");
638 DuplicateString(&deviceInfo.firmwareVersion, "myFirmwareVersion");
639 DuplicateString(&deviceInfo.hostName, "myHostName");
640 DuplicateString(&deviceInfo.manufacturerName, "myManufacturerNa");
641 DuplicateString(&deviceInfo.manufacturerUrl, "myManufacturerUrl");
642 DuplicateString(&deviceInfo.modelNumber, "myModelNumber");
643 DuplicateString(&deviceInfo.platformVersion, "myPlatformVersion");
644 DuplicateString(&deviceInfo.supportUrl, "mySupportUrl");
645 DuplicateString(&deviceInfo.version, "myVersion");
647 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
648 EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
651 TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
653 OCDeviceInfo di = {};
654 EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(di));
657 //SubscribePresence Test
658 TEST(SubscribePresenceTest,SubscribePresenceWithValidParameters)
660 std::string hostAddress = "192.168.1.2:5000";
661 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
663 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle, hostAddress,
664 OC_WIFI, &presenceHandler));
667 TEST(SubscribePresenceTest,SubscribePresenceWithNullHost)
669 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
671 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
672 OC_WIFI, &presenceHandler));
675 TEST(SubscribePresenceTest,SubscribePresenceWithNullPresenceHandler)
677 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
679 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle, nullptr,
683 TEST(SubscribePresenceTest,SubscribePresenceWithResourceType)
685 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
687 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
688 OC_MULTICAST_IP, "core.light", OC_WIFI, &presenceHandler));
691 TEST(SubscribePresenceTest,SubscribePresenceWithNullResourceType)
693 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
695 EXPECT_ANY_THROW(OCPlatform::subscribePresence(presenceHandle,
696 OC_MULTICAST_IP, nullptr, OC_WIFI, &presenceHandler));
699 //UnsubscribePresence Test
700 //We will enable it after fixing double free or corruption
701 TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
703 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
705 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
706 OC_MULTICAST_IP, "core.light", OC_WIFI, &presenceHandler));
707 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));
710 TEST(SubscribePresenceTest, UnsubscribePresenceWithNullHandle)
712 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
713 EXPECT_ANY_THROW(OCPlatform::unsubscribePresence(presenceHandle));
716 TEST(SubscribePresenceTest, UnsubscribePresenceWithValidHandle)
718 OCPlatform::OCPresenceHandle presenceHandle = nullptr;
720 EXPECT_EQ(OC_STACK_OK, OCPlatform::subscribePresence(presenceHandle,
721 OC_MULTICAST_IP, OC_WIFI, &presenceHandler));
722 EXPECT_EQ(OC_STACK_OK, OCPlatform::unsubscribePresence(presenceHandle));