Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / logger / test / arduino / ArduinoLoggerTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6
7 // Do not remove the include below
8 #include "ArduinoLoggerTest.h"
9 #include "logger.h"
10
11 const prog_char tag[] PROGMEM = "Arduino";
12 const prog_char msg[] PROGMEM = "Arduino Logger Test";
13
14 const prog_char debugMsg[] PROGMEM = "this is a DEBUG message";
15 const prog_char infoMsg[] PROGMEM = "this is a INFO message";
16 const prog_char warningMsg[] PROGMEM = "this is a WARNING message";
17 const prog_char errorMsg[] PROGMEM = "this is a ERROR message";
18 const prog_char fatalMsg[] PROGMEM = "this is a FATAL message";
19
20 const prog_char multiLineMsg[] PROGMEM = "this is a DEBUG message\non multiple\nlines";
21
22
23 //-----------------------------------------------------------------------------
24 //  Tests
25 //-----------------------------------------------------------------------------
26 void test0() {
27     OC_LOG(INFO, tag, msg);
28 }
29
30 void test1() {
31     OC_LOG(INFO, 0, msg);
32 }
33
34 void test2() {
35     OC_LOG(INFO, tag, 0);
36 }
37
38 void test3() {
39     OC_LOG(INFO, 0, 0);
40 }
41
42 void test4() {
43     OC_LOG(DEBUG, tag, debugMsg);
44     OC_LOG(INFO, tag, infoMsg);
45     OC_LOG(WARNING, tag, warningMsg);
46     OC_LOG(ERROR, tag, errorMsg);
47     OC_LOG(FATAL, tag, fatalMsg);
48 }
49
50 void test5() {
51     OC_LOG(DEBUG, tag, multiLineMsg);
52 }
53
54
55 void test6() {
56     // Log buffer
57     uint8_t buffer[50];
58     for (int i = 0; i < (int)(sizeof buffer); i++) {
59         buffer[i] = i;
60     }
61     OC_LOG_BUFFER(DEBUG, tag, buffer, sizeof buffer);
62
63     // Log buffer, 128 bytes is a good boundary (8 rows of 16 values)
64     uint8_t buffer1[128];
65     for (int i = 0; i < (int)(sizeof buffer1); i++) {
66         buffer1[i] = i;
67     }
68     OC_LOG_BUFFER(DEBUG, tag, buffer1, sizeof buffer1);
69
70     // 1 below 128 byte boundary
71     uint8_t buffer2[127];
72     for (int i = 0; i < (int)(sizeof buffer2); i++) {
73         buffer2[i] = i;
74     }
75     OC_LOG_BUFFER(DEBUG, tag, buffer2, sizeof buffer2);
76
77     // 1 above 128 byte boundary
78     uint8_t buffer3[129];
79     for (int i = 0; i < (int)(sizeof buffer3); i++) {
80         buffer3[i] = i;
81     }
82     OC_LOG_BUFFER(DEBUG, tag, buffer3, sizeof buffer3);
83 }
84
85 //The setup function is called once at startup of the sketch
86 void setup()
87 {
88     // Add your initialization code here
89     OC_LOG_INIT();
90
91     test0();
92     delay(2000);
93     test1();
94     delay(2000);
95     test2();
96     delay(2000);
97     test3();
98     delay(2000);
99     test4();
100     delay(2000);
101     test5();
102     delay(2000);
103     test6();
104     delay(2000);
105 }
106
107 // The loop function is called in an endless loop
108 void loop()
109 {
110     delay(2000);
111 }