fix some undefined behavior in tests. and fix test_file_storage

This commit is contained in:
Arvid Norberg 2015-03-22 05:31:55 +00:00
parent a516bf46e5
commit 0aece517ce
3 changed files with 9 additions and 9 deletions

View File

@ -95,7 +95,7 @@ int main()
| SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
#endif
srand((total_microseconds(clock_type::now() - min_time())) & 0x7fffffff);
srand(total_microseconds(clock_type::now().time_since_epoch()) & 0x7fffffff);
#ifdef O_NONBLOCK
// on darwin, stdout is set to non-blocking mode by default
// which sometimes causes tests to fail with EAGAIN just

View File

@ -81,7 +81,7 @@ static std::vector<std::string> failure_strings;
address rand_v4()
{
return address_v4((rand() << 16 | rand()) & 0xffffffff);
return address_v4(((boost::uint32_t(rand()) << 16) | rand()) & 0xffffffff);
}
#if TORRENT_USE_IPV6
@ -509,7 +509,7 @@ int start_proxy(int proxy_type)
if (i->second.type == proxy_type) { return i->first; }
}
unsigned int seed = total_microseconds(clock_type::now() - min_time()) & 0xffffffff;
unsigned int seed = total_microseconds(clock_type::now().time_since_epoch()) & 0xffffffff;
printf("random seed: %u\n", seed);
std::srand(seed);
@ -864,7 +864,7 @@ pid_type web_server_pid = 0;
int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
{
unsigned int seed = total_microseconds(clock_type::now() - min_time()) & 0xffffffff;
unsigned int seed = total_microseconds(clock_type::now().time_since_epoch()) & 0xffffffff;
fprintf(stderr, "random seed: %u\n", seed);
std::srand(seed);
int port = 5000 + (rand() % 55000);

View File

@ -197,14 +197,14 @@ int test_main()
// whose name collides with
file_storage fs;
fs.set_piece_length(512);
fs.add_file(combine_path("temp_storage", combine_path("foo", "test1")), 17);
fs.add_file(combine_path("temp_storage", "Foo"), 17);
fs.add_file(combine_path("temp_storage", "foo"), 612);
fprintf(stderr, "path: %s\n", fs.paths()[0].c_str());
fprintf(stderr, "path: %s\n", fs.file_path(0).c_str());
fprintf(stderr, "file: %s\n", fs.file_path(1).c_str());
boost::uint32_t file_hash = fs.file_path_hash(1, "a");
boost::uint32_t path_hash = fs.path_hash(0, "a");
TEST_EQUAL(file_hash, path_hash);
boost::uint32_t file_hash0 = fs.file_path_hash(0, "a");
boost::uint32_t file_hash1 = fs.file_path_hash(1, "a");
TEST_EQUAL(file_hash0, file_hash1);
}
// TODO: test file_storage::optimize too