ipc/chromium/src/third_party/libevent/test/tinytest.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* tinytest.h -- Copyright 2009-2012 Nick Mathewson
michael@0 2 *
michael@0 3 * Redistribution and use in source and binary forms, with or without
michael@0 4 * modification, are permitted provided that the following conditions
michael@0 5 * are met:
michael@0 6 * 1. Redistributions of source code must retain the above copyright
michael@0 7 * notice, this list of conditions and the following disclaimer.
michael@0 8 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 9 * notice, this list of conditions and the following disclaimer in the
michael@0 10 * documentation and/or other materials provided with the distribution.
michael@0 11 * 3. The name of the author may not be used to endorse or promote products
michael@0 12 * derived from this software without specific prior written permission.
michael@0 13 *
michael@0 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
michael@0 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
michael@0 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@0 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
michael@0 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
michael@0 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
michael@0 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 24 */
michael@0 25
michael@0 26 #ifndef _TINYTEST_H
michael@0 27 #define _TINYTEST_H
michael@0 28
michael@0 29 /** Flag for a test that needs to run in a subprocess. */
michael@0 30 #define TT_FORK (1<<0)
michael@0 31 /** Runtime flag for a test we've decided to skip. */
michael@0 32 #define TT_SKIP (1<<1)
michael@0 33 /** Internal runtime flag for a test we've decided to run. */
michael@0 34 #define _TT_ENABLED (1<<2)
michael@0 35 /** If you add your own flags, make them start at this point. */
michael@0 36 #define TT_FIRST_USER_FLAG (1<<3)
michael@0 37
michael@0 38 typedef void (*testcase_fn)(void *);
michael@0 39
michael@0 40 struct testcase_t;
michael@0 41
michael@0 42 /** Functions to initialize/teardown a structure for a testcase. */
michael@0 43 struct testcase_setup_t {
michael@0 44 /** Return a new structure for use by a given testcase. */
michael@0 45 void *(*setup_fn)(const struct testcase_t *);
michael@0 46 /** Clean/free a structure from setup_fn. Return 1 if ok, 0 on err. */
michael@0 47 int (*cleanup_fn)(const struct testcase_t *, void *);
michael@0 48 };
michael@0 49
michael@0 50 /** A single test-case that you can run. */
michael@0 51 struct testcase_t {
michael@0 52 const char *name; /**< An identifier for this case. */
michael@0 53 testcase_fn fn; /**< The function to run to implement this case. */
michael@0 54 unsigned long flags; /**< Bitfield of TT_* flags. */
michael@0 55 const struct testcase_setup_t *setup; /**< Optional setup/cleanup fns*/
michael@0 56 void *setup_data; /**< Extra data usable by setup function */
michael@0 57 };
michael@0 58 #define END_OF_TESTCASES { NULL, NULL, 0, NULL, NULL }
michael@0 59
michael@0 60 /** A group of tests that are selectable together. */
michael@0 61 struct testgroup_t {
michael@0 62 const char *prefix; /**< Prefix to prepend to testnames. */
michael@0 63 struct testcase_t *cases; /** Array, ending with END_OF_TESTCASES */
michael@0 64 };
michael@0 65 #define END_OF_GROUPS { NULL, NULL}
michael@0 66
michael@0 67 /** Implementation: called from a test to indicate failure, before logging. */
michael@0 68 void _tinytest_set_test_failed(void);
michael@0 69 /** Implementation: called from a test to indicate that we're skipping. */
michael@0 70 void _tinytest_set_test_skipped(void);
michael@0 71 /** Implementation: return 0 for quiet, 1 for normal, 2 for loud. */
michael@0 72 int _tinytest_get_verbosity(void);
michael@0 73 /** Implementation: Set a flag on tests matching a name; returns number
michael@0 74 * of tests that matched. */
michael@0 75 int _tinytest_set_flag(struct testgroup_t *, const char *, unsigned long);
michael@0 76
michael@0 77 /** Set all tests in 'groups' matching the name 'named' to be skipped. */
michael@0 78 #define tinytest_skip(groups, named) \
michael@0 79 _tinytest_set_flag(groups, named, TT_SKIP)
michael@0 80
michael@0 81 /** Run a single testcase in a single group. */
michael@0 82 int testcase_run_one(const struct testgroup_t *,const struct testcase_t *);
michael@0 83 /** Run a set of testcases from an END_OF_GROUPS-terminated array of groups,
michael@0 84 as selected from the command line. */
michael@0 85 int tinytest_main(int argc, const char **argv, struct testgroup_t *groups);
michael@0 86
michael@0 87 #endif

mercurial