test/logging_tests.c

Wed, 27 Feb 2013 10:09:23 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 27 Feb 2013 10:09:23 +0100
changeset 89
47f7fdbddb62
parent 81
86a23238d8a1
child 95
ecfdc1c4a552
permissions
-rw-r--r--

comparator module

/*
 *
 */

#include "logging_tests.h"

UCX_TEST_IMPLEMENT(test_ucx_logger_log) {
    char buffer[100];
    FILE *stream = tmpfile();

    UcxLogger *logger = ucx_logger_new(stream,
            UCX_LOGGER_INFO, UCX_LOGGER_SOURCE | UCX_LOGGER_LEVEL);
    
    UCX_TEST_BEGIN
    ucx_logger_info(logger, "allright");
    ucx_logger_trace(logger, "dont log this!");
    ucx_logger_error(logger, "error %d!", 42);
    fseek(stream, 0, SEEK_SET);
    int r = fread(buffer, 1, 100, stream);
    
    size_t expected_length = 76;
    UCX_TEST_ASSERT(r == expected_length && strncmp(buffer,
            "[INFO] logging_tests.c:15 - allright\n"
            "[ERROR] logging_tests.c:17 - error 42!\n", expected_length) == 0, "incorrect logs");

    UCX_TEST_END

    ucx_logger_free(logger);
    fclose(stream);
}

mercurial