Blame src/check_impl.h

Packit 0b5880
/*
Packit 0b5880
 * Check: a unit test framework for C
Packit 0b5880
 * Copyright (C) 2001, 2002 Arien Malec
Packit 0b5880
 *
Packit 0b5880
 * This library is free software; you can redistribute it and/or
Packit 0b5880
 * modify it under the terms of the GNU Lesser General Public
Packit 0b5880
 * License as published by the Free Software Foundation; either
Packit 0b5880
 * version 2.1 of the License, or (at your option) any later version.
Packit 0b5880
 *
Packit 0b5880
 * This library is distributed in the hope that it will be useful,
Packit 0b5880
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0b5880
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0b5880
 * Lesser General Public License for more details.
Packit 0b5880
 *
Packit 0b5880
 * You should have received a copy of the GNU Lesser General Public
Packit 0b5880
 * License along with this library; if not, write to the
Packit 0b5880
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
Packit 0b5880
 * MA 02110-1301, USA.
Packit 0b5880
 */
Packit 0b5880
Packit 0b5880
#ifndef CHECK_IMPL_H
Packit 0b5880
#define CHECK_IMPL_H
Packit 0b5880
Packit 0b5880
/* This header should be included by any module that needs
Packit 0b5880
   to know the implementation details of the check structures
Packit 0b5880
   Include stdio.h, time.h, & list.h before this header
Packit 0b5880
*/
Packit 0b5880
Packit 0b5880
#define US_PER_SEC 1000000
Packit 0b5880
#define NANOS_PER_SECONDS 1000000000
Packit 0b5880
Packit 0b5880
/** calculate the difference in useconds out of two "struct timespec"s */
Packit 0b5880
#define DIFF_IN_USEC(begin, end) \
Packit 0b5880
  ( (((end).tv_sec - (begin).tv_sec) * US_PER_SEC) + \
Packit 0b5880
    ((end).tv_nsec/1000) - ((begin).tv_nsec/1000) )
Packit 0b5880
Packit 0b5880
typedef struct TF
Packit 0b5880
{
Packit 0b5880
    TFun fn;
Packit 0b5880
    int loop_start;
Packit 0b5880
    int loop_end;
Packit 0b5880
    const char *name;
Packit 0b5880
    int signal;
Packit 0b5880
    signed char allowed_exit_value;
Packit 0b5880
} TF;
Packit 0b5880
Packit 0b5880
struct Suite
Packit 0b5880
{
Packit 0b5880
    const char *name;
Packit 0b5880
    List *tclst;                /* List of test cases */
Packit 0b5880
};
Packit 0b5880
Packit 0b5880
typedef struct Fixture
Packit 0b5880
{
Packit 0b5880
    int ischecked;
Packit 0b5880
    SFun fun;
Packit 0b5880
} Fixture;
Packit 0b5880
Packit 0b5880
struct TCase
Packit 0b5880
{
Packit 0b5880
    const char *name;
Packit 0b5880
    struct timespec timeout;
Packit 0b5880
    List *tflst;                /* list of test functions */
Packit 0b5880
    List *unch_sflst;
Packit 0b5880
    List *unch_tflst;
Packit 0b5880
    List *ch_sflst;
Packit 0b5880
    List *ch_tflst;
Packit 0b5880
    List *tags;
Packit 0b5880
};
Packit 0b5880
Packit 0b5880
typedef struct TestStats
Packit 0b5880
{
Packit 0b5880
    int n_checked;
Packit 0b5880
    int n_failed;
Packit 0b5880
    int n_errors;
Packit 0b5880
} TestStats;
Packit 0b5880
Packit 0b5880
struct TestResult
Packit 0b5880
{
Packit 0b5880
    enum test_result rtype;     /* Type of result */
Packit 0b5880
    enum ck_result_ctx ctx;     /* When the result occurred */
Packit 0b5880
    char *file;                 /* File where the test occured */
Packit 0b5880
    int line;                   /* Line number where the test occurred */
Packit 0b5880
    int iter;                   /* The iteration value for looping tests */
Packit 0b5880
    int duration;               /* duration of this test in microseconds */
Packit 0b5880
    const char *tcname;         /* Test case that generated the result */
Packit 0b5880
    const char *tname;          /* Test that generated the result */
Packit 0b5880
    char *msg;                  /* Failure message */
Packit 0b5880
};
Packit 0b5880
Packit 0b5880
TestResult *tr_create(void);
Packit 0b5880
void tr_reset(TestResult * tr);
Packit 0b5880
void tr_free(TestResult * tr);
Packit 0b5880
Packit 0b5880
enum cl_event
Packit 0b5880
{
Packit 0b5880
    CLINITLOG_SR,               /* Initialize log file */
Packit 0b5880
    CLENDLOG_SR,                /* Tests are complete */
Packit 0b5880
    CLSTART_SR,                 /* Suite runner start */
Packit 0b5880
    CLSTART_S,                  /* Suite start */
Packit 0b5880
    CLEND_SR,                   /* Suite runner end */
Packit 0b5880
    CLEND_S,                    /* Suite end */
Packit 0b5880
    CLSTART_T,                  /* A test case is about to run */
Packit 0b5880
    CLEND_T                     /* Test case end */
Packit 0b5880
};
Packit 0b5880
Packit 0b5880
typedef void (*LFun) (SRunner *, FILE *, enum print_output,
Packit 0b5880
                      void *, enum cl_event);
Packit 0b5880
Packit 0b5880
typedef struct Log
Packit 0b5880
{
Packit 0b5880
    FILE *lfile;
Packit 0b5880
    LFun lfun;
Packit 0b5880
    int close;
Packit 0b5880
    enum print_output mode;
Packit 0b5880
} Log;
Packit 0b5880
Packit 0b5880
struct SRunner
Packit 0b5880
{
Packit 0b5880
    List *slst;                 /* List of Suite objects */
Packit 0b5880
    TestStats *stats;           /* Run statistics */
Packit 0b5880
    List *resultlst;            /* List of unit test results */
Packit 0b5880
    const char *log_fname;      /* name of log file */
Packit 0b5880
    const char *xml_fname;      /* name of xml output file */
Packit 0b5880
    const char *tap_fname;      /* name of tap output file */
Packit 0b5880
    List *loglst;               /* list of Log objects */
Packit 0b5880
    enum fork_status fstat;     /* controls if suites are forked or not
Packit 0b5880
                                   NOTE: Don't use this value directly,
Packit 0b5880
                                   instead use srunner_fork_status */
Packit 0b5880
};
Packit 0b5880
Packit 0b5880
Packit 0b5880
void set_fork_status(enum fork_status fstat);
Packit 0b5880
enum fork_status cur_fork_status(void);
Packit 0b5880
Packit 0b5880
clockid_t check_get_clockid(void);
Packit 0b5880
Packit 0b5880
unsigned int tcase_matching_tag(TCase *tc, List *check_for);
Packit 0b5880
List *tag_string_to_list(const char *tags_string);
Packit 0b5880
Packit 0b5880
#endif /* CHECK_IMPL_H */