LCOV - code coverage report
Current view: top level - opt/gitlab-ci-multi-runner/builds/00e3338d/0/taskrambler/taskrambler/tests - loggerTest.c (source / functions) Hit Total Coverage
Test: taskrambler 0.1.9 Lines: 28 29 96.6 %
Date: 2016-04-13 23:18:54 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * \file
       3                 :            :  * loggerTest.c: tests for my logger class
       4                 :            :  * Copyright (C) 2012  Georg Hopp
       5                 :            :  *
       6                 :            :  * This program is free software: you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation, either version 3 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <stdio.h>
      21                 :            : #include <stdlib.h>
      22                 :            : 
      23                 :            : #include "runtest.h"
      24                 :            : #include "class.h"
      25                 :            : #include "logger.h"
      26                 :            : #include "mock/mock_logger.h"
      27                 :            : 
      28                 :            : 
      29                 :            : const char testname[] = "loggerTest";
      30                 :            : Logger logger = NULL;
      31                 :            : 
      32                 :            : 
      33                 :            : static
      34                 :            : int
      35                 :          3 : __setUp()
      36                 :            : {
      37                 :          3 :     return TEST_OK;
      38                 :            : }
      39                 :            : int (* const setUp)() = __setUp;
      40                 :            : 
      41                 :            : static
      42                 :            : int
      43                 :          3 : __tearDown()
      44                 :            : {
      45                 :          3 :     if (NULL != logger) {
      46                 :          3 :         ASSERT_OBJECT(logger);
      47                 :          3 :         delete(logger);
      48                 :            :     }
      49                 :            : 
      50                 :          3 :     return TEST_OK;
      51                 :            : }
      52                 :            : int (* const tearDown)() = __tearDown;
      53                 :            : 
      54                 :            : static
      55                 :            : int
      56                 :          1 : testLoggerLevel()
      57                 :            : {
      58                 :          1 :     logger = new(MockLogger, LOGGER_ERR);
      59                 :            : 
      60                 :          1 :     ASSERT_INSTANCE_OF(MockLogger, logger);
      61                 :          1 :     ASSERT_EQUAL(LOGGER_ERR, logger->min_level);
      62                 :            : 
      63                 :          1 :     loggerLog(logger, LOGGER_WARNING, "foo %d %s", 123, "bar");
      64                 :            : 
      65                 :          1 :     ASSERT_STRING_EQUAL("", ((MockLogger)logger)->message);
      66                 :            : 
      67                 :          1 :     loggerLog(logger, LOGGER_ERR, "foo %d %s", 123, "bar");
      68                 :          1 :     ASSERT_STRING_EQUAL("[ERR] foo 123 bar", ((MockLogger)logger)->message);
      69                 :            : 
      70                 :          1 :     mockLoggerCleanMsg((MockLogger)logger);
      71                 :          1 :     loggerLog(logger, LOGGER_CRIT, "foo %d %s", 123, "bar");
      72                 :          1 :     ASSERT_STRING_EQUAL("[CRIT] foo 123 bar", ((MockLogger)logger)->message);
      73                 :            : 
      74                 :          1 :     return TEST_OK;
      75                 :            : }
      76                 :            : 
      77                 :            : static
      78                 :            : int
      79                 :          1 : testLoggerStderr()
      80                 :            : {
      81                 :          1 :     logger = new(LoggerStderr, LOGGER_ERR);
      82                 :            : 
      83                 :          1 :     if (NULL == freopen("/dev/null", "w", stderr)) {
      84                 :          0 :         return TEST_ERROR;
      85                 :            :     }
      86                 :          1 :     loggerLog(logger, LOGGER_ERR, "foo %d %s", 123, "bar");
      87                 :            : 
      88                 :            :     /**
      89                 :            :      * \todo think about a way to assert something here
      90                 :            :      */
      91                 :            : 
      92                 :          1 :     return TEST_OK;
      93                 :            : }
      94                 :            : 
      95                 :            : static
      96                 :            : int
      97                 :          1 : testLoggerSyslog()
      98                 :            : {
      99                 :          1 :     logger = new(LoggerSyslog, LOGGER_ERR);
     100                 :            : 
     101                 :          1 :     loggerLog(logger, LOGGER_ERR, "foo %d %s", 123, "bar");
     102                 :            : 
     103                 :            :     /**
     104                 :            :      * \todo think about a way to assert something here
     105                 :            :      */
     106                 :            : 
     107                 :          1 :     return TEST_OK;
     108                 :            : }
     109                 :            : 
     110                 :            : const testfunc tests[] = {
     111                 :            :     testLoggerLevel,
     112                 :            :     testLoggerStderr,
     113                 :            :     testLoggerSyslog
     114                 :            : };
     115                 :            : const size_t count = FUNCS_COUNT(tests);
     116                 :            : 
     117                 :            : // vim: set et ts=4 sw=4:

Generated by: LCOV version 1.11