Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / resource / csdk / logger / test / android / loggertests.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 extern "C" {
23     #include "logger.h"
24 }
25
26 static const char tag[] = "Android";
27 static const char msg[] = "Android Logger Test";
28
29 static const char debugMsg[] = "this is a DEBUG message";
30 static const char infoMsg[] = "this is a INFO message";
31 static const char warningMsg[] = "this is a WARNING message";
32 static const char errorMsg[] = "this is a ERROR message";
33 static const char fatalMsg[] = "this is a FATAL message";
34
35 static const char multiLineMsg[] = "this is a DEBUG message\non multiple\nlines";
36
37
38 //-----------------------------------------------------------------------------
39 //  Tests
40 //-----------------------------------------------------------------------------
41 static void test0() {
42   OIC_LOG(INFO, tag, msg);
43 }
44
45 static void test1() {
46   OIC_LOG(INFO, 0, msg);
47 }
48
49 static void test2() {
50   OIC_LOG(INFO, tag, 0);
51 }
52
53 static void test3() {
54   OIC_LOG(INFO, 0, 0);
55 }
56
57 static void test4() {
58   OIC_LOG(DEBUG, tag, debugMsg);
59   OIC_LOG(INFO, tag, infoMsg);
60   OIC_LOG(WARNING, tag, warningMsg);
61   OIC_LOG(ERROR, tag, errorMsg);
62   OIC_LOG(FATAL, tag, fatalMsg);
63 }
64
65 static void test5() {
66   OIC_LOG(DEBUG, tag, multiLineMsg);
67 }
68
69
70 static 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     OIC_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     OIC_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     OIC_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     OIC_LOG_BUFFER(DEBUG, tag, buffer3, sizeof buffer3);
98 }
99
100 static void test7() {
101   OIC_LOG_V(DEBUG, tag, "this is a char: %c", 'A');
102   OIC_LOG_V(DEBUG, tag, "this is an integer: %d", 123);
103   OIC_LOG_V(DEBUG, tag, "this is a string: %s", "hello");
104   OIC_LOG_V(DEBUG, tag, "this is a float: %5.2f", 123.45);
105 }
106
107 //-----------------------------------------------------------------------------
108 //  loggertests
109 //-----------------------------------------------------------------------------
110 void loggertests() {
111   OIC_LOG(INFO, tag, "Starting logger test");
112
113   test0();
114   test1();
115   test2();
116   test3();
117   test4();
118   test5();
119   test6();
120   test7();
121 }
122
123