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 14289 2014-06-08 20:01:10Z 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 | #include <string.h> /* strlen() */ |
---|
17 | |
---|
18 | #include "transmission.h" |
---|
19 | #include "utils.h" /* tr_strcmp0 () */ |
---|
20 | |
---|
21 | extern int current_test; |
---|
22 | |
---|
23 | extern bool verbose; |
---|
24 | |
---|
25 | bool should_print (bool pass); |
---|
26 | |
---|
27 | bool check_condition_impl (const char * file, int line, bool condition); |
---|
28 | bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual); |
---|
29 | bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual); |
---|
30 | bool check_streq_impl (const char * file, int line, const char * expected, const char * actual); |
---|
31 | |
---|
32 | /*** |
---|
33 | **** |
---|
34 | ***/ |
---|
35 | |
---|
36 | #define check(condition) \ |
---|
37 | do { \ |
---|
38 | ++current_test; \ |
---|
39 | if (!check_condition_impl (__FILE__, __LINE__, (condition))) \ |
---|
40 | return current_test; \ |
---|
41 | } while (0) |
---|
42 | |
---|
43 | #define check_streq(expected, actual) \ |
---|
44 | do { \ |
---|
45 | ++current_test; \ |
---|
46 | if (!check_streq_impl (__FILE__, __LINE__, (expected), (actual))) \ |
---|
47 | return current_test; \ |
---|
48 | } while (0) |
---|
49 | |
---|
50 | #define check_int_eq(expected, actual) \ |
---|
51 | do { \ |
---|
52 | ++current_test; \ |
---|
53 | if (!check_int_eq_impl (__FILE__, __LINE__, (expected), (actual))) \ |
---|
54 | return current_test; \ |
---|
55 | } while (0) |
---|
56 | |
---|
57 | #define check_ptr_eq(expected, actual) \ |
---|
58 | do { \ |
---|
59 | ++current_test; \ |
---|
60 | if (!check_ptr_eq_impl (__FILE__, __LINE__, (expected), (actual))) \ |
---|
61 | return current_test; \ |
---|
62 | } while (0) |
---|
63 | |
---|
64 | /*** |
---|
65 | **** |
---|
66 | ***/ |
---|
67 | |
---|
68 | typedef int (*testFunc)(void); |
---|
69 | #define NUM_TESTS(tarray)((int)(sizeof (tarray)/sizeof (tarray[0]))) |
---|
70 | |
---|
71 | int runTests (const testFunc * const tests, int numTests); |
---|
72 | |
---|
73 | #define MAIN_SINGLE_TEST(test) \ |
---|
74 | int main (void) { \ |
---|
75 | const testFunc tests[] = { test }; \ |
---|
76 | return runTests (tests, 1); \ |
---|
77 | } |
---|
78 | |
---|
79 | tr_session * libttest_session_init (struct tr_variant * settings); |
---|
80 | void libttest_session_close (tr_session * session); |
---|
81 | |
---|
82 | void libttest_zero_torrent_populate (tr_torrent * tor, bool complete); |
---|
83 | tr_torrent * libttest_zero_torrent_init (tr_session * session); |
---|
84 | |
---|
85 | void libttest_blockingTorrentVerify (tr_torrent * tor); |
---|
86 | |
---|
87 | void libtest_create_file_with_contents (const char * path, const void* contents, size_t n); |
---|
88 | void libtest_create_tmpfile_with_contents (char* tmpl, const void* payload, size_t n); |
---|
89 | void libtest_create_file_with_string_contents (const char * path, const char* str); |
---|
90 | |
---|
91 | char* libtest_sandbox_create (void); |
---|
92 | void libtest_sandbox_destroy (const char * sandbox); |
---|
93 | |
---|
94 | |
---|
95 | #endif /* !LIBTRANSMISSION_TEST_H */ |
---|