merge small unit tests to make running the tests quicker. expand the test framework a bit. add ax_boost_random.m4 script to link against boost.random correctly from makefile.

This commit is contained in:
Arvid Norberg 2015-05-30 04:31:23 +00:00
parent 9b0313bd8e
commit f9c9d0ad0d
93 changed files with 667 additions and 372 deletions

View File

@ -134,7 +134,6 @@ AS_IF([test -z "$BOOST_RANDOM_LIB"],
CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS"
LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
###############################################################################
# Checking for functions and other stuffs
###############################################################################

View File

@ -38,8 +38,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent { namespace aux
{
// initialized by static initializers (in cpuid.cpp)
extern bool sse42_support;
extern bool mmx_support;
TORRENT_EXTRA_EXPORT extern bool sse42_support;
TORRENT_EXTRA_EXPORT extern bool mmx_support;
} }
#endif // TORRENT_CPUID_HPP_INCLUDED

View File

@ -89,7 +89,7 @@ namespace libtorrent
, error_code& ec);
TORRENT_EXTRA_EXPORT bool in_local_network(std::vector<ip_interface> const& net
, address const& addr);
TORRENT_EXTRA_EXPORT address get_default_gateway(error_code& ec);
#ifdef SO_BINDTODEVICE

View File

@ -54,7 +54,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#ifdef __OBJC__
#ifdef __OBJC__
#undef Protocol
#endif

123
m4/ax_boost_random.m4 Normal file
View File

@ -0,0 +1,123 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_boost_random.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_BOOST_RANDOM
#
# DESCRIPTION
#
# Test for Random library from the Boost C++ libraries. The macro requires a
# preceding call to AX_BOOST_BASE. Further documentation is available at
# <http://randspringer.de/boost/index.html>.
#
# This macro calls:
#
# AC_SUBST(BOOST_RANDOM_LIB)
#
# And sets:
#
# HAVE_BOOST_RANDOM
#
# LICENSE
#
# Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
# Copyright (c) 2008 Michael Tindal
# Copyright (c) 2013 Daniel Casimiro <dan.casimiro@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([AX_BOOST_RANDOM],
[
AC_ARG_WITH([boost-random],
AS_HELP_STRING([--with-boost-random@<:@=special-lib@:>@],
[use the Random library from boost - it is possible to specify a certain library for the linker
e.g. --with-boost-random=boost_random-gcc-mt ]), [
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ax_boost_user_random_lib=""
else
want_boost="yes"
ax_boost_user_random_lib="$withval"
fi
], [want_boost="yes"]
)
if test "x$want_boost" = "xyes"; then
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_BUILD])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_CACHE_CHECK(whether the Boost::Random library is available,
ax_cv_boost_random,
[AC_LANG_PUSH([C++])
CXXFLAGS_SAVE=$CXXFLAGS
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[@%:@include <boost/random/random_device.hpp>]],
[[boost::random::random_device()();]])],
ax_cv_boost_random=yes, ax_cv_boost_random=no)
CXXFLAGS=$CXXFLAGS_SAVE
AC_LANG_POP([C++])
])
if test "x$ax_cv_boost_random" = "xyes"; then
AC_SUBST(BOOST_CPPFLAGS)
AC_DEFINE(HAVE_BOOST_RANDOM,,[define if the Boost::Random library is available])
BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
if test "x$ax_boost_user_random_lib" = "x"; then
for libextension in `ls $BOOSTLIBDIR/libboost_random*.so* $BOOSTLIBDIR/libboost_random*.dylib* $BOOSTLIBDIR/libboost_random*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_random.*\)\.so.*$;\1;' -e 's;^lib\(boost_random.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_random.*\)\.a.*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_RANDOM_LIB="-l$ax_lib"; AC_SUBST(BOOST_RANDOM_LIB) link_random="yes"; break],
[link_random="no"])
done
if test "x$link_random" != "xyes"; then
for libextension in `ls $BOOSTLIBDIR/boost_random*.dll* $BOOSTLIBDIR/boost_random*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_random.*\)\.dll.*$;\1;' -e 's;^\(boost_random.*\)\.a.*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_RANDOM_LIB="-l$ax_lib"; AC_SUBST(BOOST_RANDOM_LIB) link_random="yes"; break],
[link_random="no"])
done
fi
else
for ax_lib in $ax_boost_user_random_lib boost_random-$ax_boost_user_random_lib; do
AC_CHECK_LIB($ax_lib, exit,
[BOOST_RANDOM_LIB="-l$ax_lib"; AC_SUBST(BOOST_RANDOM_LIB) link_random="yes"; break],
[link_random="no"])
done
fi
if test "x$ax_lib" = "x"; then
AC_MSG_ERROR(Could not find a version of the library!)
fi
if test "x$link_random" = "xno"; then
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
fi
])

View File

@ -83,6 +83,7 @@ lib advapi32 : : <name>Advapi32 ;
project
: requirements
<source>main.cpp
<source>test.cpp
<conditional>@link_test
<conditional>@link_libtorrent
: default-build
@ -91,66 +92,69 @@ project
<debug-iterators>on
<link>shared
<picker-debugging>on
;
;
feature launcher : none valgrind : composite ;
feature.compose <launcher>valgrind : <testing.launcher>"valgrind --tool=memcheck -v --num-callers=20 --read-var-info=yes --track-origins=yes --error-exitcode=222 --suppressions=valgrind_suppressions.txt" <use-valgrind>on ;
test-suite libtorrent :
[ run test_timestamp_history.cpp ]
[ run test_sha1_hash.cpp ]
[ run test_bloom_filter.cpp ]
[ run test_identify_client.cpp ]
[ run test_merkle.cpp ]
[ run test_alert_manager.cpp ]
[ run test_resolve_links.cpp ]
[ run test_crc32.cpp ]
[ run test_heterogeneous_queue.cpp ]
[ run test_ip_voter.cpp ]
[ run test_resume.cpp ]
[ run test_sliding_average.cpp ]
[ run test_socket_io.cpp ]
[ run test_random.cpp ]
[ run test_utf8.cpp ]
[ run test_gzip.cpp ]
[ run test_bitfield.cpp ]
[ run test_recheck.cpp ]
[ run test_stat_cache.cpp ]
[ run test_part_file.cpp ]
[ run test_peer_list.cpp ]
[ run test_torrent_info.cpp ]
[ run test_time.cpp ]
[ run test_file_storage.cpp ]
[ run test_priority.cpp ]
[ run test_peer_priority.cpp ]
[ run test_file.cpp ]
[ run test_privacy.cpp ]
[ run test_threads.cpp ]
[ run test_tailqueue.cpp ]
[ run test_bandwidth_limiter.cpp ]
[ run test_buffer.cpp ]
[ run test_piece_picker.cpp ]
[ run test_bencoding.cpp ]
[ run test_bdecode.cpp ]
[ run test_fast_extension.cpp ]
[ run test_primitives.cpp ]
[ run test_http_parser.cpp ]
[ run test_packet_buffer.cpp ]
[ run test_string.cpp ]
[ run test_magnet.cpp ]
[ run test_xml.cpp ]
[ run test_ip_filter.cpp ]
[ run test_hasher.cpp ]
[ run test_dht.cpp ]
[ run test_block_cache.cpp ]
[ run test_peer_classes.cpp ]
[ run test_settings_pack.cpp ]
[ run test_fence.cpp ]
test-suite libtorrent :
[ run
test_primitives.cpp
test_packet_buffer.cpp
test_timestamp_history.cpp
test_sha1_hash.cpp
test_bloom_filter.cpp
test_identify_client.cpp
test_merkle.cpp
test_alert_manager.cpp
test_resolve_links.cpp
test_crc32.cpp
test_heterogeneous_queue.cpp
test_ip_voter.cpp
test_sliding_average.cpp
test_socket_io.cpp
test_random.cpp
test_utf8.cpp
test_gzip.cpp
test_bitfield.cpp
test_part_file.cpp
test_peer_list.cpp
test_torrent_info.cpp
test_time.cpp
test_file_storage.cpp
test_peer_priority.cpp
test_threads.cpp
test_tailqueue.cpp
test_bandwidth_limiter.cpp
test_buffer.cpp
test_piece_picker.cpp
test_bencoding.cpp
test_bdecode.cpp
test_http_parser.cpp
test_string.cpp
test_magnet.cpp
test_xml.cpp
test_ip_filter.cpp
test_hasher.cpp
test_dht.cpp
test_block_cache.cpp
test_peer_classes.cpp
test_settings_pack.cpp
test_fence.cpp
test_dos_blocker.cpp
test_upnp.cpp ]
[ run test_storage.cpp ]
[ run test_session.cpp ]
[ run test_upnp.cpp ]
[ run test_read_piece.cpp ]
[ run test_file.cpp ]
[ run test_stat_cache.cpp ]
[ run test_fast_extension.cpp ]
[ run test_privacy.cpp ]
[ run test_priority.cpp ]
[ run test_recheck.cpp ]
[ run test_resume.cpp ]
[ run test_ssl.cpp ]
[ run test_tracker.cpp ]
[ run test_checking.cpp ]
@ -165,7 +169,6 @@ test-suite libtorrent :
[ run test_web_seed_chunked.cpp ]
[ run test_web_seed_ban.cpp ]
[ run test_pe_crypto.cpp ]
[ run test_dos_blocker.cpp ]
[ run test_remap_files.cpp ]
[ run test_utp.cpp ]
@ -180,5 +183,5 @@ test-suite libtorrent :
[ run test_swarm.cpp ]
[ run test_lsd.cpp ]
[ run test_pex.cpp ]
;
;

View File

@ -1,49 +1,21 @@
AUTOMAKE_OPTIONS = subdir-objects
test_programs = \
test_timestamp_history \
test_sha1_hash \
test_bloom_filter \
test_identify_client \
test_alert_manager \
test_bitfield \
test_crc32 \
test_torrent_info \
test_primitives \
test_recheck \
test_stat_cache \
test_part_file \
test_file \
test_file_storage \
test_privacy \
test_priority \
test_auto_unchoke \
test_bandwidth_limiter \
test_bdecode_performance \
test_bencoding \
test_buffer \
test_block_cache \
test_checking \
test_fast_extension \
test_hasher \
test_heterogeneous_queue \
test_http_connection \
test_ip_filter \
test_ip_voter \
test_dht \
test_lsd \
test_metadata_extension \
test_pe_crypto \
test_peer_classes \
test_peer_list \
test_peer_priority \
test_pex \
test_piece_picker \
test_xml \
test_string \
test_primitives \
test_http_parser \
test_magnet \
test_packet_buffer \
test_settings_pack \
test_read_piece \
test_resume \
test_ssl \
@ -51,24 +23,16 @@ test_programs = \
test_time_critical \
test_super_seeding \
test_swarm \
test_tailqueue \
test_threads \
test_torrent \
test_tracker \
test_trackers_extension \
test_transfer \
test_upnp \
enum_if \
test_utp \
test_session \
test_web_seed \
test_url_seed \
test_remap_files \
test_gzip \
test_utf8 \
test_socket_io \
test_sliding_average \
test_merkle
test_remap_files
if ENABLE_TESTS
check_PROGRAMS = $(test_programs)
@ -134,10 +98,11 @@ EXTRA_DIST = Jamfile \
EXTRA_PROGRAMS = $(test_programs)
noinst_HEADERS = test.hpp setup_transfer.hpp dht_server.hpp \
peer_server.hpp udp_tracker.hpp web_seed_suite.hpp swarm_suite.hpp \
test_utils.hpp
peer_server.hpp udp_tracker.hpp web_seed_suite.hpp swarm_suite.hpp \
test_utils.hpp
libtest_la_SOURCES = main.cpp \
test.cpp \
setup_transfer.cpp \
dht_server.cpp \
udp_tracker.cpp \
@ -146,79 +111,89 @@ libtest_la_SOURCES = main.cpp \
swarm_suite.cpp \
test_utils.cpp
test_timestamp_history_SOURCES = test_timestamp_history.cpp
test_sha1_hash_SOURCES = test_sha1_hash.cpp
test_bloom_filter_SOURCES = test_bloom_filter.cpp
test_identify_client_SOURCES = test_identify_client.cpp
test_alert_manager_SOURCES = test_alert_manager.cpp
test_bitfield_SOURCES = test_bitfield.cpp
test_crc32_SOURCES = test_crc32.cpp
test_torrent_info_SOURCES = test_torrent_info.cpp
test_primitives_SOURCES = \
test_primitives.cpp \
test_packet_buffer.cpp \
test_timestamp_history.cpp \
test_sha1_hash.cpp \
test_bloom_filter.cpp \
test_identify_client.cpp \
test_merkle.cpp \
test_alert_manager.cpp \
test_resolve_links.cpp \
test_crc32.cpp \
test_heterogeneous_queue.cpp \
test_ip_voter.cpp \
test_sliding_average.cpp \
test_socket_io.cpp \
test_random.cpp \
test_utf8.cpp \
test_gzip.cpp \
test_bitfield.cpp \
test_part_file.cpp \
test_peer_list.cpp \
test_torrent_info.cpp \
test_time.cpp \
test_file_storage.cpp \
test_peer_priority.cpp \
test_threads.cpp \
test_tailqueue.cpp \
test_bandwidth_limiter.cpp \
test_buffer.cpp \
test_piece_picker.cpp \
test_bencoding.cpp \
test_bdecode.cpp \
test_http_parser.cpp \
test_string.cpp \
test_magnet.cpp \
test_xml.cpp \
test_ip_filter.cpp \
test_hasher.cpp \
test_dht.cpp \
test_block_cache.cpp \
test_peer_classes.cpp \
test_settings_pack.cpp \
test_fence.cpp \
test_dos_blocker.cpp \
test_upnp.cpp
test_recheck_SOURCES = test_recheck.cpp
test_stat_cache_SOURCES = test_stat_cache.cpp
test_part_file_SOURCES = test_part_file.cpp
test_file_SOURCES = test_file.cpp
test_file_storage_SOURCES = test_file_storage.cpp
test_privacy_SOURCES = test_privacy.cpp
test_priority_SOURCES = test_priority.cpp
test_auto_unchoke_SOURCES = test_auto_unchoke.cpp
test_bandwidth_limiter_SOURCES = test_bandwidth_limiter.cpp
test_bdecode_performance_SOURCES = test_bdecode_performance.cpp
test_dht_SOURCES = test_dht.cpp
test_bencoding_SOURCES = test_bencoding.cpp
test_buffer_SOURCES = test_buffer.cpp
test_block_cache_SOURCES = test_block_cache.cpp
test_checking_SOURCES = test_checking.cpp
test_fast_extension_SOURCES = test_fast_extension.cpp
test_hasher_SOURCES = test_hasher.cpp
test_heterogeneous_queue_SOURCES = test_heterogeneous_queue.cpp
test_http_connection_SOURCES = test_http_connection.cpp
test_ip_filter_SOURCES = test_ip_filter.cpp
test_ip_voter_SOURCES = test_ip_voter.cpp
test_lsd_SOURCES = test_lsd.cpp
test_metadata_extension_SOURCES = test_metadata_extension.cpp
test_peer_priority_SOURCES = test_peer_priority.cpp
test_pe_crypto_SOURCES = test_pe_crypto.cpp
test_peer_classes_SOURCES = test_peer_classes.cpp
test_peer_list_SOURCES = test_peer_list.cpp
test_pex_SOURCES = test_pex.cpp
test_piece_picker_SOURCES = test_piece_picker.cpp
test_xml_SOURCES = test_xml.cpp
test_string_SOURCES = test_string.cpp
test_primitives_SOURCES = test_primitives.cpp
test_http_parser_SOURCES = test_http_parser.cpp
test_magnet_SOURCES = test_magnet.cpp
test_packet_buffer_SOURCES = test_packet_buffer.cpp
test_read_piece_SOURCES = test_read_piece.cpp
test_storage_SOURCES = test_storage.cpp
test_settings_pack_SOURCES = test_settings_pack.cpp
test_time_critical_SOURCES = test_time_critical.cpp
test_super_seeding_SOURCES = test_super_seeding.cpp
test_swarm_SOURCES = test_swarm.cpp
test_tailqueue_SOURCES = test_tailqueue.cpp
test_resume_SOURCES = test_resume.cpp
test_ssl_SOURCES = test_ssl.cpp
test_threads_SOURCES = test_threads.cpp
test_torrent_SOURCES = test_torrent.cpp
test_tracker_SOURCES = test_tracker.cpp
test_trackers_extension_SOURCES = test_trackers_extension.cpp
test_transfer_SOURCES = test_transfer.cpp
test_upnp_SOURCES = test_upnp.cpp
enum_if_SOURCES = enum_if.cpp
test_utp_SOURCES = test_utp.cpp
test_session_SOURCES = test_session.cpp
test_web_seed_SOURCES = test_web_seed.cpp
test_url_seed_SOURCES = test_url_seed.cpp
test_remap_files_SOURCES = test_remap_files.cpp
test_gzip_SOURCES = test_gzip.cpp
test_utf8_SOURCES = test_utf8.cpp
test_socket_io_SOURCES = test_socket_io.cpp
test_sliding_average_SOURCES = test_sliding_average.cpp
test_merkle_SOURCES = test_merkle.cpp
LDADD = libtest.la $(top_builddir)/src/libtorrent-rasterbar.la
#AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/include/libtorrent @DEBUGFLAGS@ @PTHREAD_CFLAGS@
AM_CPPFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@
AM_LDFLAGS=@BOOST_SYSTEM_LIB@ @PTHREAD_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@
AM_LDFLAGS=@BOOST_SYSTEM_LIB@ @PTHREAD_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@ \
@BOOST_CHRONO_LIB@

View File

@ -41,10 +41,8 @@ int main()
{
io_service ios;
error_code ec;
address local = guess_local_address(ios);
printf("Local address: %s\n", local.to_string(ec).c_str());
address def_gw = get_default_gateway(ios, ec);
address def_gw = get_default_gateway(ec);
if (ec)
{
fprintf(stderr, "%s\n", ec.message().c_str());
@ -54,7 +52,7 @@ int main()
printf("Default gateway: %s\n", def_gw.to_string(ec).c_str());
printf("=========== Routes ===========\n");
std::vector<ip_route> routes = enum_routes(ios, ec);
std::vector<ip_route> routes = enum_routes(ec);
if (ec)
{
printf("%s\n", ec.message().c_str());

View File

@ -37,14 +37,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h> // for exit()
#include "libtorrent/address.hpp"
#include "libtorrent/socket.hpp"
#include "setup_transfer.hpp" // for tests_failure
#include "setup_transfer.hpp" // for _g_test_failures
#include "test.hpp"
#include "dht_server.hpp" // for stop_dht
#include "peer_server.hpp" // for stop_peer
#include "udp_tracker.hpp" // for stop_udp_tracker
int test_main();
#include "libtorrent/assert.hpp"
#include "libtorrent/file.hpp"
#include <signal.h>
@ -90,8 +88,49 @@ void sig_handler(int sig)
exit(138);
}
int main()
void print_usage(char const* argv[])
{
printf("%s [options] [tests...]\n"
"\n"
"OPTIONS:\n"
"-h,--help show this help\n"
"-l,--list list the tests available to run\n"
"\n"
"for tests, specify one or more test names as printed\n"
"by -l. If no test is specified, all tests are run\n", argv[0]);
}
int main(int argc, char const* argv[])
{
if (argc > 1
&& (strcmp(argv[1], "-h") == 0
|| strcmp(argv[1], "--help") == 0))
{
print_usage(argv);
return 0;
}
if (argc > 1
&& (strcmp(argv[1], "-l") == 0
|| strcmp(argv[1], "--list") == 0))
{
printf("TESTS:\n");
for (int i = 0; i < _g_num_unit_tests; ++i)
{
printf(" - %s\n", _g_unit_tests[i].name);
}
return 0;
}
std::set<std::string> tests_to_run;
bool filter = false;
for (int i = 1; i < argc; ++i)
{
tests_to_run.insert(argv[i]);
filter = true;
}
#ifdef WIN32
// try to suppress hanging the process by windows displaying
// modal dialogs.
@ -138,25 +177,106 @@ int main()
#endif
fprintf(stderr, "cwd = \"%s\"\n", test_dir.c_str());
int total_failures = 0;
if (_g_num_unit_tests == 0)
{
fprintf(stderr, "\x1b[31mERROR: no unit tests registered\x1b[0m\n");
return 1;
}
int old_stdout = dup(fileno(stdout));
int old_stderr = dup(fileno(stderr));
int num_run = 0;
for (int i = 0; i < _g_num_unit_tests; ++i)
{
if (filter && tests_to_run.count(_g_unit_tests[i].name) == 0)
continue;
unit_test_t& t = _g_unit_tests[i];
// redirect test output to a temporary file
fflush(stdout);
fflush(stderr);
t.output = tmpfile();
int ret1 = dup2(fileno(t.output), fileno(stdout));
int ret2 = dup2(fileno(t.output), fileno(stderr));
if (ret1 < 0 /*|| ret2 < 0*/)
{
fprintf(stderr, "failed to redirect output: (%d) %s\n"
, errno, strerror(errno));
continue;
}
#ifndef BOOST_NO_EXCEPTIONS
try
{
try
{
#endif
test_main();
_g_test_failures = 0;
(*t.fun)();
#ifndef BOOST_NO_EXCEPTIONS
}
catch (std::exception const& e)
{
char buf[200];
snprintf(buf, sizeof(buf), "Terminated with exception: \"%s\"", e.what());
report_failure(buf, __FILE__, __LINE__);
}
catch (...)
{
report_failure("Terminated with unknown exception", __FILE__, __LINE__);
}
}
catch (std::exception const& e)
{
char buf[200];
snprintf(buf, sizeof(buf), "Terminated with exception: \"%s\"", e.what());
report_failure(buf, __FILE__, __LINE__);
}
catch (...)
{
report_failure("Terminated with unknown exception", __FILE__, __LINE__);
}
#endif
if (!tests_to_run.empty()) tests_to_run.erase(t.name);
if (_g_test_failures > 0)
{
fflush(stdout);
fflush(stderr);
dup2(old_stdout, fileno(stdout));
dup2(old_stderr, fileno(stderr));
fseek(t.output, 0, SEEK_SET);
fprintf(stderr, "\x1b[1m[%s]\x1b[0m\n\n", t.name);
char buf[4096];
int size = 0;
do {
size = fread(buf, 1, sizeof(buf), t.output);
if (size > 0) fwrite(buf, 1, size, stderr);
} while (size > 0);
}
t.num_failures = _g_test_failures;
t.run = true;
total_failures += _g_test_failures;
++num_run;
fclose(t.output);
}
dup2(old_stdout, fileno(stdout));
dup2(old_stderr, fileno(stderr));
if (!tests_to_run.empty())
{
fprintf(stderr, "UNKONWN tests:\n");
for (std::set<std::string>::iterator i = tests_to_run.begin()
, end(tests_to_run.end()); i != end; ++i)
{
fprintf(stderr, "%s\n", i->c_str());
}
}
if (num_run == 0)
{
fprintf(stderr, "\x1b[31mERROR: no unit tests run\x1b[0m\n");
return 1;
}
// just in case of premature exits
// make sure we try to clean up some
stop_udp_tracker();
@ -178,6 +298,6 @@ int main()
}
#endif
return ret ? 333 : 0;
return total_failures ? 333 : 0;
}

View File

@ -73,9 +73,6 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
namespace lt = libtorrent;
static int tests_failure = 0;
static std::vector<std::string> failure_strings;
#if defined TORRENT_WINDOWS
#include <conio.h>
#endif
@ -104,24 +101,6 @@ udp::endpoint rand_udp_ep()
return udp::endpoint(rand_v4(), rand() + 1024);
}
void report_failure(char const* err, char const* file, int line)
{
char buf[500];
snprintf(buf, sizeof(buf), "\x1b[41m***** %s:%d \"%s\" *****\x1b[0m\n", file, line, err);
fprintf(stderr, "\n%s\n", buf);
failure_strings.push_back(buf);
++tests_failure;
}
int print_failures()
{
if (tests_failure == 0)
fprintf(stderr, "\n\n\x1b[42;30m == %d ALL TESTS PASSED ==\x1b[0m\n\n\n", tests_failure);
else
fprintf(stderr, "\n\n\x1b[41m == %d TEST(S) FAILED ==\x1b[0m\n\n\n", tests_failure);
return tests_failure;
}
std::map<std::string, boost::int64_t> get_counters(libtorrent::session& s)
{
using namespace libtorrent;

87
test/test.cpp Normal file
View File

@ -0,0 +1,87 @@
/*
Copyright (c) 2008-2015, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <vector>
#include <stdio.h> // for tmpfile()
#include "test.hpp"
unit_test_t _g_unit_tests[1024];
int _g_num_unit_tests = 0;
int _g_test_failures = 0;
static std::vector<std::string> failure_strings;
void report_failure(char const* err, char const* file, int line)
{
char buf[500];
snprintf(buf, sizeof(buf), "\x1b[41m***** %s:%d \"%s\" *****\x1b[0m\n", file, line, err);
fprintf(stderr, "\n%s\n", buf);
failure_strings.push_back(buf);
++_g_test_failures;
}
int print_failures()
{
int longest_name = 0;
for (int i = 0; i < _g_num_unit_tests; ++i)
{
int len = strlen(_g_unit_tests[i].name);
if (len > longest_name) longest_name = len;
}
fprintf(stderr, "\n\n");
for (int i = 0; i < _g_num_unit_tests; ++i)
{
if (_g_unit_tests[i].run == false) continue;
if (_g_unit_tests[i].num_failures == 0)
{
fprintf(stderr, "\x1b[32m[%*s] ***PASS***\n"
, longest_name, _g_unit_tests[i].name);
}
else
{
fprintf(stderr, "\x1b[31m[%*s] %d FAILURES\n"
, longest_name
, _g_unit_tests[i].name
, _g_unit_tests[i].num_failures);
}
}
fprintf(stderr, "\x1b[0m");
if (_g_test_failures > 0)
fprintf(stderr, "\n\n\x1b[41m == %d TEST(S) FAILED ==\x1b[0m\n\n\n", _g_test_failures);
return _g_test_failures;
}

View File

@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/config.hpp>
#include <exception>
#include <sstream>
#include <vector>
#include <boost/preprocessor/cat.hpp>
#include "libtorrent/config.hpp"
@ -53,18 +55,35 @@ POSSIBILITY OF SUCH DAMAGE.
void EXPORT report_failure(char const* err, char const* file, int line);
int EXPORT print_failures();
#if defined(_MSC_VER)
#define COUNTER_GUARD(x)
#else
#define COUNTER_GUARD(type) \
struct BOOST_PP_CAT(type, _counter_guard) \
{ \
~BOOST_PP_CAT(type, _counter_guard()) \
{ \
TEST_CHECK(counted_type<type>::count == 0); \
} \
} BOOST_PP_CAT(type, _guard)
#endif
typedef void (*unit_test_fun_t)();
struct unit_test_t
{
unit_test_fun_t fun;
char const* name;
int num_failures;
bool run;
FILE* output;
};
extern unit_test_t _g_unit_tests[1024];
extern int _g_num_unit_tests;
extern int _g_test_failures;
#define TORRENT_TEST(test_name) \
void BOOST_PP_CAT(unit_test_, test_name)(); \
static struct BOOST_PP_CAT(register_class, __LINE__) { \
BOOST_PP_CAT(register_class, __LINE__) () { \
unit_test_t& t = _g_unit_tests[_g_num_unit_tests]; \
t.fun = &BOOST_PP_CAT(unit_test_, test_name); \
t.name = #test_name; \
t.num_failures = 0; \
t.run = false; \
t.output = NULL; \
_g_num_unit_tests++; \
} \
} BOOST_PP_CAT(_static_registrar, __LINE__); \
void BOOST_PP_CAT(unit_test_, test_name)()
#define TEST_REPORT_AUX(x, line, file) \
report_failure(x, line, file)

View File

@ -314,7 +314,7 @@ void test_alert_mask()
TEST_CHECK(!mgr.should_post<torrent_paused_alert>());
}
int test_main()
TORRENT_TEST(alert_manager)
{
test_limit();
test_priority_limit();

View File

@ -130,7 +130,7 @@ void test_swarm()
p3 = ses3.abort();
}
int test_main()
TORRENT_TEST(auto_unchoke)
{
using namespace libtorrent;
@ -141,7 +141,7 @@ int test_main()
remove_all("./tmp3_unchoke", ec);
test_swarm();
TEST_CHECK(!exists("./tmp1_unchoke/temporary"));
TEST_CHECK(!exists("./tmp2_unchoke/temporary"));
TEST_CHECK(!exists("./tmp3_unchoke/temporary"));

View File

@ -146,7 +146,7 @@ void do_change_peer_rate(connections_t& v, int limit)
i->get()->throttle(limit + limit / 2 * ((c & 1)?-1:1));
}
void nop() {}
static void nop() {}
void run_test(connections_t& v
, bandwidth_manager& manager
@ -457,7 +457,7 @@ void test_no_starvation(int limit)
TEST_CHECK(close_to(p->m_quota / sample_time, limit / 200 / num_peers, 5));
}
int test_main()
TORRENT_TEST(bandwidth_limiter)
{
using namespace libtorrent;

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
int test_main()
TORRENT_TEST(bdecode)
{
// test integer
{
@ -51,7 +51,7 @@ int test_main()
TEST_CHECK(e.type() == bdecode_node::int_t);
TEST_CHECK(e.int_value() == 12453);
}
// test string
{
char b[] = "26:abcdefghijklmnopqrstuvwxyz";
@ -358,25 +358,25 @@ int test_main()
// test invalid encoding
{
unsigned char buf[] =
{ 0x64 , 0x31 , 0x3a , 0x61 , 0x64 , 0x32 , 0x3a , 0x69
, 0x64 , 0x32 , 0x30 , 0x3a , 0x2a , 0x21 , 0x19 , 0x89
, 0x9f , 0xcd , 0x5f , 0xc9 , 0xbc , 0x80 , 0xc1 , 0x76
, 0xfe , 0xe0 , 0xc6 , 0x84 , 0x2d , 0xf6 , 0xfc , 0xb8
, 0x39 , 0x3a , 0x69 , 0x6e , 0x66 , 0x6f , 0x5f , 0x68
, 0x61 , 0xae , 0x68 , 0x32 , 0x30 , 0x3a , 0x14 , 0x78
, 0xd5 , 0xb0 , 0xdc , 0xf6 , 0x82 , 0x42 , 0x32 , 0xa0
, 0xd6 , 0x88 , 0xeb , 0x48 , 0x57 , 0x01 , 0x89 , 0x40
, 0x4e , 0xbc , 0x65 , 0x31 , 0x3a , 0x71 , 0x39 , 0x3a
, 0x67 , 0x65 , 0x74 , 0x5f , 0x70 , 0x65 , 0x65 , 0x72
, 0x78 , 0xff , 0x3a , 0x74 , 0x38 , 0x3a , 0xaa , 0xd4
, 0xa1 , 0x88 , 0x7a , 0x8d , 0xc3 , 0xd6 , 0x31 , 0x3a
, 0x79 , 0x31 , 0xae , 0x71 , 0x65 , 0};
{ 0x64, 0x31, 0x3a, 0x61, 0x64, 0x32, 0x3a, 0x69
, 0x64, 0x32, 0x30, 0x3a, 0x2a, 0x21, 0x19, 0x89
, 0x9f, 0xcd, 0x5f, 0xc9, 0xbc, 0x80, 0xc1, 0x76
, 0xfe, 0xe0, 0xc6, 0x84, 0x2d, 0xf6, 0xfc, 0xb8
, 0x39, 0x3a, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x68
, 0x61, 0xae, 0x68, 0x32, 0x30, 0x3a, 0x14, 0x78
, 0xd5, 0xb0, 0xdc, 0xf6, 0x82, 0x42, 0x32, 0xa0
, 0xd6, 0x88, 0xeb, 0x48, 0x57, 0x01, 0x89, 0x40
, 0x4e, 0xbc, 0x65, 0x31, 0x3a, 0x71, 0x39, 0x3a
, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x65, 0x65, 0x72
, 0x78, 0xff, 0x3a, 0x74, 0x38, 0x3a, 0xaa, 0xd4
, 0xa1, 0x88, 0x7a, 0x8d, 0xc3, 0xd6, 0x31, 0x3a
, 0x79, 0x31, 0xae, 0x71, 0x65, 0};
printf("%s\n", buf);
bdecode_node e;
error_code ec;
int ret = bdecode((char*)buf, (char*)buf + sizeof(buf), e, ec);
TEST_CHECK(ret == -1);
TEST_CHECK(ret == -1);
}
// test the depth limit
@ -644,7 +644,7 @@ int test_main()
error_code ec;
int ret = bdecode(b, b + sizeof(b)-1, e, ec);
TEST_EQUAL(ret, 0);
TEST_EQUAL(e.type(), bdecode_node::list_t);
TEST_EQUAL(e.list_size(), 1);
TEST_EQUAL(e.list_at(0).type(), bdecode_node::string_t);
@ -862,7 +862,7 @@ int test_main()
int ret = bdecode(b, b + sizeof(b)-1, e, ec);
TEST_EQUAL(ret, 0);
printf("%s\n", print_entry(e).c_str());
TEST_EQUAL(print_entry(e), "[ 1, 'foo', [ 1, 2 ], { 'x': 1 } ]");
}
@ -873,7 +873,7 @@ int test_main()
int ret = bdecode(b, b + sizeof(b)-1, e, ec);
TEST_EQUAL(ret, 0);
printf("%s\n", print_entry(e).c_str());
TEST_EQUAL(print_entry(e), "{ 'a': 1, 'b': 'foo', 'c': [ 1, 2 ], 'd': { 'x': 1 } }");
}
@ -886,7 +886,7 @@ int test_main()
bdecode_node e2;
error_code ec;
int ret = bdecode(b1, b1 + sizeof(b1)-1, e1, ec);
TEST_EQUAL(ret, 0);
ret = bdecode(b2, b2 + sizeof(b2)-1, e2, ec);
@ -923,7 +923,7 @@ int test_main()
bdecode_node e2;
error_code ec;
int ret = bdecode(b1, b1 + sizeof(b1)-1, e1, ec);
TEST_EQUAL(ret, 0);
@ -962,7 +962,7 @@ int test_main()
bdecode_node e2_root;
error_code ec;
int ret = bdecode(b1, b1 + sizeof(b1)-1, e1_root, ec);
TEST_EQUAL(ret, 0);
ret = bdecode(b2, b2 + sizeof(b2)-1, e2_root, ec);
@ -1001,7 +1001,7 @@ int test_main()
bdecode_node e2;
error_code ec;
int ret = bdecode(b1, b1 + sizeof(b1)-1, e1_root, ec);
TEST_EQUAL(ret, 0);
ret = bdecode(b2, b2 + sizeof(b2)-1, e2, ec);

View File

@ -58,10 +58,10 @@ entry decode(std::string const& str)
return bdecode(str.begin(), str.end());
}
int test_main()
TORRENT_TEST(bencoding)
{
// ** strings **
{
{
entry e("spam");
TEST_CHECK(encode(e) == "4:spam");
TEST_CHECK(decode(encode(e)) == e);
@ -119,7 +119,7 @@ int test_main()
TEST_CHECK(e.type() == lazy_entry::int_t);
TEST_CHECK(e.int_value() == 12453);
}
{
char b[] = "26:abcdefghijklmnopqrstuvwxyz";
lazy_entry e;
@ -256,25 +256,25 @@ int test_main()
// test invalid encoding
{
unsigned char buf[] =
{ 0x64 , 0x31 , 0x3a , 0x61 , 0x64 , 0x32 , 0x3a , 0x69
, 0x64 , 0x32 , 0x30 , 0x3a , 0x2a , 0x21 , 0x19 , 0x89
, 0x9f , 0xcd , 0x5f , 0xc9 , 0xbc , 0x80 , 0xc1 , 0x76
, 0xfe , 0xe0 , 0xc6 , 0x84 , 0x2d , 0xf6 , 0xfc , 0xb8
, 0x39 , 0x3a , 0x69 , 0x6e , 0x66 , 0x6f , 0x5f , 0x68
, 0x61 , 0xae , 0x68 , 0x32 , 0x30 , 0x3a , 0x14 , 0x78
, 0xd5 , 0xb0 , 0xdc , 0xf6 , 0x82 , 0x42 , 0x32 , 0xa0
, 0xd6 , 0x88 , 0xeb , 0x48 , 0x57 , 0x01 , 0x89 , 0x40
, 0x4e , 0xbc , 0x65 , 0x31 , 0x3a , 0x71 , 0x39 , 0x3a
, 0x67 , 0x65 , 0x74 , 0x5f , 0x70 , 0x65 , 0x65 , 0x72
, 0x78 , 0xff , 0x3a , 0x74 , 0x38 , 0x3a , 0xaa , 0xd4
, 0xa1 , 0x88 , 0x7a , 0x8d , 0xc3 , 0xd6 , 0x31 , 0x3a
, 0x79 , 0x31 , 0xae , 0x71 , 0x65 , 0};
{ 0x64, 0x31, 0x3a, 0x61, 0x64, 0x32, 0x3a, 0x69
, 0x64, 0x32, 0x30, 0x3a, 0x2a, 0x21, 0x19, 0x89
, 0x9f, 0xcd, 0x5f, 0xc9, 0xbc, 0x80, 0xc1, 0x76
, 0xfe, 0xe0, 0xc6, 0x84, 0x2d, 0xf6, 0xfc, 0xb8
, 0x39, 0x3a, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x68
, 0x61, 0xae, 0x68, 0x32, 0x30, 0x3a, 0x14, 0x78
, 0xd5, 0xb0, 0xdc, 0xf6, 0x82, 0x42, 0x32, 0xa0
, 0xd6, 0x88, 0xeb, 0x48, 0x57, 0x01, 0x89, 0x40
, 0x4e, 0xbc, 0x65, 0x31, 0x3a, 0x71, 0x39, 0x3a
, 0x67, 0x65, 0x74, 0x5f, 0x70, 0x65, 0x65, 0x72
, 0x78, 0xff, 0x3a, 0x74, 0x38, 0x3a, 0xaa, 0xd4
, 0xa1, 0x88, 0x7a, 0x8d, 0xc3, 0xd6, 0x31, 0x3a
, 0x79, 0x31, 0xae, 0x71, 0x65, 0};
printf("%s\n", buf);
lazy_entry e;
error_code ec;
int ret = lazy_bdecode((char*)buf, (char*)buf + sizeof(buf), e, ec);
TEST_CHECK(ret == -1);
TEST_CHECK(ret == -1);
}
// test the depth limit
@ -496,7 +496,7 @@ int test_main()
}
{
unsigned char buf[] = { 0x44 , 0x91 , 0x3a };
unsigned char buf[] = { 0x44, 0x91, 0x3a };
entry ent = bdecode(buf, buf + sizeof(buf));
TEST_CHECK(ent == entry());
}

View File

@ -63,7 +63,7 @@ void test_iterators(bitfield& test1)
TEST_EQUAL(num, test1.count());
}
int test_main()
TORRENT_TEST(bitfield)
{
bitfield test1(10, false);
TEST_EQUAL(test1.size(), 10);

View File

@ -76,7 +76,7 @@ struct test_storage_impl : storage_interface
virtual void finalize_file(int, storage_error&) {}
};
void nop() {}
static void nop() {}
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
#define INITIALIZE_JOB(j) j.in_use = true;
@ -455,7 +455,7 @@ void test_unaligned_read()
bc.clear(jobs);
}
int test_main()
TORRENT_TEST(block_cache)
{
test_write();
test_flush();
@ -472,6 +472,5 @@ int test_main()
// TODO: test free_piece
// TODO: test abort_dirty
// TODO: test unaligned reads
return 0;
}

View File

@ -119,7 +119,7 @@ void test_to_from_string()
TEST_EQUAL(memcmp(compare, bits_out.c_str(), 4), 0);
}
int test_main()
TORRENT_TEST(bloom_filter)
{
test_set_and_get();
test_set_bits();

View File

@ -118,7 +118,7 @@ void test_speed()
// -- test buffer --
void test_buffer()
TORRENT_TEST(buffer)
{
char data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
@ -127,16 +127,16 @@ void test_buffer()
TEST_CHECK(b.size() == 0);
TEST_CHECK(b.capacity() == 0);
TEST_CHECK(b.empty());
b.resize(10);
TEST_CHECK(b.size() == 10);
TEST_CHECK(b.capacity() == 10);
std::memcpy(b.begin(), data, 10);
b.reserve(50);
TEST_CHECK(std::memcmp(b.begin(), data, 10) == 0);
TEST_CHECK(b.capacity() == 50);
b.erase(b.begin() + 6, b.end());
TEST_CHECK(std::memcmp(b.begin(), data, 6) == 0);
TEST_CHECK(b.capacity() == 50);
@ -154,7 +154,7 @@ void test_buffer()
b.insert(b.end(), data, data + 10);
TEST_CHECK(b.size() == 10);
TEST_CHECK(std::memcmp(b.begin(), data, 10) == 0);
b.erase(b.begin(), b.end());
TEST_CHECK(b.capacity() == 50);
TEST_CHECK(b.size() == 0);
@ -209,12 +209,12 @@ bool compare_chained_buffer(chained_buffer& b, char const* mem, int size)
return std::memcmp(&flat[0], mem, size) == 0;
}
void test_chained_buffer()
TORRENT_TEST(chained_buffer)
{
char data[] = "foobar";
{
chained_buffer b;
TEST_CHECK(b.empty());
TEST_EQUAL(b.capacity(), 0);
TEST_EQUAL(b.size(), 0);
@ -308,7 +308,7 @@ void test_chained_buffer()
TEST_CHECK(ret == true);
TEST_CHECK(b.space_in_last_buffer() == 0);
std::cout << b.space_in_last_buffer() << std::endl;
char* b5 = allocate_buffer(20);
std::memcpy(b4, data, 6);
b.append_buffer(b5, 20, 6, &free_buffer, (void*)0x1337);
@ -319,10 +319,3 @@ void test_chained_buffer()
TEST_CHECK(buffer_list.empty());
}
int test_main()
{
test_buffer();
test_chained_buffer();
return 0;
}

View File

@ -275,7 +275,7 @@ void test_checking(int flags = read_only_files)
, ec.value(), ec.message().c_str());
}
int test_main()
TORRENT_TEST(checking)
{
test_checking();
test_checking(read_only_files | corrupt_files);

View File

@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/crc32c.hpp"
#include "test.hpp"
int test_main()
TORRENT_TEST(crc32)
{
using namespace libtorrent;

View File

@ -65,7 +65,7 @@ using namespace libtorrent::dht;
void nop() {}
sha1_hash to_hash(char const* s)
static sha1_hash to_hash(char const* s)
{
sha1_hash ret;
from_hex(s, 40, (char*)&ret[0]);
@ -90,7 +90,7 @@ void node_push_back(void* userdata, libtorrent::dht::node_entry const& n)
nv->push_back(n);
}
void nop(void* userdata, libtorrent::dht::node_entry const& n) {}
static void nop(void* userdata, libtorrent::dht::node_entry const& n) {}
std::list<std::pair<udp::endpoint, entry> > g_sent_packets;
@ -439,7 +439,7 @@ struct obs : dht::dht_observer
};
// TODO: test obfuscated_get_peers
int test_main()
TORRENT_TEST(dht)
{
dht_settings sett;
sett.max_torrents = 4;
@ -1960,7 +1960,7 @@ int test_main()
#else
int test_main()
TORRENT_TEST(dht)
{
return 0;
}

View File

@ -68,7 +68,7 @@ struct log_t : libtorrent::dht::dht_logger
}
};
int test_main()
TORRENT_TEST(dos_blocker)
{
#ifndef TORRENT_DISABLE_DHT
using namespace libtorrent::dht;

View File

@ -43,14 +43,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bencode.hpp"
#include "libtorrent/entry.hpp"
#include "aux_/disable_warnings_push.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstring>
#include <boost/bind.hpp>
#include <iostream>
#include <cstdarg>
#include "aux_/disable_warnings_pop.hpp"
#include "libtorrent/aux_/disable_warnings_pop.hpp"
using namespace libtorrent;
namespace lt = libtorrent;
@ -787,7 +787,7 @@ void test_invalid_metadata_requests()
print_session_log(*ses);
}
int test_main()
TORRENT_TEST(fast_extension)
{
test_reject_fast();
test_respect_suggest();

View File

@ -203,7 +203,7 @@ void test_disk_job_double_fence()
fence.job_complete(&test_job[9], jobs);
}
int test_main()
TORRENT_TEST(fence)
{
test_disk_job_fence();
test_disk_job_double_fence();

View File

@ -103,7 +103,7 @@ void test_stat()
TEST_CHECK(diff >= 2 && diff <= 4);
}
int test_main()
TORRENT_TEST(file)
{
test_create_directory();
test_stat();

View File

@ -75,13 +75,13 @@ void setup_test_storage(file_storage& st)
TEST_EQUAL(st.num_pieces(), (100000 + 0x3fff) / 0x4000);
}
int test_main()
TORRENT_TEST(file_storage)
{
{
// test rename_file
file_storage st;
setup_test_storage(st);
st.rename_file(0, combine_path("test", combine_path("c", "d")));
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test"
, combine_path("c", "d"))));

View File

@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
int test_main()
TORRENT_TEST(gzip)
{
std::vector<char> zipped;
error_code ec;

View File

@ -60,7 +60,7 @@ char const* result_array[4] =
};
int test_main()
TORRENT_TEST(hasher)
{
using namespace libtorrent;

View File

@ -137,7 +137,7 @@ private:
F& operator=(F const& f);
};
int test_main()
TORRENT_TEST(heterogeneuous_queue)
{
using namespace libtorrent;

View File

@ -190,7 +190,7 @@ void run_suite(std::string const& protocol, proxy_settings ps, int port)
stop_proxy(ps.port);
}
int test_main()
TORRENT_TEST(http_parser)
{
std::srand(std::time(0));
std::generate(data_buffer, data_buffer + sizeof(data_buffer), &std::rand);
@ -203,14 +203,14 @@ int test_main()
TEST_CHECK(!ec);
if (ec) fprintf(stderr, "file error: %s\n", ec.message().c_str());
test_file.close();
proxy_settings ps;
ps.hostname = "127.0.0.1";
ps.port = 8034;
ps.username = "testuser";
ps.password = "testpass";
int port = 0;
port = start_web_server();
for (int i = 0; i < 5; ++i)

View File

@ -76,7 +76,7 @@ tuple<int, int, bool> feed_bytes(http_parser& parser, char const* str)
return ret;
}
int test_main()
TORRENT_TEST(http_parser)
{
// HTTP request parser
http_parser parser;

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
int test_main()
TORRENT_TEST(identify_client)
{
TEST_EQUAL(identify_client(peer_id("-AZ123B-............")), "Azureus 1.2.3.11");
TEST_EQUAL(identify_client(peer_id("-AZ1230-............")), "Azureus 1.2.3");

View File

@ -43,7 +43,7 @@ IPv4 addresses. Maybe it should be extended to IPv6 as well,
but the actual code is just a template, so it is probably
pretty safe to assume that as long as it works for IPv4 it
also works for IPv6.
*/
using namespace libtorrent;
@ -79,7 +79,7 @@ void test_rules_invariant(std::vector<ip_range<T> > const& r, ip_filter const& f
TEST_CHECK(r.front().first == IP("::0"));
TEST_CHECK(r.back().last == IP("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
}
iterator i = r.begin();
for (iterator i(r.begin()), j(boost::next(r.begin()))
, end(r.end()); j != end; ++j, ++i)
@ -90,7 +90,7 @@ void test_rules_invariant(std::vector<ip_range<T> > const& r, ip_filter const& f
}
}
int test_main()
TORRENT_TEST(ip_filter)
{
using namespace libtorrent;
@ -104,7 +104,7 @@ int test_main()
, {IP4("1.0.0.0"), IP4("3.0.0.0"), ip_filter::blocked}
, {IP4("3.0.0.1"), IP4("255.255.255.255"), 0}
};
{
ip_filter f;
f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked);
@ -121,7 +121,7 @@ int test_main()
TEST_CHECK(std::equal(range.begin(), range.end(), expected1, &compare<address_v4>));
}
// **** test joining of ranges at the start ****
{
@ -139,7 +139,7 @@ int test_main()
TEST_CHECK(range.size() == 3);
TEST_CHECK(std::equal(range.begin(), range.end(), expected1, &compare<address_v4>));
}
}
// **** test joining of overlapping ranges at the start ****
@ -159,7 +159,7 @@ int test_main()
TEST_CHECK(range.size() == 3);
TEST_CHECK(std::equal(range.begin(), range.end(), expected1, &compare<address_v4>));
}
}
// **** test joining of overlapping ranges at the end ****
@ -179,7 +179,7 @@ int test_main()
TEST_CHECK(range.size() == 3);
TEST_CHECK(std::equal(range.begin(), range.end(), expected1, &compare<address_v4>));
}
}
// **** test joining of multiple overlapping ranges 1 ****
@ -192,7 +192,7 @@ int test_main()
f.add_rule(IP("7.0.0.0"), IP("8.0.0.0"), ip_filter::blocked);
f.add_rule(IP("1.0.1.0"), IP("9.0.0.0"), ip_filter::blocked);
#if TORRENT_USE_IPV6
range = boost::get<0>(f.export_filter());
#else
@ -207,10 +207,10 @@ int test_main()
, {IP4("1.0.0.0"), IP4("9.0.0.0"), ip_filter::blocked}
, {IP4("9.0.0.1"), IP4("255.255.255.255"), 0}
};
TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare<address_v4>));
}
}
// **** test joining of multiple overlapping ranges 2 ****
@ -237,7 +237,7 @@ int test_main()
, {IP4("0.0.1.0"), IP4("8.0.0.0"), ip_filter::blocked}
, {IP4("8.0.0.1"), IP4("255.255.255.255"), 0}
};
TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare<address_v4>));
}
@ -252,7 +252,7 @@ int test_main()
, {IP6("1::"), IP6("3::"), ip_filter::blocked}
, {IP6("3::1"), IP6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 0}
};
{
ip_filter f;
f.add_rule(IP("2::1"), IP("3::"), ip_filter::blocked);
@ -265,7 +265,7 @@ int test_main()
TEST_CHECK(range.size() == 3);
TEST_CHECK(std::equal(range.begin(), range.end(), expected2, &compare<address_v6>));
}
}
#endif
port_filter pf;

View File

@ -111,7 +111,7 @@ void test_one_ip()
TEST_CHECK(ipv.external_address() == addr1);
}
int test_main()
TORRENT_TEST(ip_voter)
{
test_random();
test_two_ips();

View File

@ -94,7 +94,7 @@ void test_lsd()
p2 = ses2.abort();
}
int test_main()
TORRENT_TEST(lsd)
{
using namespace libtorrent;
@ -105,7 +105,7 @@ int test_main()
remove_all("./tmp3_lsd", ec);
test_lsd();
remove_all("./tmp1_lsd", ec);
remove_all("./tmp2_lsd", ec);
remove_all("./tmp3_lsd", ec);

View File

@ -55,7 +55,7 @@ void test_remove_url(std::string url)
TEST_EQUAL(handles.size(), 0);
}
int test_main()
TORRENT_TEST(magnet)
{
session_proxy p1;
session_proxy p2;

View File

@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "test.hpp"
#include "libtorrent/aux_/merkle.hpp"
int test_main()
TORRENT_TEST(merkle)
{
using namespace libtorrent;

View File

@ -202,7 +202,7 @@ done:
remove_all("tmp2_meta", ec);
}
int test_main()
TORRENT_TEST(metadata_extension)
{
using namespace libtorrent;

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
using libtorrent::packet_buffer;
int test_main()
TORRENT_TEST(packet_buffer)
{
// test packet_buffer
{

View File

@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
int test_main()
TORRENT_TEST(part_file)
{
error_code ec;
std::string cwd = complete(".");

View File

@ -192,7 +192,7 @@ void test_enc_handler(libtorrent::crypto_plugin* a, libtorrent::crypto_plugin* b
#endif
int test_main()
TORRENT_TEST(test_pe_crypto)
{
using namespace libtorrent;

View File

@ -47,7 +47,7 @@ std::string class_name(peer_class_t id, peer_class_pool const& p)
return i.label;
}
int test_main()
TORRENT_TEST(peer_class)
{
peer_class_pool pool;

View File

@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
tcp::endpoint ep(char const* ip, int port)
static tcp::endpoint ep(char const* ip, int port)
{
return tcp::endpoint(address_v4::from_string(ip), port);
}
@ -203,7 +203,7 @@ void connect_peer(peer_list& p, mock_torrent& t, torrent_state& st)
TEST_CHECK(tp->connection);
}
int test_main()
TORRENT_TEST(peer_list)
{
torrent_peer_allocator allocator;
external_ip ext_ip;

View File

@ -46,7 +46,7 @@ boost::uint32_t hash_buffer(char const* buf, int len)
return crc.checksum();
}
int test_main()
TORRENT_TEST(peer_priority)
{
// when the IP is the same, we hash the ports, sorted

View File

@ -145,7 +145,7 @@ void test_pex()
p3 = ses3.abort();
}
int test_main()
TORRENT_TEST(pex)
{
using namespace libtorrent;
@ -156,7 +156,7 @@ int test_main()
remove_all("tmp3_pex", ec);
test_pex();
remove_all("tmp1_pex", ec);
remove_all("tmp2_pex", ec);
remove_all("tmp3_pex", ec);
@ -165,6 +165,6 @@ int test_main()
}
#else
int test_main() { return 0; }
TORRENT_TEST(pex) { return 0; }
#endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -274,7 +274,7 @@ int test_pick(boost::shared_ptr<piece_picker> const& p
return picked[0].piece_index;
}
int test_main()
TORRENT_TEST(piece_picker)
{
tcp::endpoint endp;
piece_picker::downloading_piece st;

View File

@ -71,13 +71,13 @@ address_v6 v6(char const* str)
}
#endif
tcp::endpoint ep(char const* ip, int port)
static tcp::endpoint ep(char const* ip, int port)
{
error_code ec;
return tcp::endpoint(address::from_string(ip, ec), port);
}
int test_main()
TORRENT_TEST(primitives)
{
using namespace libtorrent;
error_code ec;

View File

@ -394,7 +394,7 @@ done:
sp.push_back(ses2.abort());
}
int test_main()
TORRENT_TEST(priority)
{
using namespace libtorrent;

View File

@ -242,7 +242,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
return pr;
}
int test_main()
TORRENT_TEST(privacy)
{
session_proxy pr[20];
// not using anonymous mode

View File

@ -32,11 +32,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "test.hpp"
#include "setup_transfer.hpp"
#include "random.hpp"
#include "libtorrent/random.hpp"
using namespace libtorrent;
int test_main()
TORRENT_TEST(random)
{
const int repetitions = 200000;
@ -45,7 +45,7 @@ int test_main()
{
int buckets[256];
memset(buckets, 0, sizeof(buckets));
for (int i = 0; i < repetitions; ++i)
{
boost::uint32_t val = libtorrent::random();

View File

@ -133,7 +133,7 @@ void test_read_piece(int flags)
, ec.value(), ec.message().c_str());
}
int test_main()
TORRENT_TEST(read_piece)
{
test_read_piece(0);
test_read_piece(seed_mode);

View File

@ -66,7 +66,7 @@ void wait_for_complete(lt::session& ses, torrent_handle h)
TEST_CHECK(false);
}
int test_main()
TORRENT_TEST(recheck)
{
error_code ec;
lt::session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48675, 49000), "0.0.0.0", 0, mask);

View File

@ -487,7 +487,7 @@ void test_remap_files_prio(storage_mode_t storage_mode = storage_mode_sparse)
p2 = ses2.abort();
}
int test_main()
TORRENT_TEST(remap_files)
{
using namespace libtorrent;
@ -497,7 +497,7 @@ int test_main()
remove_all("tmp2_remap", ec);
test_remap_files_gather();
remove_all("tmp1_remap", ec);
remove_all("tmp2_remap", ec);
remove_all("tmp1_remap2", ec);
@ -513,7 +513,7 @@ int test_main()
remove_all("tmp2_remap3", ec);
test_remap_files_prio();
remove_all("tmp1_remap", ec);
remove_all("tmp2_remap", ec);
remove_all("tmp1_remap2", ec);

View File

@ -46,7 +46,7 @@ struct test_torrent_t
int expected_matches;
};
test_torrent_t test_torrents[] = {
static test_torrent_t test_torrents[] = {
// no match because shared file in test2 and test3 is not padded/aligned
{ "test2", "test1_pad_files", 0},
{ "test3", "test1_pad_files", 0},
@ -83,7 +83,7 @@ test_torrent_t test_torrents[] = {
// TODO: it would be nice to test resolving of more than just 2 files as well.
// like 3 single file torrents merged into one, resolving all 3 files.
int test_main()
TORRENT_TEST(resolve_links)
{
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS

View File

@ -128,7 +128,7 @@ torrent_status test_resume_flags(int flags)
boost::shared_ptr<torrent_info> ti = generate_torrent();
add_torrent_params p;
p.ti = ti;
p.flags = flags;
#ifdef TORRENT_WINDOWS
@ -175,7 +175,7 @@ void default_tests(torrent_status const& s)
TEST_EQUAL(s.completed_time, 1348);
}
int test_main()
TORRENT_TEST(resume)
{
torrent_status s;

View File

@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
namespace lt = libtorrent;
int test_main()
TORRENT_TEST(session)
{
settings_pack p;
p.set_int(settings_pack::alert_mask, ~0);

View File

@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
using namespace libtorrent::aux;
int test_main()
TORRENT_TEST(settings_pack)
{
settings_pack sp;

View File

@ -35,14 +35,14 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
sha1_hash to_hash(char const* s)
static sha1_hash to_hash(char const* s)
{
sha1_hash ret;
from_hex(s, 40, (char*)&ret[0]);
return ret;
}
int test_main()
TORRENT_TEST(sha1_hash)
{
sha1_hash h1(0);
sha1_hash h2(0);

View File

@ -45,7 +45,7 @@ int samples[] = {
63, 57, 61, 62, 64, 62, 61, 52, 67, 64, 59, 61, 69, 60, 54, 69 };
int test_main()
TORRENT_TEST(sliding_average)
{
using namespace libtorrent;

View File

@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
using namespace libtorrent::detail;
int test_main()
TORRENT_TEST(socket_io)
{
// test address_to_bytes
TEST_EQUAL(address_to_bytes(address_v4::from_string("10.11.12.13")), "\x0a\x0b\x0c\x0d");

View File

@ -578,7 +578,7 @@ void test_malicious_peer()
}
#endif // TORRENT_USE_OPENSSL
int test_main()
TORRENT_TEST(ssl)
{
using namespace libtorrent;
@ -590,7 +590,7 @@ int test_main()
for (int i = 0; i < sizeof(test_config)/sizeof(test_config[0]); ++i)
test_ssl(i, utp);
}
error_code ec;
remove_all("tmp1_ssl", ec);
remove_all("tmp2_ssl", ec);

View File

@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
int test_main()
TORRENT_TEST(stat_cache)
{
error_code ec;

View File

@ -934,7 +934,7 @@ void test_iovec_advance_bufs()
free_iov(iov1, 10);
}
int test_main()
TORRENT_TEST(storage)
{
test_iovec_copy_bufs();
test_iovec_clear_bufs();

View File

@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
int test_main()
TORRENT_TEST(string)
{
// test maybe_url_encode
TEST_EQUAL(maybe_url_encode("http://test:test@abc.com/abc<>abc"), "http://test:test@abc.com/abc%3c%3eabc");

View File

@ -32,14 +32,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include "swarm_suite.hpp"
int test_main()
TORRENT_TEST(super_seeding)
{
// with super seeding
test_swarm(super_seeding);
// with strict super seeding
test_swarm(super_seeding | strict_super_seeding);
return 0;
}

View File

@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "swarm_suite.hpp"
int test_main()
TORRENT_TEST(swarm)
{
// with seed mode
test_swarm(seed_mode);

View File

@ -78,7 +78,7 @@ void build_chain(tailqueue& q, char const* str)
check_chain(q, expected);
}
int test_main()
TORRENT_TEST(tailqueue)
{
tailqueue t1;
tailqueue t2;

View File

@ -68,7 +68,7 @@ void decrement(condition_variable* s, libtorrent::mutex* m, int* waiting, boost:
--*c;
}
int test_main()
TORRENT_TEST(threads)
{
condition_variable cond;
libtorrent::mutex m;

View File

@ -55,7 +55,7 @@ void check_timer_loop(mutex& m, time_point& last, condition_variable& cv)
}
}
int test_main()
TORRENT_TEST(time)
{
// make sure the time classes have correct semantics

View File

@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "swarm_suite.hpp"
int test_main()
TORRENT_TEST(time_crititcal)
{
// with time critical pieces
test_swarm(time_critical);

View File

@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "test.hpp"
#include "libtorrent/timestamp_history.hpp"
int test_main()
TORRENT_TEST(timestamp_history)
{
using namespace libtorrent;

View File

@ -152,7 +152,7 @@ void test_running_torrent(boost::shared_ptr<torrent_info> info, boost::int64_t f
}
}
int test_main()
TORRENT_TEST(torrent)
{
/* {
remove("test_torrent_dir2/tmp1");

View File

@ -90,7 +90,7 @@ struct test_torrent_t
using namespace libtorrent;
test_torrent_t test_torrents[] =
static test_torrent_t test_torrents[] =
{
{ "base.torrent" },
{ "empty_path.torrent" },
@ -715,7 +715,7 @@ void test_copy()
}
}
int test_main()
TORRENT_TEST(torrent_info)
{
for (int i = 0; i < 4; ++i)
test_resolve_duplicates(i);

View File

@ -234,7 +234,7 @@ void test_extract_peer()
}
}
int test_main()
TORRENT_TEST(traccker)
{
test_extract_peer();
test_parse_hostname_peers();

View File

@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
using boost::tuples::ignore;
int test_main()
TORRENT_TEST(trackers_extension)
{
using namespace libtorrent;
namespace lt = libtorrent;
@ -134,6 +134,6 @@ int test_main()
}
#else
int test_main() { return 0; }
TORRENT_TEST(trackers_extension) { return 0; }
#endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -347,7 +347,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
if (proxy_type) stop_proxy(proxy_port);
}
int test_main()
TORRENT_TEST(transfer)
{
using namespace libtorrent;

View File

@ -122,7 +122,7 @@ void callback(int mapping, address const& ip, int port, error_code const& err)
int run_upnp_test(char const* root_filename, char const* router_model, char const* control_name)
{
libtorrent::io_service ios;
g_port = start_web_server();
std::vector<char> buf;
@ -228,7 +228,7 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons
return 0;
}
int test_main()
TORRENT_TEST(upnp)
{
run_upnp_test(combine_path("..", "root1.xml").c_str(), "Xtreme N GIGABIT Router", "wipconn");
run_upnp_test(combine_path("..", "root2.xml").c_str(), "D-Link Router", "WANIPConnection");

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::none;
int test_main()
TORRENT_TEST(url_seed)
{
for (int keepalive = 0; keepalive < 2; ++keepalive)
{

View File

@ -167,7 +167,7 @@ void expect_error(char const* utf8, ConversionResult expect)
}
}
int test_main()
TORRENT_TEST(utf8)
{
std::vector<char> utf8_source;
error_code ec;

View File

@ -128,7 +128,7 @@ void test_transfer()
p2 = ses2.abort();
}
int test_main()
TORRENT_TEST(utp)
{
using namespace libtorrent;

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::none;
int test_main()
TORRENT_TEST(web_seed)
{
#ifdef TORRENT_USE_OPENSSL
run_http_suite(proxy, "https", false);

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::none;
int test_main()
TORRENT_TEST(web_seed_ban)
{
int ret = 0;
for (int url_seed = 0; url_seed < 2; ++url_seed)

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::none;
int test_main()
TORRENT_TEST(web_seed_chunked)
{
int ret = 0;
for (int url_seed = 0; url_seed < 2; ++url_seed)

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::http;
int test_main()
TORRENT_TEST(web_seed_http)
{
int ret = 0;
for (int url_seed = 0; url_seed < 2; ++url_seed)

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::http_pw;
int test_main()
TORRENT_TEST(web_seed_http_pw)
{
int ret = 0;
for (int url_seed = 0; url_seed < 2; ++url_seed)

View File

@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
int test_main()
TORRENT_TEST(web_seed_redirect)
{
using namespace libtorrent;

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::socks4;
int test_main()
TORRENT_TEST(web_seed_socks4)
{
int ret = 0;
for (int url_seed = 0; url_seed < 2; ++url_seed)

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::socks5;
int test_main()
TORRENT_TEST(web_seed_socks5)
{
int ret = 0;
for (int url_seed = 0; url_seed < 2; ++url_seed)

View File

@ -38,7 +38,7 @@ using namespace libtorrent;
const int proxy = libtorrent::settings_pack::socks5_pw;
int test_main()
TORRENT_TEST(web_seed_socks5_pw)
{
int ret = 0;
for (int url_seed = 0; url_seed < 2; ++url_seed)

View File

@ -289,7 +289,7 @@ void parser_callback(std::string& out, int token, char const* s, char const* val
}
}
int test_main()
TORRENT_TEST(xml)
{
// test upnp xml parser