forked from premiere/premiere-libtorrent
imrove some test coverage and fix bug in trim() function
This commit is contained in:
parent
6584423737
commit
0319b53d5f
|
@ -99,10 +99,6 @@ namespace libtorrent
|
|||
// in strict ansi mode
|
||||
char* allocate_string_copy(char const* str);
|
||||
|
||||
// returns p + x such that the pointer is 8 bytes aligned
|
||||
// x cannot be greater than 7
|
||||
void* align_pointer(void* p);
|
||||
|
||||
// searches for separator in the string 'last'. the pointer last points to
|
||||
// is set to point to the first character following the separator.
|
||||
// returns a pointer to a 0-terminated string starting at last, ending
|
||||
|
|
|
@ -465,7 +465,7 @@ namespace libtorrent
|
|||
{
|
||||
auto const first = str.find_first_not_of(" \t\n\r");
|
||||
auto const last = str.find_last_not_of(" \t\n\r");
|
||||
return str.substr(first, last - first + 1);
|
||||
return str.substr(first == string_view::npos ? str.size() : first, last - first + 1);
|
||||
}
|
||||
|
||||
string_view::size_type find(string_view haystack, string_view needle, string_view::size_type pos)
|
||||
|
|
|
@ -162,20 +162,6 @@ namespace libtorrent
|
|||
return tmp;
|
||||
}
|
||||
|
||||
// 8-byte align pointer
|
||||
void* align_pointer(void* p)
|
||||
{
|
||||
int offset = uintptr_t(p) & 0x7;
|
||||
// if we're already aligned, don't do anything
|
||||
if (offset == 0) return p;
|
||||
|
||||
// offset is how far passed the last aligned address
|
||||
// we are. We need to go forward to the next aligned
|
||||
// one. Since aligned addresses are 8 bytes apart, add
|
||||
// 8 - offset.
|
||||
return static_cast<char*>(p) + (8 - offset);
|
||||
}
|
||||
|
||||
std::string print_listen_interfaces(std::vector<listen_interface_t> const& in)
|
||||
{
|
||||
std::string ret;
|
||||
|
|
|
@ -319,14 +319,17 @@ TORRENT_TEST(parse_dht_node)
|
|||
error_code ec;
|
||||
add_torrent_params p;
|
||||
parse_magnet_uri("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
|
||||
"&dn=foo&dht=127.0.0.1:43", p, ec);
|
||||
"&dn=foo&dht=127.0.0.1:43&dht=10.0.0.1:1337", p, ec);
|
||||
TEST_CHECK(!ec);
|
||||
if (ec) std::printf("%s\n", ec.message().c_str());
|
||||
ec.clear();
|
||||
|
||||
TEST_EQUAL(p.dht_nodes.size(), 1);
|
||||
TEST_EQUAL(p.dht_nodes.size(), 2);
|
||||
TEST_EQUAL(p.dht_nodes[0].first, "127.0.0.1");
|
||||
TEST_EQUAL(p.dht_nodes[0].second, 43);
|
||||
|
||||
TEST_EQUAL(p.dht_nodes[1].first, "10.0.0.1");
|
||||
TEST_EQUAL(p.dht_nodes[1].second, 1337);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "setup_transfer.hpp"
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "libtorrent/aux_/escape_string.hpp" // for trim
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -112,6 +111,14 @@ TORRENT_TEST(parse_invalid_ipv4_endpoint)
|
|||
error_code ec;
|
||||
tcp::endpoint endp;
|
||||
|
||||
endp = parse_endpoint("", ec);
|
||||
TEST_CHECK(ec);
|
||||
ec.clear();
|
||||
|
||||
endp = parse_endpoint("\n\t ", ec);
|
||||
TEST_CHECK(ec);
|
||||
ec.clear();
|
||||
|
||||
endp = parse_endpoint("127.0.0.1-4", ec);
|
||||
TEST_CHECK(ec);
|
||||
ec.clear();
|
||||
|
@ -216,14 +223,3 @@ TORRENT_TEST(parse_valid_ipv6_endpoint)
|
|||
}
|
||||
#endif
|
||||
|
||||
TORRENT_TEST(trim)
|
||||
{
|
||||
TEST_EQUAL(trim(" a"), "a");
|
||||
TEST_EQUAL(trim(" a "), "a");
|
||||
TEST_EQUAL(trim("\t \na \t\r"), "a");
|
||||
TEST_EQUAL(trim(" \t \ta"), "a");
|
||||
TEST_EQUAL(trim("a "), "a");
|
||||
TEST_EQUAL(trim("a \t"), "a");
|
||||
TEST_EQUAL(trim("a \t\n \tb"), "a \t\n \tb");
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/string_util.hpp"
|
||||
#include <iostream>
|
||||
#include <cstring> // for strcmp
|
||||
#include "libtorrent/aux_/escape_string.hpp" // for trim
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
|
@ -387,6 +388,19 @@ TORRENT_TEST(tokenize)
|
|||
, convert_to_native("foo") + convert_to_native("bar"));
|
||||
}
|
||||
|
||||
TORRENT_TEST(trim)
|
||||
{
|
||||
TEST_EQUAL(trim(""), "");
|
||||
TEST_EQUAL(trim("\t "), "");
|
||||
TEST_EQUAL(trim(" a"), "a");
|
||||
TEST_EQUAL(trim(" a "), "a");
|
||||
TEST_EQUAL(trim("\t \na \t\r"), "a");
|
||||
TEST_EQUAL(trim(" \t \ta"), "a");
|
||||
TEST_EQUAL(trim("a "), "a");
|
||||
TEST_EQUAL(trim("a \t"), "a");
|
||||
TEST_EQUAL(trim("a \t\n \tb"), "a \t\n \tb");
|
||||
}
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
TORRENT_TEST(i2p_url)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue