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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
29 #include "gtest/gtest.h"
30 #include <sys/types.h>
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
46 #include "gtest_helper.h"
50 namespace itst = iotivity::test;
52 #define DEFAULT_CONTEXT_VALUE 0x99
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 static const char TAG[] = "TestHarness";
59 std::chrono::seconds const SHORT_TEST_TIMEOUT = std::chrono::seconds(5);
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
64 extern "C" OCStackApplicationResult asyncDoResourcesCallback(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
66 OC_LOG(INFO, TAG, "Entering asyncDoResourcesCallback");
68 EXPECT_EQ(OC_STACK_OK, clientResponse->result);
70 if(ctx == (void*)DEFAULT_CONTEXT_VALUE) {
71 OC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
73 OC_LOG_V(INFO, TAG, "result = %d", clientResponse->result);
75 return OC_STACK_KEEP_TRANSACTION;
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
81 OCEntityHandlerResult entityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest)
83 OC_LOG(INFO, TAG, "Entering entityHandler");
88 //-----------------------------------------------------------------------------
90 //-----------------------------------------------------------------------------
91 void InitStack(OCMode mode)
93 OC_LOG(INFO, TAG, "Entering InitStack");
95 EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, mode));
96 OC_LOG(INFO, TAG, "Leaving InitStack");
99 uint8_t InitNumExpectedResources()
102 // When presence is enabled, it is a resource and so is (currently) included
103 // in the returned resource count returned by the OCGetNumberOfResources API.
110 uint8_t InitResourceIndex()
113 // When presence is enabled, it is a resource and so is (currently) included
114 // in the returned resource count returned by the OCGetNumberOfResources API.
115 // The index of the presence resource is 0, so the first user app resource index
122 //-----------------------------------------------------------------------------
124 //-----------------------------------------------------------------------------
126 TEST(StackInit, StackInitNullAddr)
128 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
129 EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
130 EXPECT_EQ(OC_STACK_OK, OCStop());
133 TEST(StackInit, StackInitNullPort)
135 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
136 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
137 EXPECT_EQ(OC_STACK_OK, OCStop());
140 TEST(StackInit, StackInitNullAddrAndPort)
142 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
143 EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
144 EXPECT_EQ(OC_STACK_OK, OCStop());
147 TEST(StackInit, StackInitInvalidMode)
149 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
150 EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
151 EXPECT_EQ(OC_STACK_ERROR, OCStop());
154 TEST(StackStart, StackStartSuccessClient)
156 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
157 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
158 EXPECT_EQ(OC_STACK_OK, OCStop());
161 TEST(StackStart, StackStartSuccessServer)
163 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
164 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
165 EXPECT_EQ(OC_STACK_OK, OCStop());
168 TEST(StackStart, StackStartSuccessClientServer)
170 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
171 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER));
172 EXPECT_EQ(OC_STACK_OK, OCStop());
175 TEST(StackStart, StackStartSuccessiveInits)
177 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
178 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
179 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.2", 5683, OC_SERVER));
180 EXPECT_EQ(OC_STACK_OK, OCStop());
183 TEST(StackDiscovery, DISABLED_DoResourceDeviceDiscovery)
185 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
186 OCCallbackData cbData;
189 OC_LOG(INFO, TAG, "Starting DoResourceDeviceDiscovery test ");
190 InitStack(OC_CLIENT);
192 /* Start a discovery query*/
193 char szQueryUri[64] = { 0 };
194 strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
195 cbData.cb = asyncDoResourcesCallback;
196 cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
198 EXPECT_EQ(OC_STACK_OK, OCDoResource(&handle,
208 EXPECT_EQ(OC_STACK_OK, OCStop());
211 TEST(StackStop, StackStopWithoutInit)
213 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
214 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
215 EXPECT_EQ(OC_STACK_OK, OCStop());
216 EXPECT_EQ(OC_STACK_ERROR, OCStop());
219 TEST(StackResource, DISABLED_UpdateResourceNullURI)
221 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
222 OCCallbackData cbData;
225 OC_LOG(INFO, TAG, "Starting UpdateResourceNullURI test");
226 InitStack(OC_CLIENT);
228 /* Start a discovery query*/
229 char szQueryUri[64] = { 0 };
230 strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
231 cbData.cb = asyncDoResourcesCallback;
232 cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
234 EXPECT_EQ(OC_STACK_OK, OCDoResource(&handle,
244 EXPECT_EQ(OC_STACK_OK, OCStop());
247 TEST(StackResource, CreateResourceBadParams)
249 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
250 OC_LOG(INFO, TAG, "Starting CreateResourceBadParams test");
251 InitStack(OC_SERVER);
253 OCResourceHandle handle;
255 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(NULL, //&handle,
260 OC_DISCOVERABLE|OC_OBSERVABLE));
262 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle,
267 OC_DISCOVERABLE|OC_OBSERVABLE));
269 // Property bitmask out of range
270 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle,
275 128));// invalid bitmask for OCResourceProperty
277 EXPECT_EQ(OC_STACK_OK, OCStop());
281 TEST(StackResource, CreateResourceSuccess)
283 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
284 OC_LOG(INFO, TAG, "Starting CreateResourceSuccess test");
285 InitStack(OC_SERVER);
287 OCResourceHandle handle;
288 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
293 OC_DISCOVERABLE|OC_OBSERVABLE));
294 const char *url = OCGetResourceUri(handle);
295 EXPECT_STREQ("/a/led", url);
297 EXPECT_EQ(OC_STACK_OK, OCStop());
300 TEST(StackResource, CreateResourceFailDuplicateUri)
302 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
303 OC_LOG(INFO, TAG, "Starting CreateResourceFailDuplicateUri test");
304 InitStack(OC_SERVER);
306 OCResourceHandle handle;
307 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
312 OC_DISCOVERABLE|OC_OBSERVABLE));
313 const char *url = OCGetResourceUri(handle);
314 EXPECT_STREQ("/a/led", url);
316 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle,
321 OC_DISCOVERABLE|OC_OBSERVABLE));
323 EXPECT_EQ(OC_STACK_OK, OCStop());
326 TEST(StackResource, CreateResourceMultipleResources)
328 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
329 OC_LOG(INFO, TAG, "Starting CreateResourceMultipleResources test");
330 InitStack(OC_SERVER);
332 OCResourceHandle handle1;
333 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
338 OC_DISCOVERABLE|OC_OBSERVABLE));
340 OCResourceHandle handle2;
341 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
346 OC_DISCOVERABLE|OC_OBSERVABLE));
347 OCResourceHandle handle3;
348 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
353 OC_DISCOVERABLE|OC_OBSERVABLE));
355 const char *url = OCGetResourceUri(handle1);
356 EXPECT_STREQ("/a/led1", url);
358 url = OCGetResourceUri(handle2);
359 EXPECT_STREQ("/a/led2", url);
361 url = OCGetResourceUri(handle3);
362 EXPECT_STREQ("/a/led3", url);
364 EXPECT_EQ(OC_STACK_OK, OCStop());
367 TEST(StackResource, CreateResourceBadResoureType)
369 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
370 OC_LOG(INFO, TAG, "Starting CreateResourceBadResoureType test");
371 InitStack(OC_SERVER);
373 OCResourceHandle handle;
374 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle,
379 OC_DISCOVERABLE|OC_OBSERVABLE));
381 EXPECT_EQ(OC_STACK_OK, OCStop());
384 TEST(StackResource, CreateResourceGoodResourceType)
386 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
387 OC_LOG(INFO, TAG, "Starting CreateResourceGoodResourceType test");
388 InitStack(OC_SERVER);
390 OCResourceHandle handle;
391 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
396 OC_DISCOVERABLE|OC_OBSERVABLE));
398 EXPECT_EQ(OC_STACK_OK, OCStop());
401 TEST(StackResource, ResourceTypeName)
403 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
404 OC_LOG(INFO, TAG, "Starting ResourceTypeName test");
405 InitStack(OC_SERVER);
407 OCResourceHandle handle;
408 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
413 OC_DISCOVERABLE|OC_OBSERVABLE));
415 uint8_t numResourceTypes;
416 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
417 EXPECT_EQ(1, numResourceTypes);
418 const char *resourceTypeName = OCGetResourceTypeName(handle, 0);
419 EXPECT_STREQ("core.led", resourceTypeName);
421 // try getting resource type names with an invalid index
422 resourceTypeName = OCGetResourceTypeName(handle, 1);
423 EXPECT_STREQ(NULL, resourceTypeName);
424 // try getting resource type names with an invalid index
425 resourceTypeName = OCGetResourceTypeName(handle, 10);
426 EXPECT_STREQ(NULL, resourceTypeName);
428 EXPECT_EQ(OC_STACK_OK, OCStop());
431 TEST(StackResource, ResourceTypeAttrRepresentation)
433 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
434 OC_LOG(INFO, TAG, "Starting ResourceTypeAttrRepresentation test");
435 InitStack(OC_SERVER);
437 OCResourceHandle handle;
438 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
443 OC_DISCOVERABLE|OC_OBSERVABLE));
445 uint8_t numResourceTypes;
446 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
447 EXPECT_EQ(1, numResourceTypes);
449 EXPECT_EQ(OC_STACK_OK, OCStop());
452 TEST(StackResource, ResourceTypeInterface)
454 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
455 OC_LOG(INFO, TAG, "Starting ResourceTypeInterface test");
456 InitStack(OC_SERVER);
458 OCResourceHandle handle;
459 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
464 OC_DISCOVERABLE|OC_OBSERVABLE));
466 uint8_t numResourceInterfaces;
467 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
468 EXPECT_EQ(1, numResourceInterfaces);
469 const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
470 EXPECT_STREQ("core.rw", resourceInterfaceName);
472 // try getting resource interface names with an invalid index
473 resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
474 EXPECT_STREQ(NULL, resourceInterfaceName);
475 // try getting resource interface names with an invalid index
476 resourceInterfaceName = OCGetResourceInterfaceName(handle, 10);
477 EXPECT_STREQ(NULL, resourceInterfaceName);
479 EXPECT_EQ(OC_STACK_OK, OCStop());
482 TEST(StackResource, ResourceTypeInterfaceMethods)
484 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
485 OC_LOG(INFO, TAG, "Starting ResourceTypeInterfaceMethods test");
486 InitStack(OC_SERVER);
488 OCResourceHandle handle;
489 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
494 OC_DISCOVERABLE|OC_OBSERVABLE));
496 uint8_t numResourceInterfaces;
497 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
498 EXPECT_EQ(1, numResourceInterfaces);
500 EXPECT_EQ(OC_STACK_OK, OCStop());
503 TEST(StackResource, GetResourceProperties)
505 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
506 OC_LOG(INFO, TAG, "Starting GetResourceProperties test");
507 InitStack(OC_SERVER);
509 OCResourceHandle handle;
510 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
515 OC_DISCOVERABLE|OC_OBSERVABLE));
517 EXPECT_EQ(OC_ACTIVE|OC_DISCOVERABLE|OC_OBSERVABLE, OCGetResourceProperties(handle));
518 EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
520 EXPECT_EQ(OC_STACK_OK, OCStop());
523 TEST(StackResource, StackTestResourceDiscoverOneResourceBad)
525 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
526 OC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverOneResourceBad test");
527 InitStack(OC_SERVER);
529 OCResourceHandle handle;
530 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
535 OC_DISCOVERABLE|OC_OBSERVABLE));
536 const char *url = OCGetResourceUri(handle);
537 EXPECT_STREQ("/a1/led", url);
539 //EXPECT_EQ(OC_STACK_INVALID_URI, OCHandleServerRequest(&res, uri, query, req, rsp));
540 EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
541 uint8_t numResources = 0;
542 uint8_t numExpectedResources = InitNumExpectedResources();
544 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
545 EXPECT_EQ(numExpectedResources, numResources);
547 EXPECT_EQ(OC_STACK_OK, OCStop());
550 TEST(StackResource, StackTestResourceDiscoverOneResource)
552 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
553 OC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverOneResource test");
554 InitStack(OC_SERVER);
556 OCResourceHandle handle;
557 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
562 OC_DISCOVERABLE|OC_OBSERVABLE));
563 const char *url = OCGetResourceUri(handle);
564 EXPECT_STREQ("/a/led", url);
566 //EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
567 EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
569 EXPECT_EQ(OC_STACK_OK, OCStop());
572 TEST(StackResource, StackTestResourceDiscoverManyResources)
574 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
575 OC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverManyResources test");
576 InitStack(OC_SERVER);
578 OCResourceHandle handle1;
579 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
585 const char *url = OCGetResourceUri(handle1);
586 EXPECT_STREQ("/a/led1", url);
588 OCResourceHandle handle2;
589 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
594 OC_DISCOVERABLE|OC_OBSERVABLE));
595 url = OCGetResourceUri(handle2);
596 EXPECT_STREQ("/a/led2", url);
598 EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle2, "core.brightled"));
599 EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle2, "core.colorled"));
601 OCResourceHandle handle3;
602 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
607 OC_DISCOVERABLE|OC_OBSERVABLE));
608 url = OCGetResourceUri(handle3);
609 EXPECT_STREQ("/a/led3", url);
611 EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.ll"));
612 EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.b"));
614 OCResourceHandle handle4;
615 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
621 url = OCGetResourceUri(handle4);
622 EXPECT_STREQ("/a/led4", url);
624 EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle4, "core.brightled"));
625 EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.ll"));
626 EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.b"));
628 //EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
630 EXPECT_EQ(OC_STACK_OK, OCStop());
633 TEST(StackBind, BindResourceTypeNameBad)
635 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
636 OC_LOG(INFO, TAG, "Starting BindResourceTypeNameBad test");
637 InitStack(OC_SERVER);
639 OCResourceHandle handle;
640 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
645 OC_DISCOVERABLE|OC_OBSERVABLE));
647 uint8_t numResourceTypes;
648 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
649 EXPECT_EQ(1, numResourceTypes);
650 const char *resourceTypeName = OCGetResourceTypeName(handle, 0);
651 EXPECT_STREQ("core.led", resourceTypeName);
653 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceTypeToResource(handle, NULL));
655 EXPECT_EQ(OC_STACK_OK, OCStop());
658 TEST(StackBind, BindResourceTypeNameGood)
660 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
661 OC_LOG(INFO, TAG, "Starting BindResourceTypeNameGood test");
662 InitStack(OC_SERVER);
664 OCResourceHandle handle;
665 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
670 OC_DISCOVERABLE|OC_OBSERVABLE));
672 uint8_t numResourceTypes;
673 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
674 EXPECT_EQ(1, numResourceTypes);
675 const char *resourceTypeName = OCGetResourceTypeName(handle, 0);
676 EXPECT_STREQ("core.led", resourceTypeName);
678 EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.brightled"));
679 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
680 EXPECT_EQ(2, numResourceTypes);
681 resourceTypeName = OCGetResourceTypeName(handle, 1);
682 EXPECT_STREQ("core.brightled", resourceTypeName);
684 EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.reallybrightled"));
685 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
686 EXPECT_EQ(3, numResourceTypes);
687 resourceTypeName = OCGetResourceTypeName(handle, 2);
688 EXPECT_STREQ("core.reallybrightled", resourceTypeName);
690 EXPECT_EQ(OC_STACK_OK, OCStop());
693 TEST(StackBind, BindResourceTypeAttribRepGood)
695 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
696 OC_LOG(INFO, TAG, "Starting BindResourceTypeAttribRepGood test");
697 InitStack(OC_SERVER);
699 OCResourceHandle handle;
700 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
705 OC_DISCOVERABLE|OC_OBSERVABLE));
707 uint8_t numResourceTypes;
708 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
709 EXPECT_EQ(1, numResourceTypes);
711 EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.brightled"));
712 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
713 EXPECT_EQ(2, numResourceTypes);
715 EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.reallybrightled"));
716 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
717 EXPECT_EQ(3, numResourceTypes);
719 EXPECT_EQ(OC_STACK_OK, OCStop());
723 TEST(StackBind, BindResourceInterfaceNameBad)
725 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
726 OC_LOG(INFO, TAG, "Starting BindResourceInterfaceNameBad test");
727 InitStack(OC_SERVER);
729 OCResourceHandle handle;
730 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
735 OC_DISCOVERABLE|OC_OBSERVABLE));
737 uint8_t numResourceInterfaces;
738 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
739 EXPECT_EQ(1, numResourceInterfaces);
740 const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
741 EXPECT_STREQ("core.rw", resourceInterfaceName);
743 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceInterfaceToResource(handle, NULL));
745 EXPECT_EQ(OC_STACK_OK, OCStop());
748 TEST(StackBind, BindResourceInterfaceNameGood)
750 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
751 OC_LOG(INFO, TAG, "Starting BindResourceInterfaceNameGood test");
752 InitStack(OC_SERVER);
754 OCResourceHandle handle;
755 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
760 OC_DISCOVERABLE|OC_OBSERVABLE));
762 uint8_t numResourceInterfaces;
763 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
764 EXPECT_EQ(1, numResourceInterfaces);
765 const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
766 EXPECT_STREQ("core.rw", resourceInterfaceName);
768 EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle, "core.r"));
770 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
771 EXPECT_EQ(2, numResourceInterfaces);
772 resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
773 EXPECT_STREQ("core.r", resourceInterfaceName);
775 EXPECT_EQ(OC_STACK_OK, OCStop());
778 TEST(StackBind, BindResourceInterfaceMethodsBad)
780 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
781 OC_LOG(INFO, TAG, "Starting BindResourceInterfaceMethodsBad test");
782 InitStack(OC_SERVER);
784 OCResourceHandle handle;
785 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
790 OC_DISCOVERABLE|OC_OBSERVABLE));
792 uint8_t numResourceInterfaces;
793 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
794 EXPECT_EQ(1, numResourceInterfaces);
796 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceInterfaceToResource(handle, 0));
798 EXPECT_EQ(OC_STACK_OK, OCStop());
801 TEST(StackBind, BindResourceInterfaceMethodsGood)
803 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
804 OC_LOG(INFO, TAG, "Starting BindResourceInterfaceMethodsGood test");
805 InitStack(OC_SERVER);
807 OCResourceHandle handle;
808 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
813 OC_DISCOVERABLE|OC_OBSERVABLE));
815 uint8_t numResourceInterfaces;
816 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
817 EXPECT_EQ(1, numResourceInterfaces);
819 EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle, "core.r"));
821 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
822 EXPECT_EQ(2, numResourceInterfaces);
824 EXPECT_EQ(OC_STACK_OK, OCStop());
827 TEST(StackBind, BindContainedResourceBad)
829 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
830 OC_LOG(INFO, TAG, "Starting BindContainedResourceBad test");
831 InitStack(OC_SERVER);
833 OCResourceHandle containerHandle;
834 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
839 OC_DISCOVERABLE|OC_OBSERVABLE));
841 OCResourceHandle handle0;
842 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
847 OC_DISCOVERABLE|OC_OBSERVABLE));
849 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResource(containerHandle, containerHandle));
851 EXPECT_EQ(OC_STACK_ERROR, OCBindResource((OCResourceHandle) 0, handle0));
853 EXPECT_EQ(OC_STACK_OK, OCStop());
856 TEST(StackBind, BindContainedResourceGood)
858 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
859 OC_LOG(INFO, TAG, "Starting BindContainedResourceGood test");
860 InitStack(OC_SERVER);
862 uint8_t numResources = 0;
863 uint8_t numExpectedResources = InitNumExpectedResources();
865 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
866 EXPECT_EQ(numExpectedResources, numResources);
868 OCResourceHandle containerHandle;
869 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
874 OC_DISCOVERABLE|OC_OBSERVABLE));
875 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
876 EXPECT_EQ(++numExpectedResources, numResources);
878 OCResourceHandle handle0;
879 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
884 OC_DISCOVERABLE|OC_OBSERVABLE));
885 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
886 EXPECT_EQ(++numExpectedResources, numResources);
888 OCResourceHandle handle1;
889 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
894 OC_DISCOVERABLE|OC_OBSERVABLE));
895 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
896 EXPECT_EQ(++numExpectedResources, numResources);
898 OCResourceHandle handle2;
899 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
904 OC_DISCOVERABLE|OC_OBSERVABLE));
905 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
906 EXPECT_EQ(++numExpectedResources, numResources);
908 OCResourceHandle handle3;
909 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
914 OC_DISCOVERABLE|OC_OBSERVABLE));
915 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
916 EXPECT_EQ(++numExpectedResources, numResources);
918 OCResourceHandle handle4;
919 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
924 OC_DISCOVERABLE|OC_OBSERVABLE));
925 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
926 EXPECT_EQ(++numExpectedResources, numResources);
928 OCResourceHandle handle5;
929 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle5,
934 OC_DISCOVERABLE|OC_OBSERVABLE));
935 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
936 EXPECT_EQ(++numExpectedResources, numResources);
939 EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle0));
940 EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle1));
941 EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle2));
942 EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle3));
943 EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle4));
944 EXPECT_EQ(OC_STACK_ERROR, OCBindResource(containerHandle, handle5));
946 EXPECT_EQ(handle0, OCGetResourceHandleFromCollection(containerHandle, 0));
947 EXPECT_EQ(handle1, OCGetResourceHandleFromCollection(containerHandle, 1));
948 EXPECT_EQ(handle2, OCGetResourceHandleFromCollection(containerHandle, 2));
949 EXPECT_EQ(handle3, OCGetResourceHandleFromCollection(containerHandle, 3));
950 EXPECT_EQ(handle4, OCGetResourceHandleFromCollection(containerHandle, 4));
952 EXPECT_EQ(NULL, OCGetResourceHandleFromCollection(containerHandle, 5));
954 EXPECT_EQ(OC_STACK_OK, OCStop());
958 TEST(StackBind, BindEntityHandlerBad)
960 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
961 OC_LOG(INFO, TAG, "Starting BindEntityHandlerBad test");
962 InitStack(OC_SERVER);
964 OCResourceHandle handle;
965 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
970 OC_DISCOVERABLE|OC_OBSERVABLE));
972 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceHandler(NULL, NULL));
974 EXPECT_EQ(OC_STACK_OK, OCStop());
977 TEST(StackBind, BindEntityHandlerGood)
979 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
980 OC_LOG(INFO, TAG, "Starting BindEntityHandlerGood test");
981 InitStack(OC_SERVER);
983 OCResourceHandle handle;
984 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
989 OC_DISCOVERABLE|OC_OBSERVABLE));
991 OCEntityHandler myHandler = entityHandler;
993 EXPECT_EQ(OC_STACK_OK, OCBindResourceHandler(handle, myHandler));
995 EXPECT_EQ(myHandler, OCGetResourceHandler(handle));
997 EXPECT_EQ(OC_STACK_OK, OCStop());
1000 TEST(StackResourceAccess, GetResourceByIndex)
1002 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
1003 OC_LOG(INFO, TAG, "Starting GetResourceByIndex test");
1004 InitStack(OC_SERVER);
1006 uint8_t numResources = 0;
1007 uint8_t numExpectedResources = InitNumExpectedResources();
1008 uint8_t resourceIndex = InitResourceIndex();
1010 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1011 EXPECT_EQ(numExpectedResources, numResources);
1013 OCResourceHandle containerHandle;
1014 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
1019 OC_DISCOVERABLE|OC_OBSERVABLE));
1020 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1021 EXPECT_EQ(++numExpectedResources, numResources);
1023 OCResourceHandle handle0;
1024 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1029 OC_DISCOVERABLE|OC_OBSERVABLE));
1030 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1031 EXPECT_EQ(++numExpectedResources, numResources);
1033 OCResourceHandle handle1;
1034 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1039 OC_DISCOVERABLE|OC_OBSERVABLE));
1040 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1041 EXPECT_EQ(++numExpectedResources, numResources);
1043 OCResourceHandle handle2;
1044 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
1049 OC_DISCOVERABLE|OC_OBSERVABLE));
1050 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1051 EXPECT_EQ(++numExpectedResources, numResources);
1053 OCResourceHandle handle3;
1054 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
1059 OC_DISCOVERABLE|OC_OBSERVABLE));
1060 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1061 EXPECT_EQ(++numExpectedResources, numResources);
1063 OCResourceHandle handle4;
1064 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
1069 OC_DISCOVERABLE|OC_OBSERVABLE));
1070 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1071 EXPECT_EQ(++numExpectedResources, numResources);
1073 OCResourceHandle handle5;
1074 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle5,
1079 OC_DISCOVERABLE|OC_OBSERVABLE));
1080 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1081 EXPECT_EQ(++numExpectedResources, numResources);
1083 EXPECT_EQ(containerHandle, OCGetResourceHandle(resourceIndex));
1084 EXPECT_EQ(handle0, OCGetResourceHandle(++resourceIndex));
1085 EXPECT_EQ(handle1, OCGetResourceHandle(++resourceIndex));
1086 EXPECT_EQ(handle2, OCGetResourceHandle(++resourceIndex));
1087 EXPECT_EQ(handle3, OCGetResourceHandle(++resourceIndex));
1088 EXPECT_EQ(handle4, OCGetResourceHandle(++resourceIndex));
1089 EXPECT_EQ(handle5, OCGetResourceHandle(++resourceIndex));
1091 EXPECT_EQ(OC_STACK_OK, OCStop());
1094 TEST(StackResourceAccess, DeleteHeadResource)
1096 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
1097 OC_LOG(INFO, TAG, "Starting DeleteHeadResource test");
1098 InitStack(OC_SERVER);
1100 uint8_t numResources = 0;
1101 uint8_t numExpectedResources = InitNumExpectedResources();
1103 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1104 EXPECT_EQ(numExpectedResources, numResources);
1106 OCResourceHandle handle0;
1107 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1112 OC_DISCOVERABLE|OC_OBSERVABLE));
1113 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1114 EXPECT_EQ(++numExpectedResources, numResources);
1116 EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle0));
1117 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1118 EXPECT_EQ(--numExpectedResources, numResources);
1120 EXPECT_EQ(OC_STACK_OK, OCStop());
1123 TEST(StackResourceAccess, DeleteHeadResource2)
1125 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
1126 OC_LOG(INFO, TAG, "Starting DeleteHeadResource2 test");
1127 InitStack(OC_SERVER);
1129 uint8_t numResources = 0;
1130 uint8_t numExpectedResources = InitNumExpectedResources();
1131 uint8_t resourceIndex = InitResourceIndex();
1133 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1134 EXPECT_EQ(numExpectedResources, numResources);
1136 OCResourceHandle handle0;
1137 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1142 OC_DISCOVERABLE|OC_OBSERVABLE));
1143 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1144 EXPECT_EQ(++numExpectedResources, numResources);
1146 OCResourceHandle handle1;
1147 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1152 OC_DISCOVERABLE|OC_OBSERVABLE));
1153 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1154 EXPECT_EQ(++numExpectedResources, numResources);
1156 EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle0));
1157 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1158 EXPECT_EQ(--numExpectedResources, numResources);
1160 EXPECT_EQ(handle1, OCGetResourceHandle(resourceIndex));
1162 EXPECT_EQ(OC_STACK_OK, OCStop());
1166 TEST(StackResourceAccess, DeleteLastResource)
1168 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
1169 OC_LOG(INFO, TAG, "Starting DeleteLastResource test");
1170 InitStack(OC_SERVER);
1172 uint8_t numResources = 0;
1173 uint8_t numExpectedResources = InitNumExpectedResources();
1174 uint8_t resourceIndex = InitResourceIndex();
1176 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1177 EXPECT_EQ(numExpectedResources, numResources);
1179 OCResourceHandle handle0;
1180 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1185 OC_DISCOVERABLE|OC_OBSERVABLE));
1186 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1187 EXPECT_EQ(++numExpectedResources, numResources);
1189 OCResourceHandle handle1;
1190 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1195 OC_DISCOVERABLE|OC_OBSERVABLE));
1196 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1197 EXPECT_EQ(++numExpectedResources, numResources);
1199 EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle1));
1200 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1201 EXPECT_EQ(--numExpectedResources, numResources);
1203 EXPECT_EQ(handle0, OCGetResourceHandle(resourceIndex));
1205 OCResourceHandle handle2;
1206 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
1211 OC_DISCOVERABLE|OC_OBSERVABLE));
1212 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1213 EXPECT_EQ(++numExpectedResources, numResources);
1215 EXPECT_EQ(OC_STACK_OK, OCStop());
1218 TEST(StackResourceAccess, DeleteMiddleResource)
1220 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
1221 OC_LOG(INFO, TAG, "Starting DeleteMiddleResource test");
1222 InitStack(OC_SERVER);
1224 uint8_t numResources = 0;
1225 uint8_t numExpectedResources = InitNumExpectedResources();
1226 uint8_t resourceIndex = InitResourceIndex();
1228 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1229 EXPECT_EQ(numExpectedResources, numResources);
1231 OCResourceHandle handle0;
1232 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1237 OC_DISCOVERABLE|OC_OBSERVABLE));
1238 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1239 EXPECT_EQ(++numExpectedResources, numResources);
1241 OCResourceHandle handle1;
1242 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1247 OC_DISCOVERABLE|OC_OBSERVABLE));
1248 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1249 EXPECT_EQ(++numExpectedResources, numResources);
1251 OCResourceHandle handle2;
1252 EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
1257 OC_DISCOVERABLE|OC_OBSERVABLE));
1258 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1259 EXPECT_EQ(++numExpectedResources, numResources);
1261 EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle1));
1262 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1263 EXPECT_EQ(--numExpectedResources, numResources);
1265 EXPECT_EQ(handle0, OCGetResourceHandle(resourceIndex));
1266 EXPECT_EQ(handle2, OCGetResourceHandle(++resourceIndex));
1268 // Make sure the resource elements are still correct
1269 uint8_t numResourceInterfaces;
1270 EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle2, &numResourceInterfaces));
1271 EXPECT_EQ(1, numResourceInterfaces);
1272 const char *resourceInterfaceName = OCGetResourceInterfaceName(handle2, 0);
1273 EXPECT_STREQ("core.rw", resourceInterfaceName);
1275 EXPECT_EQ(OC_STACK_OK, OCStop());
1281 #endif // __cplusplus
1282 void parsePresencePayload(char* payload, uint32_t* seqNum, uint32_t* maxAge, char** resType);
1285 #endif // __cplusplus
1287 TEST(StackPresence, ParsePresencePayload)
1289 itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
1290 OC_LOG(INFO, TAG, "Starting ParsePresencePayload test");
1293 uint32_t seqNum = 0, maxAge = 0;
1294 char * resType = NULL;
1297 strncpy(payload, "{\"oc\":[100:99:presence]}", sizeof(payload));
1298 parsePresencePayload(payload, &seqNum, &maxAge, &resType);
1299 EXPECT_TRUE(100 == seqNum);
1300 EXPECT_TRUE(99 == maxAge);
1301 EXPECT_STREQ("presence", resType);
1304 //Bad Scenario -- should not result in Seg Fault
1305 parsePresencePayload(payload, NULL, &maxAge, &resType);
1308 seqNum = 0; maxAge = 0; resType = NULL;
1309 strncpy(payload, "{abracadabra}", sizeof(payload));
1310 parsePresencePayload(payload, &seqNum, &maxAge, &resType);
1311 EXPECT_TRUE(0 == seqNum);
1312 EXPECT_TRUE(0 == maxAge);
1313 EXPECT_EQ(NULL, resType);
1317 seqNum = 0; maxAge = 0; resType = NULL;
1318 strncpy(payload, "{\"oc\":[100]}", sizeof(payload));
1319 parsePresencePayload(payload, &seqNum, &maxAge, &resType);
1320 EXPECT_TRUE(100 == seqNum);
1321 EXPECT_TRUE(0 == maxAge);
1322 EXPECT_EQ(NULL, resType);
1326 seqNum = 0; maxAge = 0; resType = NULL;
1327 strncpy(payload, "{\"oc\":[]}", sizeof(payload));
1328 parsePresencePayload(payload, &seqNum, &maxAge, &resType);
1329 EXPECT_TRUE(0 == seqNum);
1330 EXPECT_TRUE(0 == maxAge);
1331 EXPECT_EQ(NULL, resType);
1335 strncpy(payload, "{:]}", sizeof(payload));
1336 parsePresencePayload(payload, &seqNum, &maxAge, &resType);
1337 EXPECT_TRUE(0 == seqNum);
1338 EXPECT_TRUE(0 == maxAge);
1339 EXPECT_EQ(NULL, resType);
1343 strncpy(payload, "{:[presence}", sizeof(payload));
1344 parsePresencePayload(payload, &seqNum, &maxAge, &resType);
1345 EXPECT_TRUE(0 == seqNum);
1346 EXPECT_TRUE(0 == maxAge);
1347 EXPECT_EQ(NULL, resType);