source: trunk/libtransmission/libtransmission-test.h @ 14289

Last change on this file since 14289 was 14289, checked in by jordan, 8 years ago

add tr_makeMetaInfo() unit test for creating a single-file torrent

  • Property svn:keywords set to Date Rev Author Id
File size: 2.6 KB
Line 
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
21extern int current_test;
22
23extern bool verbose;
24
25bool should_print (bool pass);
26
27bool check_condition_impl (const char * file, int line, bool condition);
28bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual);
29bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual);
30bool 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
68typedef int (*testFunc)(void);
69#define NUM_TESTS(tarray)((int)(sizeof (tarray)/sizeof (tarray[0])))
70
71int runTests (const testFunc * const tests, int numTests);
72
73#define MAIN_SINGLE_TEST(test) \
74int main (void) { \
75    const testFunc tests[] = { test }; \
76    return runTests (tests, 1); \
77}
78
79tr_session * libttest_session_init (struct tr_variant * settings);
80void         libttest_session_close (tr_session * session);
81
82void         libttest_zero_torrent_populate (tr_torrent * tor, bool complete);
83tr_torrent * libttest_zero_torrent_init (tr_session * session);
84
85void         libttest_blockingTorrentVerify (tr_torrent * tor);
86
87void         libtest_create_file_with_contents (const char * path, const void* contents, size_t n);
88void         libtest_create_tmpfile_with_contents (char* tmpl, const void* payload, size_t n);
89void         libtest_create_file_with_string_contents (const char * path, const char* str);
90
91char*        libtest_sandbox_create (void);
92void         libtest_sandbox_destroy (const char * sandbox);
93
94
95#endif /* !LIBTRANSMISSION_TEST_H */
Note: See TracBrowser for help on using the repository browser.