1/* 2 * Copyright (c) 2008-2010 Kungliga Tekniska Högskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Portions Copyright (c) 2008-2010 Apple Inc. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * 3. Neither the name of the Institute nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36/* 37 * 1) Create an test abstraction layer for integration into other systems. 38 * 2) Create a simplified way to collect and report test results. 39 * 3) Low impact in the test source. 40 * 41 * 42 * Convenience functions: 43 * ---------------------- 44 * test_collection_t *tests_init_and_start(const char*); 45 * int tests_stop_and_free(test_collection_t*); 46 * time_t tests_start_timer(test_collection_t*); 47 * time_t tests_stop_timer(test_collection_t*); 48 * 49 * Test status functions: 50 * ---------------------- 51 * void test_passed(test_collection_t*, const char*); 52 * void test_failed(test_collection_t*, const char*, const char*, ...) 53 * int test_evaluate(test_collection_t*, const char*, int, const char*, ...) 54 * 55 * Setting library options: 56 * ------------------------ 57 * uint32_t tests_set_flags(test_collection_t*, uint32_t); 58 * uint32_t tests_unset_flags(test_collection_t*, uint32_t); 59 * 60 * Other important functions: 61 * -------------------------- 62 * size_t tests_set_total_count_hint(test_collection_t*, size_t); 63 * int tests_return_value(const test_collection_t*); 64 * double tests_duration(test_collection_t*); 65 * 66 * 67 */ 68 69#include <inttypes.h> 70#include <stdarg.h> 71#include <time.h> 72 73#if !defined(_TEST_COLLECTION_H_) 74#define _TEST_COLLECTION_H_ 75 76/* Possible test statuses. */ 77enum test_collection_return_values { 78 TC_TESTS_PASSED = 0, 79 TC_TESTS_FAILED 80}; 81 82/* Maximum string length for name. */ 83#define TC_NAME_MAX_LENGTH 512 84 85/* Available flags. */ 86#define TC_FLAG_NONE 0u 87#define TC_FLAG_EXIT_ON_FAILURE (1u<<1) 88#define TC_FLAG_SUMMARY_ON_STOP (1u<<2) 89 90#define TC_FLAG_DEFAULTS (TC_FLAG_SUMMARY_ON_STOP) 91 92/* Structure representing a collections of tests. */ 93typedef struct _struct_test_collection_t { 94 char *name; 95 size_t failed_count; 96 size_t passed_count; 97 size_t total_count_hint; 98 time_t start_time; 99 time_t stop_time; 100 uint32_t flags; 101} test_collection_t; 102 103test_collection_t *tests_init_and_start(const char*); 104int tests_stop_and_free(test_collection_t*); 105 106void test_passed(test_collection_t*, const char*); 107void test_failed(test_collection_t*, const char*, const char*, ...) 108 __attribute__((format(printf, 2, 4))); 109int test_evaluate(test_collection_t*, const char*, int); 110int vtest_evaluate(test_collection_t*, const char*, int, const char*, ...) 111 __attribute__((format(printf, 4, 5))); 112 113 114test_collection_t *test_collection_init(const char*); 115void test_collection_free(test_collection_t*); 116 117int tests_return_value(const test_collection_t*); 118 119time_t tests_start_timer(test_collection_t*); 120time_t tests_stop_timer(test_collection_t*); 121time_t tests_get_start_time(test_collection_t*); 122time_t tests_set_start_time(test_collection_t*, time_t); 123time_t tests_get_stop_time(test_collection_t*); 124time_t tests_set_stop_time(test_collection_t*, time_t); 125double tests_duration(test_collection_t*); 126 127uint32_t tests_get_flags(const test_collection_t*); 128uint32_t tests_set_flags(test_collection_t*, uint32_t); 129uint32_t tests_unset_flags(test_collection_t*, uint32_t); 130 131size_t tests_get_total_count_hint(const test_collection_t*); 132size_t tests_set_total_count_hint(test_collection_t*, size_t); 133 134char *tests_get_name(const test_collection_t*); 135char *tests_set_name(test_collection_t*, const char*); 136 137#endif /* _TEST_COLLECTION_H_ */ 138 139