~ubuntu-branches/ubuntu/edgy/syslog-ng/edgy

« back to all changes in this revision

Viewing changes to tests/unit/test_template.c

  • Committer: Bazaar Package Importer
  • Author(s): SZALAY Attila
  • Date: 2006-05-25 11:21:50 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060525112150-b18srkxcrz980xi9
Tags: 1.9.11-1
* New upstream version
  - Fixed log facility and priority detecting. (Closes: #350120, #350344, #357071, #367256)
* Added bison to Build-Dependency. (Closes: #368765)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "syslog-ng.h"
 
2
#include "logmsg.h"
 
3
#include "templates.h"
 
4
#include "misc.h"
 
5
 
 
6
#include <time.h>
 
7
#include <stdlib.h>
 
8
#include <stdio.h>
 
9
 
 
10
gboolean success = TRUE;
 
11
 
 
12
void
 
13
testcase(LogMessage *msg, gchar *template, gchar *expected)
 
14
{
 
15
  LogTemplate *templ;
 
16
  GString *res = g_string_sized_new(128);
 
17
  
 
18
  templ = log_template_new("dummy", template);
 
19
  log_template_format(templ, msg, 0, TS_FMT_BSD, -1, 3, res);
 
20
  
 
21
  if (strcmp(res->str, expected) != 0)
 
22
    {
 
23
      fprintf(stderr, "template test failed, template=%s, %s <=> %s\n", template, res->str, expected);
 
24
      success = FALSE;
 
25
    }
 
26
  else
 
27
    {
 
28
      fprintf(stderr, "template test success, template=%s => %s\n", template, expected);
 
29
    }
 
30
  log_template_unref(templ);
 
31
  g_string_free(res, TRUE);
 
32
}
 
33
 
 
34
int 
 
35
main(int argc G_GNUC_UNUSED, char *argv[] G_GNUC_UNUSED)
 
36
{
 
37
  LogMessage *msg;
 
38
  char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]: test message";
 
39
  
 
40
  putenv("TZ=CET");
 
41
  tzset();
 
42
 
 
43
  msg = log_msg_new(msg_str, strlen(msg_str), g_sockaddr_inet_new("10.10.10.10", 1010), 0, NULL);
 
44
  
 
45
  /* fix some externally or automatically defined values */
 
46
  g_string_assign(msg->host_from, "kismacska");
 
47
  msg->recvd.time.tv_sec = 1139684315;
 
48
  msg->recvd.time.tv_usec = 639000;
 
49
  msg->recvd.zone_offset = get_local_timezone_ofs(1139684315);
 
50
 
 
51
  /* pri 3, fac 19 == local3 */
 
52
 
 
53
  testcase(msg, "$FACILITY", "local3");
 
54
  testcase(msg, "$PRIORITY", "err");
 
55
  testcase(msg, "$LEVEL", "err");
 
56
  testcase(msg, "$TAG", "9b");
 
57
  testcase(msg, "$PRI", "155");
 
58
  testcase(msg, "$DATE", "Feb 11 10:34:56");
 
59
  testcase(msg, "$FULLDATE", "2006 Feb 11 10:34:56");
 
60
  testcase(msg, "$ISODATE", "2006-02-11T10:34:56.000+01:00");
 
61
  testcase(msg, "$STAMP", "Feb 11 10:34:56");
 
62
  testcase(msg, "$YEAR", "2006");
 
63
  testcase(msg, "$MONTH", "02");
 
64
  testcase(msg, "$DAY", "11");
 
65
  testcase(msg, "$HOUR", "10");
 
66
  testcase(msg, "$MIN", "34");
 
67
  testcase(msg, "$SEC", "56");
 
68
  testcase(msg, "$WEEKDAY", "Sat");
 
69
  testcase(msg, "$WEEK", "06");
 
70
  testcase(msg, "$UNIXTIME", "1139650496");
 
71
  testcase(msg, "$TZOFFSET", "+01:00");
 
72
  testcase(msg, "$TZ", "+01:00");
 
73
  testcase(msg, "$R_DATE", "Feb 11 19:58:35");
 
74
  testcase(msg, "$R_FULLDATE", "2006 Feb 11 19:58:35");
 
75
  testcase(msg, "$R_ISODATE", "2006-02-11T19:58:35.639+01:00");
 
76
  testcase(msg, "$R_STAMP", "Feb 11 19:58:35");
 
77
  testcase(msg, "$R_YEAR", "2006");
 
78
  testcase(msg, "$R_MONTH", "02");
 
79
  testcase(msg, "$R_DAY", "11");
 
80
  testcase(msg, "$R_HOUR", "19");
 
81
  testcase(msg, "$R_MIN", "58");
 
82
  testcase(msg, "$R_SEC", "35");
 
83
  testcase(msg, "$R_WEEKDAY", "Sat");
 
84
  testcase(msg, "$R_WEEK", "06");
 
85
  testcase(msg, "$R_UNIXTIME", "1139684315");
 
86
  testcase(msg, "$R_TZOFFSET", "+01:00");
 
87
  testcase(msg, "$R_TZ", "+01:00");
 
88
  testcase(msg, "$S_DATE", "Feb 11 10:34:56");
 
89
  testcase(msg, "$S_FULLDATE", "2006 Feb 11 10:34:56");
 
90
  testcase(msg, "$S_ISODATE", "2006-02-11T10:34:56.000+01:00");
 
91
  testcase(msg, "$S_STAMP", "Feb 11 10:34:56");
 
92
  testcase(msg, "$S_YEAR", "2006");
 
93
  testcase(msg, "$S_MONTH", "02");
 
94
  testcase(msg, "$S_DAY", "11");
 
95
  testcase(msg, "$S_HOUR", "10");
 
96
  testcase(msg, "$S_MIN", "34");
 
97
  testcase(msg, "$S_SEC", "56");
 
98
  testcase(msg, "$S_WEEKDAY", "Sat");
 
99
  testcase(msg, "$S_WEEK", "06");
 
100
  testcase(msg, "$S_UNIXTIME", "1139650496");
 
101
  testcase(msg, "$S_TZOFFSET", "+01:00");
 
102
  testcase(msg, "$S_TZ", "+01:00");
 
103
  testcase(msg, "$HOST_FROM", "kismacska");
 
104
  testcase(msg, "$FULLHOST_FROM", "kismacska");
 
105
  testcase(msg, "$HOST", "bzorp");
 
106
  testcase(msg, "$FULLHOST", "bzorp");
 
107
  testcase(msg, "$PROGRAM", "syslog-ng");
 
108
  testcase(msg, "$PID", "23323");
 
109
  testcase(msg, "$MSG", "syslog-ng[23323]: test message");
 
110
  testcase(msg, "$MSGONLY", "test message");
 
111
  testcase(msg, "$MESSAGE", "syslog-ng[23323]: test message");
 
112
  testcase(msg, "$SOURCEIP", "10.10.10.10");
 
113
  testcase(msg, "$PROGRAM/var/log/messages/$HOST/$HOST_FROM/$MONTH$DAY$QQQQQvalami", "syslog-ng/var/log/messages/bzorp/kismacska/0211valami");
 
114
  if (success)
 
115
    return 0;
 
116
  return 1;
 
117
}