Back to index

tor  0.2.3.19-rc
tinytest.h
Go to the documentation of this file.
00001 /* tinytest.h -- Copyright 2009-2012 Nick Mathewson
00002  *
00003  * Redistribution and use in source and binary forms, with or without
00004  * modification, are permitted provided that the following conditions
00005  * are met:
00006  * 1. Redistributions of source code must retain the above copyright
00007  *    notice, this list of conditions and the following disclaimer.
00008  * 2. Redistributions in binary form must reproduce the above copyright
00009  *    notice, this list of conditions and the following disclaimer in the
00010  *    documentation and/or other materials provided with the distribution.
00011  * 3. The name of the author may not be used to endorse or promote products
00012  *    derived from this software without specific prior written permission.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 
00026 #ifndef TINYTEST_H_INCLUDED_
00027 #define TINYTEST_H_INCLUDED_
00028 
00030 #define TT_FORK  (1<<0)
00031 
00032 #define TT_SKIP  (1<<1)
00033 
00034 #define TT_ENABLED_  (1<<2)
00035 
00036 #define TT_FIRST_USER_FLAG (1<<3)
00037 
00038 typedef void (*testcase_fn)(void *);
00039 
00040 struct testcase_t;
00041 
00043 struct testcase_setup_t {
00045        void *(*setup_fn)(const struct testcase_t *);
00047        int (*cleanup_fn)(const struct testcase_t *, void *);
00048 };
00049 
00051 struct testcase_t {
00052        const char *name; 
00053        testcase_fn fn; 
00054        unsigned long flags; 
00055        const struct testcase_setup_t *setup; 
00056        void *setup_data; 
00057 };
00058 #define END_OF_TESTCASES { NULL, NULL, 0, NULL, NULL }
00059 
00061 struct testgroup_t {
00062        const char *prefix; 
00063        struct testcase_t *cases; 
00064 };
00065 #define END_OF_GROUPS { NULL, NULL}
00066 
00068 void tinytest_set_test_failed_(void);
00070 void tinytest_set_test_skipped_(void);
00072 int tinytest_get_verbosity_(void);
00075 int tinytest_set_flag_(struct testgroup_t *, const char *, unsigned long);
00076 
00078 #define tinytest_skip(groups, named) \
00079        tinytest_set_flag_(groups, named, TT_SKIP)
00080 
00082 int testcase_run_one(const struct testgroup_t *,const struct testcase_t *);
00085 int tinytest_main(int argc, const char **argv, struct testgroup_t *groups);
00086 
00087 #endif