Transform `check_str_eq` into generic `check_str` (libtest)

This commit is contained in:
Mike Gelfand 2017-05-29 22:48:02 +03:00
parent 341b778099
commit 14c30119d4
18 changed files with 183 additions and 182 deletions

View File

@ -13,7 +13,7 @@
#define TEST_CLIENT(A, B) \
tr_clientForId(buf, sizeof(buf), A); \
check_str_eq(B, buf);
check_str(buf, ==, B);
int main(void)
{

View File

@ -86,13 +86,13 @@ static int test_encrypt_decrypt(void)
tr_cryptoEncrypt(&a, sizeof(test1), test1, buf11);
tr_cryptoDecryptInit_(&b);
tr_cryptoDecrypt_(&b, sizeof(test1), buf11, buf12);
check_str_eq(test1, buf12);
check_str(buf12, ==, test1);
tr_cryptoEncryptInit_(&b);
tr_cryptoEncrypt_(&b, sizeof(test2), test2, buf21);
tr_cryptoDecryptInit(&a);
tr_cryptoDecrypt(&a, sizeof(test2), buf21, buf22);
check_str_eq(test2, buf22);
check_str(buf22, ==, test2);
tr_cryptoDestruct_(&b);
tr_cryptoDestruct(&a);
@ -240,17 +240,17 @@ static int test_base64(void)
check(base64_eq("WU9ZTyE=", out));
in = tr_base64_decode_str(out, &len);
check_uint_eq(5, len);
check_str_eq("YOYO!", in);
check_str(in, ==, "YOYO!");
tr_free(in);
tr_free(out);
out = tr_base64_encode("", 0, &len);
check_uint_eq(0, len);
check_str_eq("", out);
check_str(out, ==, "");
tr_free(out);
out = tr_base64_decode("", 0, &len);
check_uint_eq(0, len);
check_str_eq("", out);
check_str(out, ==, "");
tr_free(out);
out = tr_base64_encode(NULL, 0, &len);
@ -290,7 +290,7 @@ static int test_base64(void)
check_uint_eq(strlen(out), len);
in = tr_base64_decode_str(out, &len);
check_uint_eq(i, len);
check_str_eq(in, buf);
check_str(buf, ==, in);
tr_free(in);
tr_free(out);
}

View File

@ -21,19 +21,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_str_eq("error: oops (2)", err->message);
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_str_eq("oops", err->message);
check_str(err->message, ==, "oops");
tr_error_prefix(&err, "error: ");
check(err != NULL);
check_int_eq(2, err->code);
check_str_eq("error: oops", err->message);
check_str(err->message, ==, "error: oops");
tr_error_free(err);
@ -48,18 +48,18 @@ static int test_error_propagate(void)
tr_error_set_literal(&err, 1, "oops");
check(err != NULL);
check_int_eq(1, err->code);
check_str_eq("oops", err->message);
check_str(err->message, ==, "oops");
tr_error_propagate(&err2, &err);
check(err2 != NULL);
check_int_eq(1, err2->code);
check_str_eq("oops", err2->message);
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_str_eq("error: oops", err->message);
check_str(err->message, ==, "error: oops");
check(err2 == NULL);
tr_error_propagate(NULL, &err);

View File

@ -650,7 +650,7 @@ static int test_path_xname(struct xname_test_data const* data, size_t data_size,
{
check(name != NULL);
check(err == NULL);
check_str_eq(data[i].output, name);
check_str(name, ==, data[i].output);
tr_free(name);
}
else
@ -1307,31 +1307,31 @@ static int test_file_utilities(void)
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("a", buffer);
check_str(buffer, ==, "a");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("bc", buffer);
check_str(buffer, ==, "bc");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("def", buffer);
check_str(buffer, ==, "def");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("ghij", buffer);
check_str(buffer, ==, "ghij");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("", buffer);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("", buffer);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, 4, &err));
check(err == NULL);
check_str_eq("klmn", buffer);
check_str(buffer, ==, "klmn");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("o", buffer);
check_str(buffer, ==, "o");
check(!tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("o", buffer); /* on EOF, buffer stays unchanged */
check_str(buffer, ==, "o"); /* on EOF, buffer stays unchanged */
tr_sys_file_close(fd, NULL);
@ -1356,28 +1356,28 @@ static int test_file_utilities(void)
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("p", buffer);
check_str(buffer, ==, "p");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("", buffer);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("qr", buffer);
check_str(buffer, ==, "qr");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("stu", buffer);
check_str(buffer, ==, "stu");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("", buffer);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("", buffer);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("vwxy2", buffer);
check_str(buffer, ==, "vwxy2");
check(!tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
check(err == NULL);
check_str_eq("vwxy2", buffer); /* on EOF, buffer stays unchanged */
check_str(buffer, ==, "vwxy2"); /* on EOF, buffer stays unchanged */
tr_sys_file_close(fd, NULL);

View File

@ -43,9 +43,9 @@ static int test_elements(void)
str = NULL;
key = tr_quark_new("string", 6);
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str_eq("hello world", str);
check_str(str, ==, "hello world");
check(tr_variantDictFindStr(&top, tr_quark_new("escaped", 7), &str, NULL));
check_str_eq("bell \b formfeed \f linefeed \n carriage return \r tab \t", str);
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);
@ -58,7 +58,7 @@ static int test_elements(void)
check(tr_variantDictFindBool(&top, tr_quark_new("false", 5), &f));
check_int_eq(false, f);
check(tr_variantDictFindStr(&top, tr_quark_new("null", 4), &str, NULL));
check_str_eq("", str);
check_str(str, ==, "");
if (err == 0)
{
@ -81,7 +81,7 @@ static int test_utf8(void)
check(err == 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str_eq("Letöltések", str);
check_str(str, ==, "Letöltések");
if (err == 0)
{
@ -93,7 +93,7 @@ static int test_utf8(void)
check(err == 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str_eq("\\", str);
check_str(str, ==, "\\");
if (err == 0)
{
@ -113,7 +113,7 @@ static int test_utf8(void)
check(err == 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str_eq("Letöltések", str);
check_str(str, ==, "Letöltések");
json = tr_variantToStr(&top, TR_VARIANT_FMT_JSON, NULL);
if (err == 0)
@ -128,7 +128,7 @@ static int test_utf8(void)
check(err == 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str_eq("Letöltések", str);
check_str(str, ==, "Letöltések");
if (err == 0)
{
@ -169,12 +169,12 @@ static int test1(void)
check((headers = tr_variantDictFind(&top, tr_quark_new("headers", 7))) != NULL);
check(tr_variantIsDict(headers));
check(tr_variantDictFindStr(headers, tr_quark_new("type", 4), &str, NULL));
check_str_eq("request", str);
check_str(str, ==, "request");
check(tr_variantDictFindInt(headers, TR_KEY_tag, &i));
check_int_eq(666, i);
check((body = tr_variantDictFind(&top, tr_quark_new("body", 4))) != NULL);
check(tr_variantDictFindStr(body, TR_KEY_name, &str, NULL));
check_str_eq("torrent-info", str);
check_str(str, ==, "torrent-info");
check((args = tr_variantDictFind(body, tr_quark_new("arguments", 9))) != NULL);
check(tr_variantIsDict(args));
check((ids = tr_variantDictFind(args, TR_KEY_ids)) != NULL);
@ -218,7 +218,7 @@ static int test3(void)
int const err = tr_variantFromJson(&top, in, strlen(in));
check(err == 0);
check(tr_variantDictFindStr(&top, TR_KEY_errorString, &str, NULL));
check_str_eq("torrent not registered with this tracker 6UHsVW'*C", str);
check_str(str, ==, "torrent not registered with this tracker 6UHsVW'*C");
tr_variantFree(&top);
return 0;
@ -233,7 +233,7 @@ static int test_unescape(void)
int const err = tr_variantFromJson(&top, in, strlen(in));
check_int_eq(0, err);
check(tr_variantDictFindStr(&top, tr_quark_new("string-1", 8), &str, NULL));
check_str_eq("/usr/lib", str);
check_str(str, ==, "/usr/lib");
tr_variantFree(&top);
return 0;

View File

@ -62,21 +62,16 @@ bool check_condition_impl(char const* file, int line, bool condition)
return pass;
}
bool check_str_eq_impl(char const* file, int line, char const* expected, char 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 const pass = tr_strcmp0(expected, actual) == 0;
if (should_print(pass))
{
if (pass)
{
fprintf(stderr, "PASS %s:%d\n", file, line);
}
else
{
fprintf(stderr, "FAIL %s:%d, expected \"%s\", got \"%s\"\n", file, line, expected != NULL ? expected : "(null)",
actual != NULL ? actual : "(null)");
}
char const* const lhs_quote = lhs != NULL ? "\"" : "";
char const* const rhs_quote = rhs != NULL ? "\"" : "";
fprintf(stderr, "%s %s:%d: %s %s %s (%s%s%s %s %s%s%s)\n", pass ? "PASS" : "FAIL", file, line, lhs_str, op_str, rhs_str,
lhs_quote, lhs != NULL ? lhs : "NULL", lhs_quote, op_str, rhs_quote, rhs != NULL ? rhs : "NULL", rhs_quote);
}
return pass;

View File

@ -26,7 +26,9 @@ 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 check_str_eq_impl(char const* file, int line, char const* expected, char 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);
/***
****
@ -44,12 +46,16 @@ bool check_str_eq_impl(char const* file, int line, char const* expected, char co
} \
while (0)
#define check_str_eq(expected, actual) \
#define check_str(lhs, op, rhs) \
do \
{ \
++current_test; \
\
if (!check_str_eq_impl(__FILE__, __LINE__, (expected), (actual))) \
char const* const check_str_lhs = (lhs); \
char const* const check_str_rhs = (rhs); \
\
if (!libtest_check_str(__FILE__, __LINE__, tr_strcmp0(check_str_lhs, check_str_rhs) op 0, check_str_lhs, \
check_str_rhs, #lhs, #op, #rhs)) \
{ \
return current_test; \
} \

View File

@ -32,11 +32,11 @@ static int test1(void)
info = tr_magnetParse(uri);
check(info != NULL);
check_int_eq(2, info->trackerCount);
check_str_eq(info->trackers[0], "http://tracker.openbittorrent.com/announce");
check_str_eq(info->trackers[1], "http://tracker.opentracker.org/announce");
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_str_eq("http://server.webseed.org/path/to/file", info->webseeds[0]);
check_str_eq("Display Name", info->displayName);
check_str(info->webseeds[0], ==, "http://server.webseed.org/path/to/file");
check_str(info->displayName, ==, "Display Name");
for (int i = 0; i < 20; ++i)
{
@ -57,11 +57,11 @@ static int test1(void)
info = tr_magnetParse(uri);
check(info != NULL);
check_int_eq(2, info->trackerCount);
check_str_eq("http://tracker.openbittorrent.com/announce", info->trackers[0]);
check_str_eq("http://tracker.opentracker.org/announce", info->trackers[1]);
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_str_eq("http://server.webseed.org/path/to/file", info->webseeds[0]);
check_str_eq("Display Name", info->displayName);
check_str(info->webseeds[0], ==, "http://server.webseed.org/path/to/file");
check_str(info->displayName, ==, "Display Name");
for (int i = 0; i < 20; ++i)
{

View File

@ -35,9 +35,9 @@ static int test_single_file_impl(tr_tracker_info const* trackers, size_t const t
input_file = tr_buildPath(sandbox, "test.XXXXXX", NULL);
libtest_create_tmpfile_with_contents(input_file, payload, payloadSize);
builder = tr_metaInfoBuilderCreate(input_file);
check_str_eq(input_file, builder->top);
check_str(builder->top, ==, input_file);
check_int_eq(1, builder->fileCount);
check_str_eq(input_file, builder->files[0].filename);
check_str(builder->files[0].filename, ==, input_file);
check_int_eq(payloadSize, builder->files[0].size);
check_int_eq(payloadSize, builder->totalSize);
check(!builder->isFolder);
@ -47,8 +47,8 @@ static int test_single_file_impl(tr_tracker_info const* trackers, size_t const t
torrent_file = tr_strdup_printf("%s.torrent", input_file);
tr_makeMetaInfo(builder, torrent_file, trackers, trackerCount, comment, isPrivate);
check(isPrivate == builder->isPrivate);
check_str_eq(torrent_file, builder->outputFile);
check_str_eq(comment, builder->comment);
check_str(builder->outputFile, ==, torrent_file);
check_str(builder->comment, ==, comment);
check_int_eq(trackerCount, builder->trackerCount);
while (!builder->isDone)
@ -66,9 +66,9 @@ static int test_single_file_impl(tr_tracker_info const* trackers, size_t const t
/* quick check of some of the parsed metainfo */
check_int_eq(payloadSize, inf.totalSize);
tmpstr = tr_sys_path_basename(input_file, NULL);
check_str_eq(tmpstr, inf.name);
check_str(inf.name, ==, tmpstr);
tr_free(tmpstr);
check_str_eq(comment, inf.comment);
check_str(inf.comment, ==, comment);
check_int_eq(1, inf.fileCount);
check_int_eq(isPrivate, inf.isPrivate);
check(!inf.isFolder);
@ -149,14 +149,14 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
/* init the builder */
builder = tr_metaInfoBuilderCreate(top);
check(!builder->abortFlag);
check_str_eq(top, builder->top);
check_str(builder->top, ==, top);
check_int_eq(payloadCount, builder->fileCount);
check_int_eq(totalSize, builder->totalSize);
check(builder->isFolder);
for (size_t i = 0; i < builder->fileCount; i++)
{
check_str_eq(files[i], builder->files[i].filename);
check_str(builder->files[i].filename, ==, files[i]);
check_int_eq(payloadSizes[i], builder->files[i].size);
}
@ -164,8 +164,8 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
torrent_file = tr_strdup_printf("%s.torrent", top);
tr_makeMetaInfo(builder, torrent_file, trackers, trackerCount, comment, isPrivate);
check(isPrivate == builder->isPrivate);
check_str_eq(torrent_file, builder->outputFile);
check_str_eq(comment, builder->comment);
check_str(builder->outputFile, ==, torrent_file);
check_str(builder->comment, ==, comment);
check_int_eq(trackerCount, builder->trackerCount);
while (!builder->isDone)
@ -183,9 +183,9 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
/* quick check of some of the parsed metainfo */
check_int_eq(totalSize, inf.totalSize);
tmpstr = tr_sys_path_basename(top, NULL);
check_str_eq(tmpstr, inf.name);
check_str(inf.name, ==, tmpstr);
tr_free(tmpstr);
check_str_eq(comment, inf.comment);
check_str(inf.comment, ==, comment);
check_int_eq(payloadCount, inf.fileCount);
check_int_eq(isPrivate, inf.isPrivate);
check_int_eq(builder->isFolder, inf.isFolder);

View File

@ -34,10 +34,10 @@ static int test_magnet_link(void)
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_str_eq("http://tracker.publicbt.com/announce", inf.trackers[0].announce);
check_str_eq("udp://tracker.publicbt.com:80", inf.trackers[1].announce);
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_str_eq("http://transmissionbt.com", inf.webseeds[0]);
check_str(inf.webseeds[0], ==, "http://transmissionbt.com");
/* cleanup */
tr_metainfoFree(&inf);

View File

@ -37,7 +37,7 @@ static void zeroes_completeness_func(tr_torrent* torrent UNUSED, tr_completeness
{ \
char* path = tr_torrentFindFile(tor, i); \
char* expected = expected_path; \
check_str_eq(expected, path); \
check_str(path, ==, expected); \
tr_free(expected); \
tr_free(path); \
} \

View File

@ -41,7 +41,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_str_eq("", tr_quark_get_string(q, NULL));
check_str(tr_quark_get_string(q, NULL), ==, "");
return 0;
}

View File

@ -150,7 +150,7 @@ static int test_single_filename_torrent(void)
/* sanity check the info */
check_int_eq(1, tor->info.fileCount);
check_str_eq("hello-world.txt", tor->info.files[0].name);
check_str(tor->info.files[0].name, ==, "hello-world.txt");
check(!tor->info.files[0].is_renamed);
/* sanity check the (empty) stats */
@ -185,7 +185,7 @@ static int test_single_filename_torrent(void)
check_int_eq(EINVAL, torrentRenameAndWait(tor, "hello-world.txt", "hello/world.txt"));
check(!tor->info.files[0].is_renamed);
check_str_eq("hello-world.txt", tor->info.files[0].name);
check_str(tor->info.files[0].name, ==, "hello-world.txt");
/***
**** Now try a rename that should succeed
@ -193,13 +193,13 @@ 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_eq("hello-world.txt", tr_torrentName(tor));
check_str(tr_torrentName(tor), ==, "hello-world.txt");
check_int_eq(0, torrentRenameAndWait(tor, tor->info.name, "foobar"));
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 */
check_str_eq("foobar", tr_torrentName(tor)); /* confirm the torrent's name is now 'foobar' */
check_str_eq("foobar", tor->info.files[0].name); /* confirm the file's name is now 'foobar' in our struct */
check_str(tr_torrentName(tor), ==, "foobar"); /* confirm the torrent's name is now 'foobar' */
check_str(tor->info.files[0].name, ==, "foobar"); /* confirm the file's name is now 'foobar' in our struct */
check(strstr(tor->info.torrent, "foobar") == NULL); /* confirm the name in the .torrent file hasn't changed */
tmpstr = tr_buildPath(tor->currentDir, "foobar", NULL);
check(tr_sys_path_exists(tmpstr, NULL)); /* confirm the file's name is now 'foobar' on the disk */
@ -210,7 +210,7 @@ static int test_single_filename_torrent(void)
tr_torrentSaveResume(tor);
libttest_sync();
loaded = tr_torrentLoadResume(tor, ~0, ctor);
check_str_eq("foobar", tr_torrentName(tor));
check_str(tr_torrentName(tor), ==, "foobar");
check((loaded & TR_FR_NAME) != 0);
/***
@ -222,8 +222,8 @@ static int test_single_filename_torrent(void)
check_int_eq(0, torrentRenameAndWait(tor, "foobar", "hello-world.txt"));
check(!tr_sys_path_exists(tmpstr, NULL));
check(tor->info.files[0].is_renamed);
check_str_eq("hello-world.txt", tor->info.files[0].name);
check_str_eq("hello-world.txt", tr_torrentName(tor));
check_str(tor->info.files[0].name, ==, "hello-world.txt");
check_str(tr_torrentName(tor), ==, "hello-world.txt");
tr_free(tmpstr);
check(testFileExistsAndConsistsOfThisString(tor, 0, "hello, world!\n"));
@ -302,13 +302,13 @@ static int test_multifile_torrent(void)
files = tor->info.files;
/* sanity check the info */
check_str_eq(tor->info.name, "Felidae");
check_str(tor->info.name, ==, "Felidae");
check_uint_eq(totalSize, tor->info.totalSize);
check_uint_eq(4, tor->info.fileCount);
for (tr_file_index_t i = 0; i < 4; ++i)
{
check_str_eq(expected_files[i], files[i].name);
check_str(files[i].name, ==, expected_files[i]);
}
/* sanity check the (empty) stats */
@ -335,20 +335,20 @@ static int test_multifile_torrent(void)
/* rename a leaf... */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus/Kyphi", "placeholder"));
check_str_eq(files[1].name, "Felidae/Felinae/Felis/catus/placeholder");
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_str_eq(files[1].name, "Felidae/Felinae/Felis/catus/Kyphi");
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_str_eq(expected_files[0], files[0].name);
check_str_eq("Felidae/Felinae/Felis/placeholder/Kyphi", files[1].name);
check_str_eq("Felidae/Felinae/Felis/placeholder/Saffron", files[2].name);
check_str_eq(expected_files[3], files[3].name);
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");
check_str(files[3].name, ==, expected_files[3]);
check(testFileExistsAndConsistsOfThisString(tor, 1, expected_contents[1]));
check(testFileExistsAndConsistsOfThisString(tor, 2, expected_contents[2]));
check(!files[0].is_renamed);
@ -363,17 +363,17 @@ static int test_multifile_torrent(void)
tor->info.files[1].name = tr_strdup("gabba gabba hey");
loaded = tr_torrentLoadResume(tor, ~0, ctor);
check((loaded & TR_FR_FILENAMES) != 0);
check_str_eq(expected_files[0], files[0].name);
check_str_eq("Felidae/Felinae/Felis/placeholder/Kyphi", files[1].name);
check_str_eq("Felidae/Felinae/Felis/placeholder/Saffron", files[2].name);
check_str_eq(expected_files[3], files[3].name);
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");
check_str(files[3].name, ==, expected_files[3]);
/* ...and back again */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/placeholder", "catus"));
for (tr_file_index_t i = 0; i < 4; ++i)
{
check_str_eq(expected_files[i], files[i].name);
check_str(files[i].name, ==, expected_files[i]);
check(testFileExistsAndConsistsOfThisString(tor, i, expected_contents[i]));
}
@ -405,7 +405,7 @@ static int test_multifile_torrent(void)
for (tr_file_index_t i = 1; i <= 2; ++i)
{
str = tr_torrentFindFile(tor, i);
check_str_eq(NULL, str);
check_str(str, ==, NULL);
tr_free(str);
}
@ -413,17 +413,17 @@ static int test_multifile_torrent(void)
/* rename a branch... */
check_int_eq(0, torrentRenameAndWait(tor, "Felidae/Felinae/Felis/catus", "foo"));
check_str_eq(expected_files[0], files[0].name);
check_str_eq("Felidae/Felinae/Felis/foo/Kyphi", files[1].name);
check_str_eq("Felidae/Felinae/Felis/foo/Saffron", files[2].name);
check_str_eq(expected_files[3], files[3].name);
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"));
for (tr_file_index_t i = 0; i < 4; ++i)
{
check_str_eq(expected_files[i], files[i].name);
check_str(files[i].name, ==, expected_files[i]);
}
check_int_eq(0, torrentRenameAndWait(tor, "Felidae", "gabba"));
@ -434,7 +434,7 @@ static int test_multifile_torrent(void)
for (tr_file_index_t i = 0; i < 4; ++i)
{
check_str_eq(strings[i], files[i].name);
check_str(files[i].name, ==, strings[i]);
testFileExistsAndConsistsOfThisString(tor, i, expected_contents[i]);
}
@ -449,7 +449,7 @@ static int test_multifile_torrent(void)
for (tr_file_index_t i = 0; i < 4; ++i)
{
check_str_eq(strings[i], files[i].name);
check_str(files[i].name, ==, strings[i]);
testFileExistsAndConsistsOfThisString(tor, i, expected_contents[i]);
}
@ -475,7 +475,7 @@ static int test_multifile_torrent(void)
/* rename prefix of top */
check_int_eq(EINVAL, torrentRenameAndWait(tor, "Feli", "FelidaeX"));
check_str_eq(tor->info.name, "Felidae");
check_str(tor->info.name, ==, "Felidae");
check(!files[0].is_renamed);
check(!files[1].is_renamed);
check(!files[2].is_renamed);
@ -483,7 +483,7 @@ static int test_multifile_torrent(void)
/* rename false path */
check_int_eq(EINVAL, torrentRenameAndWait(tor, "Felidae/FelinaeX", "Genus Felinae"));
check_str_eq(tor->info.name, "Felidae");
check_str(tor->info.name, ==, "Felidae");
check(!files[0].is_renamed);
check(!files[1].is_renamed);
check(!files[2].is_renamed);
@ -522,9 +522,9 @@ static int test_partial_file(void)
check_uint_eq(totalSize, tor->info.totalSize);
check_uint_eq(pieceSize, tor->info.pieceSize);
check_uint_eq(pieceCount, tor->info.pieceCount);
check_str_eq("files-filled-with-zeroes/1048576", tor->info.files[0].name);
check_str_eq("files-filled-with-zeroes/4096", tor->info.files[1].name);
check_str_eq("files-filled-with-zeroes/512", tor->info.files[2].name);
check_str(tor->info.files[0].name, ==, "files-filled-with-zeroes/1048576");
check_str(tor->info.files[1].name, ==, "files-filled-with-zeroes/4096");
check_str(tor->info.files[2].name, ==, "files-filled-with-zeroes/512");
libttest_zero_torrent_populate(tor, false);
fst = tr_torrentFiles(tor, NULL);
@ -548,7 +548,7 @@ static int test_partial_file(void)
for (tr_file_index_t i = 0; i < 3; ++i)
{
check_str_eq(strings[i], tor->info.files[i].name);
check_str(tor->info.files[i].name, ==, strings[i]);
}
strings[0] = "foo/bar.part";
@ -557,7 +557,7 @@ static int test_partial_file(void)
{
char* expected = tr_buildPath(tor->currentDir, strings[i], NULL);
char* path = tr_torrentFindFile(tor, i);
check_str_eq(expected, path);
check_str(path, ==, expected);
tr_free(path);
tr_free(expected);
}

View File

@ -45,7 +45,7 @@ static int test_list(void)
check(tr_variantIsString(&top));
check(tr_variantGetStr(&top, &str, &len));
check_uint_eq(4, len);
check_str_eq("asdf", str);
check_str(str, ==, "asdf");
tr_variantFree(&top);
tr_rpc_parse_list_str(&top, "1,3-5", TR_BAD_SIZE);

View File

@ -36,7 +36,7 @@ static int run_test(int argc, char const** argv, int expected_n, int* expected_c
{
check(n < expected_n);
check_int_eq(expected_c[n], c);
check_str_eq(optarg, expected_optarg[n]);
check_str(optarg, ==, expected_optarg[n]);
++n;
}

View File

@ -41,12 +41,12 @@ static int test_strip_positional_args(void)
in = "Hello %1$s foo %2$.*f";
expected = "Hello %s foo %.*f";
out = tr_strip_positional_args(in);
check_str_eq(expected, out);
check_str(out, ==, expected);
in = "Hello %1$'d foo %2$'f";
expected = "Hello %d foo %f";
out = tr_strip_positional_args(in);
check_str_eq(expected, out);
check_str(out, ==, expected);
return 0;
}
@ -60,21 +60,21 @@ static int test_strstrip(void)
in = tr_strdup(" test ");
out = tr_strstrip(in);
check(in == out);
check_str_eq("test", out);
check_str(out, ==, "test");
tr_free(in);
/* strstrip */
in = tr_strdup(" test test ");
out = tr_strstrip(in);
check(in == out);
check_str_eq("test test", out);
check_str(out, ==, "test test");
tr_free(in);
/* strstrip */
in = tr_strdup("test");
out = tr_strstrip(in);
check(in == out);
check_str_eq("test", out);
check_str(out, ==, "test");
tr_free(in);
return 0;
@ -85,11 +85,11 @@ static int test_buildpath(void)
char* out;
out = tr_buildPath("foo", "bar", NULL);
check_str_eq("foo" TR_PATH_DELIMITER_STR "bar", out);
check_str(out, ==, "foo" TR_PATH_DELIMITER_STR "bar");
tr_free(out);
out = tr_buildPath("", "foo", "bar", NULL);
check_str_eq(TR_PATH_DELIMITER_STR "foo" TR_PATH_DELIMITER_STR "bar", out);
check_str(out, ==, TR_PATH_DELIMITER_STR "foo" TR_PATH_DELIMITER_STR "bar");
tr_free(out);
return 0;
@ -102,12 +102,12 @@ static int test_utf8(void)
in = "hello world";
out = tr_utf8clean(in, TR_BAD_SIZE);
check_str_eq(in, out);
check_str(out, ==, in);
tr_free(out);
in = "hello world";
out = tr_utf8clean(in, 5);
check_str_eq("hello", out);
check_str(out, ==, "hello");
tr_free(out);
/* this version is not utf-8 (but cp866) */
@ -123,7 +123,7 @@ static int test_utf8(void)
out = tr_utf8clean(in, TR_BAD_SIZE);
check(out != NULL);
check(tr_utf8_validate(out, TR_BAD_SIZE, NULL));
check_str_eq(in, out);
check_str(out, ==, in);
tr_free(out);
in = "\xF4\x00\x81\x82";
@ -304,7 +304,7 @@ static int test_hex(void)
memcpy(hex1, "fb5ef5507427b17e04b69cef31fa3379b456735a", 41);
tr_hex_to_binary(hex1, binary, 20);
tr_binary_to_hex(binary, hex2, 20);
check_str_eq(hex1, hex2);
check_str(hex1, ==, hex2);
return 0;
}
@ -350,9 +350,9 @@ static int test_url(void)
url = "http://1";
check(tr_urlParse(url, TR_BAD_SIZE, &scheme, &host, &port, &path));
check_str_eq("http", scheme);
check_str_eq("1", host);
check_str_eq("/", path);
check_str(scheme, ==, "http");
check_str(host, ==, "1");
check_str(path, ==, "/");
check_int_eq(80, port);
tr_free(scheme);
tr_free(path);
@ -360,9 +360,9 @@ static int test_url(void)
url = "http://www.some-tracker.org/some/path";
check(tr_urlParse(url, TR_BAD_SIZE, &scheme, &host, &port, &path));
check_str_eq("http", scheme);
check_str_eq("www.some-tracker.org", host);
check_str_eq("/some/path", path);
check_str(scheme, ==, "http");
check_str(host, ==, "www.some-tracker.org");
check_str(path, ==, "/some/path");
check_int_eq(80, port);
tr_free(scheme);
tr_free(path);
@ -370,9 +370,9 @@ static int test_url(void)
url = "http://www.some-tracker.org:80/some/path";
check(tr_urlParse(url, TR_BAD_SIZE, &scheme, &host, &port, &path));
check_str_eq("http", scheme);
check_str_eq("www.some-tracker.org", host);
check_str_eq("/some/path", path);
check_str(scheme, ==, "http");
check_str(host, ==, "www.some-tracker.org");
check_str(path, ==, "/some/path");
check_int_eq(80, port);
tr_free(scheme);
tr_free(path);
@ -380,7 +380,7 @@ static int test_url(void)
url = "http%3A%2F%2Fwww.example.com%2F~user%2F%3Ftest%3D1%26test1%3D2";
str = tr_http_unescape(url, strlen(url));
check_str_eq("http://www.example.com/~user/?test=1&test1=2", str);
check_str(str, ==, "http://www.example.com/~user/?test=1&test1=2");
tr_free(str);
return 0;
@ -392,25 +392,25 @@ static int test_truncd(void)
double const nan = sqrt(-1);
tr_snprintf(buf, sizeof(buf), "%.2f%%", 99.999);
check_str_eq("100.00%", buf);
check_str(buf, ==, "100.00%");
tr_snprintf(buf, sizeof(buf), "%.2f%%", tr_truncd(99.999, 2));
check_str_eq("99.99%", buf);
check_str(buf, ==, "99.99%");
tr_snprintf(buf, sizeof(buf), "%.4f", tr_truncd(403650.656250, 4));
check_str_eq("403650.6562", buf);
check_str(buf, ==, "403650.6562");
tr_snprintf(buf, sizeof(buf), "%.2f", tr_truncd(2.15, 2));
check_str_eq("2.15", buf);
check_str(buf, ==, "2.15");
tr_snprintf(buf, sizeof(buf), "%.2f", tr_truncd(2.05, 2));
check_str_eq("2.05", buf);
check_str(buf, ==, "2.05");
tr_snprintf(buf, sizeof(buf), "%.2f", tr_truncd(3.3333, 2));
check_str_eq("3.33", buf);
check_str(buf, ==, "3.33");
tr_snprintf(buf, sizeof(buf), "%.0f", tr_truncd(3.3333, 0));
check_str_eq("3", buf);
check_str(buf, ==, "3");
#if !(defined(_MSC_VER) || (defined(__MINGW32__) && defined(__MSVCRT__)))
/* FIXME: MSCVRT behaves differently in case of nan */
@ -442,11 +442,11 @@ static int test_strdup_printf(void)
char* s3;
s = tr_strdup_printf("%s", "test");
check_str_eq("test", s);
check_str(s, ==, "test");
tr_free(s);
s = tr_strdup_printf("%d %s %c %u", -1, "0", '1', 2);
check_str_eq("-1 0 1 2", s);
check_str(s, ==, "-1 0 1 2");
tr_free(s);
s3 = tr_malloc0(4098);
@ -462,19 +462,19 @@ static int test_strdup_printf(void)
s2[2048] = 's';
s = tr_strdup_printf(s2, "test");
check_str_eq(s3, s);
check_str(s, ==, s3);
tr_free(s);
tr_free(s2);
s = tr_strdup_printf("%s", s3);
check_str_eq(s3, s);
check_str(s, ==, s3);
tr_free(s);
tr_free(s3);
s = test_strdup_printf_valist("\n-%s-%s-%s-\n", "\r", "\t", "\b");
check_str_eq("\n-\r-\t-\b-\n", s);
check_str(s, ==, "\n-\r-\t-\b-\n");
tr_free(s);
return 0;
@ -494,7 +494,7 @@ static int test_env(void)
s = tr_env_get_string(test_key, NULL);
check(s == NULL);
s = tr_env_get_string(test_key, "a");
check_str_eq("a", s);
check_str(s, ==, "a");
tr_free(s);
setenv(test_key, "", 1);
@ -503,10 +503,10 @@ static int test_env(void)
x = tr_env_get_int(test_key, 456);
check_int_eq(456, x);
s = tr_env_get_string(test_key, NULL);
check_str_eq("", s);
check_str(s, ==, "");
tr_free(s);
s = tr_env_get_string(test_key, "b");
check_str_eq("", s);
check_str(s, ==, "");
tr_free(s);
setenv(test_key, "135", 1);
@ -515,10 +515,10 @@ static int test_env(void)
x = tr_env_get_int(test_key, 789);
check_int_eq(135, x);
s = tr_env_get_string(test_key, NULL);
check_str_eq("135", s);
check_str(s, ==, "135");
tr_free(s);
s = tr_env_get_string(test_key, "c");
check_str_eq("135", s);
check_str(s, ==, "135");
tr_free(s);
return 0;

View File

@ -173,7 +173,7 @@ static int testString(char const* str, bool isGood)
#endif
check(end == str + len);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &savedLen);
check_str_eq(str, saved);
check_str(saved, ==, str);
check_uint_eq(savedLen, len);
tr_free(saved);
tr_variantFree(&val);
@ -214,7 +214,7 @@ static int testParse(void)
check(tr_variantGetInt(&val.val.l.vals[2], &i));
check_int_eq(16, i);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str_eq((char*)buf, saved);
check_str(saved, ==, buf);
tr_free(saved);
tr_variantFree(&val);
@ -230,7 +230,7 @@ static int testParse(void)
check(err == 0);
check(end == buf + 2);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str_eq("le", saved);
check_str(saved, ==, "le");
tr_free(saved);
tr_variantFree(&val);
@ -290,7 +290,7 @@ static int testParse(void)
check((child = tr_variantListChild(&val, 0)) != NULL);
check((child2 = tr_variantListChild(child, 0)) != NULL);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str_eq("lld1:ai64e1:bi32eeee", saved);
check_str(saved, ==, "lld1:ai64e1:bi32eeee");
tr_free(saved);
tr_variantFree(&val);
@ -301,7 +301,7 @@ static int testParse(void)
check(err == 0);
check(end == buf + 2);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str_eq("le", saved);
check_str(saved, ==, "le");
tr_free(saved);
tr_variantFree(&val);
@ -350,7 +350,7 @@ static int testJSONSnippet(char const* benc_str, char const* expected)
fprintf(stderr, "json: %s\n", serialized);
fprintf(stderr, "want: %s\n", expected);
#endif
check_str_eq(expected, serialized);
check_str(serialized, ==, expected);
tr_variantFree(&top);
evbuffer_free(buf);
return 0;
@ -451,16 +451,16 @@ static int testMerge(void)
check_int_eq(-35, i);
check(tr_variantDictFindStr(&dest, s5, &s, &len));
check_uint_eq(3, len);
check_str_eq("abc", s);
check_str(s, ==, "abc");
check(tr_variantDictFindStr(&dest, s6, &s, &len));
check_uint_eq(3, len);
check_str_eq("xyz", s);
check_str(s, ==, "xyz");
check(tr_variantDictFindStr(&dest, s7, &s, &len));
check_uint_eq(9, len);
check_str_eq("127.0.0.1", s);
check_str(s, ==, "127.0.0.1");
check(tr_variantDictFindStr(&dest, s8, &s, &len));
check_uint_eq(3, len);
check_str_eq("ghi", s);
check_str(s, ==, "ghi");
tr_variantFree(&dest);
tr_variantFree(&src);
@ -490,7 +490,7 @@ static int testStackSmash(void)
check_int_eq(0, err);
check(end == in + depth * 2);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str_eq((char*)in, saved);
check_str(saved, ==, in);
tr_free(in);
tr_free(saved);
tr_variantFree(&val);
@ -559,8 +559,8 @@ static int testParse2(void)
tr_variantDictAddStr(&top, key_str, "this-is-a-string");
benc = tr_variantToStr(&top, TR_VARIANT_FMT_BENC, &len);
check_str_eq("d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-int"
"i1234ee", benc);
check_str(benc, ==, "d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-"
"inti1234ee");
check(tr_variantFromBencFull(&top2, benc, len, NULL, &end) == 0);
check(end == benc + len);
check(tr_variantIsDict(&top2));
@ -570,7 +570,7 @@ static int testParse2(void)
check(boolVal == true);
check(tr_variantDictFindStr(&top, key_str, &strVal, &strLen));
check_uint_eq(16, strLen);
check_str_eq("this-is-a-string", strVal);
check_str(strVal, ==, "this-is-a-string");
check(tr_variantDictFindReal(&top, key_real, &realVal));
check_int_eq(50, (int)(realVal * 100));

View File

@ -162,7 +162,7 @@ static int test_initial_scan(void)
process_events();
check_ptr_eq(wd, wd_data.dir);
check_str_eq("test", wd_data.name);
check_str(wd_data.name, ==, "test");
tr_watchdir_free(wd);
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);
@ -198,14 +198,14 @@ static int test_watch(void)
process_events();
check_ptr_eq(wd, wd_data.dir);
check_str_eq("test", wd_data.name);
check_str(wd_data.name, ==, "test");
reset_callback_data(&wd_data, TR_WATCHDIR_IGNORE);
create_file(test_dir, "test2");
process_events();
check_ptr_eq(wd, wd_data.dir);
check_str_eq("test2", wd_data.name);
check_str(wd_data.name, ==, "test2");
reset_callback_data(&wd_data, TR_WATCHDIR_IGNORE);
create_dir(test_dir, "test3");
@ -260,7 +260,7 @@ static int test_watch_two_dirs(void)
process_events();
check_ptr_eq(wd1, wd1_data.dir);
check_str_eq("test", wd1_data.name);
check_str(wd1_data.name, ==, "test");
check_ptr_eq(NULL, wd2_data.dir);
check_ptr_eq(NULL, wd2_data.name);
@ -272,7 +272,7 @@ static int test_watch_two_dirs(void)
check_ptr_eq(NULL, wd1_data.dir);
check_ptr_eq(NULL, wd1_data.name);
check_ptr_eq(wd2, wd2_data.dir);
check_str_eq("test2", wd2_data.name);
check_str(wd2_data.name, ==, "test2");
reset_callback_data(&wd1_data, TR_WATCHDIR_IGNORE);
reset_callback_data(&wd2_data, TR_WATCHDIR_IGNORE);
@ -281,9 +281,9 @@ static int test_watch_two_dirs(void)
process_events();
check_ptr_eq(wd1, wd1_data.dir);
check_str_eq("test3", wd1_data.name);
check_str(wd1_data.name, ==, "test3");
check_ptr_eq(wd2, wd2_data.dir);
check_str_eq("test4", wd2_data.name);
check_str(wd2_data.name, ==, "test4");
reset_callback_data(&wd1_data, TR_WATCHDIR_ACCEPT);
reset_callback_data(&wd2_data, TR_WATCHDIR_ACCEPT);
@ -292,7 +292,7 @@ static int test_watch_two_dirs(void)
process_events();
check_ptr_eq(wd1, wd1_data.dir);
check_str_eq("test5", wd1_data.name);
check_str(wd1_data.name, ==, "test5");
check_ptr_eq(NULL, wd2_data.dir);
check_ptr_eq(NULL, wd2_data.name);
@ -305,7 +305,7 @@ static int test_watch_two_dirs(void)
check_ptr_eq(NULL, wd1_data.dir);
check_ptr_eq(NULL, wd1_data.name);
check_ptr_eq(wd2, wd2_data.dir);
check_str_eq("test6", wd2_data.name);
check_str(wd2_data.name, ==, "test6");
reset_callback_data(&wd1_data, TR_WATCHDIR_ACCEPT);
reset_callback_data(&wd2_data, TR_WATCHDIR_ACCEPT);
@ -367,7 +367,7 @@ static int test_retry(void)
process_events();
check_ptr_eq(wd, wd_data.dir);
check_str_eq("test", wd_data.name);
check_str(wd_data.name, ==, "test");
tr_watchdir_free(wd);
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);