From f9c9d0ad0d19ad96a5aee38c0b346d2651af06ee Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 30 May 2015 04:31:23 +0000 Subject: [PATCH] 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. --- configure.ac | 1 - include/libtorrent/aux_/cpuid.hpp | 4 +- include/libtorrent/enum_net.hpp | 2 +- include/libtorrent/io_service.hpp | 2 +- m4/ax_boost_random.m4 | 123 +++++++++++++++++++++++ test/Jamfile | 111 +++++++++++---------- test/Makefile.am | 135 +++++++++++-------------- test/enum_if.cpp | 6 +- test/main.cpp | 158 ++++++++++++++++++++++++++---- test/setup_transfer.cpp | 21 ---- test/test.cpp | 87 ++++++++++++++++ test/test.hpp | 43 +++++--- test/test_alert_manager.cpp | 2 +- test/test_auto_unchoke.cpp | 4 +- test/test_bandwidth_limiter.cpp | 4 +- test/test_bdecode.cpp | 46 ++++----- test/test_bencoding.cpp | 36 +++---- test/test_bitfield.cpp | 2 +- test/test_block_cache.cpp | 5 +- test/test_bloom_filter.cpp | 2 +- test/test_buffer.cpp | 23 ++--- test/test_checking.cpp | 2 +- test/test_crc32.cpp | 2 +- test/test_dht.cpp | 8 +- test/test_dos_blocker.cpp | 2 +- test/test_fast_extension.cpp | 6 +- test/test_fence.cpp | 2 +- test/test_file.cpp | 2 +- test/test_file_storage.cpp | 4 +- test/test_gzip.cpp | 2 +- test/test_hasher.cpp | 2 +- test/test_heterogeneous_queue.cpp | 2 +- test/test_http_connection.cpp | 6 +- test/test_http_parser.cpp | 2 +- test/test_identify_client.cpp | 2 +- test/test_ip_filter.cpp | 28 +++--- test/test_ip_voter.cpp | 2 +- test/test_lsd.cpp | 4 +- test/test_magnet.cpp | 2 +- test/test_merkle.cpp | 2 +- test/test_metadata_extension.cpp | 2 +- test/test_packet_buffer.cpp | 2 +- test/test_part_file.cpp | 2 +- test/test_pe_crypto.cpp | 2 +- test/test_peer_classes.cpp | 2 +- test/test_peer_list.cpp | 4 +- test/test_peer_priority.cpp | 2 +- test/test_pex.cpp | 6 +- test/test_piece_picker.cpp | 2 +- test/test_primitives.cpp | 4 +- test/test_priority.cpp | 2 +- test/test_privacy.cpp | 2 +- test/test_random.cpp | 6 +- test/test_read_piece.cpp | 2 +- test/test_recheck.cpp | 2 +- test/test_remap_files.cpp | 6 +- test/test_resolve_links.cpp | 4 +- test/test_resume.cpp | 4 +- test/test_session.cpp | 2 +- test/test_settings_pack.cpp | 2 +- test/test_sha1_hash.cpp | 4 +- test/test_sliding_average.cpp | 2 +- test/test_socket_io.cpp | 2 +- test/test_ssl.cpp | 4 +- test/test_stat_cache.cpp | 2 +- test/test_storage.cpp | 2 +- test/test_string.cpp | 2 +- test/test_super_seeding.cpp | 6 +- test/test_swarm.cpp | 2 +- test/test_tailqueue.cpp | 2 +- test/test_threads.cpp | 2 +- test/test_time.cpp | 2 +- test/test_time_critical.cpp | 2 +- test/test_timestamp_history.cpp | 2 +- test/test_torrent.cpp | 2 +- test/test_torrent_info.cpp | 4 +- test/test_tracker.cpp | 2 +- test/test_trackers_extension.cpp | 4 +- test/test_transfer.cpp | 2 +- test/test_upnp.cpp | 4 +- test/test_url_seed.cpp | 2 +- test/test_utf8.cpp | 2 +- test/test_utp.cpp | 2 +- test/test_web_seed.cpp | 2 +- test/test_web_seed_ban.cpp | 2 +- test/test_web_seed_chunked.cpp | 2 +- test/test_web_seed_http.cpp | 2 +- test/test_web_seed_http_pw.cpp | 2 +- test/test_web_seed_redirect.cpp | 2 +- test/test_web_seed_socks4.cpp | 2 +- test/test_web_seed_socks5.cpp | 2 +- test/test_web_seed_socks5_pw.cpp | 2 +- test/test_xml.cpp | 2 +- 93 files changed, 667 insertions(+), 372 deletions(-) create mode 100644 m4/ax_boost_random.m4 create mode 100644 test/test.cpp diff --git a/configure.ac b/configure.ac index 240172b85..7a425f2cd 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ############################################################################### diff --git a/include/libtorrent/aux_/cpuid.hpp b/include/libtorrent/aux_/cpuid.hpp index 025cff274..0165e5172 100644 --- a/include/libtorrent/aux_/cpuid.hpp +++ b/include/libtorrent/aux_/cpuid.hpp @@ -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 diff --git a/include/libtorrent/enum_net.hpp b/include/libtorrent/enum_net.hpp index e0e9d6903..38826ccaf 100644 --- a/include/libtorrent/enum_net.hpp +++ b/include/libtorrent/enum_net.hpp @@ -89,7 +89,7 @@ namespace libtorrent , error_code& ec); TORRENT_EXTRA_EXPORT bool in_local_network(std::vector const& net , address const& addr); - + TORRENT_EXTRA_EXPORT address get_default_gateway(error_code& ec); #ifdef SO_BINDTODEVICE diff --git a/include/libtorrent/io_service.hpp b/include/libtorrent/io_service.hpp index b97c16532..204e5474e 100644 --- a/include/libtorrent/io_service.hpp +++ b/include/libtorrent/io_service.hpp @@ -54,7 +54,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" -#ifdef __OBJC__ +#ifdef __OBJC__ #undef Protocol #endif diff --git a/m4/ax_boost_random.m4 b/m4/ax_boost_random.m4 new file mode 100644 index 000000000..f7cf64530 --- /dev/null +++ b/m4/ax_boost_random.m4 @@ -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 +# . +# +# This macro calls: +# +# AC_SUBST(BOOST_RANDOM_LIB) +# +# And sets: +# +# HAVE_BOOST_RANDOM +# +# LICENSE +# +# Copyright (c) 2008 Thomas Porschberg +# Copyright (c) 2008 Michael Tindal +# Copyright (c) 2013 Daniel Casimiro +# +# 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()();]])], + 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 +]) + diff --git a/test/Jamfile b/test/Jamfile index 0e15c2ec3..3d029edab 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -83,6 +83,7 @@ lib advapi32 : : Advapi32 ; project : requirements main.cpp + test.cpp @link_test @link_libtorrent : default-build @@ -91,66 +92,69 @@ project on shared on - ; + ; feature launcher : none valgrind : composite ; feature.compose valgrind : "valgrind --tool=memcheck -v --num-callers=20 --read-var-info=yes --track-origins=yes --error-exitcode=222 --suppressions=valgrind_suppressions.txt" 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 ] - ; + ; diff --git a/test/Makefile.am b/test/Makefile.am index 6b3303a9b..a62babf43 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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@ diff --git a/test/enum_if.cpp b/test/enum_if.cpp index d233e64a6..acb7d152f 100644 --- a/test/enum_if.cpp +++ b/test/enum_if.cpp @@ -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 routes = enum_routes(ios, ec); + std::vector routes = enum_routes(ec); if (ec) { printf("%s\n", ec.message().c_str()); diff --git a/test/main.cpp b/test/main.cpp index 0e1b27b97..44d008ceb 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -37,14 +37,12 @@ POSSIBILITY OF SUCH DAMAGE. #include // 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 @@ -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 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::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; } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 4d388ba1f..2d8efcd82 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -73,9 +73,6 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; namespace lt = libtorrent; -static int tests_failure = 0; -static std::vector failure_strings; - #if defined TORRENT_WINDOWS #include #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 get_counters(libtorrent::session& s) { using namespace libtorrent; diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 000000000..61b4439e9 --- /dev/null +++ b/test/test.cpp @@ -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 +#include // 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 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; +} + diff --git a/test/test.hpp b/test/test.hpp index 509c80003..b87182278 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #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::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) diff --git a/test/test_alert_manager.cpp b/test/test_alert_manager.cpp index 1d0fa920d..c87a27419 100644 --- a/test/test_alert_manager.cpp +++ b/test/test_alert_manager.cpp @@ -314,7 +314,7 @@ void test_alert_mask() TEST_CHECK(!mgr.should_post()); } -int test_main() +TORRENT_TEST(alert_manager) { test_limit(); test_priority_limit(); diff --git a/test/test_auto_unchoke.cpp b/test/test_auto_unchoke.cpp index 13983ab5d..16951ef5b 100644 --- a/test/test_auto_unchoke.cpp +++ b/test/test_auto_unchoke.cpp @@ -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")); diff --git a/test/test_bandwidth_limiter.cpp b/test/test_bandwidth_limiter.cpp index b384f07d3..238526a18 100644 --- a/test/test_bandwidth_limiter.cpp +++ b/test/test_bandwidth_limiter.cpp @@ -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; diff --git a/test/test_bdecode.cpp b/test/test_bdecode.cpp index dd4b6f7c0..da9e786c2 100644 --- a/test/test_bdecode.cpp +++ b/test/test_bdecode.cpp @@ -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); diff --git a/test/test_bencoding.cpp b/test/test_bencoding.cpp index cfabb3ccb..41eec30dc 100644 --- a/test/test_bencoding.cpp +++ b/test/test_bencoding.cpp @@ -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()); } diff --git a/test/test_bitfield.cpp b/test/test_bitfield.cpp index 06f641bef..b0a670da5 100644 --- a/test/test_bitfield.cpp +++ b/test/test_bitfield.cpp @@ -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); diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index 87b67b53e..c6fa9e5b8 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -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; } diff --git a/test/test_bloom_filter.cpp b/test/test_bloom_filter.cpp index b8c251205..6bb3006ef 100644 --- a/test/test_bloom_filter.cpp +++ b/test/test_bloom_filter.cpp @@ -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(); diff --git a/test/test_buffer.cpp b/test/test_buffer.cpp index e989fe573..a36335cb9 100644 --- a/test/test_buffer.cpp +++ b/test/test_buffer.cpp @@ -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; -} - diff --git a/test/test_checking.cpp b/test/test_checking.cpp index 60b11cd80..7150405c7 100644 --- a/test/test_checking.cpp +++ b/test/test_checking.cpp @@ -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); diff --git a/test/test_crc32.cpp b/test/test_crc32.cpp index aa6dadb2a..082f65db7 100644 --- a/test/test_crc32.cpp +++ b/test/test_crc32.cpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/crc32c.hpp" #include "test.hpp" -int test_main() +TORRENT_TEST(crc32) { using namespace libtorrent; diff --git a/test/test_dht.cpp b/test/test_dht.cpp index ff128166f..2395a119c 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -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 > 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; } diff --git a/test/test_dos_blocker.cpp b/test/test_dos_blocker.cpp index 9d19f3e3b..f463d297a 100644 --- a/test/test_dos_blocker.cpp +++ b/test/test_dos_blocker.cpp @@ -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; diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index bfec05310..56eec299a 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -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 #include #include #include -#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(); diff --git a/test/test_fence.cpp b/test/test_fence.cpp index e4af164ce..c24d36f75 100644 --- a/test/test_fence.cpp +++ b/test/test_fence.cpp @@ -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(); diff --git a/test/test_file.cpp b/test/test_file.cpp index 09081848a..5be90ca05 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -103,7 +103,7 @@ void test_stat() TEST_CHECK(diff >= 2 && diff <= 4); } -int test_main() +TORRENT_TEST(file) { test_create_directory(); test_stat(); diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp index 7145b58a0..f3361ae15 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -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")))); diff --git a/test/test_gzip.cpp b/test/test_gzip.cpp index a58a78d25..532c1e2f0 100644 --- a/test/test_gzip.cpp +++ b/test/test_gzip.cpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; -int test_main() +TORRENT_TEST(gzip) { std::vector zipped; error_code ec; diff --git a/test/test_hasher.cpp b/test/test_hasher.cpp index b74828e80..229224cc1 100644 --- a/test/test_hasher.cpp +++ b/test/test_hasher.cpp @@ -60,7 +60,7 @@ char const* result_array[4] = }; -int test_main() +TORRENT_TEST(hasher) { using namespace libtorrent; diff --git a/test/test_heterogeneous_queue.cpp b/test/test_heterogeneous_queue.cpp index a7ea895fa..45ac13a89 100644 --- a/test/test_heterogeneous_queue.cpp +++ b/test/test_heterogeneous_queue.cpp @@ -137,7 +137,7 @@ private: F& operator=(F const& f); }; -int test_main() +TORRENT_TEST(heterogeneuous_queue) { using namespace libtorrent; diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index e3b6a23b0..013613304 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -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) diff --git a/test/test_http_parser.cpp b/test/test_http_parser.cpp index 375d70d6d..0587a5486 100644 --- a/test/test_http_parser.cpp +++ b/test/test_http_parser.cpp @@ -76,7 +76,7 @@ tuple feed_bytes(http_parser& parser, char const* str) return ret; } -int test_main() +TORRENT_TEST(http_parser) { // HTTP request parser http_parser parser; diff --git a/test/test_identify_client.cpp b/test/test_identify_client.cpp index 5331154dc..bc2866aa1 100644 --- a/test/test_identify_client.cpp +++ b/test/test_identify_client.cpp @@ -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"); diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index 5ee7476bd..7968088f6 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -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 > 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 > 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)); } - + // **** 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)); - } + } // **** 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)); - } + } // **** 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)); - } + } // **** 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)); - } + } // **** 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)); } @@ -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)); - } + } #endif port_filter pf; diff --git a/test/test_ip_voter.cpp b/test/test_ip_voter.cpp index fa77ab2c5..0704ec929 100644 --- a/test/test_ip_voter.cpp +++ b/test/test_ip_voter.cpp @@ -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(); diff --git a/test/test_lsd.cpp b/test/test_lsd.cpp index 9681821af..66415d0e9 100644 --- a/test/test_lsd.cpp +++ b/test/test_lsd.cpp @@ -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); diff --git a/test/test_magnet.cpp b/test/test_magnet.cpp index c6d1801d3..e31bc2cda 100644 --- a/test/test_magnet.cpp +++ b/test/test_magnet.cpp @@ -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; diff --git a/test/test_merkle.cpp b/test/test_merkle.cpp index e6fa0aef4..c658dd2f5 100644 --- a/test/test_merkle.cpp +++ b/test/test_merkle.cpp @@ -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; diff --git a/test/test_metadata_extension.cpp b/test/test_metadata_extension.cpp index bc53221fe..81ca6b28d 100644 --- a/test/test_metadata_extension.cpp +++ b/test/test_metadata_extension.cpp @@ -202,7 +202,7 @@ done: remove_all("tmp2_meta", ec); } -int test_main() +TORRENT_TEST(metadata_extension) { using namespace libtorrent; diff --git a/test/test_packet_buffer.cpp b/test/test_packet_buffer.cpp index b4c3f3b38..accf03a19 100644 --- a/test/test_packet_buffer.cpp +++ b/test/test_packet_buffer.cpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. using libtorrent::packet_buffer; -int test_main() +TORRENT_TEST(packet_buffer) { // test packet_buffer { diff --git a/test/test_part_file.cpp b/test/test_part_file.cpp index 3b6d7d7c9..9ee4a2683 100644 --- a/test/test_part_file.cpp +++ b/test/test_part_file.cpp @@ -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("."); diff --git a/test/test_pe_crypto.cpp b/test/test_pe_crypto.cpp index a13cd6166..65a990efc 100644 --- a/test/test_pe_crypto.cpp +++ b/test/test_pe_crypto.cpp @@ -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; diff --git a/test/test_peer_classes.cpp b/test/test_peer_classes.cpp index e3aec9847..60d13e3f1 100644 --- a/test/test_peer_classes.cpp +++ b/test/test_peer_classes.cpp @@ -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; diff --git a/test/test_peer_list.cpp b/test/test_peer_list.cpp index 9fa494e93..7f7cf14e5 100644 --- a/test/test_peer_list.cpp +++ b/test/test_peer_list.cpp @@ -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; diff --git a/test/test_peer_priority.cpp b/test/test_peer_priority.cpp index b8232c76b..8d2cb3688 100644 --- a/test/test_peer_priority.cpp +++ b/test/test_peer_priority.cpp @@ -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 diff --git a/test/test_pex.cpp b/test/test_pex.cpp index 983a2e3eb..4fc32dbc7 100644 --- a/test/test_pex.cpp +++ b/test/test_pex.cpp @@ -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 diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 872582e8c..0fba00b89 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -274,7 +274,7 @@ int test_pick(boost::shared_ptr const& p return picked[0].piece_index; } -int test_main() +TORRENT_TEST(piece_picker) { tcp::endpoint endp; piece_picker::downloading_piece st; diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index 8345d19ae..c839f515f 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -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; diff --git a/test/test_priority.cpp b/test/test_priority.cpp index 50bb978be..656c27fc6 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -394,7 +394,7 @@ done: sp.push_back(ses2.abort()); } -int test_main() +TORRENT_TEST(priority) { using namespace libtorrent; diff --git a/test/test_privacy.cpp b/test/test_privacy.cpp index 22a500add..ef892e360 100644 --- a/test/test_privacy.cpp +++ b/test/test_privacy.cpp @@ -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 diff --git a/test/test_random.cpp b/test/test_random.cpp index da6e964bf..ed964df7f 100644 --- a/test/test_random.cpp +++ b/test/test_random.cpp @@ -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(); diff --git a/test/test_read_piece.cpp b/test/test_read_piece.cpp index 355f26701..37122eeb5 100644 --- a/test/test_read_piece.cpp +++ b/test/test_read_piece.cpp @@ -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); diff --git a/test/test_recheck.cpp b/test/test_recheck.cpp index 7a74ecd2a..51b404096 100644 --- a/test/test_recheck.cpp +++ b/test/test_recheck.cpp @@ -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); diff --git a/test/test_remap_files.cpp b/test/test_remap_files.cpp index 2847a66d2..277e4d99b 100644 --- a/test/test_remap_files.cpp +++ b/test/test_remap_files.cpp @@ -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); diff --git a/test/test_resolve_links.cpp b/test/test_resolve_links.cpp index 16aa1d7ae..964d6f7ab 100644 --- a/test/test_resolve_links.cpp +++ b/test/test_resolve_links.cpp @@ -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 diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 7fa5c72ba..41b797b73 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -128,7 +128,7 @@ torrent_status test_resume_flags(int flags) boost::shared_ptr 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; diff --git a/test/test_session.cpp b/test/test_session.cpp index af81e6820..f46594a91 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -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); diff --git a/test/test_settings_pack.cpp b/test/test_settings_pack.cpp index 0e91e57b2..a4d4e6f8e 100644 --- a/test/test_settings_pack.cpp +++ b/test/test_settings_pack.cpp @@ -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; diff --git a/test/test_sha1_hash.cpp b/test/test_sha1_hash.cpp index 93777101a..61228130f 100644 --- a/test/test_sha1_hash.cpp +++ b/test/test_sha1_hash.cpp @@ -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); diff --git a/test/test_sliding_average.cpp b/test/test_sliding_average.cpp index 731a0274e..aef11b34e 100644 --- a/test/test_sliding_average.cpp +++ b/test/test_sliding_average.cpp @@ -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; diff --git a/test/test_socket_io.cpp b/test/test_socket_io.cpp index ed5543d9c..4f6788bdf 100644 --- a/test/test_socket_io.cpp +++ b/test/test_socket_io.cpp @@ -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"); diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index 8f1106af8..9f20cdd45 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -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); diff --git a/test/test_stat_cache.cpp b/test/test_stat_cache.cpp index 30db026e3..3c5bb5e40 100644 --- a/test/test_stat_cache.cpp +++ b/test/test_stat_cache.cpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; -int test_main() +TORRENT_TEST(stat_cache) { error_code ec; diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 157f350d1..0640960d9 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -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(); diff --git a/test/test_string.cpp b/test/test_string.cpp index 7a9a6d935..5d7f79187 100644 --- a/test/test_string.cpp +++ b/test/test_string.cpp @@ -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"); diff --git a/test/test_super_seeding.cpp b/test/test_super_seeding.cpp index 9e9d92730..dabc8c41f 100644 --- a/test/test_super_seeding.cpp +++ b/test/test_super_seeding.cpp @@ -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; } diff --git a/test/test_swarm.cpp b/test/test_swarm.cpp index aa837cf05..ed6ce7ea6 100644 --- a/test/test_swarm.cpp +++ b/test/test_swarm.cpp @@ -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); diff --git a/test/test_tailqueue.cpp b/test/test_tailqueue.cpp index d929d0b11..6abc649cc 100644 --- a/test/test_tailqueue.cpp +++ b/test/test_tailqueue.cpp @@ -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; diff --git a/test/test_threads.cpp b/test/test_threads.cpp index 29d21f9ea..6dcbb5c3c 100644 --- a/test/test_threads.cpp +++ b/test/test_threads.cpp @@ -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; diff --git a/test/test_time.cpp b/test/test_time.cpp index a590545cc..17d9fc543 100644 --- a/test/test_time.cpp +++ b/test/test_time.cpp @@ -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 diff --git a/test/test_time_critical.cpp b/test/test_time_critical.cpp index 1aa0ec7aa..9b52092c6 100644 --- a/test/test_time_critical.cpp +++ b/test/test_time_critical.cpp @@ -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); diff --git a/test/test_timestamp_history.cpp b/test/test_timestamp_history.cpp index 39290007e..6dcf86842 100644 --- a/test/test_timestamp_history.cpp +++ b/test/test_timestamp_history.cpp @@ -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; diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index 78a13af2e..adf4214b1 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -152,7 +152,7 @@ void test_running_torrent(boost::shared_ptr info, boost::int64_t f } } -int test_main() +TORRENT_TEST(torrent) { /* { remove("test_torrent_dir2/tmp1"); diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 2c98fff07..2c96293c0 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -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); diff --git a/test/test_tracker.cpp b/test/test_tracker.cpp index 7cd7b5daf..d6b239806 100644 --- a/test/test_tracker.cpp +++ b/test/test_tracker.cpp @@ -234,7 +234,7 @@ void test_extract_peer() } } -int test_main() +TORRENT_TEST(traccker) { test_extract_peer(); test_parse_hostname_peers(); diff --git a/test/test_trackers_extension.cpp b/test/test_trackers_extension.cpp index 9336a913b..6be2eaa6e 100644 --- a/test/test_trackers_extension.cpp +++ b/test/test_trackers_extension.cpp @@ -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 diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index ced6b1b67..95e8196fb 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -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; diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index 1b673f36d..6b5c450f3 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -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 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"); diff --git a/test/test_url_seed.cpp b/test/test_url_seed.cpp index 720bd43aa..c4edb5cae 100644 --- a/test/test_url_seed.cpp +++ b/test/test_url_seed.cpp @@ -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) { diff --git a/test/test_utf8.cpp b/test/test_utf8.cpp index 1b2e473af..abb77325a 100644 --- a/test/test_utf8.cpp +++ b/test/test_utf8.cpp @@ -167,7 +167,7 @@ void expect_error(char const* utf8, ConversionResult expect) } } -int test_main() +TORRENT_TEST(utf8) { std::vector utf8_source; error_code ec; diff --git a/test/test_utp.cpp b/test/test_utp.cpp index 67961db42..bcfc6d2a8 100644 --- a/test/test_utp.cpp +++ b/test/test_utp.cpp @@ -128,7 +128,7 @@ void test_transfer() p2 = ses2.abort(); } -int test_main() +TORRENT_TEST(utp) { using namespace libtorrent; diff --git a/test/test_web_seed.cpp b/test/test_web_seed.cpp index cc1c8cbe0..d001abd2a 100644 --- a/test/test_web_seed.cpp +++ b/test/test_web_seed.cpp @@ -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); diff --git a/test/test_web_seed_ban.cpp b/test/test_web_seed_ban.cpp index 015e4cffa..32a47667c 100644 --- a/test/test_web_seed_ban.cpp +++ b/test/test_web_seed_ban.cpp @@ -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) diff --git a/test/test_web_seed_chunked.cpp b/test/test_web_seed_chunked.cpp index 507591a17..07a4a926f 100644 --- a/test/test_web_seed_chunked.cpp +++ b/test/test_web_seed_chunked.cpp @@ -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) diff --git a/test/test_web_seed_http.cpp b/test/test_web_seed_http.cpp index fa37c1e91..084463ed2 100644 --- a/test/test_web_seed_http.cpp +++ b/test/test_web_seed_http.cpp @@ -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) diff --git a/test/test_web_seed_http_pw.cpp b/test/test_web_seed_http_pw.cpp index 2ff669e24..61838d0ed 100644 --- a/test/test_web_seed_http_pw.cpp +++ b/test/test_web_seed_http_pw.cpp @@ -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) diff --git a/test/test_web_seed_redirect.cpp b/test/test_web_seed_redirect.cpp index 954e2ecf2..1d0b3da82 100644 --- a/test/test_web_seed_redirect.cpp +++ b/test/test_web_seed_redirect.cpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; -int test_main() +TORRENT_TEST(web_seed_redirect) { using namespace libtorrent; diff --git a/test/test_web_seed_socks4.cpp b/test/test_web_seed_socks4.cpp index 313af4364..25472615c 100644 --- a/test/test_web_seed_socks4.cpp +++ b/test/test_web_seed_socks4.cpp @@ -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) diff --git a/test/test_web_seed_socks5.cpp b/test/test_web_seed_socks5.cpp index 48e35e4ec..709acb6a3 100644 --- a/test/test_web_seed_socks5.cpp +++ b/test/test_web_seed_socks5.cpp @@ -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) diff --git a/test/test_web_seed_socks5_pw.cpp b/test/test_web_seed_socks5_pw.cpp index a9527afba..4361f7718 100644 --- a/test/test_web_seed_socks5_pw.cpp +++ b/test/test_web_seed_socks5_pw.cpp @@ -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) diff --git a/test/test_xml.cpp b/test/test_xml.cpp index 2ea9be78b..7548b6e87 100644 --- a/test/test_xml.cpp +++ b/test/test_xml.cpp @@ -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