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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
25 #include "ocstackinternal.h"
28 #include <sys/types.h>
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 static const char TAG[] = "TestHarness";
49 static OCUri SERVICE_URI = "coap://127.0.0.1:5683/";
51 void EXPECT_EQ(int a, int b) {
53 OC_LOG(INFO, TAG, "PASS");
55 OC_LOG(ERROR, TAG, "**FAIL**");
59 void EXPECT_STREQ(const char *a, const char *b) {
60 if (strcmp(a, b) == 0) {
61 OC_LOG(INFO, TAG, "PASS");
63 OC_LOG(ERROR, TAG, "**FAIL**");
66 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 extern "C" void asyncDoResourcesCallback(OCStackResult result, OCRepresentationHandle representation) {
71 OC_LOG(INFO, TAG, "Entering asyncDoResourcesCallback");
73 EXPECT_EQ(OC_STACK_OK, result);
74 OCResource *resource = (OCResource *)representation;
75 OC_LOG_V(INFO, TAG, "URI = %s", resource->uri);
76 EXPECT_STREQ(SERVICE_URI, resource->uri);
79 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
83 EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
87 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
91 EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
95 EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
99 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
100 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
101 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER));
105 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
106 EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, OC_EXPLICIT_DEVICE_DISCOVERY_URI, 0, 0, asyncDoResourcesCallback), NULL, 0);
107 EXPECT_EQ(OC_STACK_OK, OCUpdateResources(SERVICE_URI));
108 EXPECT_EQ(OC_STACK_OK, OCStop());
112 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
113 EXPECT_EQ(OC_STACK_OK, OCStop());
114 EXPECT_EQ(OC_STACK_ERROR, OCStop());
118 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
119 EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, OC_EXPLICIT_DEVICE_DISCOVERY_URI, 0, 0, asyncDoResourcesCallback), NULL, 0);
120 EXPECT_EQ(OC_STACK_INVALID_URI, OCUpdateResources(0));
121 EXPECT_EQ(OC_STACK_OK, OCStop());