test/logging_tests.c

Fri, 08 Feb 2013 17:09:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 08 Feb 2013 17:09:12 +0100
changeset 83
3b552d7a9610
parent 81
86a23238d8a1
child 95
ecfdc1c4a552
permissions
-rw-r--r--

modified code to compile with -pedantic

/*
 *
 */

#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