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"
30 #define PCF(str) ((PROGMEM const char *)(F(str)))
32 PROGMEM const char TAG[] = "Arduino";
33 static OCUri SERVICE_URI = "coap://127.0.0.1:5683/";
35 #if 0 // Turn off logger test stuff
36 PROGMEM const char tag[] = "Arduino";
37 PROGMEM const char msg[] = "Arduino Logger Test";
39 PROGMEM const char debugMsg[] = "this is a DEBUG message";
40 PROGMEM const char infoMsg[] = "this is a INFO message";
41 PROGMEM const char warningMsg[] = "this is a WARNING message";
42 PROGMEM const char errorMsg[] = "this is a ERROR message";
43 PROGMEM const char fatalMsg[] = "this is a FATAL message";
45 PROGMEM const char multiLineMsg[] = "this is a DEBUG message\non multiple\nlines";
48 void EXPECT_EQ(int a, int b) {
50 OC_LOG(INFO, TAG, PCF("PASS"));
52 OC_LOG(ERROR, TAG, PCF("FAIL"));
56 void EXPECT_STREQ(const char *a, const char *b) {
57 if (strcmp(a, b) == 0) {
58 OC_LOG(INFO, TAG, PCF("PASS"));
60 OC_LOG(ERROR, TAG, PCF("FAIL"));
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
66 #if 0 // Turn off logger tests
68 OC_LOG(INFO, tag, msg);
84 OC_LOG(DEBUG, tag, debugMsg);
85 OC_LOG(INFO, tag, infoMsg);
86 OC_LOG(WARNING, tag, warningMsg);
87 OC_LOG(ERROR, tag, errorMsg);
88 OC_LOG(FATAL, tag, fatalMsg);
92 OC_LOG(DEBUG, tag, multiLineMsg);
99 for (int i = 0; i < (int)(sizeof buffer); i++) {
102 OC_LOG_BUFFER(DEBUG, tag, buffer, sizeof buffer);
104 // Log buffer, 128 bytes is a good boundary (8 rows of 16 values)
105 uint8_t buffer1[128];
106 for (int i = 0; i < (int)(sizeof buffer1); i++) {
109 OC_LOG_BUFFER(DEBUG, tag, buffer1, sizeof buffer1);
111 // 1 below 128 byte boundary
112 uint8_t buffer2[127];
113 for (int i = 0; i < (int)(sizeof buffer2); i++) {
116 OC_LOG_BUFFER(DEBUG, tag, buffer2, sizeof buffer2);
118 // 1 above 128 byte boundary
119 uint8_t buffer3[129];
120 for (int i = 0; i < (int)(sizeof buffer3); i++) {
123 OC_LOG_BUFFER(DEBUG, tag, buffer3, sizeof buffer3);
127 extern "C" void asyncDoResourcesCallback(OCStackResult result, OCRepresentationHandle representation) {
128 OC_LOG(INFO, TAG, PCF("Entering asyncDoResourcesCallback"));
130 EXPECT_EQ(OC_STACK_OK, result);
131 OCResource *resource = (OCResource *)representation;
132 OC_LOG_V(INFO, TAG, "URI = %s", resource->uri);
133 EXPECT_STREQ(SERVICE_URI, resource->uri);
137 OC_LOG(INFO, TAG, PCF("test0"));
138 EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
142 OC_LOG(INFO, TAG, PCF("test1"));
143 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
147 OC_LOG(INFO, TAG, PCF("test2"));
148 EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
152 OC_LOG(INFO, TAG, PCF("test3"));
153 EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
157 OC_LOG(INFO, TAG, PCF("test4"));
158 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
159 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
160 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER));
164 OC_LOG(INFO, TAG, PCF("test5"));
165 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
166 EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, OC_EXPLICIT_DEVICE_DISCOVERY_URI, 0, 0, asyncDoResourcesCallback), NULL, 0);
167 EXPECT_EQ(OC_STACK_OK, OCUpdateResources(SERVICE_URI));
168 EXPECT_EQ(OC_STACK_OK, OCStop());
172 OC_LOG(INFO, TAG, PCF("test6"));
173 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
174 EXPECT_EQ(OC_STACK_OK, OCStop());
175 EXPECT_EQ(OC_STACK_ERROR, OCStop());
179 OC_LOG(INFO, TAG, PCF("test7"));
180 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
181 EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, OC_EXPLICIT_DEVICE_DISCOVERY_URI, 0, 0, asyncDoResourcesCallback), NULL, 0);
182 EXPECT_EQ(OC_STACK_INVALID_URI, OCUpdateResources(0));
183 EXPECT_EQ(OC_STACK_OK, OCStop());
188 //The setup function is called once at startup of the sketch
191 // Add your initialization code here
216 // The loop function is called in an endless loop