2014-01-19 01:09:44 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2010-2014 Mnemosyne LLC
|
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-08-18 16:07:05 +00:00
|
|
|
/* Note VERBOSE needs to be (un)defined before including this file */
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2012-08-18 16:07:05 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2014-06-08 20:01:10 +00:00
|
|
|
#include <string.h> /* strlen() */
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2013-01-21 00:00:00 +00:00
|
|
|
#include "transmission.h"
|
2017-04-21 07:40:57 +00:00
|
|
|
#include "utils.h" /* tr_strcmp0() */
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
extern int current_test;
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
extern bool verbose;
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool should_print(bool pass);
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool check_condition_impl(char const* file, int line, bool condition);
|
2017-05-29 16:51:25 +00:00
|
|
|
bool check_uint_eq_impl(char const* file, int line, uintmax_t expected, uintmax_t actual);
|
2017-04-20 16:02:19 +00:00
|
|
|
bool check_ptr_eq_impl(char const* file, int line, void const* expected, void const* actual);
|
2017-05-29 19:48:02 +00:00
|
|
|
|
|
|
|
bool libtest_check_str(char const* file, int line, bool pass, char const* lhs, char const* rhs, char const* lhs_str,
|
|
|
|
char const* op_str, char const* rhs_str);
|
2017-05-29 20:22:36 +00:00
|
|
|
bool libtest_check_int(char const* file, int line, bool pass, intmax_t lhs, intmax_t rhs, char const* lhs_str,
|
|
|
|
char const* op_str, char const* rhs_str);
|
2012-12-10 01:24:50 +00:00
|
|
|
|
2012-10-14 17:59:24 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
#define check(condition) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
++current_test; \
|
|
|
|
\
|
|
|
|
if (!check_condition_impl(__FILE__, __LINE__, (condition))) \
|
|
|
|
{ \
|
|
|
|
return current_test; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2017-05-29 19:48:02 +00:00
|
|
|
#define check_str(lhs, op, rhs) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
++current_test; \
|
|
|
|
\
|
2017-05-29 19:48:02 +00:00
|
|
|
char const* const check_str_lhs = (lhs); \
|
|
|
|
char const* const check_str_rhs = (rhs); \
|
|
|
|
\
|
|
|
|
if (!libtest_check_str(__FILE__, __LINE__, tr_strcmp0(check_str_lhs, check_str_rhs) op 0, check_str_lhs, \
|
|
|
|
check_str_rhs, #lhs, #op, #rhs)) \
|
2017-04-19 12:04:45 +00:00
|
|
|
{ \
|
|
|
|
return current_test; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2017-05-29 20:22:36 +00:00
|
|
|
#define check_int(lhs, op, rhs) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
++current_test; \
|
|
|
|
\
|
2017-05-29 20:22:36 +00:00
|
|
|
intmax_t const check_int_lhs = (lhs); \
|
|
|
|
intmax_t const check_int_rhs = (rhs); \
|
|
|
|
\
|
|
|
|
if (!libtest_check_int(__FILE__, __LINE__, check_int_lhs op check_int_rhs, check_int_lhs, check_int_rhs, #lhs, #op, \
|
|
|
|
#rhs)) \
|
2017-04-19 12:04:45 +00:00
|
|
|
{ \
|
|
|
|
return current_test; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
2012-12-10 01:24:50 +00:00
|
|
|
|
2016-03-29 03:04:54 +00:00
|
|
|
#define check_uint_eq(expected, actual) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
++current_test; \
|
|
|
|
\
|
|
|
|
if (!check_uint_eq_impl(__FILE__, __LINE__, (expected), (actual))) \
|
|
|
|
{ \
|
|
|
|
return current_test; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
2016-03-29 03:04:54 +00:00
|
|
|
|
2012-12-10 01:24:50 +00:00
|
|
|
#define check_ptr_eq(expected, actual) \
|
2017-04-19 12:04:45 +00:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
++current_test; \
|
|
|
|
\
|
|
|
|
if (!check_ptr_eq_impl(__FILE__, __LINE__, (expected), (actual))) \
|
|
|
|
{ \
|
|
|
|
return current_test; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2012-10-14 17:59:24 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
typedef int (* testFunc)(void);
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
#define NUM_TESTS(tarray) ((int)(sizeof(tarray) / sizeof(tarray[0])))
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int runTests(testFunc const* const tests, int numTests);
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
#define MAIN_SINGLE_TEST(test) \
|
|
|
|
int main(void) \
|
|
|
|
{ \
|
2017-04-20 16:02:19 +00:00
|
|
|
testFunc const tests[] = { test }; \
|
2017-04-19 12:04:45 +00:00
|
|
|
return runTests(tests, 1); \
|
|
|
|
}
|
2013-01-21 21:11:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_session* libttest_session_init(struct tr_variant* settings);
|
|
|
|
void libttest_session_close(tr_session* session);
|
2013-01-21 00:00:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void libttest_zero_torrent_populate(tr_torrent* tor, bool complete);
|
|
|
|
tr_torrent* libttest_zero_torrent_init(tr_session* session);
|
2013-01-31 21:58:25 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void libttest_blockingTorrentVerify(tr_torrent* tor);
|
2014-06-08 19:09:41 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void libtest_create_file_with_contents(char const* path, void const* contents, size_t n);
|
|
|
|
void libtest_create_tmpfile_with_contents(char* tmpl, void const* payload, size_t n);
|
|
|
|
void libtest_create_file_with_string_contents(char const* path, char const* str);
|
2014-06-08 19:09:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
char* libtest_sandbox_create(void);
|
2017-04-20 16:02:19 +00:00
|
|
|
void libtest_sandbox_destroy(char const* sandbox);
|
2014-06-08 19:09:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void libttest_sync(void);
|