Merge branch 'security-CKM' into 'master'
[platform/upstream/iotivity.git] / resource / csdk / logger / test / arduino / ArduinoLoggerTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21
22 // Do not remove the include below
23 #include "ArduinoLoggerTest.h"
24 #include "logger.h"
25
26 #define tag "Arduino"
27 #define msg "Arduino Logger Test"
28
29 #define debugMsg "this is a DEBUG message"
30 #define infoMsg "this is a INFO message"
31 #define warningMsg "this is a WARNING message"
32 #define errorMsg "this is a ERROR message"
33 #define fatalMsg "this is a FATAL message"
34
35 #define multiLineMsg "this is a DEBUG message\non multiple\nlines"
36
37
38 //-----------------------------------------------------------------------------
39 //  Tests
40 //-----------------------------------------------------------------------------
41 void test0() {
42     OC_LOG(INFO, tag, msg);
43 }
44
45 void test1() {
46     OC_LOG(INFO, 0, msg);
47 }
48
49 void test2() {
50     OC_LOG(INFO, tag, 0);
51 }
52
53 void test3() {
54     OC_LOG(INFO, 0, 0);
55 }
56
57 void test4() {
58     OC_LOG(DEBUG, tag, debugMsg);
59     OC_LOG(INFO, tag, infoMsg);
60     OC_LOG(WARNING, tag, warningMsg);
61     OC_LOG(ERROR, tag, errorMsg);
62     OC_LOG(FATAL, tag, fatalMsg);
63 }
64
65 void test5() {
66     OC_LOG(DEBUG, tag, multiLineMsg);
67 }
68
69
70 void test6() {
71     // Log buffer
72     uint8_t buffer[50];
73     for (int i = 0; i < (int)(sizeof buffer); i++) {
74         buffer[i] = i;
75     }
76     OC_LOG_BUFFER(DEBUG, tag, buffer, sizeof buffer);
77
78     // Log buffer, 128 bytes is a good boundary (8 rows of 16 values)
79     uint8_t buffer1[128];
80     for (int i = 0; i < (int)(sizeof buffer1); i++) {
81         buffer1[i] = i;
82     }
83     OC_LOG_BUFFER(DEBUG, tag, buffer1, sizeof buffer1);
84
85     // 1 below 128 byte boundary
86     uint8_t buffer2[127];
87     for (int i = 0; i < (int)(sizeof buffer2); i++) {
88         buffer2[i] = i;
89     }
90     OC_LOG_BUFFER(DEBUG, tag, buffer2, sizeof buffer2);
91
92     // 1 above 128 byte boundary
93     uint8_t buffer3[129];
94     for (int i = 0; i < (int)(sizeof buffer3); i++) {
95         buffer3[i] = i;
96     }
97     OC_LOG_BUFFER(DEBUG, tag, buffer3, sizeof buffer3);
98 }
99
100 //The setup function is called once at startup of the sketch
101 void setup()
102 {
103     // Add your initialization code here
104     OC_LOG_INIT();
105
106     test0();
107     delay(2000);
108     test1();
109     delay(2000);
110     test2();
111     delay(2000);
112     test3();
113     delay(2000);
114     test4();
115     delay(2000);
116     test5();
117     delay(2000);
118     test6();
119     delay(2000);
120 }
121
122 // The loop function is called in an endless loop
123 void loop()
124 {
125     delay(2000);
126 }