1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..54\n"; }
END {print "not ok 1\n" unless $loaded;}
use Unix::Syslog qw(:macros :subs);
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
sub check_defined($$) {
printf "%-20s", $_[0];
if (defined eval "$_[0]") {
print " ok $_[1]\n";
return 0;
}
else {
print " not ok $_[1]\n";
return 1;
}
}
sub check_defined_skip($$) {
printf "%-20s", $_[0];
if (defined eval "$_[0]") {
print " ok $_[1]\n";
return 0;
}
else {
print " skipped $_[1]\n";
return 1;
}
}
my $n = 2;
my $failures = 0;
print "Testing priorities:\n";
$failures += check_defined('LOG_EMERG', $n++);
$failures += check_defined('LOG_EMERG', $n++);
$failures += check_defined('LOG_ALERT', $n++);
$failures += check_defined('LOG_CRIT', $n++);
$failures += check_defined('LOG_ERR', $n++);
$failures += check_defined('LOG_WARNING', $n++);
$failures += check_defined('LOG_NOTICE', $n++);
$failures += check_defined('LOG_INFO', $n++);
$failures += check_defined('LOG_DEBUG', $n++);
$failures += check_defined('LOG_EMERG', $n++);
$failures += check_defined('LOG_ALERT', $n++);
$failures += check_defined('LOG_CRIT', $n++);
$failures += check_defined('LOG_ERR', $n++);
$failures += check_defined('LOG_WARNING', $n++);
$failures += check_defined('LOG_NOTICE', $n++);
$failures += check_defined('LOG_INFO', $n++);
$failures += check_defined('LOG_DEBUG', $n++);
print "\nTesting facilities\n";
$fac = 0;
$failures += check_defined('LOG_KERN', $n++);
$failures += check_defined('LOG_USER', $n++);
$failures += check_defined('LOG_MAIL', $n++);
$failures += check_defined('LOG_DAEMON', $n++);
$failures += check_defined('LOG_AUTH', $n++);
$failures += check_defined('LOG_SYSLOG', $n++);
$failures += check_defined('LOG_LPR', $n++);
$failures += check_defined('LOG_NEWS', $n++);
$failures += check_defined('LOG_UUCP', $n++);
$failures += check_defined('LOG_CRON', $n++);
$failures += check_defined('LOG_LOCAL0', $n++);
$failures += check_defined('LOG_LOCAL1', $n++);
$failures += check_defined('LOG_LOCAL2', $n++);
$failures += check_defined('LOG_LOCAL3', $n++);
$failures += check_defined('LOG_LOCAL4', $n++);
$failures += check_defined('LOG_LOCAL5', $n++);
$failures += check_defined('LOG_LOCAL6', $n++);
$failures += check_defined('LOG_LOCAL7', $n++);
print "\nThese facilities are not defined on all systems:\n";
$failures += check_defined_skip('LOG_AUTHPRIV', $n++);
$failures += check_defined_skip('LOG_FTP', $n++);
print "\nThe number of available facilities is:\n";
$failures += check_defined('LOG_NFACILITIES ', $n++);
$failures += check_defined('LOG_FACMASK', $n++);
print "\nTesting options\n";
$failures += check_defined('LOG_PID', $n++);
$failures += check_defined('LOG_CONS', $n++);
$failures += check_defined('LOG_ODELAY', $n++);
$failures += check_defined('LOG_NDELAY', $n++);
$failures += check_defined('LOG_NOWAIT', $n++);
print "\nThese options are not defined on all systems:\n";
$failures += check_defined_skip('LOG_PERROR', $n++);
print "\nTesting macros for setlogmask()\n";
$failures += check_defined('LOG_MASK(1)', $n++);
$failures += check_defined('LOG_UPTO(1)', $n++);
print "\nThese macros are not defined on all systems:\n";
$failures += check_defined_skip('LOG_PRI(1)', $n++);
$failures += check_defined_skip('LOG_MAKEPRI(1,1)', $n++);
$failures += check_defined_skip('LOG_FAC(1)', $n++);
print "\nOn some systems these functions are undefined and\n",
"return just empty strings:\n";
$failures += check_defined_skip('priorityname(LOG_EMERG)', $n++);
$failures += check_defined_skip('facilityname(LOG_KERN)', $n++);
print "\nTesting setlogmask:\n";
print "Setting mask to ", LOG_MASK(LOG_INFO), "\n";
$oldmask = setlogmask(LOG_MASK(LOG_INFO));
$newmask = setlogmask($oldmask);
print "New mask is $newmask ";
if ($newmask != LOG_MASK(LOG_INFO)) {
$failures++;
print "not ";
}
print "ok ", $n++, "\n";
if ($failures == 0) {
print "\n*** Congratulations! All tests passed.\n\n";
}
else {
print "\n*** Test results: ", $n-1-$failures, " tests of ", $n-1, " passed!\n\n";
}
print <<EOM;
Testing functions
As the functions `openlog', `closelog' and `syslog' do not return any
value that indicates success or failure, please have a look at the log
file generated by syslogd(8). The following tests print a message of
the facility `local7' and the priority `info'.
EOM
sub basename {
my $name = shift;
$name =~ s@.*/@@;
return $name;
}
print "Calling closelog() without preceeding openlog() ";
closelog;
print "ok\n"; # if we got this far, things must have worked right.
print "openlog\n";
openlog(basename($0), LOG_PID, LOG_LOCAL7);
print "syslog\n";
# We need some error message
open(DUMMY, "<foo");
syslog(LOG_INFO, "Unix::Syslog testsuite: The ident string should be \`%s\' (Test %d)", basename($0), $n++);
syslog(LOG_INFO, "Unix::Syslog testsuite: Testing quote character \`%%\' (Test %d)", $n++);
syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints an error message: %m (Test %d)", $n++);
syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints a percent sign followed by the character \`m\': %%m (Test %d)", $n++);
syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints a percent sign followed by an error message: %%%m (Test %d)", $n++);
syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints a percent sign followed by the character \`m\': %s (Test %d)", '%m', $n++);
syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints two percent signs followed by the character \`m\': %s (Test %d)", '%%m', $n++);
syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints three percent signs followed by the character \`m\': %s (Test %d)", '%%%m', $n++);
print "setlogmask\n";
setlogmask(LOG_MASK(LOG_INFO));
print "syslog\n";
syslog(LOG_INFO, "Unix::Syslog testsuite: (LOG_MASK) This message should be visible (Test %d)\n", $n++);
syslog(LOG_EMERG, "Unix::Syslog testsuite: (LOG_MASK) This message should NOT be visible (Test %d)\n", $n++);
setlogmask(LOG_UPTO(LOG_INFO));
syslog(LOG_INFO, "Unix::Syslog testsuite: (LOG_UPTO) This message should be visible (Test %d)\n", $n++);
syslog(LOG_EMERG, "Unix::Syslog testsuite: (LOG_UPTO) This message should be visible (Test %d)\n", $n++);
syslog((LOG_INFO()+1), "Unix::Syslog testsuite: (LOG_UPTO) This message should NOT be visible (Test %d)\n", $n++);
print "closelog\n\n";
closelog;
print "Testing pointer handling in closelog().\n";
print "Calling closelog() a second time.\n";
closelog;
print "This message should not be preceeded by an error message\n";
print " about dereferenced pointers.\n\n";
|