Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / logger / test / android / loggertests.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6
7 extern "C" {
8     #include "logger.h"
9 }
10
11 static const char tag[] = "Android";
12 static const char msg[] = "Android Logger Test";
13
14 static const char debugMsg[] = "this is a DEBUG message";
15 static const char infoMsg[] = "this is a INFO message";
16 static const char warningMsg[] = "this is a WARNING message";
17 static const char errorMsg[] = "this is a ERROR message";
18 static const char fatalMsg[] = "this is a FATAL message";
19
20 static const char multiLineMsg[] = "this is a DEBUG message\non multiple\nlines";
21
22
23 //-----------------------------------------------------------------------------
24 //  Tests
25 //-----------------------------------------------------------------------------
26 static void test0() {
27   OC_LOG(INFO, tag, msg);
28 }
29
30 static void test1() {
31   OC_LOG(INFO, 0, msg);
32 }
33
34 static void test2() {
35   OC_LOG(INFO, tag, 0);
36 }
37
38 static void test3() {
39   OC_LOG(INFO, 0, 0);
40 }
41
42 static 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 static void test5() {
51   OC_LOG(DEBUG, tag, multiLineMsg);
52 }
53
54
55 static 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 static void test7() {
86   OC_LOG_V(DEBUG, tag, "this is a char: %c", 'A');
87   OC_LOG_V(DEBUG, tag, "this is an integer: %d", 123);
88   OC_LOG_V(DEBUG, tag, "this is a string: %s", "hello");
89   OC_LOG_V(DEBUG, tag, "this is a float: %5.2f", 123.45);
90 }
91
92 //-----------------------------------------------------------------------------
93 //  loggertests
94 //-----------------------------------------------------------------------------
95 void loggertests() {
96   OC_LOG(INFO, tag, "Starting logger test");
97
98   test0();
99   test1();
100   test2();
101   test3();
102   test4();
103   test5();
104   test6();
105   test7();
106 }
107
108