88 lines
2.7 KiB
C++
88 lines
2.7 KiB
C++
![]() |
/*
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|