diff --git a/CMakeLists.txt b/CMakeLists.txt index 8aad8b68b..53ebe0d72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,6 +290,7 @@ endif(build_examples) # === build tests === if(build_tests) set(tests + test_file_storage test_auto_unchoke test_http_connection test_buffer diff --git a/test/Jamfile b/test/Jamfile index 6673fe3b5..72f5cab0e 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -39,6 +39,7 @@ project ; test-suite libtorrent : + [ run test_file_storage.cpp ] [ run test_peer_priority.cpp ] [ run test_file.cpp ] [ run test_threads.cpp ] diff --git a/test/Makefile.am b/test/Makefile.am index 71f6de62b..f851686b3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,5 +1,6 @@ test_programs = \ test_file \ + test_file_storage \ test_auto_unchoke \ test_bandwidth_limiter \ test_bdecode_performance \ @@ -94,6 +95,7 @@ noinst_HEADERS = test.hpp setup_transfer.hpp libtest_la_SOURCES = main.cpp setup_transfer.cpp test_file_SOURCES = test_file.cpp +test_file_storage_SOURCES = test_file_storage.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 @@ -132,3 +134,4 @@ LDADD = $(top_builddir)/src/libtorrent-rasterbar.la libtest.la AM_CPPFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@ #AM_LDFLAGS= @BOOST_SYSTEM_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_THREAD_LIB@ @PTHREAD_LIBS@ @SSL_LDFLAGS@ @SSL_LIBS@ + diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp new file mode 100644 index 000000000..bcd35b5a5 --- /dev/null +++ b/test/test_file_storage.cpp @@ -0,0 +1,87 @@ +/* + +Copyright (c) 2013, 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 "test.hpp" +#include "setup_transfer.hpp" + +#include "libtorrent/file_storage.hpp" + +using namespace libtorrent; + +void setup_test_storage(file_storage& st) +{ + st.add_file("test/a", 10000); + st.add_file("test/b", 20000); + st.add_file("test/c/a", 30000); + st.add_file("test/c/b", 40000); + + st.set_piece_length(0x4000); + st.set_num_pieces((st.total_size() + st.piece_length() - 1) / 0x4000); + + TEST_EQUAL(st.file_name(0), "a"); + TEST_EQUAL(st.file_name(1), "b"); + TEST_EQUAL(st.file_name(2), "a"); + TEST_EQUAL(st.file_name(3), "b"); + TEST_EQUAL(st.name(), "test"); + + TEST_EQUAL(st.file_path(0), "test/a"); + TEST_EQUAL(st.file_path(1), "test/b"); + TEST_EQUAL(st.file_path(2), "test/c/a"); + TEST_EQUAL(st.file_path(3), "test/c/b"); + + TEST_EQUAL(st.file_size(0), 10000); + TEST_EQUAL(st.file_size(1), 20000); + TEST_EQUAL(st.file_size(2), 30000); + TEST_EQUAL(st.file_size(3), 40000); + + TEST_EQUAL(st.file_offset(0), 0); + TEST_EQUAL(st.file_offset(1), 10000); + TEST_EQUAL(st.file_offset(2), 30000); + TEST_EQUAL(st.file_offset(3), 60000); + + TEST_EQUAL(st.total_size(), 100000); + TEST_EQUAL(st.piece_length(), 0x4000); + printf("%d\n", st.num_pieces()); + TEST_EQUAL(st.num_pieces(), (100000 + 0x3fff) / 0x4000); +} + +int test_main() +{ + { + file_storage a; + setup_test_storage(a); + + } + + return 0; +} +