test multiple loggers

This commit is contained in:
Enno Rehling 2016-05-01 13:36:00 +02:00
parent 13156a47a4
commit 1fa1693119
3 changed files with 35 additions and 0 deletions

View File

@ -84,6 +84,7 @@ int RunAllTests(int argc, char *argv[])
ADD_SUITE(umlaut);
ADD_SUITE(unicode);
ADD_SUITE(strings);
ADD_SUITE(log);
ADD_SUITE(rng);
/* items */
ADD_SUITE(xerewards);

View File

@ -8,6 +8,7 @@ attrib.test.c
strings.test.c
bsdstring.test.c
functions.test.c
log.test.c
umlaut.test.c
unicode.test.c
rng.test.c

33
src/util/log.test.c Normal file
View File

@ -0,0 +1,33 @@
#include <CuTest.h>
#include "log.h"
#include <stdarg.h>
#include <string.h>
void log_string(void *data, int level, const char *module, const char *format, va_list args) {
char *str = (char *)data;
const char *arg = va_arg(args, const char *);
strncpy(str, arg, 32);
}
static void test_logging(CuTest * tc)
{
char str1[32];
char str2[32];
int id1 = log_create(LOG_CPWARNING, str1, log_string);
int id2 = log_create(LOG_CPWARNING, str2, log_string);
CuAssertTrue(tc, id1!=id2);
log_warning("Hello %s", "World");
CuAssertStrEquals(tc, str1, "World");
CuAssertStrEquals(tc, str2, "World");
log_destroy(id1);
log_destroy(id2);
}
CuSuite *get_log_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_logging);
return suite;
}