55#include "macro.h"
66#include "string-util.h"
77#include "syslog-util.h"
8+ #include "tests.h"
89
9- static void test_syslog_parse_identifier (const char * str ,
10+ static void test_syslog_parse_identifier_one (const char * str ,
1011 const char * ident , const char * pid , const char * rest , int ret ) {
1112 const char * buf = str ;
1213 _cleanup_free_ char * ident2 = NULL , * pid2 = NULL ;
@@ -20,40 +21,50 @@ static void test_syslog_parse_identifier(const char *str,
2021 assert_se (streq (buf , rest ));
2122}
2223
23- static void test_syslog_parse_priority (const char * str , int priority , int ret ) {
24- const char * buf = str ;
24+ static void test_syslog_parse_priority_one (const char * str , bool with_facility , int priority , int ret ) {
2525 int priority2 = 0 , ret2 ;
2626
27- ret2 = syslog_parse_priority (& buf , & priority2 , false );
27+ ret2 = syslog_parse_priority (& str , & priority2 , with_facility );
2828
2929 assert_se (ret == ret2 );
3030 if (ret2 == 1 )
3131 assert_se (priority == priority2 );
3232}
3333
34- int main (void ) {
35- test_syslog_parse_identifier ("pidu[111]: xxx" , "pidu" , "111" , "xxx" , 11 );
36- test_syslog_parse_identifier ("pidu: xxx" , "pidu" , NULL , "xxx" , 6 );
37- test_syslog_parse_identifier ("pidu: xxx" , "pidu" , NULL , " xxx" , 6 );
38- test_syslog_parse_identifier ("pidu xxx" , NULL , NULL , "pidu xxx" , 0 );
39- test_syslog_parse_identifier (" pidu xxx" , NULL , NULL , " pidu xxx" , 0 );
40- test_syslog_parse_identifier ("" , NULL , NULL , "" , 0 );
41- test_syslog_parse_identifier (" " , NULL , NULL , " " , 0 );
42- test_syslog_parse_identifier (":" , "" , NULL , "" , 1 );
43- test_syslog_parse_identifier (": " , "" , NULL , " " , 2 );
44- test_syslog_parse_identifier (" :" , "" , NULL , "" , 2 );
45- test_syslog_parse_identifier (" pidu:" , "pidu" , NULL , "" , 8 );
46- test_syslog_parse_identifier ("pidu:" , "pidu" , NULL , "" , 5 );
47- test_syslog_parse_identifier ("pidu: " , "pidu" , NULL , "" , 6 );
48- test_syslog_parse_identifier ("pidu : " , NULL , NULL , "pidu : " , 0 );
49-
50- test_syslog_parse_priority ("<>" , 0 , 0 );
51- test_syslog_parse_priority ("<>aaa" , 0 , 0 );
52- test_syslog_parse_priority ("<aaaa>" , 0 , 0 );
53- test_syslog_parse_priority ("<aaaa>aaa" , 0 , 0 );
54- test_syslog_parse_priority (" <aaaa>" , 0 , 0 );
55- test_syslog_parse_priority (" <aaaa>aaa" , 0 , 0 );
56- /* TODO: add test cases of valid priorities */
57-
58- return 0 ;
34+ TEST (syslog_parse_identifier ) {
35+ test_syslog_parse_identifier_one ("pidu[111]: xxx" , "pidu" , "111" , "xxx" , 11 );
36+ test_syslog_parse_identifier_one ("pidu: xxx" , "pidu" , NULL , "xxx" , 6 );
37+ test_syslog_parse_identifier_one ("pidu: xxx" , "pidu" , NULL , " xxx" , 6 );
38+ test_syslog_parse_identifier_one ("pidu xxx" , NULL , NULL , "pidu xxx" , 0 );
39+ test_syslog_parse_identifier_one (" pidu xxx" , NULL , NULL , " pidu xxx" , 0 );
40+ test_syslog_parse_identifier_one ("" , NULL , NULL , "" , 0 );
41+ test_syslog_parse_identifier_one (" " , NULL , NULL , " " , 0 );
42+ test_syslog_parse_identifier_one (":" , "" , NULL , "" , 1 );
43+ test_syslog_parse_identifier_one (": " , "" , NULL , " " , 2 );
44+ test_syslog_parse_identifier_one (" :" , "" , NULL , "" , 2 );
45+ test_syslog_parse_identifier_one (" pidu:" , "pidu" , NULL , "" , 8 );
46+ test_syslog_parse_identifier_one ("pidu:" , "pidu" , NULL , "" , 5 );
47+ test_syslog_parse_identifier_one ("pidu: " , "pidu" , NULL , "" , 6 );
48+ test_syslog_parse_identifier_one ("pidu : " , NULL , NULL , "pidu : " , 0 );
49+ }
50+
51+ TEST (syslog_parse_priority ) {
52+ test_syslog_parse_priority_one ("" , false, 0 , 0 );
53+ test_syslog_parse_priority_one ("<>" , false, 0 , 0 );
54+ test_syslog_parse_priority_one ("<>aaa" , false, 0 , 0 );
55+ test_syslog_parse_priority_one ("<aaaa>" , false, 0 , 0 );
56+ test_syslog_parse_priority_one ("<aaaa>aaa" , false, 0 , 0 );
57+ test_syslog_parse_priority_one (" <aaaa>" , false, 0 , 0 );
58+ test_syslog_parse_priority_one (" <aaaa>aaa" , false, 0 , 0 );
59+ test_syslog_parse_priority_one (" <aaaa>aaa" , false, 0 , 0 );
60+ test_syslog_parse_priority_one (" <1>" , false, 0 , 0 );
61+ test_syslog_parse_priority_one ("<1>" , false, 1 , 1 );
62+ test_syslog_parse_priority_one ("<7>" , false, 7 , 1 );
63+ test_syslog_parse_priority_one ("<8>" , false, 0 , 0 );
64+ test_syslog_parse_priority_one ("<9>" , true, 9 , 1 );
65+ test_syslog_parse_priority_one ("<22>" , true, 22 , 1 );
66+ test_syslog_parse_priority_one ("<111>" , false, 0 , 0 );
67+ test_syslog_parse_priority_one ("<111>" , true, 111 , 1 );
5968}
69+
70+ DEFINE_TEST_MAIN (LOG_INFO );
0 commit comments