1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/third_party/libevent/test/tinytest.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* tinytest.h -- Copyright 2009-2012 Nick Mathewson 1.5 + * 1.6 + * Redistribution and use in source and binary forms, with or without 1.7 + * modification, are permitted provided that the following conditions 1.8 + * are met: 1.9 + * 1. Redistributions of source code must retain the above copyright 1.10 + * notice, this list of conditions and the following disclaimer. 1.11 + * 2. Redistributions in binary form must reproduce the above copyright 1.12 + * notice, this list of conditions and the following disclaimer in the 1.13 + * documentation and/or other materials provided with the distribution. 1.14 + * 3. The name of the author may not be used to endorse or promote products 1.15 + * derived from this software without specific prior written permission. 1.16 + * 1.17 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1.18 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1.19 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1.20 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1.21 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1.22 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.23 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.24 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.25 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 1.26 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.27 + */ 1.28 + 1.29 +#ifndef _TINYTEST_H 1.30 +#define _TINYTEST_H 1.31 + 1.32 +/** Flag for a test that needs to run in a subprocess. */ 1.33 +#define TT_FORK (1<<0) 1.34 +/** Runtime flag for a test we've decided to skip. */ 1.35 +#define TT_SKIP (1<<1) 1.36 +/** Internal runtime flag for a test we've decided to run. */ 1.37 +#define _TT_ENABLED (1<<2) 1.38 +/** If you add your own flags, make them start at this point. */ 1.39 +#define TT_FIRST_USER_FLAG (1<<3) 1.40 + 1.41 +typedef void (*testcase_fn)(void *); 1.42 + 1.43 +struct testcase_t; 1.44 + 1.45 +/** Functions to initialize/teardown a structure for a testcase. */ 1.46 +struct testcase_setup_t { 1.47 + /** Return a new structure for use by a given testcase. */ 1.48 + void *(*setup_fn)(const struct testcase_t *); 1.49 + /** Clean/free a structure from setup_fn. Return 1 if ok, 0 on err. */ 1.50 + int (*cleanup_fn)(const struct testcase_t *, void *); 1.51 +}; 1.52 + 1.53 +/** A single test-case that you can run. */ 1.54 +struct testcase_t { 1.55 + const char *name; /**< An identifier for this case. */ 1.56 + testcase_fn fn; /**< The function to run to implement this case. */ 1.57 + unsigned long flags; /**< Bitfield of TT_* flags. */ 1.58 + const struct testcase_setup_t *setup; /**< Optional setup/cleanup fns*/ 1.59 + void *setup_data; /**< Extra data usable by setup function */ 1.60 +}; 1.61 +#define END_OF_TESTCASES { NULL, NULL, 0, NULL, NULL } 1.62 + 1.63 +/** A group of tests that are selectable together. */ 1.64 +struct testgroup_t { 1.65 + const char *prefix; /**< Prefix to prepend to testnames. */ 1.66 + struct testcase_t *cases; /** Array, ending with END_OF_TESTCASES */ 1.67 +}; 1.68 +#define END_OF_GROUPS { NULL, NULL} 1.69 + 1.70 +/** Implementation: called from a test to indicate failure, before logging. */ 1.71 +void _tinytest_set_test_failed(void); 1.72 +/** Implementation: called from a test to indicate that we're skipping. */ 1.73 +void _tinytest_set_test_skipped(void); 1.74 +/** Implementation: return 0 for quiet, 1 for normal, 2 for loud. */ 1.75 +int _tinytest_get_verbosity(void); 1.76 +/** Implementation: Set a flag on tests matching a name; returns number 1.77 + * of tests that matched. */ 1.78 +int _tinytest_set_flag(struct testgroup_t *, const char *, unsigned long); 1.79 + 1.80 +/** Set all tests in 'groups' matching the name 'named' to be skipped. */ 1.81 +#define tinytest_skip(groups, named) \ 1.82 + _tinytest_set_flag(groups, named, TT_SKIP) 1.83 + 1.84 +/** Run a single testcase in a single group. */ 1.85 +int testcase_run_one(const struct testgroup_t *,const struct testcase_t *); 1.86 +/** Run a set of testcases from an END_OF_GROUPS-terminated array of groups, 1.87 + as selected from the command line. */ 1.88 +int tinytest_main(int argc, const char **argv, struct testgroup_t *groups); 1.89 + 1.90 +#endif