1 /***********************************************************************************************************************************
2 Test Debug Macros and Routines
3 ***********************************************************************************************************************************/
4 #include "common/log.h"
5
6 #include "common/harnessLog.h"
7 #include "common/macro.h"
8
9 static void
testFunction3(void)10 testFunction3(void)
11 {
12 FUNCTION_TEST_VOID();
13 FUNCTION_TEST_RETURN_VOID();
14 }
15
16 static void
testFunction2(void)17 testFunction2(void)
18 {
19 FUNCTION_LOG_VOID(logLevelTrace);
20
21 testFunction3();
22
23 FUNCTION_LOG_RETURN_VOID();
24 }
25
26 static int
testFunction1(int paramInt,bool paramBool,bool * paramBoolP,bool ** paramBoolPP,void * paramVoidP,double paramDouble,mode_t paramMode)27 testFunction1(
28 int paramInt, bool paramBool, bool *paramBoolP, bool **paramBoolPP, void *paramVoidP, double paramDouble, mode_t paramMode)
29 {
30 FUNCTION_LOG_BEGIN(logLevelDebug);
31 FUNCTION_LOG_PARAM(INT, paramInt);
32 FUNCTION_LOG_PARAM(BOOL, paramBool);
33 FUNCTION_LOG_PARAM_P(BOOL, paramBoolP);
34 FUNCTION_LOG_PARAM_PP(BOOL, paramBoolPP);
35 FUNCTION_LOG_PARAM_P(VOID, paramVoidP);
36 FUNCTION_LOG_PARAM(DOUBLE, paramDouble);
37 FUNCTION_LOG_PARAM(MODE, paramMode);
38 FUNCTION_LOG_END();
39
40 testFunction2();
41
42 FUNCTION_LOG_RETURN(INT, 1);
43 }
44
45 /***********************************************************************************************************************************
46 Test Run
47 ***********************************************************************************************************************************/
48 void
testRun(void)49 testRun(void)
50 {
51 FUNCTION_HARNESS_VOID();
52
53 // *****************************************************************************************************************************
54 if (testBegin("objToLog(), ptrToLog, and strzToLog()"))
55 {
56 char buffer[STACK_TRACE_PARAM_MAX];
57
58 TEST_RESULT_UINT(objToLog(NULL, "Object", buffer, 4), 4, "truncated null");
59 TEST_RESULT_Z(buffer, "nul", " check truncated null");
60
61 TEST_RESULT_UINT(objToLog(NULL, "Object", buffer, sizeof(buffer)), 4, "full null");
62 TEST_RESULT_Z(buffer, "null", " check full null");
63
64 TEST_RESULT_UINT(objToLog((void *)1, "Object", buffer, 4), 8, "truncated object");
65 TEST_RESULT_Z(buffer, "{Ob", " check truncated object");
66
67 TEST_RESULT_UINT(objToLog((void *)1, "Object", buffer, sizeof(buffer)), 8, "full object");
68 TEST_RESULT_Z(buffer, "{Object}", " check full object");
69
70 // -------------------------------------------------------------------------------------------------------------------------
71 TEST_RESULT_UINT(ptrToLog(NULL, "char *", buffer, 4), 4, "truncated null");
72 TEST_RESULT_Z(buffer, "nul", " check truncated null");
73
74 TEST_RESULT_UINT(ptrToLog(NULL, "char *", buffer, sizeof(buffer)), 4, "full null");
75 TEST_RESULT_Z(buffer, "null", " check full null");
76
77 TEST_RESULT_UINT(ptrToLog((void *)1, "char *", buffer, 4), 8, "truncated pointer");
78 TEST_RESULT_Z(buffer, "(ch", " check truncated pointer");
79
80 TEST_RESULT_UINT(ptrToLog((void *)1, "char *", buffer, sizeof(buffer)), 8, "full pointer");
81 TEST_RESULT_Z(buffer, "(char *)", " check full pointer");
82
83 // -------------------------------------------------------------------------------------------------------------------------
84 TEST_RESULT_UINT(strzToLog(NULL, buffer, 4), 4, "truncated null");
85 TEST_RESULT_Z(buffer, "nul", " check truncated null");
86
87 TEST_RESULT_UINT(strzToLog(NULL, buffer, sizeof(buffer)), 4, "full null");
88 TEST_RESULT_Z(buffer, "null", " check full null");
89
90 TEST_RESULT_UINT(strzToLog("test", buffer, 4), 6, "truncated string");
91 TEST_RESULT_Z(buffer, "\"te", " check truncated string");
92
93 TEST_RESULT_UINT(strzToLog("test2", buffer, sizeof(buffer)), 7, "full string");
94 TEST_RESULT_Z(buffer, "\"test2\"", " check full string");
95 }
96
97 // *****************************************************************************************************************************
98 if (testBegin("DEBUG"))
99 {
100 #ifdef DEBUG
101 bool debug = true;
102 #else
103 bool debug = false;
104 #endif
105
106 TEST_RESULT_BOOL(debug, true, "DEBUG is defined");
107 }
108
109 // *****************************************************************************************************************************
110 if (testBegin("FUNCTION_DEBUG() and FUNCTION_LOG_RETURN()"))
111 {
112 harnessLogLevelSet(logLevelTrace);
113 testFunction1(99, false, NULL, NULL, NULL, 1.17, 0755);
114
115 TEST_RESULT_LOG(
116 "P00 DEBUG: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction1: (paramInt: 99, paramBool: false,"
117 " paramBoolP: null, paramBoolPP: null, paramVoidP: null, paramDouble: 1.17, paramMode: 0755)\n"
118 "P00 TRACE: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction2: (void)\n"
119 "P00 TRACE: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction2: => void\n"
120 "P00 DEBUG: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction1: => 1");
121
122 // -------------------------------------------------------------------------------------------------------------------------
123 bool testBool = true;
124 bool *testBoolP = &testBool;
125 bool **testBoolPP = &testBoolP;
126 void *testVoidP = NULL;
127
128 testFunction1(99, false, testBoolP, testBoolPP, testVoidP, 1.17, 0755);
129
130 TEST_RESULT_LOG(
131 "P00 DEBUG: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction1: (paramInt: 99, paramBool: false,"
132 " paramBoolP: *true, paramBoolPP: **true, paramVoidP: null, paramDouble: 1.17, paramMode: 0755)\n"
133 "P00 TRACE: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction2: (void)\n"
134 "P00 TRACE: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction2: => void\n"
135 "P00 DEBUG: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction1: => 1");
136
137 testBoolP = NULL;
138 testVoidP = (void *)1;
139
140 testFunction1(99, false, testBoolP, testBoolPP, testVoidP, 1.17, 0755);
141
142 TEST_RESULT_LOG(
143 "P00 DEBUG: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction1: (paramInt: 99, paramBool: false,"
144 " paramBoolP: null, paramBoolPP: *null, paramVoidP: *void, paramDouble: 1.17, paramMode: 0755)\n"
145 "P00 TRACE: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction2: (void)\n"
146 "P00 TRACE: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction2: => void\n"
147 "P00 DEBUG: " TEST_PGB_PATH "/test/src/module/common/debugOnTest::testFunction1: => 1");
148
149 // -------------------------------------------------------------------------------------------------------------------------
150 harnessLogLevelReset();
151 testFunction1(55, true, NULL, NULL, NULL, 0.99, 0755);
152
153 TEST_RESULT_LOG("");
154 }
155
156 FUNCTION_HARNESS_RETURN_VOID();
157 }
158