8ab94c71 |
#include <cstdio>
#include <cstring>
|
1c7f8bf0 |
#include <syslog.h>
|
6f45b32f |
#include "logging.h"
|
1c7f8bf0 |
#include "test_util.h"
|
a26b1d7c |
|
9fe53359 |
int logged_priority = -1000;
|
a4c373a6 |
const char *logged_message = "";
|
b017a4d2 |
void fake_syslog (int priority, const char *message, ...)
|
cdf7fd74 |
{
|
9fe53359 |
logged_priority = priority;
|
a4c373a6 |
logged_message = message;
|
6f45b32f |
}
|
4a5fbc12 |
int close_log_invoked = 0;
|
b017a4d2 |
void fake_closelog (void)
|
cdf7fd74 |
{
|
4a5fbc12 |
close_log_invoked = 1;
|
6f45b32f |
}
int opened_facility = -1000;
|
b9244c44 |
const char *opened_program_name = "";
|
08aca5aa |
int opened_logopt = -1000;
|
b017a4d2 |
void fake_openlog (const char *ident, int logopt, int facility)
|
cdf7fd74 |
{
|
6f45b32f |
opened_facility = facility;
|
b9244c44 |
opened_program_name = ident;
|
08aca5aa |
opened_logopt = logopt;
|
6f45b32f |
}
|
704ed597 |
RESET_VARS_START
logged_priority = -1000;
close_log_invoked = 0;
opened_facility = -1000;
const char *opened_program_name = "";
int opened_logopt = -1000;
RESET_VARS_END
|
cdf7fd74 |
int test_log_success()
{
|
6f45b32f |
// given
// when
log_success();
// then
|
b017a4d2 |
checkint (LOG_AUTHPRIV, opened_facility, "facility");
checkint (LOG_NOTICE, logged_priority, "priority");
checkint (0, opened_logopt, "logopt");
check (close_log_invoked, "log closed");
checkstr ("pam_dual_control", opened_program_name, "program name");
checkstr ("dual control succeeded", logged_message, "logged message");
|
f2d9dbb5 |
succeed();
|
6f45b32f |
}
|
cdf7fd74 |
int test_log_failure()
{
|
6120f050 |
//given
//when
log_failure();
//then
|
b017a4d2 |
checkint (LOG_AUTHPRIV, opened_facility, "facility");
checkint (LOG_NOTICE, logged_priority, "priority");
checkint (0, opened_logopt, "logopt");
check (close_log_invoked, "log closed");
checkstr ("pam_dual_control", opened_program_name, "program name");
checkstr ("dual control failed", logged_message, "logged message");
|
6120f050 |
succeed();
}
|
cdf7fd74 |
int test_runner()
{
|
b017a4d2 |
test (test_log_success);
test (test_log_failure);
|
9dd224b0 |
succeed();
}
|
6f45b32f |
|
b017a4d2 |
int main (int numargs, char **args)
|
cdf7fd74 |
{
|
9dd224b0 |
return !test_runner();
|
6f45b32f |
}
|
704ed597 |
|