test/logging_tests.c

Wed, 27 Feb 2013 13:53:28 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 27 Feb 2013 13:53:28 +0100
changeset 96
fbbff331beba
parent 95
ecfdc1c4a552
child 103
08018864fb91
permissions
-rw-r--r--

added sstrtrim

/*
 *
 */

#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);
    size_t 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