import testing ;
import feature : feature ;

use-project /torrent : .. ;

exe test_natpmp : test_natpmp.cpp /torrent//torrent
	: <threading>multi <debug-iterators>on <invariant-checks>full ;

exe enum_if : enum_if.cpp /torrent//torrent
	: <threading>multi <debug-iterators>on <invariant-checks>full ;

exe bdecode_benchmark : bdecode_benchmark.cpp /torrent//torrent
	: <variant>release ;

explicit test_natpmp ;
explicit enum_if ;
explicit bdecode_benchmark ;

rule link_test ( properties * )
{
	local result ;
	if <link>shared in $(properties)
	{
		result +=
			<library>libtorrent_test/<link>shared ;
	}
	else
	{
		result +=
			<library>libtorrent_test/<link>static ;
	}
	return $(result) ;
}

rule link_libtorrent ( properties * )
{
	local result ;
	if <link>shared in $(properties)
	{
		result +=
			<library>/torrent//torrent/<link>shared/<logging>on/<boost-link>shared/<export-extra>on/<debug-iterators>on ;
	}
	else
	{
		result +=
			<library>/torrent//torrent/<link>static/<logging>on/<boost-link>static/<export-extra>on/<debug-iterators>on ;
	}
	return $(result) ;
}

lib libtorrent_test
	: # sources
	main.cpp
	test.cpp
	setup_transfer.cpp
	dht_server.cpp
	udp_tracker.cpp
	peer_server.cpp
	web_seed_suite.cpp
	swarm_suite.cpp
	test_utils.cpp
	settings.cpp

	: # requirements
	# this is used to determine whether
	# symbols are exported or imported
	<link>shared:<define>TORRENT_BUILDING_TEST_SHARED
	<link>shared:<define>ED25519_BUILD_DLL
	<include>../ed25519/src
	<target-os>windows:<library>advapi32
	<conditional>@link_libtorrent
	<toolset>darwin:<cflags>-Wno-unused-command-line-argument
	<debug-iterators>on

	: # default build
	<link>shared
	<logging>on

	: # user-requirements
	<link>shared:<define>TORRENT_LINK_TEST_SHARED
	<debug-iterators>on
	<logging>on
	<include>.
;

explicit libtorrent_test ;

lib advapi32 : : <name>Advapi32 ;

project
	: requirements
	<conditional>@link_test
	<conditional>@link_libtorrent
	<toolset>darwin:<cflags>-Wno-unused-command-line-argument
	: default-build
	<threading>multi
	<invariant-checks>full
	<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_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_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_xml.cpp
		test_ip_filter.cpp
		test_hasher.cpp
		test_dht_storage.cpp
		test_dht.cpp
		test_block_cache.cpp
		test_peer_classes.cpp
		test_settings_pack.cpp
		test_fence.cpp
		test_dos_blocker.cpp
		test_stat_cache.cpp
		test_enum_net.cpp
		test_linked_list.cpp
		test_file_progress.cpp ]

	[ run test_alert_manager.cpp ]
	[ run test_direct_dht.cpp ]
	[ run test_magnet.cpp ]
	[ run test_storage.cpp ]
	[ run test_session.cpp ]
	[ run test_read_piece.cpp ]

	[ run test_file.cpp ]
	[ run test_fast_extension.cpp ]
	[ run test_privacy.cpp ]
	[ run test_recheck.cpp ]
	[ run test_resume.cpp ]
	[ run test_ssl.cpp ]
	[ run test_tracker.cpp ]
	[ run test_checking.cpp ]
	[ run test_url_seed.cpp ]
	[ run test_web_seed.cpp ]
	[ run test_web_seed_redirect.cpp ]
	[ run test_web_seed_socks4.cpp ]
	[ run test_web_seed_socks5.cpp ]
	[ run test_web_seed_socks5_no_peers.cpp ]
	[ run test_web_seed_socks5_pw.cpp ]
	[ run test_web_seed_http.cpp ]
	[ run test_web_seed_http_pw.cpp ]
	[ run test_web_seed_chunked.cpp ]
	[ run test_web_seed_ban.cpp ]
	[ run test_pe_crypto.cpp ]

	[ run test_remap_files.cpp ]
	[ run test_utp.cpp ]
	[ run test_auto_unchoke.cpp ]
	[ run test_http_connection.cpp ]
	[ run test_torrent.cpp ]
	[ run test_transfer.cpp ]
	[ run test_time_critical.cpp ]
	[ run test_pex.cpp ]
	[ run test_priority.cpp ]

# turn these tests into simulations
#	[ run test_upnp.cpp ]
#	[ run test_lsd.cpp ]
	;

# these are the tests run on appveyor, while the flapping ones are being
# transitioned into simulations
alias win-tests :
	test_primitives
	test_pe_crypto
	test_remap_files
	test_auto_unchoke
	test_torrent
	test_transfer
	test_time_critical
	test_pex
	test_priority
	test_storage
	test_session
	test_read_piece
	test_file
	test_fast_extension
	test_recheck
	test_resume
	test_tracker
	test_checking
	;

# the openssl test hangs on the travis osx machine. difficult to debug
alias osx-tests :
	test_primitives
	test_alert_manager
	test_direct_dht
	test_magnet
	test_storage
	test_session
	test_read_piece
	test_file
	test_fast_extension
	test_privacy
	test_recheck
	test_resume
#	test_ssl
	test_tracker
	test_checking
	test_url_seed
	test_web_seed
	test_web_seed_redirect
	test_web_seed_socks4
	test_web_seed_socks5
	test_web_seed_socks5_pw
	test_web_seed_http
	test_web_seed_http_pw
	test_web_seed_chunked
	test_web_seed_ban
	test_pe_crypto
	test_remap_files
	test_utp
	test_auto_unchoke
	test_http_connection
	test_torrent
	test_transfer
	test_time_critical
	test_pex
	test_priority
;

explicit win-tests ;