~ubuntu-branches/ubuntu/trusty/syslog-ng/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/unit/test_filters.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2010-03-14 12:57:49 UTC
  • mfrom: (1.3.1 upstream) (12.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100314125749-m3ats648sp2urg0f
Tags: 3.0.5-1
New upstream release, new maintainer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include "syslog-names.h"
3
3
#include "filter.h"
4
4
#include "logmsg.h"
 
5
#include "apphook.h"
5
6
 
6
7
#include <time.h>
7
8
#include <string.h>
9
10
#include <stdio.h>
10
11
 
11
12
int debug = 1;
 
13
GSockAddr *sender_saddr;
12
14
 
13
15
static gint
14
16
facility_bits(gchar *fac)
15
17
{
16
 
  return 1 << syslog_name_lookup_facility_by_name(fac);
 
18
  return 1 << (syslog_name_lookup_facility_by_name(fac) >> 3);
17
19
}
18
20
 
19
21
static gint
32
34
  return syslog_make_range(r1, r2);
33
35
}
34
36
 
 
37
FilterExprNode *
 
38
create_posix_regexp_filter(gint field, gchar* regexp, gint flags)
 
39
{
 
40
  FilterRE *f;
 
41
  f = (FilterRE*)filter_re_new((gchar *) GINT_TO_POINTER(field));
 
42
  filter_re_set_matcher(f, log_matcher_posix_re_new());
 
43
  filter_re_set_flags(f, flags);
 
44
  if (filter_re_set_regexp(f, regexp))
 
45
    return &f->super;
 
46
  else 
 
47
    return NULL;
 
48
}
 
49
 
 
50
FilterExprNode *
 
51
create_posix_regexp_match(gchar* regexp, gint flags)
 
52
{
 
53
  FilterRE *f;
 
54
  f = (FilterRE*)filter_match_new();
 
55
  filter_re_set_matcher(f, log_matcher_posix_re_new());
 
56
  filter_re_set_flags(f, flags);
 
57
  if (filter_re_set_regexp(f, regexp))
 
58
    return &f->super;
 
59
  else 
 
60
    return NULL;
 
61
}
 
62
 
 
63
#if ENABLE_PCRE
 
64
FilterExprNode *
 
65
create_pcre_regexp_filter(gint field, gchar* regexp, gint flags)
 
66
{
 
67
  FilterRE *f;
 
68
  f = (FilterRE*)filter_re_new((gchar *) GINT_TO_POINTER(field));
 
69
  filter_re_set_matcher(f, log_matcher_pcre_re_new());
 
70
  filter_re_set_flags(f, flags);
 
71
  if (filter_re_set_regexp(f, regexp))
 
72
    return &f->super;
 
73
  else 
 
74
    return NULL;
 
75
}
 
76
 
 
77
FilterExprNode *
 
78
create_pcre_regexp_match(gchar* regexp, gint flags)
 
79
{
 
80
  FilterRE *f;
 
81
  f = (FilterRE*)filter_match_new();
 
82
  filter_re_set_matcher(f, log_matcher_pcre_re_new());
 
83
  filter_re_set_flags(f, flags);
 
84
  if (filter_re_set_regexp(f, regexp))
 
85
    return &f->super;
 
86
  else 
 
87
    return NULL;
 
88
}
 
89
#endif
 
90
 
35
91
void
36
92
testcase(gchar *msg, 
37
93
         gint parse_flags,
43
99
  static gint testno = 0;
44
100
  
45
101
  testno++;
46
 
  logmsg = log_msg_new(msg, strlen(msg), NULL, parse_flags, NULL);
 
102
  logmsg = log_msg_new(msg, strlen(msg), NULL, parse_flags, NULL, -1, 0xFFFF);
 
103
  logmsg->saddr = g_sockaddr_ref(sender_saddr);
 
104
  
 
105
  res = filter_expr_eval(f, logmsg);
 
106
  if (res != expected_result)
 
107
    {
 
108
      fprintf(stderr, "Filter test failed; num='%d', msg='%s'\n", testno, msg);
 
109
      exit(1);
 
110
    }
 
111
    
 
112
  f->comp = 1;
 
113
  res = filter_expr_eval(f, logmsg);
 
114
  if (res != !expected_result)
 
115
    {
 
116
      fprintf(stderr, "Filter test failed (negated); num='%d', msg='%s'\n", testno, msg);
 
117
      exit(1);
 
118
    }
 
119
  
 
120
  log_msg_unref(logmsg);
 
121
  filter_expr_free(f);
 
122
}
 
123
 
 
124
void
 
125
testcase_with_backref_chk(gchar *msg, 
 
126
         gint parse_flags,
 
127
         FilterExprNode *f,
 
128
         gboolean expected_result, 
 
129
         const gchar *name,
 
130
         const gchar *value
 
131
         )
 
132
{
 
133
  LogMessage *logmsg;
 
134
  gchar *value_msg;
 
135
  gboolean res;
 
136
  static gint testno = 0;
 
137
  gssize length;
 
138
  
 
139
  testno++;
 
140
  logmsg = log_msg_new(msg, strlen(msg), NULL, parse_flags, NULL, -1, 0xFFFF);
47
141
  logmsg->saddr = g_sockaddr_inet_new("10.10.0.1", 5000);
48
142
  
 
143
  /* NOTE: we test how our filters cope with non-zero terminated values. We don't change message_len, only the value */
 
144
  LOG_MESSAGE_WRITABLE_FIELD(logmsg->message) = g_realloc(logmsg->message, logmsg->message_len + 10);
 
145
  memset(logmsg->message + logmsg->message_len, 'A', 10);
 
146
  
49
147
  res = filter_expr_eval(f, logmsg);
50
148
  if (res != expected_result)
51
149
    {
60
158
      fprintf(stderr, "Filter test failed (negated); num='%d', msg='%s'\n", testno, msg);
61
159
      exit(1);
62
160
    }
63
 
  
 
161
  value_msg = log_msg_get_value(logmsg, name, &length);
 
162
 
 
163
  if(value == NULL || value[0] == 0) 
 
164
     {  
 
165
       if (value_msg != NULL && value_msg[0] != 0)
 
166
         {
 
167
           fprintf(stderr, "Filter test failed (NULL value chk); num='%d', msg='%s', expected_value='%s', value_in_msg='%s'", testno, msg, value, value_msg);
 
168
           exit(1);
 
169
         }
 
170
      }
 
171
  else 
 
172
    { 
 
173
      if (strncmp(value_msg, value, length) != 0)
 
174
        {
 
175
          fprintf(stderr, "Filter test failed (value chk); num='%d', msg='%s', expected_value='%s', value_in_msg='%s'", testno, msg, value, value_msg);
 
176
          exit(1);
 
177
        }
 
178
    }
64
179
  log_msg_unref(logmsg);
65
180
  filter_expr_free(f);
66
181
}
67
182
 
 
183
 
68
184
#define TEST_ASSERT(cond)                                       \
69
185
  if (!(cond))                                                  \
70
186
    {                                                           \
77
193
{
78
194
  gint i;
79
195
  
80
 
  msg_init(1);
 
196
  app_startup();
81
197
  
82
198
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, filter_facility_new(facility_bits("user")), 1);
83
199
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, filter_facility_new(facility_bits("daemon")), 0);
94
210
  testcase("<32> openvpn[2499]: PTHREAD support initialized", 0, filter_facility_new(facility_bits("local1")), 0);
95
211
  testcase("<32> openvpn[2499]: PTHREAD support initialized", 0, filter_facility_new(facility_bits("auth")), 1);
96
212
  testcase("<32> openvpn[2499]: PTHREAD support initialized", 0, filter_facility_new(0x80000000 | (LOG_AUTH >> 3)), 1);
 
213
#ifdef LOG_AUTHPRIV
97
214
  testcase("<80> openvpn[2499]: PTHREAD support initialized", 0, filter_facility_new(facility_bits("authpriv")), 1);
98
 
#ifdef LOG_AUTHPRIV
99
215
  testcase("<80> openvpn[2499]: PTHREAD support initialized", 0, filter_facility_new(0x80000000 | (LOG_AUTHPRIV >> 3)), 1);
100
216
#endif
101
217
 
132
248
      testcase("<7> openvpn[2499]: PTHREAD support initialized", 0, filter_level_new(level_bits("debug")), 1);
133
249
    }
134
250
    
135
 
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, filter_prog_new("^openvpn$"), 1);
136
 
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, filter_prog_new("^open$"), 0);
137
 
  fprintf(stderr, "One \"invalid regular expression\" message is to be expected\n");
138
 
  TEST_ASSERT(filter_prog_new("((") == NULL);
139
 
 
140
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_host_new("^host$"), 1);
141
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_host_new("^hos$"), 0);
142
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_host_new("pthread"), 0);
143
 
  fprintf(stderr, "One \"invalid regular expressions\" message is to be expected\n");
144
 
  TEST_ASSERT(filter_host_new("((") == NULL);
145
 
 
146
 
  fprintf(stderr, "One \"invalid regular expressions\" message is to be expected\n");
147
 
  TEST_ASSERT(filter_host_new("(?iana") == NULL);
148
 
 
149
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_match_new(" PTHREAD "), 1);
150
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_match_new("^PTHREAD$"), 0);
151
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_match_new("(?i)pthread"), 1);
152
 
  fprintf(stderr, "One \"invalid regular expression\" message is to be expected\n");
153
 
  TEST_ASSERT(filter_match_new("((") == NULL);
154
 
 
 
251
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_PROGRAM, "^openvpn$", 0), 1);
 
252
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_PROGRAM, "^open$", 0), 0);
 
253
  fprintf(stderr, "One \"invalid regular expression\" message is to be expected\n");
 
254
  TEST_ASSERT(create_posix_regexp_filter(LM_F_PROGRAM, "((", 0) == NULL);
 
255
  
 
256
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_HOST, "^host$", 0), 1);
 
257
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_HOST, "^hos$", 0), 0);
 
258
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_HOST, "pthread", 0), 0);
 
259
  fprintf(stderr, "One \"invalid regular expressions\" message is to be expected\n");
 
260
  TEST_ASSERT(create_posix_regexp_filter(LM_F_HOST, "((", 0) == NULL);
 
261
  
 
262
 
 
263
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_MESSAGE, "^PTHREAD ", 0), 1);
 
264
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_MESSAGE, "PTHREAD s", 0), 1);
 
265
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_MESSAGE, "^PTHREAD$", 0), 0);
 
266
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_filter(LM_F_MESSAGE, "(?i)pthread", 0), 1);
 
267
  
 
268
 
 
269
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_match(" PTHREAD ", 0), 1);
 
270
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_match("^openvpn\\[2499\\]: PTHREAD", 0), 1);
 
271
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_match("^PTHREAD$", 0), 0);
 
272
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_match("(?i)pthread", 0), 1);
 
273
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_posix_regexp_match("pthread", LMF_ICASE), 1);
 
274
  
 
275
 
 
276
  fprintf(stderr, "One \"invalid regular expression\" message is to be expected\n");
 
277
  TEST_ASSERT(create_posix_regexp_match("((", 0) == NULL);
 
278
  
 
279
 
 
280
  sender_saddr = g_sockaddr_inet_new("10.10.0.1", 5000);
155
281
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_netmask_new("10.10.0.0/16"), 1);
156
282
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_netmask_new("10.10.0.0/24"), 1);
157
283
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_netmask_new("10.10.10.0/24"), 0);
158
284
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_netmask_new("0.0.10.10/24"), 0);
159
 
 
160
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(filter_match_new(" PTHREAD "), filter_match_new("PTHREAD")), 1);
161
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(filter_match_new(" PTHREAD "), filter_match_new("^PTHREAD$")), 1);
162
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(filter_match_new("^PTHREAD$"), filter_match_new(" PTHREAD ")), 1);
163
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(filter_match_new(" PAD "), filter_match_new("^PTHREAD$")), 0);
164
 
 
165
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(filter_match_new(" PTHREAD "), filter_match_new("PTHREAD")), 1);
166
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(filter_match_new(" PTHREAD "), filter_match_new("^PTHREAD$")), 0);
167
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(filter_match_new("^PTHREAD$"), filter_match_new(" PTHREAD ")), 0);
168
 
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(filter_match_new(" PAD "), filter_match_new("^PTHREAD$")), 0);
169
 
 
 
285
  g_sockaddr_unref(sender_saddr);
 
286
  sender_saddr = NULL;
 
287
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_netmask_new("127.0.0.1/32"), 1);
 
288
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, filter_netmask_new("127.0.0.2/32"), 0);
 
289
 
 
290
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_posix_regexp_match(" PTHREAD ", 0), create_posix_regexp_match("PTHREAD", 0)), 1);
 
291
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_posix_regexp_match(" PTHREAD ", 0), create_posix_regexp_match("^PTHREAD$", 0)), 1);
 
292
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_posix_regexp_match("^PTHREAD$", 0), create_posix_regexp_match(" PTHREAD ", 0)), 1);
 
293
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_posix_regexp_match(" PAD ", 0), create_posix_regexp_match("^PTHREAD$", 0)), 0);
 
294
  
 
295
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_posix_regexp_match(" PTHREAD ", 0), create_posix_regexp_match("PTHREAD", 0)), 1);
 
296
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_posix_regexp_match(" PTHREAD ", 0), create_posix_regexp_match("^PTHREAD$", 0)), 0);
 
297
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_posix_regexp_match("^PTHREAD$", 0), create_posix_regexp_match(" PTHREAD ", 0)), 0);
 
298
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_posix_regexp_match(" PAD ", 0), create_posix_regexp_match("^PTHREAD$", 0)), 0);
 
299
  
 
300
 
 
301
 
 
302
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: al fa", 0, create_posix_regexp_filter(LM_F_MESSAGE, "(a)(l) (fa)", LMF_STORE_MATCHES), 1, "1","a");
 
303
  
 
304
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: al fa", 0, create_posix_regexp_filter(LM_F_MESSAGE, "(a)(l) (fa)", LMF_STORE_MATCHES), 1, "0","al fa");
 
305
  
 
306
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: al fa", 0, create_posix_regexp_filter(LM_F_MESSAGE, "(a)(l) (fa)", LMF_STORE_MATCHES), 1, "232", NULL);
 
307
  
 
308
 
 
309
#if ENABLE_PCRE
 
310
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_PROGRAM, "^openvpn$", 0), 1);
 
311
  testcase("<15> openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_PROGRAM, "^open$", 0), 0);
 
312
  fprintf(stderr, "One \"invalid regular expression\" message is to be expected\n");
 
313
  TEST_ASSERT(create_pcre_regexp_filter(LM_F_PROGRAM, "((", 0) == NULL);
 
314
 
 
315
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_HOST, "^host$", 0), 1);
 
316
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_HOST, "^hos$", 0), 0);
 
317
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_HOST, "pthread", 0), 0);
 
318
  fprintf(stderr, "One \"invalid regular expressions\" message is to be expected\n");
 
319
  TEST_ASSERT(create_pcre_regexp_filter(LM_F_HOST, "((", 0) == NULL);
 
320
 
 
321
  fprintf(stderr, "One \"invalid regular expressions\" message is to be expected\n");
 
322
  TEST_ASSERT(create_posix_regexp_filter(LM_F_HOST, "(?iana", 0) == NULL);
 
323
  
 
324
  fprintf(stderr, "One \"invalid regular expressions\" message is to be expected\n");
 
325
  TEST_ASSERT(create_pcre_regexp_filter(LM_F_HOST, "(?iana", 0) == NULL);
 
326
 
 
327
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "^PTHREAD ", 0), 1);
 
328
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "PTHREAD s", 0), 1);
 
329
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "^PTHREAD$", 0), 0);
 
330
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "(?i)pthread", 0), 1);
 
331
 
 
332
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_pcre_regexp_match(" PTHREAD ", 0), create_posix_regexp_match("PTHREAD", 0)), 1);
 
333
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_pcre_regexp_match(" PTHREAD ", 0), create_posix_regexp_match("^PTHREAD$", 0)), 0);
 
334
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_pcre_regexp_match("^PTHREAD$", 0), create_posix_regexp_match(" PTHREAD ", 0)), 0);
 
335
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_and_new(create_pcre_regexp_match(" PAD ", 0), create_posix_regexp_match("^PTHREAD$", 0)), 0);
 
336
 
 
337
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_pcre_regexp_match(" PTHREAD ", 0), create_pcre_regexp_match("PTHREAD", 0)), 1);
 
338
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_pcre_regexp_match(" PTHREAD ", 0), create_pcre_regexp_match("^PTHREAD$", 0)), 1);
 
339
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_pcre_regexp_match("^PTHREAD$", 0), create_pcre_regexp_match(" PTHREAD ", 0)), 1);
 
340
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, fop_or_new(create_pcre_regexp_match(" PAD ", 0), create_pcre_regexp_match("^PTHREAD$", 0)), 0);
 
341
 
 
342
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_match(" PTHREAD ", 0), 1);
 
343
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_match("^openvpn\\[2499\\]: PTHREAD", 0), 1);
 
344
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_match("^PTHREAD$", 0), 0);
 
345
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_match("(?i)pthread", 0), 1);
 
346
  testcase("<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", 0, create_pcre_regexp_match("pthread", LMF_ICASE), 1);
 
347
 
 
348
  fprintf(stderr, "One \"invalid regular expression\" message is to be expected\n");
 
349
  TEST_ASSERT(create_pcre_regexp_match("((", 0) == NULL);
 
350
 
 
351
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: alma fa", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "(?P<a>a)(?P<l>l)(?P<MM>m)(?P<aa>a) (?P<fa>fa)", LMF_STORE_MATCHES), 1, "MM","m");
 
352
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: alma fa", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "(?P<a>a)(?P<l>l)(?P<MM>m)(?P<aa>a) (?P<fa>fa)", LMF_STORE_MATCHES), 1, "aaaa", NULL);
 
353
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: alma fa", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "(?P<a>a)(?P<l>l)(?P<MM>m)(?P<aa>a) (?P<fa_name>fa)", LMF_STORE_MATCHES), 1, "fa_name","fa");
 
354
 
 
355
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: al fa", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "(a)(l) (fa)", LMF_STORE_MATCHES), 1, "2","l");
 
356
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: al fa", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "(a)(l) (fa)", LMF_STORE_MATCHES), 1, "0","al fa");
 
357
  testcase_with_backref_chk("<15>Oct 15 16:17:01 host openvpn[2499]: al fa", 0, create_pcre_regexp_filter(LM_F_MESSAGE, "(a)(l) (fa)", LMF_STORE_MATCHES), 1, "233",NULL);
 
358
#endif
 
359
 
 
360
  app_shutdown();
170
361
  return 0;
171
362
}
172
363
 
173