Add safe connect, fix possible seg fault in RTC
[ric-plt/lib/rmr.git] / test / logging_test.c
1 // : vim ts=4 sw=4 noet :
2 /*
3 ==================================================================================
4             Copyright (c) 2019-2020 Nokia
5             Copyright (c) 2018-2020 AT&T Intellectual Property.
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 /*
23         Mnemonic:       symtab_test.c
24         Abstract:       This is the unit test module that will drive tests against
25                                 the symbol table portion of RMr.  Run with:
26                                         ksh unit_test.ksh symtab_test.c
27         Date:           1 April 2019
28         Author:         E. Scott Daniels
29 */
30
31 #define NO_DUMMY_RMR 1                  // no dummy rmr functions; we don't pull in rmr.h or agnostic.h
32 #define NO_EMULATION
33
34 #include "rmr_logging.h"
35 #include "logging.c"
36 #include "test_support.c"
37
38 /*
39         Logging can be difficult to verify as stderr needs to be captured and examined.
40         We will verify internally what we can, and drive logging functions for coverage.
41 */
42 int main( ) {
43         int llevel = 99;
44         int errors = 0;
45
46         setenv( "RMR_HR_LOG", "1", 1 );                 // drive for coverage in init
47         setenv( "RMR_LOG_VLEVEL", "90", 1 );    // force test for out of range during init
48
49         rmr_vlog( RMR_VL_CRIT, "debug message should not be written\n" );               // force coverage with init call 
50
51         llevel = rmr_vlog_init( );
52         errors += fail_if_equal( llevel, 99, "llevel was not reset by vlog init" );
53         errors += fail_if_equal( llevel, 90, "vlog init did not catch out of range vlog" );
54
55         llevel = 99;
56         setenv( "RMR_LOG_VLEVEL", "-10", 1 );   // force test for out of range during init
57         llevel = rmr_vlog_init( );
58         errors += fail_if_equal( llevel, 99, "neg llevel was not reset by vlog init" );
59         errors += fail_if_equal( llevel, -10, "vlog init did not catch out of range (neg) vlog" );
60
61         rmr_set_vlevel( 2 );
62         
63         rmr_vlog( RMR_VL_DEBUG, "debug message should not be written\n" );
64         rmr_vlog( RMR_VL_INFO, "info message should not be written\n" );
65         rmr_vlog( RMR_VL_WARN, "warn message should not be written\n" );
66         rmr_vlog( RMR_VL_ERR, "error message should be written\n" );
67         rmr_vlog( RMR_VL_CRIT, "crit message should be written\n" );
68         
69         rmr_set_vlevel( 5 );
70         rmr_vlog( RMR_VL_DEBUG, "debug message should be written\n" );
71         rmr_vlog( RMR_VL_INFO, "info message should be written\n" );
72         rmr_vlog( RMR_VL_WARN, "warn message should be written\n" );
73         rmr_vlog( RMR_VL_ERR, "error message should be written\n" );
74         rmr_vlog( RMR_VL_CRIT, "crit message should be written\n" );
75         
76         rmr_set_vlevel( 0 );
77         rmr_vlog( RMR_VL_DEBUG, "debug message should not be written\n" );
78         rmr_vlog( RMR_VL_INFO, "info message should not be written\n" );
79         rmr_vlog( RMR_VL_WARN, "warn message should not be written\n" );
80         rmr_vlog( RMR_VL_ERR, "error message should not be written\n" );
81         rmr_vlog( RMR_VL_CRIT, "crit message should not be written\n" );
82
83         rmr_set_vlevel( 1 );
84         rmr_vlog_force( RMR_VL_DEBUG, "debug forced message should be written\n" );
85         rmr_vlog_force( RMR_VL_INFO, "info forced message should be written\n" );
86         rmr_vlog_force( RMR_VL_WARN, "warn forced message should be written\n" );
87         rmr_vlog_force( RMR_VL_ERR, "error forced message should be written\n" );
88         rmr_vlog_force( RMR_VL_CRIT, "crit forced message should be written\n" );
89
90
91         rmr_vlog( -1, "out of range message might be written\n" );                      // drive range checks
92         rmr_vlog( 10, "out of range message should not be written\n" );
93
94         rmr_vlog_force( -1, "out of range message might be written\n" );                        // drive range checks
95         rmr_vlog_force( 10, "out of range message should not be written\n" );
96
97         return errors > 0;
98 }