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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 // Do not remove the include below
23 #include "ArduinoStackTest.h"
27 #include "ocstackinternal.h"
31 static OCUri SERVICE_URI = "coap://127.0.0.1:5683/";
33 #if 0 // Turn off logger test stuff
34 PROGMEM const char tag[] = "Arduino";
35 PROGMEM const char msg[] = "Arduino Logger Test";
37 PROGMEM const char debugMsg[] = "this is a DEBUG message";
38 PROGMEM const char infoMsg[] = "this is a INFO message";
39 PROGMEM const char warningMsg[] = "this is a WARNING message";
40 PROGMEM const char errorMsg[] = "this is a ERROR message";
41 PROGMEM const char fatalMsg[] = "this is a FATAL message";
43 PROGMEM const char multiLineMsg[] = "this is a DEBUG message\non multiple\nlines";
46 void EXPECT_EQ(int a, int b) {
48 OIC_LOG(INFO, TAG, ("PASS"));
50 OIC_LOG(ERROR, TAG, ("FAIL"));
54 void EXPECT_STREQ(const char *a, const char *b) {
55 if (strcmp(a, b) == 0) {
56 OIC_LOG(INFO, TAG, ("PASS"));
58 OIC_LOG(ERROR, TAG, ("FAIL"));
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
64 #if 0 // Turn off logger tests
66 OIC_LOG(INFO, tag, msg);
70 OIC_LOG(INFO, 0, msg);
74 OIC_LOG(INFO, tag, 0);
82 OIC_LOG(DEBUG, tag, debugMsg);
83 OIC_LOG(INFO, tag, infoMsg);
84 OIC_LOG(WARNING, tag, warningMsg);
85 OIC_LOG(ERROR, tag, errorMsg);
86 OIC_LOG(FATAL, tag, fatalMsg);
90 OIC_LOG(DEBUG, tag, multiLineMsg);
97 for (int i = 0; i < (int)(sizeof buffer); i++) {
100 OIC_LOG_BUFFER(DEBUG, tag, buffer, sizeof buffer);
102 // Log buffer, 128 bytes is a good boundary (8 rows of 16 values)
103 uint8_t buffer1[128];
104 for (int i = 0; i < (int)(sizeof buffer1); i++) {
107 OIC_LOG_BUFFER(DEBUG, tag, buffer1, sizeof buffer1);
109 // 1 below 128 byte boundary
110 uint8_t buffer2[127];
111 for (int i = 0; i < (int)(sizeof buffer2); i++) {
114 OIC_LOG_BUFFER(DEBUG, tag, buffer2, sizeof buffer2);
116 // 1 above 128 byte boundary
117 uint8_t buffer3[129];
118 for (int i = 0; i < (int)(sizeof buffer3); i++) {
121 OIC_LOG_BUFFER(DEBUG, tag, buffer3, sizeof buffer3);
125 extern "C" void asyncDoResourcesCallback(OCStackResult result, OCRepresentationHandle representation) {
126 OIC_LOG(INFO, TAG, ("Entering asyncDoResourcesCallback"));
128 EXPECT_EQ(OC_STACK_OK, result);
129 OCResource *resource = (OCResource *)representation;
130 OIC_LOG_V(INFO, TAG, "URI = %s", resource->uri);
131 EXPECT_STREQ(SERVICE_URI, resource->uri);
135 OIC_LOG(INFO, TAG, ("test0"));
136 EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
140 OIC_LOG(INFO, TAG, ("test1"));
141 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
145 OIC_LOG(INFO, TAG, ("test2"));
146 EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
150 OIC_LOG(INFO, TAG, ("test3"));
151 EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
155 OIC_LOG(INFO, TAG, ("test4"));
156 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
157 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
158 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER));
162 OIC_LOG(INFO, TAG, ("test5"));
163 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
164 EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, OC_EXPLICIT_DEVICE_DISCOVERY_URI, 0, 0, asyncDoResourcesCallback), NULL, 0);
165 EXPECT_EQ(OC_STACK_OK, OCUpdateResources(SERVICE_URI));
166 EXPECT_EQ(OC_STACK_OK, OCStop());
170 OIC_LOG(INFO, TAG, ("test6"));
171 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
172 EXPECT_EQ(OC_STACK_OK, OCStop());
173 EXPECT_EQ(OC_STACK_ERROR, OCStop());
177 OIC_LOG(INFO, TAG, ("test7"));
178 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
179 EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, OC_EXPLICIT_DEVICE_DISCOVERY_URI, 0, 0, asyncDoResourcesCallback), NULL, 0);
180 EXPECT_EQ(OC_STACK_INVALID_URI, OCUpdateResources(0));
181 EXPECT_EQ(OC_STACK_OK, OCStop());
186 //The setup function is called once at startup of the sketch
189 // Add your initialization code here
214 // The loop function is called in an endless loop