1 | /* |
---|
2 | * This file Copyright (C) 2010-2014 Mnemosyne LLC |
---|
3 | * |
---|
4 | * It may be used under the GNU GPL versions 2 or 3 |
---|
5 | * or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: libtransmission-test.h 14288 2014-06-08 19:09:41Z jordan $ |
---|
8 | */ |
---|
9 | |
---|
10 | /* Note VERBOSE needs to be (un)defined before including this file */ |
---|
11 | |
---|
12 | #ifndef LIBTRANSMISSION_TEST_H |
---|
13 | #define LIBTRANSMISSION_TEST_H 1 |
---|
14 | |
---|
15 | #include <stdio.h> |
---|
16 | |
---|
17 | #include "transmission.h" |
---|
18 | #include "utils.h" /* tr_strcmp0 () */ |
---|
19 | |
---|
20 | extern int current_test; |
---|
21 | |
---|
22 | extern bool verbose; |
---|
23 | |
---|
24 | bool should_print (bool pass); |
---|
25 | |
---|
26 | bool check_condition_impl (const char * file, int line, bool condition); |
---|
27 | bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual); |
---|
28 | bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual); |
---|
29 | bool check_streq_impl (const char * file, int line, const char * expected, const char * actual); |
---|
30 | |
---|
31 | /*** |
---|
32 | **** |
---|
33 | ***/ |
---|
34 | |
---|
35 | #define check(condition) \ |
---|
36 | do { \ |
---|
37 | ++current_test; \ |
---|
38 | if (!check_condition_impl (__FILE__, __LINE__, (condition))) \ |
---|
39 | return current_test; \ |
---|
40 | } while (0) |
---|
41 | |
---|
42 | #define check_streq(expected, actual) \ |
---|
43 | do { \ |
---|
44 | ++current_test; \ |
---|
45 | if (!check_streq_impl (__FILE__, __LINE__, (expected), (actual))) \ |
---|
46 | return current_test; \ |
---|
47 | } while (0) |
---|
48 | |
---|
49 | #define check_int_eq(expected, actual) \ |
---|
50 | do { \ |
---|
51 | ++current_test; \ |
---|
52 | if (!check_int_eq_impl (__FILE__, __LINE__, (expected), (actual))) \ |
---|
53 | return current_test; \ |
---|
54 | } while (0) |
---|
55 | |
---|
56 | #define check_ptr_eq(expected, actual) \ |
---|
57 | do { \ |
---|
58 | ++current_test; \ |
---|
59 | if (!check_ptr_eq_impl (__FILE__, __LINE__, (expected), (actual))) \ |
---|
60 | return current_test; \ |
---|
61 | } while (0) |
---|
62 | |
---|
63 | /*** |
---|
64 | **** |
---|
65 | ***/ |
---|
66 | |
---|
67 | typedef int (*testFunc)(void); |
---|
68 | #define NUM_TESTS(tarray)((int)(sizeof (tarray)/sizeof (tarray[0]))) |
---|
69 | |
---|
70 | int runTests (const testFunc * const tests, int numTests); |
---|
71 | |
---|
72 | #define MAIN_SINGLE_TEST(test) \ |
---|
73 | int main (void) { \ |
---|
74 | const testFunc tests[] = { test }; \ |
---|
75 | return runTests (tests, 1); \ |
---|
76 | } |
---|
77 | |
---|
78 | tr_session * libttest_session_init (struct tr_variant * settings); |
---|
79 | void libttest_session_close (tr_session * session); |
---|
80 | |
---|
81 | void libttest_zero_torrent_populate (tr_torrent * tor, bool complete); |
---|
82 | tr_torrent * libttest_zero_torrent_init (tr_session * session); |
---|
83 | |
---|
84 | void libttest_blockingTorrentVerify (tr_torrent * tor); |
---|
85 | |
---|
86 | void libtest_create_file_with_contents (const char * path, const char * str); |
---|
87 | |
---|
88 | char* libtest_sandbox_create (void); |
---|
89 | void libtest_sandbox_destroy (const char * sandbox); |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | #endif /* !LIBTRANSMISSION_TEST_H */ |
---|