1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Do not remove the include below
8 #include "ArduinoStackTest.h"
12 #include "ocstackinternal.h"
15 #define PCF(str) ((const prog_char*)(F(str)))
17 const prog_char TAG[] PROGMEM = "Arduino";
18 static OCUri SERVICE_URI = "coap://127.0.0.1:5683/";
20 #if 0 // Turn off logger test stuff
21 const prog_char tag[] PROGMEM = "Arduino";
22 const prog_char msg[] PROGMEM = "Arduino Logger Test";
24 const prog_char debugMsg[] PROGMEM = "this is a DEBUG message";
25 const prog_char infoMsg[] PROGMEM = "this is a INFO message";
26 const prog_char warningMsg[] PROGMEM = "this is a WARNING message";
27 const prog_char errorMsg[] PROGMEM = "this is a ERROR message";
28 const prog_char fatalMsg[] PROGMEM = "this is a FATAL message";
30 const prog_char multiLineMsg[] PROGMEM = "this is a DEBUG message\non multiple\nlines";
33 void EXPECT_EQ(int a, int b) {
35 OC_LOG(INFO, TAG, PCF("PASS"));
37 OC_LOG(ERROR, TAG, PCF("FAIL"));
41 void EXPECT_STREQ(const char *a, const char *b) {
42 if (strcmp(a, b) == 0) {
43 OC_LOG(INFO, TAG, "PASS");
45 OC_LOG(ERROR, TAG, "FAIL");
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 #if 0 // Turn off logger tests
53 OC_LOG(INFO, tag, msg);
69 OC_LOG(DEBUG, tag, debugMsg);
70 OC_LOG(INFO, tag, infoMsg);
71 OC_LOG(WARNING, tag, warningMsg);
72 OC_LOG(ERROR, tag, errorMsg);
73 OC_LOG(FATAL, tag, fatalMsg);
77 OC_LOG(DEBUG, tag, multiLineMsg);
84 for (int i = 0; i < (int)(sizeof buffer); i++) {
87 OC_LOG_BUFFER(DEBUG, tag, buffer, sizeof buffer);
89 // Log buffer, 128 bytes is a good boundary (8 rows of 16 values)
91 for (int i = 0; i < (int)(sizeof buffer1); i++) {
94 OC_LOG_BUFFER(DEBUG, tag, buffer1, sizeof buffer1);
96 // 1 below 128 byte boundary
98 for (int i = 0; i < (int)(sizeof buffer2); i++) {
101 OC_LOG_BUFFER(DEBUG, tag, buffer2, sizeof buffer2);
103 // 1 above 128 byte boundary
104 uint8_t buffer3[129];
105 for (int i = 0; i < (int)(sizeof buffer3); i++) {
108 OC_LOG_BUFFER(DEBUG, tag, buffer3, sizeof buffer3);
112 extern "C" void asyncDoResourcesCallback(OCStackResult result, OCRepresentationHandle representation) {
113 OC_LOG(INFO, TAG, PCF("Entering asyncDoResourcesCallback"));
115 EXPECT_EQ(OC_STACK_OK, result);
116 OCResource *resource = (OCResource *)representation;
117 OC_LOG_V(INFO, TAG, "URI = %s", resource->uri);
118 EXPECT_STREQ(SERVICE_URI, resource->uri);
122 OC_LOG(INFO, TAG, PCF("test0"));
123 EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
127 OC_LOG(INFO, TAG, PCF("test1"));
128 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
132 OC_LOG(INFO, TAG, PCF("test2"));
133 EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
137 OC_LOG(INFO, TAG, PCF("test3"));
138 EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
142 OC_LOG(INFO, TAG, PCF("test4"));
143 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
144 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
145 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER));
149 OC_LOG(INFO, TAG, PCF("test5"));
150 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
151 EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, OC_EXPLICIT_DEVICE_DISCOVERY_URI, 0, 0, asyncDoResourcesCallback));
152 EXPECT_EQ(OC_STACK_OK, OCUpdateResources(SERVICE_URI));
153 EXPECT_EQ(OC_STACK_OK, OCStop());
157 OC_LOG(INFO, TAG, PCF("test6"));
158 EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
159 EXPECT_EQ(OC_STACK_OK, OCStop());
160 EXPECT_EQ(OC_STACK_ERROR, OCStop());
164 OC_LOG(INFO, TAG, PCF("test7"));
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));
167 EXPECT_EQ(OC_STACK_INVALID_URI, OCUpdateResources(0));
168 EXPECT_EQ(OC_STACK_OK, OCStop());
173 //The setup function is called once at startup of the sketch
176 // Add your initialization code here
201 // The loop function is called in an endless loop