Transform `check_int_eq` into generic `check_int` (libtest)

This commit is contained in:
Mike Gelfand 2017-05-29 23:22:36 +03:00
parent 14c30119d4
commit 9c3c6f11e0
17 changed files with 178 additions and 180 deletions

View File

@ -63,7 +63,7 @@ static int test_parsing(void)
/* init the session */
session = libttest_session_init(NULL);
check(!tr_blocklistExists(session));
check_int_eq(0, tr_blocklistGetRuleCount(session));
check_int(tr_blocklistGetRuleCount(session), ==, 0);
/* init the blocklist */
path = tr_buildPath(tr_sessionGetConfigDir(session), "blocklists", "level1", NULL);
@ -71,7 +71,7 @@ static int test_parsing(void)
tr_free(path);
tr_sessionReloadBlocklists(session);
check(tr_blocklistExists(session));
check_int_eq(4, tr_blocklistGetRuleCount(session));
check_int(tr_blocklistGetRuleCount(session), ==, 4);
/* enable the blocklist */
check(!tr_blocklistIsEnabled(session));
@ -112,27 +112,27 @@ static int test_updating(void)
path = tr_buildPath(tr_sessionGetConfigDir(session), "blocklists", "level1", NULL);
/* no blocklist to start with... */
check_int_eq(0, tr_blocklistGetRuleCount(session));
check_int(tr_blocklistGetRuleCount(session), ==, 0);
/* test that updated source files will get loaded */
create_text_file(path, contents1);
tr_sessionReloadBlocklists(session);
check_int_eq(4, tr_blocklistGetRuleCount(session));
check_int(tr_blocklistGetRuleCount(session), ==, 4);
/* test that updated source files will get loaded */
create_text_file(path, contents2);
tr_sessionReloadBlocklists(session);
check_int_eq(5, tr_blocklistGetRuleCount(session));
check_int(tr_blocklistGetRuleCount(session), ==, 5);
/* test that updated source files will get loaded */
create_text_file(path, contents1);
tr_sessionReloadBlocklists(session);
check_int_eq(4, tr_blocklistGetRuleCount(session));
check_int(tr_blocklistGetRuleCount(session), ==, 4);
/* ensure that new files, if bad, get skipped */
create_text_file(path, "# nothing useful\n");
tr_sessionReloadBlocklists(session);
check_int_eq(4, tr_blocklistGetRuleCount(session));
check_int(tr_blocklistGetRuleCount(session), ==, 4);
/* cleanup */
libttest_session_close(session);

View File

@ -20,19 +20,19 @@ static int test_error_set(void)
tr_error_set(&err, 1, "error: %s (%d)", "oops", 2);
check(err != NULL);
check_int_eq(1, err->code);
check_int(err->code, ==, 1);
check_str(err->message, ==, "error: oops (2)");
tr_error_clear(&err);
check(err == NULL);
tr_error_set_literal(&err, 2, "oops");
check(err != NULL);
check_int_eq(2, err->code);
check_int(err->code, ==, 2);
check_str(err->message, ==, "oops");
tr_error_prefix(&err, "error: ");
check(err != NULL);
check_int_eq(2, err->code);
check_int(err->code, ==, 2);
check_str(err->message, ==, "error: oops");
tr_error_free(err);
@ -47,18 +47,18 @@ static int test_error_propagate(void)
tr_error_set_literal(&err, 1, "oops");
check(err != NULL);
check_int_eq(1, err->code);
check_int(err->code, ==, 1);
check_str(err->message, ==, "oops");
tr_error_propagate(&err2, &err);
check(err2 != NULL);
check_int_eq(1, err2->code);
check_int(err2->code, ==, 1);
check_str(err2->message, ==, "oops");
check(err == NULL);
tr_error_propagate_prefixed(&err, &err2, "error: ");
check(err != NULL);
check_int_eq(1, err->code);
check_int(err->code, ==, 1);
check_str(err->message, ==, "error: oops");
check(err2 == NULL);

View File

@ -182,7 +182,7 @@ static int test_get_info(void)
clear_path_info(&info);
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(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint_eq(4, info.size);
check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
@ -191,7 +191,7 @@ static int test_get_info(void)
clear_path_info(&info);
check(tr_sys_file_get_info(fd, &info, &err));
check(err == NULL);
check_int_eq(TR_SYS_PATH_IS_FILE, info.type);
check_int(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint_eq(4, info.size);
check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
tr_sys_file_close(fd, NULL);
@ -204,7 +204,7 @@ static int test_get_info(void)
clear_path_info(&info);
check(tr_sys_path_get_info(path1, 0, &info, &err));
check(err == NULL);
check_int_eq(TR_SYS_PATH_IS_DIRECTORY, info.type);
check_int(info.type, ==, TR_SYS_PATH_IS_DIRECTORY);
check(info.size != (uint64_t)-1);
check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
tr_sys_path_remove(path1, NULL);
@ -223,7 +223,7 @@ static int test_get_info(void)
clear_path_info(&info);
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(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint_eq(4, info.size);
check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
@ -232,7 +232,7 @@ static int test_get_info(void)
clear_path_info(&info);
check(tr_sys_file_get_info(fd, &info, &err));
check(err == NULL);
check_int_eq(TR_SYS_PATH_IS_FILE, info.type);
check_int(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint_eq(4, info.size);
check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
tr_sys_file_close(fd, NULL);
@ -245,7 +245,7 @@ static int test_get_info(void)
clear_path_info(&info);
check(tr_sys_path_get_info(path1, 0, &info, &err));
check(err == NULL);
check_int_eq(TR_SYS_PATH_IS_DIRECTORY, info.type);
check_int(info.type, ==, TR_SYS_PATH_IS_DIRECTORY);
check(info.size != (uint64_t)-1);
check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
@ -1085,7 +1085,7 @@ static int test_file_read_write_seek(void)
check(err == NULL);
check_uint_eq(4, n);
check_int_eq(0, memcmp(buf, "test", 4));
check_int(memcmp(buf, "test", 4), ==, 0);
check(tr_sys_file_seek(fd, -3, TR_SEEK_CUR, &n, &err));
check(err == NULL);
@ -1103,7 +1103,7 @@ static int test_file_read_write_seek(void)
check(err == NULL);
check_uint_eq(4, n);
check_int_eq(0, memcmp(buf, "tEst", 4));
check_int(memcmp(buf, "tEst", 4), ==, 0);
check(tr_sys_file_seek(fd, 0, TR_SEEK_END, &n, &err));
check(err == NULL);
@ -1121,7 +1121,7 @@ static int test_file_read_write_seek(void)
check(err == NULL);
check_uint_eq(7, n);
check_int_eq(0, memcmp(buf, "tEst ok", 7));
check_int(memcmp(buf, "tEst ok", 7), ==, 0);
check(tr_sys_file_write_at(fd, "-", 1, 4, &n, &err));
check(err == NULL);
@ -1131,7 +1131,7 @@ static int test_file_read_write_seek(void)
check(err == NULL);
check_uint_eq(5, n);
check_int_eq(0, memcmp(buf, "st-ok", 5));
check_int(memcmp(buf, "st-ok", 5), ==, 0);
tr_sys_file_close(fd, NULL);
@ -1268,13 +1268,13 @@ static int test_file_map(void)
check(view != NULL);
check(err == NULL);
check_int_eq(0, memcmp(view, "test", 4));
check_int(memcmp(view, "test", 4), ==, 0);
#ifdef HAVE_UNIFIED_BUFFER_CACHE
tr_sys_file_write_at(fd, "E", 1, 1, NULL, NULL);
check_int_eq(0, memcmp(view, "tEst", 4));
check_int(memcmp(view, "tEst", 4), ==, 0);
#endif

View File

@ -20,14 +20,14 @@ static int test1(void)
memset(&h, 0, sizeof(tr_recentHistory));
tr_historyAdd(&h, 10000, 1);
check_int_eq(0, (int)tr_historyGet(&h, 12000, 1000));
check_int_eq(1, (int)tr_historyGet(&h, 12000, 3000));
check_int_eq(1, (int)tr_historyGet(&h, 12000, 5000));
check_int((int)tr_historyGet(&h, 12000, 1000), ==, 0);
check_int((int)tr_historyGet(&h, 12000, 3000), ==, 1);
check_int((int)tr_historyGet(&h, 12000, 5000), ==, 1);
tr_historyAdd(&h, 20000, 1);
check_int_eq(0, (int)tr_historyGet(&h, 22000, 1000));
check_int_eq(1, (int)tr_historyGet(&h, 22000, 3000));
check_int_eq(2, (int)tr_historyGet(&h, 22000, 15000));
check_int_eq(2, (int)tr_historyGet(&h, 22000, 20000));
check_int((int)tr_historyGet(&h, 22000, 1000), ==, 0);
check_int((int)tr_historyGet(&h, 22000, 3000), ==, 1);
check_int((int)tr_historyGet(&h, 22000, 15000), ==, 2);
check_int((int)tr_historyGet(&h, 22000, 20000), ==, 2);
return 0;
}

View File

@ -38,7 +38,7 @@ static int test_elements(void)
" \"null\": null }";
err = tr_variantFromJson(&top, in, strlen(in));
check_int_eq(0, err);
check_int(err, ==, 0);
check(tr_variantIsDict(&top));
str = NULL;
key = tr_quark_new("string", 6);
@ -48,15 +48,15 @@ static int test_elements(void)
check_str(str, ==, "bell \b formfeed \f linefeed \n carriage return \r tab \t");
i = 0;
check(tr_variantDictFindInt(&top, tr_quark_new("int", 3), &i));
check_int_eq(5, i);
check_int(i, ==, 5);
d = 0;
check(tr_variantDictFindReal(&top, tr_quark_new("float", 5), &d));
check_int_eq(65, ((int)(d * 10)));
check_int(((int)(d * 10)), ==, 65);
f = false;
check(tr_variantDictFindBool(&top, tr_quark_new("true", 4), &f));
check_int_eq(true, f);
check_int(f, ==, true);
check(tr_variantDictFindBool(&top, tr_quark_new("false", 5), &f));
check_int_eq(false, f);
check_int(f, ==, false);
check(tr_variantDictFindStr(&top, tr_quark_new("null", 4), &str, NULL));
check_str(str, ==, "");
@ -171,7 +171,7 @@ static int test1(void)
check(tr_variantDictFindStr(headers, tr_quark_new("type", 4), &str, NULL));
check_str(str, ==, "request");
check(tr_variantDictFindInt(headers, TR_KEY_tag, &i));
check_int_eq(666, i);
check_int(i, ==, 666);
check((body = tr_variantDictFind(&top, tr_quark_new("body", 4))) != NULL);
check(tr_variantDictFindStr(body, TR_KEY_name, &str, NULL));
check_str(str, ==, "torrent-info");
@ -181,9 +181,9 @@ static int test1(void)
check(tr_variantIsList(ids));
check_uint_eq(2, tr_variantListSize(ids));
check(tr_variantGetInt(tr_variantListChild(ids, 0), &i));
check_int_eq(7, i);
check_int(i, ==, 7);
check(tr_variantGetInt(tr_variantListChild(ids, 1), &i));
check_int_eq(10, i);
check_int(i, ==, 10);
tr_variantFree(&top);
return 0;
@ -231,7 +231,7 @@ static int test_unescape(void)
char const* str;
int const err = tr_variantFromJson(&top, in, strlen(in));
check_int_eq(0, err);
check_int(err, ==, 0);
check(tr_variantDictFindStr(&top, tr_quark_new("string-1", 8), &str, NULL));
check_str(str, ==, "/usr/lib");

View File

@ -77,20 +77,13 @@ bool libtest_check_str(char const* file, int line, bool pass, char const* lhs, c
return pass;
}
bool check_int_eq_impl(char const* file, int line, intmax_t expected, intmax_t actual)
bool libtest_check_int(char const* file, int line, bool pass, intmax_t lhs, intmax_t rhs, char const* lhs_str,
char const* op_str, char const* rhs_str)
{
bool const pass = expected == actual;
if (should_print(pass))
{
if (pass)
{
fprintf(stderr, "PASS %s:%d\n", file, line);
}
else
{
fprintf(stderr, "FAIL %s:%d, expected \"%jd\", got \"%jd\"\n", file, line, expected, actual);
}
fprintf(stderr, "%s %s:%d: %s %s %s (%jd %s %jd)\n", pass ? "PASS" : "FAIL", file, line, lhs_str, op_str, rhs_str, lhs,
op_str, rhs);
}
return pass;

View File

@ -23,12 +23,13 @@ extern bool verbose;
bool should_print(bool pass);
bool check_condition_impl(char const* file, int line, bool condition);
bool check_int_eq_impl(char const* file, int line, intmax_t expected, intmax_t actual);
bool check_uint_eq_impl(char const* file, int line, uintmax_t expected, uintmax_t actual);
bool check_ptr_eq_impl(char const* file, int line, void const* expected, void const* actual);
bool libtest_check_str(char const* file, int line, bool pass, char const* lhs, char const* rhs, char const* lhs_str,
char const* op_str, char const* rhs_str);
bool libtest_check_int(char const* file, int line, bool pass, intmax_t lhs, intmax_t rhs, char const* lhs_str,
char const* op_str, char const* rhs_str);
/***
****
@ -62,12 +63,16 @@ bool libtest_check_str(char const* file, int line, bool pass, char const* lhs, c
} \
while (0)
#define check_int_eq(expected, actual) \
#define check_int(lhs, op, rhs) \
do \
{ \
++current_test; \
\
if (!check_int_eq_impl(__FILE__, __LINE__, (expected), (actual))) \
intmax_t const check_int_lhs = (lhs); \
intmax_t const check_int_rhs = (rhs); \
\
if (!libtest_check_int(__FILE__, __LINE__, check_int_lhs op check_int_rhs, check_int_lhs, check_int_rhs, #lhs, #op, \
#rhs)) \
{ \
return current_test; \
} \

View File

@ -31,10 +31,10 @@ static int test1(void)
"&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile";
info = tr_magnetParse(uri);
check(info != NULL);
check_int_eq(2, info->trackerCount);
check_int(info->trackerCount, ==, 2);
check_str(info->trackers[0], ==, "http://tracker.openbittorrent.com/announce");
check_str(info->trackers[1], ==, "http://tracker.opentracker.org/announce");
check_int_eq(1, info->webseedCount);
check_int(info->webseedCount, ==, 1);
check_str(info->webseeds[0], ==, "http://server.webseed.org/path/to/file");
check_str(info->displayName, ==, "Display Name");
@ -56,10 +56,10 @@ static int test1(void)
"&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce";
info = tr_magnetParse(uri);
check(info != NULL);
check_int_eq(2, info->trackerCount);
check_int(info->trackerCount, ==, 2);
check_str(info->trackers[0], ==, "http://tracker.openbittorrent.com/announce");
check_str(info->trackers[1], ==, "http://tracker.opentracker.org/announce");
check_int_eq(1, info->webseedCount);
check_int(info->webseedCount, ==, 1);
check_str(info->webseeds[0], ==, "http://server.webseed.org/path/to/file");
check_str(info->displayName, ==, "Display Name");

View File

@ -36,10 +36,10 @@ static int test_single_file_impl(tr_tracker_info const* trackers, size_t const t
libtest_create_tmpfile_with_contents(input_file, payload, payloadSize);
builder = tr_metaInfoBuilderCreate(input_file);
check_str(builder->top, ==, input_file);
check_int_eq(1, builder->fileCount);
check_int(builder->fileCount, ==, 1);
check_str(builder->files[0].filename, ==, input_file);
check_int_eq(payloadSize, builder->files[0].size);
check_int_eq(payloadSize, builder->totalSize);
check_int(builder->files[0].size, ==, payloadSize);
check_int(builder->totalSize, ==, payloadSize);
check(!builder->isFolder);
check(!builder->abortFlag);
@ -49,7 +49,7 @@ static int test_single_file_impl(tr_tracker_info const* trackers, size_t const t
check(isPrivate == builder->isPrivate);
check_str(builder->outputFile, ==, torrent_file);
check_str(builder->comment, ==, comment);
check_int_eq(trackerCount, builder->trackerCount);
check_int(builder->trackerCount, ==, trackerCount);
while (!builder->isDone)
{
@ -61,18 +61,18 @@ static int test_single_file_impl(tr_tracker_info const* trackers, size_t const t
libttest_sync();
tr_ctorSetMetainfoFromFile(ctor, torrent_file);
parse_result = tr_torrentParse(ctor, &inf);
check_int_eq(TR_PARSE_OK, parse_result);
check_int(parse_result, ==, TR_PARSE_OK);
/* quick check of some of the parsed metainfo */
check_int_eq(payloadSize, inf.totalSize);
check_int(inf.totalSize, ==, payloadSize);
tmpstr = tr_sys_path_basename(input_file, NULL);
check_str(inf.name, ==, tmpstr);
tr_free(tmpstr);
check_str(inf.comment, ==, comment);
check_int_eq(1, inf.fileCount);
check_int_eq(isPrivate, inf.isPrivate);
check_int(inf.fileCount, ==, 1);
check_int(inf.isPrivate, ==, isPrivate);
check(!inf.isFolder);
check_int_eq(trackerCount, inf.trackerCount);
check_int(inf.trackerCount, ==, trackerCount);
/* cleanup */
tr_free(torrent_file);
@ -150,14 +150,14 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
builder = tr_metaInfoBuilderCreate(top);
check(!builder->abortFlag);
check_str(builder->top, ==, top);
check_int_eq(payloadCount, builder->fileCount);
check_int_eq(totalSize, builder->totalSize);
check_int(builder->fileCount, ==, payloadCount);
check_int(builder->totalSize, ==, totalSize);
check(builder->isFolder);
for (size_t i = 0; i < builder->fileCount; i++)
{
check_str(builder->files[i].filename, ==, files[i]);
check_int_eq(payloadSizes[i], builder->files[i].size);
check_int(builder->files[i].size, ==, payloadSizes[i]);
}
/* call tr_makeMetaInfo() to build the .torrent file */
@ -166,7 +166,7 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
check(isPrivate == builder->isPrivate);
check_str(builder->outputFile, ==, torrent_file);
check_str(builder->comment, ==, comment);
check_int_eq(trackerCount, builder->trackerCount);
check_int(builder->trackerCount, ==, trackerCount);
while (!builder->isDone)
{
@ -178,18 +178,18 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
libttest_sync();
tr_ctorSetMetainfoFromFile(ctor, torrent_file);
parse_result = tr_torrentParse(ctor, &inf);
check_int_eq(TR_PARSE_OK, parse_result);
check_int(parse_result, ==, TR_PARSE_OK);
/* quick check of some of the parsed metainfo */
check_int_eq(totalSize, inf.totalSize);
check_int(inf.totalSize, ==, totalSize);
tmpstr = tr_sys_path_basename(top, NULL);
check_str(inf.name, ==, tmpstr);
tr_free(tmpstr);
check_str(inf.comment, ==, comment);
check_int_eq(payloadCount, inf.fileCount);
check_int_eq(isPrivate, inf.isPrivate);
check_int_eq(builder->isFolder, inf.isFolder);
check_int_eq(trackerCount, inf.trackerCount);
check_int(inf.fileCount, ==, payloadCount);
check_int(inf.isPrivate, ==, isPrivate);
check_int(inf.isFolder, ==, builder->isFolder);
check_int(inf.trackerCount, ==, trackerCount);
/* cleanup */
tr_free(torrent_file);

View File

@ -31,12 +31,12 @@ static int test_magnet_link(void)
ctor = tr_ctorNew(NULL);
tr_ctorSetMetainfoFromMagnetLink(ctor, magnet_link);
parse_result = tr_torrentParse(ctor, &inf);
check_int_eq(inf.fileCount, 0); /* cos it's a magnet link */
check_int_eq(parse_result, TR_PARSE_OK);
check_int_eq(inf.trackerCount, 2);
check_int(inf.fileCount, ==, 0); /* cos it's a magnet link */
check_int(parse_result, ==, TR_PARSE_OK);
check_int(inf.trackerCount, ==, 2);
check_str(inf.trackers[0].announce, ==, "http://tracker.publicbt.com/announce");
check_str(inf.trackers[1].announce, ==, "udp://tracker.publicbt.com:80");
check_int_eq(inf.webseedCount, 1);
check_int(inf.webseedCount, ==, 1);
check_str(inf.webseeds[0], ==, "http://transmissionbt.com");
/* cleanup */
@ -87,12 +87,12 @@ static int test_metainfo(void)
{
tr_ctor* ctor = tr_ctorNew(NULL);
int const err = tr_ctorSetMetainfo(ctor, metainfo[i].benc, strlen(metainfo[i].benc));
check_int_eq(metainfo[i].expected_benc_err, err);
check_int(err, ==, metainfo[i].expected_benc_err);
if (err == 0)
{
tr_parse_result const parse_result = tr_torrentParse(ctor, NULL);
check_int_eq(metainfo[i].expected_parse_result, parse_result);
check_int(parse_result, ==, metainfo[i].expected_parse_result);
}
tr_ctorFree(ctor);

View File

@ -134,7 +134,7 @@ static int test_incomplete_dir_impl(char const* incomplete_dir, char const* down
tr_wait_msec(50);
}
check_int_eq(TR_SEED, completeness);
check_int(completeness, ==, TR_SEED);
for (tr_file_index_t file_index = 0; file_index < tor->info.fileCount; ++file_index)
{
@ -204,7 +204,7 @@ static int test_set_location(void)
tr_wait_msec(50);
}
check_int_eq(TR_LOC_DONE, state);
check_int(state, ==, TR_LOC_DONE);
/* confirm the torrent is still complete after being moved */
libttest_blockingTorrentVerify(tor);

View File

@ -23,7 +23,7 @@ static int test_static_quarks(void)
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, (int)q);
check_int((int)q, ==, i);
}
for (int i = 0; i + 1 < TR_N_KEYS; i++)
@ -40,7 +40,7 @@ static int test_static_quarks(void)
}
tr_quark const q = tr_quark_new(NULL, TR_BAD_SIZE);
check_int_eq(TR_KEY_NONE, (int)q);
check_int((int)q, ==, TR_KEY_NONE);
check_str(tr_quark_get_string(q, NULL), ==, "");
return 0;

View File

@ -30,8 +30,8 @@ static tr_session* session = NULL;
do \
{ \
tr_stat const* tst = tr_torrentStat(tor); \
check_int_eq(TR_STATUS_STOPPED, tst->activity); \
check_int_eq(TR_STAT_OK, tst->error); \
check_int(tst->activity, ==, TR_STATUS_STOPPED); \
check_int(tst->error, ==, TR_STAT_OK); \
check_uint_eq(totalSize, tst->sizeWhenDone); \
check_uint_eq(totalSize, tst->leftUntilDone); \
check_uint_eq(totalSize, tor->info.totalSize); \
@ -149,7 +149,7 @@ static int test_single_filename_torrent(void)
check(tr_isTorrent(tor));
/* sanity check the info */
check_int_eq(1, tor->info.fileCount);
check_int(tor->info.fileCount, ==, 1);
check_str(tor->info.files[0].name, ==, "hello-world.txt");
check(!tor->info.files[0].is_renamed);
@ -162,8 +162,8 @@ static int test_single_filename_torrent(void)
/* sanity check the stats again, now that we've added the file */
libttest_blockingTorrentVerify(tor);
st = tr_torrentStat(tor);
check_int_eq(TR_STATUS_STOPPED, st->activity);
check_int_eq(TR_STAT_OK, st->error);
check_int(st->activity, ==, TR_STATUS_STOPPED);
check_int(st->error, ==, TR_STAT_OK);
check_uint_eq(0, st->leftUntilDone);
check_uint_eq(0, st->haveUnchecked);
check_uint_eq(0, st->desiredAvailable);
@ -177,12 +177,12 @@ static int test_single_filename_torrent(void)
/* confirm that bad inputs get caught */
check_int_eq(EINVAL, torrentRenameAndWait(tor, "hello-world.txt", NULL));
check_int_eq(EINVAL, torrentRenameAndWait(tor, "hello-world.txt", ""));
check_int_eq(EINVAL, torrentRenameAndWait(tor, "hello-world.txt", "."));
check_int_eq(EINVAL, torrentRenameAndWait(tor, "hello-world.txt", ".."));
check_int_eq(0, torrentRenameAndWait(tor, "hello-world.txt", "hello-world.txt"));
check_int_eq(EINVAL, torrentRenameAndWait(tor, "hello-world.txt", "hello/world.txt"));
check_int(torrentRenameAndWait(tor, "hello-world.txt", NULL), ==, EINVAL);
check_int(torrentRenameAndWait(tor, "hello-world.txt", ""), ==, EINVAL);
check_int(torrentRenameAndWait(tor, "hello-world.txt", "."), ==, EINVAL);
check_int(torrentRenameAndWait(tor, "hello-world.txt", ".."), ==, EINVAL);
check_int(torrentRenameAndWait(tor, "hello-world.txt", "hello-world.txt"), ==, 0);
check_int(torrentRenameAndWait(tor, "hello-world.txt", "hello/world.txt"), ==, EINVAL);
check(!tor->info.files[0].is_renamed);
check_str(tor->info.files[0].name, ==, "hello-world.txt");
@ -194,7 +194,7 @@ static int test_single_filename_torrent(void)
tmpstr = tr_buildPath(tor->currentDir, "hello-world.txt", NULL);
check(tr_sys_path_exists(tmpstr, NULL));
check_str(tr_torrentName(tor), ==, "hello-world.txt");
check_int_eq(0, torrentRenameAndWait(tor, tor->info.name, "foobar"));
check_int(torrentRenameAndWait(tor, tor->info.name, "foobar"), ==, 0);
check(!tr_sys_path_exists(tmpstr, NULL)); /* confirm the old filename can't be found */
tr_free(tmpstr);
check(tor->info.files[0].is_renamed); /* confirm the file's 'renamed' flag is set */
@ -219,7 +219,7 @@ static int test_single_filename_torrent(void)
tmpstr = tr_buildPath(tor->currentDir, "foobar", NULL);
check(tr_sys_path_exists(tmpstr, NULL));
check_int_eq(0, torrentRenameAndWait(tor, "foobar", "hello-world.txt"));
check_int(torrentRenameAndWait(tor, "foobar", "hello-world.txt"), ==, 0);
check(!tr_sys_path_exists(tmpstr, NULL));
check(tor->info.files[0].is_renamed);
check_str(tor->info.files[0].name, ==, "hello-world.txt");
@ -321,8 +321,8 @@ static int test_multifile_torrent(void)
/* sanity check the (full) stats */
libttest_blockingTorrentVerify(tor);
st = tr_torrentStat(tor);
check_int_eq(TR_STATUS_STOPPED, st->activity);
check_int_eq(TR_STAT_OK, st->error);
check_int(st->activity, ==, TR_STATUS_STOPPED);
check_int(st->error, ==, TR_STAT_OK);
check_uint_eq(0, st->leftUntilDone);
check_uint_eq(0, st->haveUnchecked);
check_uint_eq(0, st->desiredAvailable);
@ -334,17 +334,17 @@ static int test_multifile_torrent(void)
**/
/* rename a leaf... */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus/Kyphi", "placeholder"));
check_int(torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus/Kyphi", "placeholder"), ==, 0);
check_str(files[1].name, ==, "Felidae/Felinae/Felis/catus/placeholder");
check(testFileExistsAndConsistsOfThisString(tor, 1, "Inquisitive\n"));
/* ...and back again */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus/placeholder", "Kyphi"));
check_int(torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus/placeholder", "Kyphi"), ==, 0);
check_str(files[1].name, ==, "Felidae/Felinae/Felis/catus/Kyphi");
testFileExistsAndConsistsOfThisString(tor, 1, "Inquisitive\n");
/* rename a branch... */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus", "placeholder"));
check_int(torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus", "placeholder"), ==, 0);
check_str(files[0].name, ==, expected_files[0]);
check_str(files[1].name, ==, "Felidae/Felinae/Felis/placeholder/Kyphi");
check_str(files[2].name, ==, "Felidae/Felinae/Felis/placeholder/Saffron");
@ -369,7 +369,7 @@ static int test_multifile_torrent(void)
check_str(files[3].name, ==, expected_files[3]);
/* ...and back again */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/placeholder", "catus"));
check_int(torrentRenameAndWait(tor, "Felidae/Felinae/Felis/placeholder", "catus"), ==, 0);
for (tr_file_index_t i = 0; i < 4; ++i)
{
@ -412,21 +412,21 @@ static int test_multifile_torrent(void)
testFileExistsAndConsistsOfThisString(tor, 3, expected_contents[3]);
/* rename a branch... */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus", "foo"));
check_int(torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus", "foo"), ==, 0);
check_str(files[0].name, ==, expected_files[0]);
check_str(files[1].name, ==, "Felidae/Felinae/Felis/foo/Kyphi");
check_str(files[2].name, ==, "Felidae/Felinae/Felis/foo/Saffron");
check_str(files[3].name, ==, expected_files[3]);
/* ...and back again */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/foo", "catus"));
check_int(torrentRenameAndWait(tor, "Felidae/Felinae/Felis/foo", "catus"), ==, 0);
for (tr_file_index_t i = 0; i < 4; ++i)
{
check_str(files[i].name, ==, expected_files[i]);
}
check_int_eq(0, torrentRenameAndWait(tor, "Felidae", "gabba"));
check_int(torrentRenameAndWait(tor, "Felidae", "gabba"), ==, 0);
strings[0] = "gabba/Felinae/Acinonyx/Cheetah/Chester";
strings[1] = "gabba/Felinae/Felis/catus/Kyphi";
strings[2] = "gabba/Felinae/Felis/catus/Saffron";
@ -439,9 +439,9 @@ static int test_multifile_torrent(void)
}
/* rename the root, then a branch, and then a leaf... */
check_int_eq(0, torrentRenameAndWait(tor, "gabba", "Felidae"));
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Pantherinae/Panthera/Tiger", "Snow Leopard"));
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Pantherinae/Panthera/Snow Leopard/Tony", "10.6"));
check_int(torrentRenameAndWait(tor, "gabba", "Felidae"), ==, 0);
check_int(torrentRenameAndWait(tor, "Felidae/Pantherinae/Panthera/Tiger", "Snow Leopard"), ==, 0);
check_int(torrentRenameAndWait(tor, "Felidae/Pantherinae/Panthera/Snow Leopard/Tony", "10.6"), ==, 0);
strings[0] = "Felidae/Felinae/Acinonyx/Cheetah/Chester";
strings[1] = "Felidae/Felinae/Felis/catus/Kyphi";
strings[2] = "Felidae/Felinae/Felis/catus/Saffron";
@ -474,7 +474,7 @@ static int test_multifile_torrent(void)
files = tor->info.files;
/* rename prefix of top */
check_int_eq(EINVAL, torrentRenameAndWait(tor, "Feli", "FelidaeX"));
check_int(torrentRenameAndWait(tor, "Feli", "FelidaeX"), ==, EINVAL);
check_str(tor->info.name, ==, "Felidae");
check(!files[0].is_renamed);
check(!files[1].is_renamed);
@ -482,7 +482,7 @@ static int test_multifile_torrent(void)
check(!files[3].is_renamed);
/* rename false path */
check_int_eq(EINVAL, torrentRenameAndWait(tor, "Felidae/FelinaeX", "Genus Felinae"));
check_int(torrentRenameAndWait(tor, "Felidae/FelinaeX", "Genus Felinae"), ==, EINVAL);
check_str(tor->info.name, ==, "Felidae");
check(!files[0].is_renamed);
check(!files[1].is_renamed);
@ -540,8 +540,8 @@ static int test_partial_file(void)
****
***/
check_int_eq(0, torrentRenameAndWait(tor, "files-filled-with-zeroes", "foo"));
check_int_eq(0, torrentRenameAndWait(tor, "foo/1048576", "bar"));
check_int(torrentRenameAndWait(tor, "files-filled-with-zeroes", "foo"), ==, 0);
check_int(torrentRenameAndWait(tor, "foo/1048576", "bar"), ==, 0);
strings[0] = "foo/bar";
strings[1] = "foo/4096";
strings[2] = "foo/512";

View File

@ -23,22 +23,22 @@ static int test_list(void)
tr_rpc_parse_list_str(&top, "12", TR_BAD_SIZE);
check(tr_variantIsInt(&top));
check(tr_variantGetInt(&top, &i));
check_int_eq(12, i);
check_int(i, ==, 12);
tr_variantFree(&top);
tr_rpc_parse_list_str(&top, "12", 1);
check(tr_variantIsInt(&top));
check(tr_variantGetInt(&top, &i));
check_int_eq(1, i);
check_int(i, ==, 1);
tr_variantFree(&top);
tr_rpc_parse_list_str(&top, "6,7", TR_BAD_SIZE);
check(tr_variantIsList(&top));
check(tr_variantListSize(&top) == 2);
check(tr_variantGetInt(tr_variantListChild(&top, 0), &i));
check_int_eq(6, i);
check_int(i, ==, 6);
check(tr_variantGetInt(tr_variantListChild(&top, 1), &i));
check_int_eq(7, i);
check_int(i, ==, 7);
tr_variantFree(&top);
tr_rpc_parse_list_str(&top, "asdf", TR_BAD_SIZE);
@ -52,13 +52,13 @@ static int test_list(void)
check(tr_variantIsList(&top));
check(tr_variantListSize(&top) == 4);
check(tr_variantGetInt(tr_variantListChild(&top, 0), &i));
check_int_eq(1, i);
check_int(i, ==, 1);
check(tr_variantGetInt(tr_variantListChild(&top, 1), &i));
check_int_eq(3, i);
check_int(i, ==, 3);
check(tr_variantGetInt(tr_variantListChild(&top, 2), &i));
check_int_eq(4, i);
check_int(i, ==, 4);
check(tr_variantGetInt(tr_variantListChild(&top, 3), &i));
check_int_eq(5, i);
check_int(i, ==, 5);
tr_variantFree(&top);
return 0;

View File

@ -35,12 +35,12 @@ static int run_test(int argc, char const** argv, int expected_n, int* expected_c
while ((c = tr_getopt("summary", argc, argv, options, &optarg)) != TR_OPT_DONE)
{
check(n < expected_n);
check_int_eq(expected_c[n], c);
check_int(c, ==, expected_c[n]);
check_str(optarg, ==, expected_optarg[n]);
++n;
}
check_int_eq(expected_n, n);
check_int(n, ==, expected_n);
return 0;
}

View File

@ -149,13 +149,13 @@ static int test_numbers(void)
int* numbers;
numbers = tr_parseNumberRange("1-10,13,16-19", TR_BAD_SIZE, &count);
check_int_eq(15, count);
check_int_eq(1, numbers[0]);
check_int_eq(6, numbers[5]);
check_int_eq(10, numbers[9]);
check_int_eq(13, numbers[10]);
check_int_eq(16, numbers[11]);
check_int_eq(19, numbers[14]);
check_int(count, ==, 15);
check_int(numbers[0], ==, 1);
check_int(numbers[5], ==, 6);
check_int(numbers[9], ==, 10);
check_int(numbers[10], ==, 13);
check_int(numbers[11], ==, 16);
check_int(numbers[14], ==, 19);
tr_free(numbers);
numbers = tr_parseNumberRange("1-5,3-7,2-6", TR_BAD_SIZE, &count);
@ -164,21 +164,21 @@ static int test_numbers(void)
for (int i = 0; i < count; ++i)
{
check_int_eq(i + 1, numbers[i]);
check_int(numbers[i], ==, i + 1);
}
tr_free(numbers);
numbers = tr_parseNumberRange("1-Hello", TR_BAD_SIZE, &count);
check_int_eq(0, count);
check_int(count, ==, 0);
check(numbers == NULL);
numbers = tr_parseNumberRange("1-", TR_BAD_SIZE, &count);
check_int_eq(0, count);
check_int(count, ==, 0);
check(numbers == NULL);
numbers = tr_parseNumberRange("Hello", TR_BAD_SIZE, &count);
check_int_eq(0, count);
check_int(count, ==, 0);
check(numbers == NULL);
return 0;
@ -219,8 +219,8 @@ static int test_lowerbound(void)
#endif
check_int_eq(expected_pos[i - 1], pos);
check_int_eq(expected_exact[i - 1], exact);
check_int(pos, ==, expected_pos[i - 1]);
check_int(exact, ==, expected_exact[i - 1]);
}
return 0;
@ -276,7 +276,7 @@ static int test_quickfindFirst(void)
for (size_t i = 0; i < n_trials; ++i)
{
check_int_eq(0, test_quickFindFirst_Iteration(k, n, buf, 100));
check_int(test_quickFindFirst_Iteration(k, n, buf, 100), ==, 0);
}
tr_free(buf);
@ -318,14 +318,14 @@ static int test_array(void)
for (size_t i = 0; i < n; ++i)
{
check_int_eq(i < 5 ? i : i + 1, array[i]);
check_int(array[i], ==, i < 5 ? i : i + 1);
}
tr_removeElementFromArray(array, 0u, sizeof(size_t), n--);
for (size_t i = 0; i < n; ++i)
{
check_int_eq(i < 4 ? i + 1 : i + 2, array[i]);
check_int(array[i], ==, i < 4 ? i + 1 : i + 2);
}
tr_removeElementFromArray(array, n - 1, sizeof(size_t), n);
@ -333,7 +333,7 @@ static int test_array(void)
for (size_t i = 0; i < n; ++i)
{
check_int_eq(i < 4 ? i + 1 : i + 2, array[i]);
check_int(array[i], ==, i < 4 ? i + 1 : i + 2);
}
return 0;
@ -353,7 +353,7 @@ static int test_url(void)
check_str(scheme, ==, "http");
check_str(host, ==, "1");
check_str(path, ==, "/");
check_int_eq(80, port);
check_int(port, ==, 80);
tr_free(scheme);
tr_free(path);
tr_free(host);
@ -363,7 +363,7 @@ static int test_url(void)
check_str(scheme, ==, "http");
check_str(host, ==, "www.some-tracker.org");
check_str(path, ==, "/some/path");
check_int_eq(80, port);
check_int(port, ==, 80);
tr_free(scheme);
tr_free(path);
tr_free(host);
@ -373,7 +373,7 @@ static int test_url(void)
check_str(scheme, ==, "http");
check_str(host, ==, "www.some-tracker.org");
check_str(path, ==, "/some/path");
check_int_eq(80, port);
check_int(port, ==, 80);
tr_free(scheme);
tr_free(path);
tr_free(host);
@ -490,7 +490,7 @@ static int test_env(void)
check(!tr_env_key_exists(test_key));
x = tr_env_get_int(test_key, 123);
check_int_eq(123, x);
check_int(x, ==, 123);
s = tr_env_get_string(test_key, NULL);
check(s == NULL);
s = tr_env_get_string(test_key, "a");
@ -501,7 +501,7 @@ static int test_env(void)
check(tr_env_key_exists(test_key));
x = tr_env_get_int(test_key, 456);
check_int_eq(456, x);
check_int(x, ==, 456);
s = tr_env_get_string(test_key, NULL);
check_str(s, ==, "");
tr_free(s);
@ -513,7 +513,7 @@ static int test_env(void)
check(tr_env_key_exists(test_key));
x = tr_env_get_int(test_key, 789);
check_int_eq(135, x);
check_int(x, ==, 135);
s = tr_env_get_string(test_key, NULL);
check_str(s, ==, "135");
tr_free(s);

View File

@ -36,43 +36,43 @@ static int testInt(void)
/* good int string */
tr_snprintf((char*)buf, sizeof(buf), "i64e");
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int_eq(0, err);
check_int_eq(64, val);
check_int(err, ==, 0);
check_int(val, ==, 64);
check(buf + 4 == end);
/* missing 'e' */
end = NULL;
val = 888;
err = tr_bencParseInt(buf, buf + 3, &end, &val);
check_int_eq(EILSEQ, err);
check_int_eq(888, val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 888);
check(end == NULL);
/* empty buffer */
err = tr_bencParseInt(buf, buf + 0, &end, &val);
check_int_eq(EILSEQ, err);
check_int_eq(888, val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 888);
check(end == NULL);
/* bad number */
tr_snprintf((char*)buf, sizeof(buf), "i6z4e");
err = tr_bencParseInt(buf, buf + 5, &end, &val);
check_int_eq(EILSEQ, err);
check_int_eq(888, val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 888);
check(end == NULL);
/* negative number */
tr_snprintf((char*)buf, sizeof(buf), "i-3e");
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int_eq(0, err);
check_int_eq(-3, val);
check_int(err, ==, 0);
check_int(val, ==, -3);
check(buf + 4 == end);
/* zero */
tr_snprintf((char*)buf, sizeof(buf), "i0e");
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int_eq(0, err);
check_int_eq(0, val);
check_int(err, ==, 0);
check_int(val, ==, 0);
check(buf + 3 == end);
/* no leading zeroes allowed */
@ -80,8 +80,8 @@ static int testInt(void)
end = NULL;
tr_snprintf((char*)buf, sizeof(buf), "i04e");
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int_eq(EILSEQ, err);
check_int_eq(0, val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 0);
check(NULL == end);
return 0;
@ -99,7 +99,7 @@ static int testStr(void)
/* string len is designed to overflow */
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(err, ==, EILSEQ);
check_uint_eq(0, len);
check(str == NULL);
check(end == NULL);
@ -108,7 +108,7 @@ static int testStr(void)
/* good string */
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(err, ==, 0);
check_uint_eq(4, len);
check(strncmp((char const*)str, "boat", len) == 0);
check(end == buf + 6);
@ -118,7 +118,7 @@ static int 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(err, ==, EILSEQ);
check_uint_eq(0, len);
check(str == NULL);
check(end == NULL);
@ -127,7 +127,7 @@ static int testStr(void)
/* empty string */
n = tr_snprintf((char*)buf, sizeof(buf), "0:");
err = tr_bencParseStr(buf, buf + n, &end, &str, &len);
check_int_eq(0, err);
check_int(err, ==, 0);
check_uint_eq(0, len);
check(*str == '\0');
check(end == buf + 2);
@ -138,7 +138,7 @@ static int testStr(void)
/* short string */
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(err, ==, 0);
check_uint_eq(3, len);
check(strncmp((char const*)str, "boa", len) == 0);
check(end == buf + 5);
@ -198,7 +198,7 @@ static int testParse(void)
err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end);
check(err == 0);
check(tr_variantGetInt(&val, &i));
check_int_eq(64, i);
check_int(i, ==, 64);
check(end == buf + 4);
tr_variantFree(&val);
@ -208,11 +208,11 @@ static int testParse(void)
check(end == buf + strlen((char*)buf));
check(val.val.l.count == 3);
check(tr_variantGetInt(&val.val.l.vals[0], &i));
check_int_eq(64, i);
check_int(i, ==, 64);
check(tr_variantGetInt(&val.val.l.vals[1], &i));
check_int_eq(32, i);
check_int(i, ==, 32);
check(tr_variantGetInt(&val.val.l.vals[2], &i));
check_int_eq(16, i);
check_int(i, ==, 16);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str(saved, ==, buf);
tr_free(saved);
@ -442,13 +442,13 @@ static int testMerge(void)
tr_variantMergeDicts(&dest, /*const*/ &src);
check(tr_variantDictFindInt(&dest, i1, &i));
check_int_eq(1, i);
check_int(i, ==, 1);
check(tr_variantDictFindInt(&dest, i2, &i));
check_int_eq(4, i);
check_int(i, ==, 4);
check(tr_variantDictFindInt(&dest, i3, &i));
check_int_eq(3, i);
check_int(i, ==, 3);
check(tr_variantDictFindInt(&dest, i4, &i));
check_int_eq(-35, i);
check_int(i, ==, -35);
check(tr_variantDictFindStr(&dest, s5, &s, &len));
check_uint_eq(3, len);
check_str(s, ==, "abc");
@ -487,7 +487,7 @@ static int testStackSmash(void)
in[depth * 2] = '\0';
err = tr_variantFromBencFull(&val, in, depth * 2, NULL, &end);
check_int_eq(0, err);
check_int(err, ==, 0);
check(end == in + depth * 2);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str(saved, ==, in);
@ -565,14 +565,14 @@ static int testParse2(void)
check(end == benc + len);
check(tr_variantIsDict(&top2));
check(tr_variantDictFindInt(&top, key_int, &intVal));
check_int_eq(1234, intVal);
check_int(intVal, ==, 1234);
check(tr_variantDictFindBool(&top, key_bool, &boolVal));
check(boolVal == true);
check(tr_variantDictFindStr(&top, key_str, &strVal, &strLen));
check_uint_eq(16, strLen);
check_str(strVal, ==, "this-is-a-string");
check(tr_variantDictFindReal(&top, key_real, &realVal));
check_int_eq(50, (int)(realVal * 100));
check_int((int)(realVal * 100), ==, 50);
tr_variantFree(&top2);
tr_free(benc);