fix a handful of minor compiler warnings, mostly in the unit tests, eg field width shortening or implicit signed/unsigned conversions
This commit is contained in:
parent
7fb8708efd
commit
5fbd24fda5
|
@ -22,7 +22,7 @@ test_torrent_hash (void)
|
|||
{
|
||||
tr_crypto a;
|
||||
uint8_t hash[SHA_DIGEST_LENGTH];
|
||||
int i;
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < SHA_DIGEST_LENGTH; ++i)
|
||||
hash[i] = i;
|
||||
|
@ -70,7 +70,7 @@ test_encrypt_decrypt (void)
|
|||
int i;
|
||||
|
||||
for (i = 0; i < SHA_DIGEST_LENGTH; ++i)
|
||||
hash[i] = i;
|
||||
hash[i] = (uint8_t)i;
|
||||
|
||||
tr_cryptoConstruct (&a, hash, false);
|
||||
tr_cryptoConstruct_ (&b, hash, true);
|
||||
|
@ -215,59 +215,59 @@ test_base64 (void)
|
|||
{
|
||||
size_t len;
|
||||
char * in, * out;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
out = tr_base64_encode_str ("YOYO!", &len);
|
||||
check_int_eq (strlen (out), len);
|
||||
check_uint_eq (strlen (out), len);
|
||||
check (base64_eq ("WU9ZTyE=", out));
|
||||
in = tr_base64_decode_str (out, &len);
|
||||
check_int_eq (5, len);
|
||||
check_uint_eq (5, len);
|
||||
check_streq ("YOYO!", in);
|
||||
tr_free (in);
|
||||
tr_free (out);
|
||||
|
||||
out = tr_base64_encode ("", 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check_uint_eq (0, len);
|
||||
check_streq ("", out);
|
||||
tr_free (out);
|
||||
out = tr_base64_decode ("", 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check_uint_eq (0, len);
|
||||
check_streq ("", out);
|
||||
tr_free (out);
|
||||
|
||||
out = tr_base64_encode (NULL, 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check_uint_eq (0, len);
|
||||
check (out == NULL);
|
||||
out = tr_base64_decode (NULL, 0, &len);
|
||||
check_int_eq (0, len);
|
||||
check_uint_eq (0, len);
|
||||
check (out == NULL);
|
||||
|
||||
#define MAX_BUF_SIZE 1024
|
||||
|
||||
for (i = 1; i <= MAX_BUF_SIZE; ++i)
|
||||
{
|
||||
int j;
|
||||
size_t j;
|
||||
char buf[MAX_BUF_SIZE + 1];
|
||||
|
||||
for (j = 0; j < i; ++j)
|
||||
buf[j] = tr_rand_int_weak (256);
|
||||
buf[j] = (char) tr_rand_int_weak (256);
|
||||
|
||||
out = tr_base64_encode (buf, j, &len);
|
||||
check_int_eq (strlen (out), len);
|
||||
check_uint_eq (strlen (out), len);
|
||||
in = tr_base64_decode (out, len, &len);
|
||||
check_int_eq (j, len);
|
||||
check_uint_eq (j, len);
|
||||
check (memcmp (in, buf, len) == 0);
|
||||
tr_free (in);
|
||||
tr_free (out);
|
||||
|
||||
for (j = 0; j < i; ++j)
|
||||
buf[j] = 1 + tr_rand_int_weak (255);
|
||||
buf[j] = (char)(1 + tr_rand_int_weak (255));
|
||||
buf[j] = '\0';
|
||||
|
||||
out = tr_base64_encode_str (buf, &len);
|
||||
check_int_eq (strlen (out), len);
|
||||
check_uint_eq (strlen (out), len);
|
||||
in = tr_base64_decode_str (out, &len);
|
||||
check_int_eq (j, len);
|
||||
check_uint_eq (j, len);
|
||||
check_streq (in, buf);
|
||||
tr_free (in);
|
||||
tr_free (out);
|
||||
|
|
|
@ -120,7 +120,7 @@ path_contains_no_symlinks (const char * path)
|
|||
if (slashPos == NULL)
|
||||
slashPos = p + strlen (p) - 1;
|
||||
|
||||
pathPart = tr_strndup (path, slashPos - path + 1);
|
||||
pathPart = tr_strndup (path, (size_t)(slashPos - path + 1));
|
||||
|
||||
if (!tr_sys_path_get_info (pathPart, TR_SYS_PATH_NO_FOLLOW, &info, NULL) ||
|
||||
(info.type != TR_SYS_PATH_IS_FILE && info.type != TR_SYS_PATH_IS_DIRECTORY))
|
||||
|
@ -183,7 +183,7 @@ test_get_info (void)
|
|||
check (tr_sys_path_get_info (path1, 0, &info, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
|
||||
check_int_eq (4, info.size);
|
||||
check_uint_eq (4, info.size);
|
||||
check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
|
||||
|
||||
/* Good file info (by handle) */
|
||||
|
@ -192,7 +192,7 @@ test_get_info (void)
|
|||
check (tr_sys_file_get_info (fd, &info, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
|
||||
check_int_eq (4, info.size);
|
||||
check_uint_eq (4, info.size);
|
||||
check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
|
||||
tr_sys_file_close (fd, NULL);
|
||||
|
||||
|
@ -224,7 +224,7 @@ test_get_info (void)
|
|||
check (tr_sys_path_get_info (path1, 0, &info, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
|
||||
check_int_eq (4, info.size);
|
||||
check_uint_eq (4, info.size);
|
||||
check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
|
||||
|
||||
/* Good file info (by handle) */
|
||||
|
@ -233,7 +233,7 @@ test_get_info (void)
|
|||
check (tr_sys_file_get_info (fd, &info, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
|
||||
check_int_eq (4, info.size);
|
||||
check_uint_eq (4, info.size);
|
||||
check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
|
||||
tr_sys_file_close (fd, NULL);
|
||||
|
||||
|
@ -1010,30 +1010,30 @@ test_file_open (void)
|
|||
check (err != NULL);
|
||||
tr_error_clear (&err);
|
||||
tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL);
|
||||
check_int_eq (4, info.size);
|
||||
check_uint_eq (4, info.size);
|
||||
|
||||
/* Pointer is at the end of file */
|
||||
tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL);
|
||||
check_int_eq (4, info.size);
|
||||
check_uint_eq (4, info.size);
|
||||
fd = tr_sys_file_open (path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_APPEND, 0600, &err);
|
||||
check (fd != TR_BAD_SYS_FILE);
|
||||
check (err == NULL);
|
||||
tr_sys_file_write (fd, "s", 1, NULL, NULL); /* On *NIX, pointer is positioned on each write but not initially */
|
||||
tr_sys_file_seek (fd, 0, TR_SEEK_CUR, &n, NULL);
|
||||
check_int_eq (5, n);
|
||||
check_uint_eq (5, n);
|
||||
tr_sys_file_close (fd, NULL);
|
||||
|
||||
/* File gets truncated */
|
||||
tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL);
|
||||
check_int_eq (5, info.size);
|
||||
check_uint_eq (5, info.size);
|
||||
fd = tr_sys_file_open (path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_TRUNCATE, 0600, &err);
|
||||
check (fd != TR_BAD_SYS_FILE);
|
||||
check (err == NULL);
|
||||
tr_sys_file_get_info (fd, &info, NULL);
|
||||
check_int_eq (0, info.size);
|
||||
check_uint_eq (0, info.size);
|
||||
tr_sys_file_close (fd, NULL);
|
||||
tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL);
|
||||
check_int_eq (0, info.size);
|
||||
check_uint_eq (0, info.size);
|
||||
|
||||
/* TODO: symlink and hardlink tests */
|
||||
|
||||
|
@ -1061,69 +1061,69 @@ test_file_read_write_seek (void)
|
|||
|
||||
check (tr_sys_file_seek (fd, 0, TR_SEEK_CUR, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (0, n);
|
||||
check_uint_eq (0, n);
|
||||
|
||||
check (tr_sys_file_write (fd, "test", 4, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (4, n);
|
||||
check_uint_eq (4, n);
|
||||
|
||||
check (tr_sys_file_seek (fd, 0, TR_SEEK_CUR, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (4, n);
|
||||
check_uint_eq (4, n);
|
||||
|
||||
check (tr_sys_file_seek (fd, 0, TR_SEEK_SET, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (0, n);
|
||||
check_uint_eq (0, n);
|
||||
|
||||
check (tr_sys_file_read (fd, buf, sizeof (buf), &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (4, n);
|
||||
check_uint_eq (4, n);
|
||||
|
||||
check_int_eq (0, memcmp (buf, "test", 4));
|
||||
|
||||
check (tr_sys_file_seek (fd, -3, TR_SEEK_CUR, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (1, n);
|
||||
check_uint_eq (1, n);
|
||||
|
||||
check (tr_sys_file_write (fd, "E", 1, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (1, n);
|
||||
check_uint_eq (1, n);
|
||||
|
||||
check (tr_sys_file_seek (fd, -2, TR_SEEK_CUR, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (0, n);
|
||||
check_uint_eq (0, n);
|
||||
|
||||
check (tr_sys_file_read (fd, buf, sizeof (buf), &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (4, n);
|
||||
check_uint_eq (4, n);
|
||||
|
||||
check_int_eq (0, memcmp (buf, "tEst", 4));
|
||||
|
||||
check (tr_sys_file_seek (fd, 0, TR_SEEK_END, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (4, n);
|
||||
check_uint_eq (4, n);
|
||||
|
||||
check (tr_sys_file_write (fd, " ok", 3, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (3, n);
|
||||
check_uint_eq (3, n);
|
||||
|
||||
check (tr_sys_file_seek (fd, 0, TR_SEEK_SET, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (0, n);
|
||||
check_uint_eq (0, n);
|
||||
|
||||
check (tr_sys_file_read (fd, buf, sizeof (buf), &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (7, n);
|
||||
check_uint_eq (7, n);
|
||||
|
||||
check_int_eq (0, memcmp (buf, "tEst ok", 7));
|
||||
|
||||
check (tr_sys_file_write_at (fd, "-", 1, 4, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (1, n);
|
||||
check_uint_eq (1, n);
|
||||
|
||||
check (tr_sys_file_read_at (fd, buf, 5, 2, &n, &err));
|
||||
check (err == NULL);
|
||||
check_int_eq (5, n);
|
||||
check_uint_eq (5, n);
|
||||
|
||||
check_int_eq (0, memcmp (buf, "st-ok", 5));
|
||||
|
||||
|
@ -1153,17 +1153,17 @@ test_file_truncate (void)
|
|||
check (tr_sys_file_truncate (fd, 10, &err));
|
||||
check (err == NULL);
|
||||
tr_sys_file_get_info (fd, &info, NULL);
|
||||
check_int_eq (10, info.size);
|
||||
check_uint_eq (10, info.size);
|
||||
|
||||
check (tr_sys_file_truncate (fd, 20, &err));
|
||||
check (err == NULL);
|
||||
tr_sys_file_get_info (fd, &info, NULL);
|
||||
check_int_eq (20, info.size);
|
||||
check_uint_eq (20, info.size);
|
||||
|
||||
check (tr_sys_file_truncate (fd, 0, &err));
|
||||
check (err == NULL);
|
||||
tr_sys_file_get_info (fd, &info, NULL);
|
||||
check_int_eq (0, info.size);
|
||||
check_uint_eq (0, info.size);
|
||||
|
||||
check (tr_sys_file_truncate (fd, 50, &err));
|
||||
check (err == NULL);
|
||||
|
@ -1171,7 +1171,7 @@ test_file_truncate (void)
|
|||
tr_sys_file_close (fd, NULL);
|
||||
|
||||
tr_sys_path_get_info (path1, 0, &info, NULL);
|
||||
check_int_eq (50, info.size);
|
||||
check_uint_eq (50, info.size);
|
||||
|
||||
fd = tr_sys_file_open (path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0600, NULL);
|
||||
|
||||
|
@ -1181,7 +1181,7 @@ test_file_truncate (void)
|
|||
tr_sys_file_close (fd, NULL);
|
||||
|
||||
tr_sys_path_get_info (path1, 0, &info, NULL);
|
||||
check_int_eq (25, info.size);
|
||||
check_uint_eq (25, info.size);
|
||||
|
||||
tr_sys_path_remove (path1, NULL);
|
||||
|
||||
|
@ -1208,7 +1208,7 @@ test_file_preallocate (void)
|
|||
{
|
||||
check (err == NULL);
|
||||
tr_sys_file_get_info (fd, &info, NULL);
|
||||
check_int_eq (50, info.size);
|
||||
check_uint_eq (50, info.size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1227,7 +1227,7 @@ test_file_preallocate (void)
|
|||
{
|
||||
check (err == NULL);
|
||||
tr_sys_file_get_info (fd, &info, NULL);
|
||||
check_int_eq (500 * 1024 * 1024, info.size);
|
||||
check_uint_eq (500 * 1024 * 1024, info.size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -161,7 +161,7 @@ test1 (void)
|
|||
check (tr_variantIsDict (args));
|
||||
check ((ids = tr_variantDictFind (args, TR_KEY_ids)));
|
||||
check (tr_variantIsList (ids));
|
||||
check_int_eq (2, tr_variantListSize (ids));
|
||||
check_uint_eq (2, tr_variantListSize (ids));
|
||||
check (tr_variantGetInt (tr_variantListChild (ids, 0), &i));
|
||||
check_int_eq (7, i);
|
||||
check (tr_variantGetInt (tr_variantListChild (ids, 1), &i));
|
||||
|
|
|
@ -89,6 +89,21 @@ check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual
|
|||
return pass;
|
||||
}
|
||||
|
||||
bool
|
||||
check_uint_eq_impl (const char * file, int line, uint64_t expected, uint64_t actual)
|
||||
{
|
||||
const bool pass = expected == actual;
|
||||
|
||||
if (should_print (pass)) {
|
||||
if (pass)
|
||||
fprintf (stderr, "PASS %s:%d\n", file, line);
|
||||
else
|
||||
fprintf (stderr, "FAIL %s:%d, expected \"%"PRIu64"\", got \"%"PRIu64"\"\n", file, line, expected, actual);
|
||||
}
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
bool
|
||||
check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual)
|
||||
{
|
||||
|
@ -194,21 +209,18 @@ libtest_sandbox_destroy (const char * sandbox)
|
|||
***/
|
||||
|
||||
#define MEM_K 1024
|
||||
#define MEM_B_STR "B"
|
||||
#define MEM_K_STR "KiB"
|
||||
#define MEM_M_STR "MiB"
|
||||
#define MEM_G_STR "GiB"
|
||||
#define MEM_T_STR "TiB"
|
||||
|
||||
#define DISK_K 1000
|
||||
#define DISK_B_STR "B"
|
||||
#define DISK_K_STR "kB"
|
||||
#define DISK_M_STR "MB"
|
||||
#define DISK_G_STR "GB"
|
||||
#define DISK_T_STR "TB"
|
||||
|
||||
#define SPEED_K 1000
|
||||
#define SPEED_B_STR "B/s"
|
||||
#define SPEED_K_STR "kB/s"
|
||||
#define SPEED_M_STR "MB/s"
|
||||
#define SPEED_G_STR "GB/s"
|
||||
|
|
|
@ -25,9 +25,10 @@ extern bool verbose;
|
|||
bool should_print (bool pass);
|
||||
|
||||
bool check_condition_impl (const char * file, int line, bool condition);
|
||||
bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual);
|
||||
bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual);
|
||||
bool check_streq_impl (const char * file, int line, const char * expected, const char * actual);
|
||||
bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual);
|
||||
bool check_uint_eq_impl (const char * file, int line, uint64_t expected, uint64_t actual);
|
||||
bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual);
|
||||
bool check_streq_impl (const char * file, int line, const char * expected, const char * actual);
|
||||
|
||||
/***
|
||||
****
|
||||
|
@ -54,6 +55,13 @@ bool check_streq_impl (const char * file, int line, const char * expected, const
|
|||
return current_test; \
|
||||
} while (0)
|
||||
|
||||
#define check_uint_eq(expected, actual) \
|
||||
do { \
|
||||
++current_test; \
|
||||
if (!check_uint_eq_impl (__FILE__, __LINE__, (expected), (actual))) \
|
||||
return current_test; \
|
||||
} while (0)
|
||||
|
||||
#define check_ptr_eq(expected, actual) \
|
||||
do { \
|
||||
++current_test; \
|
||||
|
|
|
@ -68,7 +68,7 @@ test_incomplete_dir_threadfunc (void * vdata)
|
|||
static int
|
||||
test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir)
|
||||
{
|
||||
size_t i;
|
||||
tr_file_index_t file_index;
|
||||
tr_session * session;
|
||||
tr_torrent * tor;
|
||||
tr_completeness completeness;
|
||||
|
@ -93,13 +93,14 @@ test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir
|
|||
check (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
|
||||
check_file_location (tor, 0, tr_strdup_printf("%s/%s.part", incomplete_dir, tor->info.files[0].name));
|
||||
check_file_location (tor, 1, tr_buildPath(incomplete_dir, tor->info.files[1].name, NULL));
|
||||
check_int_eq (tor->info.pieceSize, tr_torrentStat(tor)->leftUntilDone);
|
||||
check_uint_eq (tor->info.pieceSize, tr_torrentStat(tor)->leftUntilDone);
|
||||
|
||||
completeness = completeness_unset;
|
||||
tr_torrentSetCompletenessCallback (tor, zeroes_completeness_func, &completeness);
|
||||
|
||||
/* now finish writing it */
|
||||
{
|
||||
tr_block_index_t block_index;
|
||||
tr_block_index_t first, last;
|
||||
char * zero_block = tr_new0 (char, tor->blockSize);
|
||||
struct test_incomplete_dir_data data;
|
||||
|
@ -110,10 +111,10 @@ test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir
|
|||
data.buf = evbuffer_new ();
|
||||
|
||||
tr_torGetPieceBlockRange (tor, data.pieceIndex, &first, &last);
|
||||
for (i=first; i<=last; ++i)
|
||||
for (block_index=first; block_index<=last; ++block_index)
|
||||
{
|
||||
evbuffer_add (data.buf, zero_block, tor->blockSize);
|
||||
data.block = i;
|
||||
data.block = block_index;
|
||||
data.done = false;
|
||||
data.offset = data.block * tor->blockSize;
|
||||
tr_runInEventThread (session, test_incomplete_dir_threadfunc, &data);
|
||||
|
@ -125,14 +126,14 @@ test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir
|
|||
}
|
||||
|
||||
libttest_blockingTorrentVerify (tor);
|
||||
check_int_eq (0, tr_torrentStat(tor)->leftUntilDone);
|
||||
check_uint_eq (0, tr_torrentStat(tor)->leftUntilDone);
|
||||
|
||||
while ((completeness==completeness_unset) && (time(NULL)<=deadline))
|
||||
tr_wait_msec (50);
|
||||
|
||||
check_int_eq (TR_SEED, completeness);
|
||||
for (i=0; i<tor->info.fileCount; ++i)
|
||||
check_file_location (tor, i, tr_buildPath (download_dir, tor->info.files[i].name, NULL));
|
||||
for (file_index=0; file_index<tor->info.fileCount; ++file_index)
|
||||
check_file_location (tor, file_index, tr_buildPath (download_dir, tor->info.files[file_index].name, NULL));
|
||||
|
||||
/* cleanup */
|
||||
tr_torrentRemove (tor, true, tr_sys_path_remove);
|
||||
|
@ -167,7 +168,7 @@ test_incomplete_dir (void)
|
|||
static int
|
||||
test_set_location (void)
|
||||
{
|
||||
size_t i;
|
||||
tr_file_index_t file_index;
|
||||
int state;
|
||||
char * target_dir;
|
||||
tr_torrent * tor;
|
||||
|
@ -183,7 +184,7 @@ test_set_location (void)
|
|||
tor = libttest_zero_torrent_init (session);
|
||||
libttest_zero_torrent_populate (tor, true);
|
||||
libttest_blockingTorrentVerify (tor);
|
||||
check_int_eq (0, tr_torrentStat(tor)->leftUntilDone);
|
||||
check_uint_eq (0, tr_torrentStat(tor)->leftUntilDone);
|
||||
|
||||
/* now move it */
|
||||
state = -1;
|
||||
|
@ -194,12 +195,12 @@ test_set_location (void)
|
|||
|
||||
/* confirm the torrent is still complete after being moved */
|
||||
libttest_blockingTorrentVerify (tor);
|
||||
check_int_eq (0, tr_torrentStat(tor)->leftUntilDone);
|
||||
check_uint_eq (0, tr_torrentStat(tor)->leftUntilDone);
|
||||
|
||||
/* confirm the filest really got moved */
|
||||
libttest_sync ();
|
||||
for (i=0; i<tor->info.fileCount; ++i)
|
||||
check_file_location (tor, i, tr_buildPath (target_dir, tor->info.files[i].name, NULL));
|
||||
for (file_index=0; file_index<tor->info.fileCount; ++file_index)
|
||||
check_file_location (tor, file_index, tr_buildPath (target_dir, tor->info.files[file_index].name, NULL));
|
||||
|
||||
/* cleanup */
|
||||
tr_free (target_dir);
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
#error only libtransmission should #include this header.
|
||||
#endif
|
||||
|
||||
#ifndef _TR_NET_H_
|
||||
#define _TR_NET_H_
|
||||
#ifndef TR_NET_H
|
||||
#define TR_NET_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <inttypes.h>
|
||||
|
@ -174,4 +174,4 @@ char* tr_net_strerror (char * buf, size_t buflen, int err);
|
|||
|
||||
const unsigned char *tr_globalIPv6 (void);
|
||||
|
||||
#endif /* _TR_NET_H_ */
|
||||
#endif /* TR_NET_H */
|
||||
|
|
|
@ -54,7 +54,7 @@ tr_thread* tr_threadNew (void (*func)(void *), void * arg);
|
|||
|
||||
/** @brief Return nonzero if this function is being called from `thread'
|
||||
@param thread the thread being tested */
|
||||
bool tr_amInThread (const tr_thread *);
|
||||
bool tr_amInThread (const tr_thread * thread);
|
||||
|
||||
/***
|
||||
****
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#error only libtransmission should #include this header.
|
||||
#endif
|
||||
|
||||
#ifndef _TR_PTR_ARRAY_H_
|
||||
#define _TR_PTR_ARRAY_H_
|
||||
#ifndef TR_PTR_ARRAY_H
|
||||
#define TR_PTR_ARRAY_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ test_static_quarks (void)
|
|||
size_t len;
|
||||
const char * str;
|
||||
|
||||
str = tr_quark_get_string (i, &len);
|
||||
check_int_eq (strlen(str), len);
|
||||
str = tr_quark_get_string ((tr_quark)i, &len);
|
||||
check_uint_eq (strlen(str), len);
|
||||
check (tr_quark_lookup (str, len, &q));
|
||||
check_int_eq (i, q);
|
||||
check_int_eq (i, (int)q);
|
||||
}
|
||||
|
||||
for (i=0; i+1<TR_N_KEYS; i++)
|
||||
|
@ -35,14 +35,14 @@ test_static_quarks (void)
|
|||
size_t len1, len2;
|
||||
const char *str1, *str2;
|
||||
|
||||
str1 = tr_quark_get_string (i, &len1);
|
||||
str2 = tr_quark_get_string (i+1, &len2);
|
||||
str1 = tr_quark_get_string ((tr_quark)i, &len1);
|
||||
str2 = tr_quark_get_string ((tr_quark)(i+1), &len2);
|
||||
|
||||
check (strcmp (str1, str2) < 0);
|
||||
}
|
||||
|
||||
const tr_quark q = tr_quark_new (NULL, TR_BAD_SIZE);
|
||||
check_int_eq (TR_KEY_NONE, q);
|
||||
check_int_eq (TR_KEY_NONE, (int)q);
|
||||
check_streq ("", tr_quark_get_string (q, NULL));
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -29,13 +29,13 @@ static tr_session * session = NULL;
|
|||
|
||||
#define check_have_none(tor, totalSize) \
|
||||
do { \
|
||||
const tr_stat * st = tr_torrentStat(tor); \
|
||||
check_int_eq (TR_STATUS_STOPPED, st->activity); \
|
||||
check_int_eq (TR_STAT_OK, st->error); \
|
||||
check_int_eq (totalSize, st->sizeWhenDone); \
|
||||
check_int_eq (totalSize, st->leftUntilDone); \
|
||||
check_int_eq (totalSize, tor->info.totalSize); \
|
||||
check_int_eq (0, st->haveValid); \
|
||||
const tr_stat * tst = tr_torrentStat(tor); \
|
||||
check_int_eq (TR_STATUS_STOPPED, tst->activity); \
|
||||
check_int_eq (TR_STAT_OK, tst->error); \
|
||||
check_uint_eq (totalSize, tst->sizeWhenDone); \
|
||||
check_uint_eq (totalSize, tst->leftUntilDone); \
|
||||
check_uint_eq (totalSize, tor->info.totalSize); \
|
||||
check_uint_eq (0, tst->haveValid); \
|
||||
} while (0)
|
||||
|
||||
static bool
|
||||
|
@ -157,11 +157,11 @@ test_single_filename_torrent (void)
|
|||
st = tr_torrentStat (tor);
|
||||
check_int_eq (TR_STATUS_STOPPED, st->activity);
|
||||
check_int_eq (TR_STAT_OK, st->error);
|
||||
check_int_eq (0, st->leftUntilDone);
|
||||
check_int_eq (0, st->haveUnchecked);
|
||||
check_int_eq (0, st->desiredAvailable);
|
||||
check_int_eq (totalSize, st->sizeWhenDone);
|
||||
check_int_eq (totalSize, st->haveValid);
|
||||
check_uint_eq (0, st->leftUntilDone);
|
||||
check_uint_eq (0, st->haveUnchecked);
|
||||
check_uint_eq (0, st->desiredAvailable);
|
||||
check_uint_eq (totalSize, st->sizeWhenDone);
|
||||
check_uint_eq (totalSize, st->haveValid);
|
||||
|
||||
/**
|
||||
*** okay! we've finally put together all the scaffolding to test
|
||||
|
@ -297,8 +297,8 @@ test_multifile_torrent (void)
|
|||
|
||||
/* sanity check the info */
|
||||
check_streq (tor->info.name, "Felidae");
|
||||
check_int_eq (totalSize, tor->info.totalSize);
|
||||
check_int_eq (4, tor->info.fileCount);
|
||||
check_uint_eq (totalSize, tor->info.totalSize);
|
||||
check_uint_eq (4, tor->info.fileCount);
|
||||
for (i=0; i<4; ++i)
|
||||
check_streq (expected_files[i], files[i].name);
|
||||
|
||||
|
@ -314,11 +314,11 @@ test_multifile_torrent (void)
|
|||
st = tr_torrentStat (tor);
|
||||
check_int_eq (TR_STATUS_STOPPED, st->activity);
|
||||
check_int_eq (TR_STAT_OK, st->error);
|
||||
check_int_eq (0, st->leftUntilDone);
|
||||
check_int_eq (0, st->haveUnchecked);
|
||||
check_int_eq (0, st->desiredAvailable);
|
||||
check_int_eq (totalSize, st->sizeWhenDone);
|
||||
check_int_eq (totalSize, st->haveValid);
|
||||
check_uint_eq (0, st->leftUntilDone);
|
||||
check_uint_eq (0, st->haveUnchecked);
|
||||
check_uint_eq (0, st->desiredAvailable);
|
||||
check_uint_eq (totalSize, st->sizeWhenDone);
|
||||
check_uint_eq (totalSize, st->haveValid);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -506,22 +506,22 @@ test_partial_file (void)
|
|||
***/
|
||||
|
||||
tor = libttest_zero_torrent_init (session);
|
||||
check_int_eq (totalSize, tor->info.totalSize);
|
||||
check_int_eq (pieceSize, tor->info.pieceSize);
|
||||
check_int_eq (pieceCount, tor->info.pieceCount);
|
||||
check_uint_eq (totalSize, tor->info.totalSize);
|
||||
check_uint_eq (pieceSize, tor->info.pieceSize);
|
||||
check_uint_eq (pieceCount, tor->info.pieceCount);
|
||||
check_streq ("files-filled-with-zeroes/1048576", tor->info.files[0].name);
|
||||
check_streq ("files-filled-with-zeroes/4096", tor->info.files[1].name);
|
||||
check_streq ("files-filled-with-zeroes/512", tor->info.files[2].name);
|
||||
|
||||
libttest_zero_torrent_populate (tor, false);
|
||||
fst = tr_torrentFiles (tor, NULL);
|
||||
check_int_eq (length[0] - pieceSize, fst[0].bytesCompleted);
|
||||
check_int_eq (length[1], fst[1].bytesCompleted);
|
||||
check_int_eq (length[2], fst[2].bytesCompleted);
|
||||
check_uint_eq (length[0] - pieceSize, fst[0].bytesCompleted);
|
||||
check_uint_eq (length[1], fst[1].bytesCompleted);
|
||||
check_uint_eq (length[2], fst[2].bytesCompleted);
|
||||
tr_torrentFilesFree (fst, tor->info.fileCount);
|
||||
st = tr_torrentStat (tor);
|
||||
check_int_eq (totalSize, st->sizeWhenDone);
|
||||
check_int_eq (pieceSize, st->leftUntilDone);
|
||||
check_uint_eq (totalSize, st->sizeWhenDone);
|
||||
check_uint_eq (pieceSize, st->leftUntilDone);
|
||||
|
||||
/***
|
||||
****
|
||||
|
|
|
@ -46,7 +46,7 @@ test_list (void)
|
|||
tr_rpc_parse_list_str (&top, "asdf", TR_BAD_SIZE);
|
||||
check (tr_variantIsString (&top));
|
||||
check (tr_variantGetStr (&top, &str, &len));
|
||||
check_int_eq (4, len);
|
||||
check_uint_eq (4, len);
|
||||
check_streq ("asdf", str);
|
||||
tr_variantFree (&top);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ testPeerId (void)
|
|||
|
||||
for (j = 8; j < PEER_ID_LEN; ++j)
|
||||
{
|
||||
char tmp[2] = { peer_id[j], '\0' };
|
||||
char tmp[2] = { (char)peer_id[j], '\0' };
|
||||
val += strtoul (tmp, NULL, 36);
|
||||
}
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ toSpeedKBps (unsigned int Bps) { return Bps / (double)tr_speed_K; }
|
|||
static inline uint64_t
|
||||
toMemBytes (unsigned int MB) { uint64_t B = tr_mem_K * tr_mem_K; B *= MB; return B; }
|
||||
static inline int
|
||||
toMemMB (uint64_t B) { return B / (tr_mem_K * tr_mem_K); }
|
||||
toMemMB (uint64_t B) { return (int)(B / (tr_mem_K * tr_mem_K)); }
|
||||
|
||||
/**
|
||||
**/
|
||||
|
|
|
@ -25,8 +25,8 @@ THE SOFTWARE.
|
|||
#error only libtransmission should #include this header.
|
||||
#endif
|
||||
|
||||
#ifndef _TR_UTP_H_
|
||||
#define _TR_UTP_H_
|
||||
#ifndef TR_UTP_H
|
||||
#define TR_UTP_H
|
||||
|
||||
int tr_utpPacket (const unsigned char *buf, size_t buflen,
|
||||
const struct sockaddr *from, socklen_t fromlen,
|
||||
|
@ -37,4 +37,4 @@ void tr_utpClose (tr_session *);
|
|||
void tr_utpSendTo (void *closure, const unsigned char *buf, size_t buflen,
|
||||
const struct sockaddr *to, socklen_t tolen);
|
||||
|
||||
#endif /* #ifndef _TR_UTP_H_ */
|
||||
#endif /* #ifndef TR_UTP_H */
|
||||
|
|
|
@ -20,6 +20,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define TR_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(__clang__)
|
||||
#define TR_DEPRECATED __attribute__((gnu::deprecated))
|
||||
#else
|
||||
#define TR_DEPRECATED
|
||||
#endif
|
||||
|
||||
/***
|
||||
****
|
||||
**** Basic Types
|
||||
|
@ -145,23 +153,24 @@ const char* tr_getDefaultDownloadDir (void);
|
|||
* tr_variantFree (&settings);
|
||||
* @endcode
|
||||
*
|
||||
* @param initme pointer to a tr_variant dictionary
|
||||
* @param setme_dictionary pointer to a tr_variant dictionary
|
||||
* @see tr_sessionLoadSettings ()
|
||||
* @see tr_sessionInit ()
|
||||
* @see tr_getDefaultConfigDir ()
|
||||
*/
|
||||
void tr_sessionGetDefaultSettings (struct tr_variant * dictionary);
|
||||
void tr_sessionGetDefaultSettings (struct tr_variant * setme_dictionary);
|
||||
|
||||
/**
|
||||
* Add the session's current configuration settings to the benc dictionary.
|
||||
*
|
||||
* FIXME: this probably belongs in libtransmissionapp
|
||||
*
|
||||
* @param session
|
||||
* @param dictionary
|
||||
* @param session the session to query
|
||||
* @param setme_dictionary the dictionary to populate
|
||||
* @see tr_sessionGetDefaultSettings ()
|
||||
*/
|
||||
void tr_sessionGetSettings (tr_session *, struct tr_variant * dictionary);
|
||||
void tr_sessionGetSettings (tr_session * session,
|
||||
struct tr_variant * setme_dictionary);
|
||||
|
||||
/**
|
||||
* Load settings from the configuration directory's settings.json file,
|
||||
|
@ -187,13 +196,14 @@ bool tr_sessionLoadSettings (struct tr_variant * dictionary,
|
|||
*
|
||||
* FIXME: this belongs in libtransmissionapp
|
||||
*
|
||||
* @param session
|
||||
* @param dictionary
|
||||
* @param session the session to save
|
||||
* @param configDir the directory to write to
|
||||
* @param dictionary the dictionary to save
|
||||
* @see tr_sessionLoadSettings ()
|
||||
*/
|
||||
void tr_sessionSaveSettings (tr_session * session,
|
||||
const char * configDir,
|
||||
const struct tr_variant * dictonary);
|
||||
const struct tr_variant * dictionary);
|
||||
|
||||
/**
|
||||
* @brief Initialize a libtransmission session.
|
||||
|
@ -355,8 +365,8 @@ tr_port tr_sessionGetRPCPort (const tr_session * session);
|
|||
/**
|
||||
* @brief Specify which base URL to use.
|
||||
*
|
||||
* @detail The RPC API is accessible under <url>/rpc, the web interface under
|
||||
* <url>/web.
|
||||
* @param session the session to set
|
||||
* @param url the base url to use. The RPC API is accessible under <url>/rpc, the web interface under * <url>/web.
|
||||
*
|
||||
* @see tr_sessionGetRPCUrl
|
||||
*/
|
||||
|
@ -895,8 +905,9 @@ typedef enum
|
|||
tr_ctorMode;
|
||||
|
||||
/** @brief Create a torrent constructor object used to instantiate a tr_torrent
|
||||
@param session the tr_session. This is required if you're going to call
|
||||
tr_torrentNew (), but you can use NULL for tr_torrentParse ().
|
||||
@param session_or_NULL the tr_session.
|
||||
This is required if you're going to call tr_torrentNew (),
|
||||
but you can use NULL for tr_torrentParse ().
|
||||
@see tr_torrentNew (), tr_torrentParse () */
|
||||
tr_ctor* tr_ctorNew (const tr_session * session_or_NULL);
|
||||
|
||||
|
@ -1012,9 +1023,9 @@ tr_parse_result;
|
|||
* TR_PARSE_OK if parsing succeeded and it's not a duplicate;
|
||||
* TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
|
||||
*
|
||||
* @param setme_info If parsing is successful and setme_info is non-NULL,
|
||||
* the parsed metainfo is stored there and sould be freed
|
||||
* by calling tr_metainfoFree () when no longer needed.
|
||||
* @param setme_info_or_NULL If parsing is successful and setme_info is non-NULL,
|
||||
* the parsed metainfo is stored there and sould be freed
|
||||
* by calling tr_metainfoFree () when no longer needed.
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
|
@ -1038,12 +1049,12 @@ void tr_metainfoFree (tr_info * inf);
|
|||
*
|
||||
* Returns a pointer to the torrent on success, or NULL on failure.
|
||||
*
|
||||
* @param setme_error: TR_PARSE_ERR if the parsing failed;
|
||||
* TR_PARSE_OK if parsing succeeded and it's not a duplicate;
|
||||
* TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
|
||||
*
|
||||
* @param setme_duplicate_id: when setmeError is TR_PARSE_DUPLICATE,
|
||||
* this field is set to the duplicate torrent's id.
|
||||
* @param ctor the builder struct
|
||||
* @param setme_error TR_PARSE_ERR if the parsing failed;
|
||||
* TR_PARSE_OK if parsing succeeded and it's not a duplicate;
|
||||
* TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
|
||||
* @param setme_duplicate_id when setmeError is TR_PARSE_DUPLICATE,
|
||||
* this field is set to the duplicate torrent's id.
|
||||
*/
|
||||
tr_torrent * tr_torrentNew (const tr_ctor * ctor,
|
||||
int * setme_error,
|
||||
|
@ -1082,11 +1093,11 @@ typedef void (*tr_torrent_rename_done_func)(tr_torrent * torrent,
|
|||
/**
|
||||
* @brief Rename a file or directory in a torrent.
|
||||
*
|
||||
* @tor: the torrent whose path will be renamed.
|
||||
* @oldpath: the path to the file or folder that will be renamed
|
||||
* @newname: the file or folder's new name
|
||||
* @callback: the callback invoked when the renaming finishes, or NULL
|
||||
* @callback_data: the pointer to pass in the callback's user_data arg
|
||||
* @param tor the torrent whose path will be renamed
|
||||
* @param oldpath the path to the file or folder that will be renamed
|
||||
* @param newname the file or folder's new name
|
||||
* @param callback the callback invoked when the renaming finishes, or NULL
|
||||
* @param callback_data the pointer to pass in the callback's user_data arg
|
||||
*
|
||||
* As a special case, renaming the root file in a torrent will also
|
||||
* update tr_info.name.
|
||||
|
@ -1124,7 +1135,7 @@ void tr_torrentRenamePath (tr_torrent * tor,
|
|||
const char * oldpath,
|
||||
const char * newname,
|
||||
tr_torrent_rename_done_func callback,
|
||||
void * callback_user_data);
|
||||
void * callback_data);
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -1180,7 +1191,7 @@ const char* tr_torrentName (const tr_torrent *);
|
|||
* @param tor the torrent whose file we're looking for
|
||||
* @param fileNum the fileIndex, in [0...tr_info.fileCount)
|
||||
*/
|
||||
char* tr_torrentFindFile (const tr_torrent * tor, tr_file_index_t fileNo);
|
||||
char* tr_torrentFindFile (const tr_torrent * tor, tr_file_index_t fileNum);
|
||||
|
||||
|
||||
/***
|
||||
|
@ -1710,7 +1721,7 @@ void tr_torrentAmountFinished (const tr_torrent * torrent,
|
|||
* @param aborted true if the verify ended prematurely for some reason,
|
||||
* such as tr_torrentStop() or tr_torrentSetLocation()
|
||||
* being called during verification.
|
||||
* @param callback_data the user-defined pointer from tr_torrentVerify()
|
||||
* @param user_data the user-defined pointer from tr_torrentVerify()
|
||||
*/
|
||||
typedef void (*tr_verify_done_func)(tr_torrent * torrent,
|
||||
bool aborted,
|
||||
|
@ -2030,14 +2041,14 @@ const tr_stat * tr_torrentStatCached (tr_torrent * torrent);
|
|||
|
||||
/** @deprecated */
|
||||
void tr_torrentSetAddedDate (tr_torrent * torrent,
|
||||
time_t addedDate);
|
||||
time_t addedDate) TR_DEPRECATED;
|
||||
|
||||
/** @deprecated */
|
||||
void tr_torrentSetActivityDate (tr_torrent * torrent,
|
||||
time_t activityDate);
|
||||
time_t activityDate) TR_DEPRECATED;
|
||||
|
||||
/** @deprecated */
|
||||
void tr_torrentSetDoneDate (tr_torrent * torrent, time_t doneDate);
|
||||
void tr_torrentSetDoneDate (tr_torrent * torrent, time_t doneDate) TR_DEPRECATED;
|
||||
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -301,19 +301,19 @@ test_hex (void)
|
|||
static int
|
||||
test_array (void)
|
||||
{
|
||||
int i;
|
||||
int array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int n = sizeof (array) / sizeof (array[0]);
|
||||
size_t i;
|
||||
size_t array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
size_t n = sizeof (array) / sizeof (array[0]);
|
||||
|
||||
tr_removeElementFromArray (array, 5u, sizeof (int), n--);
|
||||
tr_removeElementFromArray (array, 5u, sizeof (size_t), n--);
|
||||
for (i=0; i<n; ++i)
|
||||
check_int_eq ((i<5 ? i : i+1), array[i]);
|
||||
|
||||
tr_removeElementFromArray (array, 0u, sizeof (int), n--);
|
||||
tr_removeElementFromArray (array, 0u, sizeof (size_t), n--);
|
||||
for (i=0; i<n; ++i)
|
||||
check_int_eq ((i<4 ? i+1 : i+2), array[i]);
|
||||
|
||||
tr_removeElementFromArray (array, n-1, sizeof (int), n); n--;
|
||||
tr_removeElementFromArray (array, n-1, sizeof (size_t), n); n--;
|
||||
for (i=0; i<n; ++i)
|
||||
check_int_eq ((i<4 ? i+1 : i+2), array[i]);
|
||||
|
||||
|
|
|
@ -164,16 +164,16 @@ int64_t tr_getDirFreeSpace (const char * path);
|
|||
|
||||
/**
|
||||
* @brief Convenience wrapper around timer_add () to have a timer wake up in a number of seconds and microseconds
|
||||
* @param timer
|
||||
* @param seconds
|
||||
* @param microseconds
|
||||
* @param timer the timer to set
|
||||
* @param seconds seconds to wait
|
||||
* @param microseconds microseconds to wait
|
||||
*/
|
||||
void tr_timerAdd (struct event * timer, int seconds, int microseconds) TR_GNUC_NONNULL (1);
|
||||
|
||||
/**
|
||||
* @brief Convenience wrapper around timer_add () to have a timer wake up in a number of milliseconds
|
||||
* @param timer
|
||||
* @param milliseconds
|
||||
* @param timer the timer to set
|
||||
* @param milliseconds milliseconds to wait
|
||||
*/
|
||||
void tr_timerAddMsec (struct event * timer, int milliseconds) TR_GNUC_NONNULL (1);
|
||||
|
||||
|
@ -329,8 +329,8 @@ int tr_snprintf (char * buf, size_t buflen,
|
|||
const char * fmt, ...) TR_GNUC_PRINTF (3, 4) TR_GNUC_NONNULL (1,3);
|
||||
|
||||
/** @brief Convenience wrapper around strerorr () guaranteed to not return NULL
|
||||
@param errno */
|
||||
const char* tr_strerror (int);
|
||||
@param errnum the error number to describe */
|
||||
const char* tr_strerror (int errnum);
|
||||
|
||||
/** @brief strips leading and trailing whitspace from a string
|
||||
@return the stripped string */
|
||||
|
@ -412,10 +412,10 @@ double tr_truncd (double x, int decimal_places);
|
|||
char* tr_strpercent (char * buf, double x, size_t buflen);
|
||||
|
||||
/**
|
||||
* @param buf the buffer to write the string to
|
||||
* @param buflef buf's size
|
||||
* @param ratio the ratio to convert to a string
|
||||
* @param the string represntation of "infinity"
|
||||
* @param buf the buffer to write the string to
|
||||
* @param buflen buf's size
|
||||
* @param ratio the ratio to convert to a string
|
||||
* @param infinity the string represntation of "infinity"
|
||||
*/
|
||||
char* tr_strratio (char * buf, size_t buflen, double ratio, const char * infinity) TR_GNUC_NONNULL (1,4);
|
||||
|
||||
|
@ -494,7 +494,7 @@ char* tr_formatter_speed_KBps (char * buf, double KBps, size_t buflen);
|
|||
char* tr_formatter_mem_B (char * buf, int64_t bytes, size_t buflen);
|
||||
|
||||
/* format a memory size from MB into a user-readable string. */
|
||||
static inline char* tr_formatter_mem_MB (char * buf, double MBps, size_t buflen) { return tr_formatter_mem_B (buf, MBps * tr_mem_K * tr_mem_K, buflen); }
|
||||
static inline char* tr_formatter_mem_MB (char * buf, double MBps, size_t buflen) { return tr_formatter_mem_B (buf, (int64_t)(MBps * tr_mem_K * tr_mem_K), buflen); }
|
||||
|
||||
/* format a file size from bytes into a user-readable string. */
|
||||
char* tr_formatter_size_B (char * buf, int64_t bytes, size_t buflen);
|
||||
|
|
|
@ -103,7 +103,7 @@ testStr (void)
|
|||
n = tr_snprintf ((char*)buf, sizeof (buf), "%zu:boat", (size_t)(SIZE_MAX-2));
|
||||
err = tr_bencParseStr (buf, buf+n, &end, &str, &len);
|
||||
check_int_eq (EILSEQ, err);
|
||||
check_int_eq (0, len);
|
||||
check_uint_eq (0, len);
|
||||
check (str == NULL);
|
||||
check (end == NULL);
|
||||
check (!len);
|
||||
|
@ -112,7 +112,7 @@ testStr (void)
|
|||
n = tr_snprintf ((char*)buf, sizeof (buf), "4:boat");
|
||||
err = tr_bencParseStr (buf, buf+n, &end, &str, &len);
|
||||
check_int_eq (0, err);
|
||||
check_int_eq (4, len);
|
||||
check_uint_eq (4, len);
|
||||
check (strncmp ((const char*)str, "boat", len) == 0);
|
||||
check (end == buf + 6);
|
||||
str = NULL;
|
||||
|
@ -122,7 +122,7 @@ testStr (void)
|
|||
/* string goes past end of buffer */
|
||||
err = tr_bencParseStr (buf, buf+(n-1), &end, &str, &len);
|
||||
check_int_eq (EILSEQ, err);
|
||||
check_int_eq (0, len);
|
||||
check_uint_eq (0, len);
|
||||
check (str == NULL);
|
||||
check (end == NULL);
|
||||
check (!len);
|
||||
|
@ -131,7 +131,7 @@ testStr (void)
|
|||
n = tr_snprintf ((char*)buf, sizeof (buf), "0:");
|
||||
err = tr_bencParseStr (buf, buf+n, &end, &str, &len);
|
||||
check_int_eq (0, err);
|
||||
check_int_eq (0, len);
|
||||
check_uint_eq (0, len);
|
||||
check (!*str);
|
||||
check (end == buf + 2);
|
||||
str = NULL;
|
||||
|
@ -142,7 +142,7 @@ testStr (void)
|
|||
n = tr_snprintf ((char*)buf, sizeof (buf), "3:boat");
|
||||
err = tr_bencParseStr (buf, buf+n, &end, &str, &len);
|
||||
check_int_eq (0, err);
|
||||
check_int_eq (3, len);
|
||||
check_uint_eq (3, len);
|
||||
check (strncmp ((const char*)str, "boa", len) == 0);
|
||||
check (end == buf + 5);
|
||||
str = NULL;
|
||||
|
@ -178,7 +178,7 @@ testString (const char * str, bool isGood)
|
|||
check (end == str + len);
|
||||
saved = tr_variantToStr (&val, TR_VARIANT_FMT_BENC, &savedLen);
|
||||
check_streq (str, saved);
|
||||
check_int_eq (savedLen, len);
|
||||
check_uint_eq (savedLen, len);
|
||||
tr_free (saved);
|
||||
tr_variantFree (&val);
|
||||
}
|
||||
|
@ -414,16 +414,16 @@ testMerge (void)
|
|||
check (tr_variantDictFindInt (&dest, i4, &i));
|
||||
check_int_eq (-35, i);
|
||||
check (tr_variantDictFindStr (&dest, s5, &s, &len));
|
||||
check_int_eq (3, len);
|
||||
check_uint_eq (3, len);
|
||||
check_streq ("abc", s);
|
||||
check (tr_variantDictFindStr (&dest, s6, &s, &len));
|
||||
check_int_eq (3, len);
|
||||
check_uint_eq (3, len);
|
||||
check_streq ("xyz", s);
|
||||
check (tr_variantDictFindStr (&dest, s7, &s, &len));
|
||||
check_int_eq (9, len);
|
||||
check_uint_eq (9, len);
|
||||
check_streq ("127.0.0.1", s);
|
||||
check (tr_variantDictFindStr (&dest, s8, &s, &len));
|
||||
check_int_eq (3, len);
|
||||
check_uint_eq (3, len);
|
||||
check_streq ("ghi", s);
|
||||
|
||||
tr_variantFree (&dest);
|
||||
|
@ -534,7 +534,7 @@ testParse2 (void)
|
|||
check (tr_variantDictFindBool (&top, key_bool, &boolVal));
|
||||
check (boolVal == true);
|
||||
check (tr_variantDictFindStr (&top, key_str, &strVal, &strLen));
|
||||
check_int_eq (16, strLen);
|
||||
check_uint_eq (16, strLen);
|
||||
check_streq ("this-is-a-string", strVal);
|
||||
check (tr_variantDictFindReal (&top, key_real, &realVal));
|
||||
check_int_eq (50, (int)(realVal*100));
|
||||
|
|
|
@ -31,16 +31,16 @@ callback_data;
|
|||
|
||||
#define CB_DATA_STATIC_INIT { NULL, NULL, 0 }
|
||||
|
||||
struct event_base * ev_base = NULL;
|
||||
static struct event_base * ev_base = NULL;
|
||||
|
||||
extern struct timeval tr_watchdir_generic_interval;
|
||||
extern unsigned int tr_watchdir_retry_limit;
|
||||
extern struct timeval tr_watchdir_retry_start_interval;
|
||||
extern struct timeval tr_watchdir_retry_max_interval;
|
||||
|
||||
const struct timeval FIFTY_MSEC = { 0, 50000 };
|
||||
const struct timeval ONE_HUNDRED_MSEC = { 0, 100000 };
|
||||
const struct timeval TWO_HUNDRED_MSEC = { 0, 200000 };
|
||||
static const struct timeval FIFTY_MSEC = { 0, 50000 };
|
||||
static const struct timeval ONE_HUNDRED_MSEC = { 0, 100000 };
|
||||
static const struct timeval TWO_HUNDRED_MSEC = { 0, 200000 };
|
||||
|
||||
static void
|
||||
process_events (void)
|
||||
|
|
Loading…
Reference in New Issue