LCOV - code coverage report
Current view: top level - opt/gitlab-ci-multi-runner/builds/00e3338d/0/taskrambler/taskrambler/tests - runtest.c (source / functions) Hit Total Coverage
Test: taskrambler v0.1.8 Lines: 30 36 83.3 %
Date: 2016-04-13 22:40:30 Functions: 3 3 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                 :            :  * runtest.c: the main runner for my tests
       4                 :            :  * Copyright (C) 2011  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                 :            : #include <stdio.h>
      20                 :            : #include <stdlib.h>
      21                 :            : #include <string.h>
      22                 :            : #include <sys/types.h>
      23                 :            : 
      24                 :            : #include "runtest.h"
      25                 :            : #include "class.h"
      26                 :            : 
      27                 :            : 
      28                 :            : #define TEST_OK_CHAR            '.'
      29                 :            : #define TEST_FAILED_CHAR        'F'
      30                 :            : #define TEST_ERROR_CHAR         'E'
      31                 :            : 
      32                 :            : 
      33                 :            : const char results[3] = {
      34                 :            :     TEST_OK_CHAR,
      35                 :            :     TEST_FAILED_CHAR,
      36                 :            :     TEST_ERROR_CHAR
      37                 :            : };
      38                 :            : 
      39                 :            : int
      40                 :          1 : isObjectNull(void * object)
      41                 :            : {
      42                 :          1 :     class_ptr class = GET_CLASS(object);
      43                 :            : 
      44                 :          1 :     if (! IS_OBJECT(object)) {
      45                 :          0 :         return 0;
      46                 :            :     }
      47                 :            : 
      48                 :          1 :     return isMemNull(object, class->object_size);
      49                 :            : }
      50                 :            : 
      51                 :            : int
      52                 :          1 : isMemNull(void * _mem, size_t size)
      53                 :            : {
      54                 :            :     size_t index;
      55                 :            : 
      56                 :          1 :     if (NULL == _mem) {
      57                 :          0 :         return 0;
      58                 :            :     }
      59                 :            : 
      60                 :          1 :     for(index=0; index<size && 0 == ((char *)_mem)[index]; index++);
      61                 :            : 
      62                 :          1 :     return (size == index);
      63                 :            : }
      64                 :            : 
      65                 :            : int
      66                 :          4 : main(int argc, char * argv[])
      67                 :            : {
      68                 :          4 :     size_t errors     = 0;
      69                 :          4 :     size_t failures   = 0;
      70                 :            :     // size_t assertions = 0;   // @TODO find a way to count assertions
      71                 :            : 
      72                 :            :     size_t index;
      73                 :            : 
      74                 :          4 :     printf("running tests for %s\n", testname);
      75                 :            : 
      76                 :         14 :     for (index=0; index<count; index++) {
      77                 :         10 :         int result = TEST_ERROR, _setUp = 0;  // initialize setup to false
      78                 :            : 
      79                 :         10 :         if (NULL != setUp) {
      80                 :         10 :             if (TEST_OK == (result = setUp())) {
      81                 :         10 :                 _setUp = 1;  // we successfully set up the test
      82                 :            :             }
      83                 :            :         }
      84                 :            : 
      85                 :         10 :         if (_setUp) {
      86                 :         10 :             result = tests[index]();
      87                 :            :         }
      88                 :            : 
      89                 :         10 :         if (_setUp && NULL != tearDown) {
      90                 :         10 :             int _tearDown = tearDown();
      91                 :            : 
      92                 :         10 :             if ((! TEST_OK == _tearDown) && TEST_OK == result) {
      93                 :          0 :                 result = _tearDown;
      94                 :            :             }
      95                 :            :         }
      96                 :            : 
      97                 :         10 :         switch (result) {
      98                 :          0 :             case TEST_FAILED: failures++; break;
      99                 :          0 :             case TEST_ERROR:  errors++; break;
     100                 :            :         }
     101                 :            : 
     102                 :         10 :         putchar(results[result]);
     103                 :            : 
     104                 :         10 :         if (79 == index%80) {
     105                 :          0 :             putchar('\n');
     106                 :            :         }
     107                 :            : 
     108                 :         10 :         fflush(stdout);
     109                 :            :     }
     110                 :          4 :     puts("\n");
     111                 :            : 
     112                 :          4 :     printf("running %lu tests: %lu - OK, %lu - FAILED, %lu - ERRORS\n",
     113                 :            :             count,
     114                 :          4 :             count - errors - failures,
     115                 :            :             failures,
     116                 :            :             errors);
     117                 :            : 
     118                 :          4 :     return failures + errors;
     119                 :            : }
     120                 :            : 
     121                 :            : // vim: set et ts=4 sw=4:

Generated by: LCOV version 1.11