}
count2 = tr_bitfieldCountRange(&bf, begin, end);
- check(count1 == count2);
+ check_int(count1, ==, count2);
/* cleanup */
tr_bitfieldDestruct(&bf);
for (unsigned int i = 0; i < bitcount; i++)
{
- check(tr_bitfieldHas(&field, i) == (i % 7 == 0));
+ check_bool(tr_bitfieldHas(&field, i), ==, (i % 7 == 0));
}
/* test tr_bitfieldAddRange */
for (unsigned int i = 0; i < bitcount; i++)
{
- check(tr_bitfieldHas(&field, i) == (i % 7 == 0));
+ check_bool(tr_bitfieldHas(&field, i), ==, (i % 7 == 0));
}
/* test tr_bitfieldRemRange in the middle of a boundary */
for (unsigned int i = 0; i < 64; i++)
{
- check(tr_bitfieldHas(&field, i) == (i < 4 || i >= 21));
+ check_bool(tr_bitfieldHas(&field, i), ==, (i < 4 || i >= 21));
}
/* test tr_bitfieldRemRange on the boundaries */
for (unsigned int i = 0; i < 64; i++)
{
- check(tr_bitfieldHas(&field, i) == (i < 8 || i >= 24));
+ check_bool(tr_bitfieldHas(&field, i), ==, (i < 8 || i >= 24));
}
/* test tr_bitfieldRemRange when begin & end is on the same word */
for (unsigned int i = 0; i < 64; i++)
{
- check(tr_bitfieldHas(&field, i) == (i < 4 || i >= 5));
+ check_bool(tr_bitfieldHas(&field, i), ==, (i < 4 || i >= 5));
}
/* test tr_bitfieldAddRange */
for (unsigned int i = 0; i < 64; i++)
{
- check(tr_bitfieldHas(&field, i) == (4 <= i && i < 21));
+ check_bool(tr_bitfieldHas(&field, i), ==, (4 <= i && i < 21));
}
/* test tr_bitfieldAddRange on the boundaries */
for (unsigned int i = 0; i < 64; i++)
{
- check(tr_bitfieldHas(&field, i) == (8 <= i && i < 24));
+ check_bool(tr_bitfieldHas(&field, i), ==, (8 <= i && i < 24));
}
/* test tr_bitfieldAddRange when begin & end is on the same word */
for (unsigned int i = 0; i < 64; i++)
{
- check(tr_bitfieldHas(&field, i) == (4 <= i && i < 5));
+ check_bool(tr_bitfieldHas(&field, i), ==, (4 <= i && i < 5));
}
tr_bitfieldDestruct(&field);
tr_cryptoConstruct(&a, NULL, true);
check(!tr_cryptoHasTorrentHash(&a));
- check(tr_cryptoGetTorrentHash(&a) == NULL);
+ check_ptr(tr_cryptoGetTorrentHash(&a), ==, NULL);
tr_cryptoSetTorrentHash(&a, hash);
check(tr_cryptoHasTorrentHash(&a));
- check(tr_cryptoGetTorrentHash(&a) != NULL);
- check(memcmp(tr_cryptoGetTorrentHash(&a), hash, SHA_DIGEST_LENGTH) == 0);
+ check_ptr(tr_cryptoGetTorrentHash(&a), !=, NULL);
+ check_mem(tr_cryptoGetTorrentHash(&a), ==, hash, SHA_DIGEST_LENGTH);
tr_cryptoDestruct(&a);
tr_cryptoConstruct(&a, hash, false);
check(tr_cryptoHasTorrentHash(&a));
- check(tr_cryptoGetTorrentHash(&a) != NULL);
- check(memcmp(tr_cryptoGetTorrentHash(&a), hash, SHA_DIGEST_LENGTH) == 0);
+ check_ptr(tr_cryptoGetTorrentHash(&a), !=, NULL);
+ check_mem(tr_cryptoGetTorrentHash(&a), ==, hash, SHA_DIGEST_LENGTH);
tr_cryptoSetTorrentHash(&a, NULL);
check(!tr_cryptoHasTorrentHash(&a));
- check(tr_cryptoGetTorrentHash(&a) == NULL);
+ check_ptr(tr_cryptoGetTorrentHash(&a), ==, NULL);
tr_cryptoDestruct(&a);
check(tr_sha1(hash, "test", 4, NULL));
check(tr_sha1_(hash_, "test", 4, NULL));
- check(memcmp(hash, "\xa9\x4a\x8f\xe5\xcc\xb1\x9b\xa6\x1c\x4c\x08\x73\xd3\x91\xe9\x87\x98\x2f\xbb\xd3",
- SHA_DIGEST_LENGTH) == 0);
- check(memcmp(hash, hash_, SHA_DIGEST_LENGTH) == 0);
+ check_mem(hash, ==, "\xa9\x4a\x8f\xe5\xcc\xb1\x9b\xa6\x1c\x4c\x08\x73\xd3\x91\xe9\x87\x98\x2f\xbb\xd3", SHA_DIGEST_LENGTH);
+ check_mem(hash, ==, hash_, SHA_DIGEST_LENGTH);
check(tr_sha1(hash, "1", 1, "22", 2, "333", 3, NULL));
check(tr_sha1_(hash_, "1", 1, "22", 2, "333", 3, NULL));
- check(memcmp(hash, "\x1f\x74\x64\x8e\x50\xa6\xa6\x70\x8e\xc5\x4a\xb3\x27\xa1\x63\xd5\x53\x6b\x7c\xed",
- SHA_DIGEST_LENGTH) == 0);
- check(memcmp(hash, hash_, SHA_DIGEST_LENGTH) == 0);
+ check_mem(hash, ==, "\x1f\x74\x64\x8e\x50\xa6\xa6\x70\x8e\xc5\x4a\xb3\x27\xa1\x63\xd5\x53\x6b\x7c\xed", SHA_DIGEST_LENGTH);
+ check_mem(hash, ==, hash_, SHA_DIGEST_LENGTH);
return 0;
}
{
hashes[j] = j % 2 == 0 ? tr_ssha1(phrase) : tr_ssha1_(phrase);
- check(hashes[j] != NULL);
+ check_ptr(hashes[j], !=, NULL);
/* phrase matches each of generated hashes */
check(tr_ssha1_matches(hashes[j], phrase));
/* all hashes are different */
for (size_t k = 0; k < HASH_COUNT; ++k)
{
- check(k == j || strcmp(hashes[j], hashes[k]) != 0);
+ if (k != j)
+ {
+ check_str(hashes[j], !=, hashes[k]);
+ }
}
}
for (int i = 0; i < 100000; ++i)
{
int const val = tr_rand_int(100);
- check(val >= 0);
- check(val < 100);
+ check_int(val, >=, 0);
+ check_int(val, <, 100);
}
return 0;
out = tr_base64_encode(NULL, 0, &len);
check_uint(len, ==, 0);
- check(out == NULL);
+ check_str(out, ==, NULL);
out = tr_base64_decode(NULL, 0, &len);
check_uint(len, ==, 0);
- check(out == NULL);
+ check_str(out, ==, NULL);
#define MAX_BUF_SIZE 1024
check_uint(len, ==, strlen(out));
in = tr_base64_decode(out, len, &len);
check_uint(len, ==, i);
- check(memcmp(in, buf, len) == 0);
+ check_mem(in, ==, buf, len);
tr_free(in);
tr_free(out);
tr_error* err = NULL;
tr_error_prefix(&err, "error: ");
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_error_set(&err, 1, "error: %s (%d)", "oops", 2);
check(err != NULL);
check_int(err->code, ==, 1);
check_str(err->message, ==, "error: oops (2)");
tr_error_clear(&err);
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_error_set_literal(&err, 2, "oops");
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check_int(err->code, ==, 2);
check_str(err->message, ==, "oops");
tr_error_prefix(&err, "error: ");
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check_int(err->code, ==, 2);
check_str(err->message, ==, "error: oops");
tr_error* err2 = NULL;
tr_error_set_literal(&err, 1, "oops");
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check_int(err->code, ==, 1);
check_str(err->message, ==, "oops");
tr_error_propagate(&err2, &err);
- check(err2 != NULL);
+ check_ptr(err2, !=, NULL);
check_int(err2->code, ==, 1);
check_str(err2->message, ==, "oops");
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_error_propagate_prefixed(&err, &err2, "error: ");
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check_int(err->code, ==, 1);
check_str(err->message, ==, "error: oops");
- check(err2 == NULL);
+ check_ptr(err2, ==, NULL);
tr_error_propagate(NULL, &err);
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_error_free(err2);
/* Can't get info of non-existent file/directory */
check(!tr_sys_path_get_info(path1, 0, &info, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
t = time(NULL);
/* Good file info */
clear_path_info(&info);
check(tr_sys_path_get_info(path1, 0, &info, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_int(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint(info.size, ==, 4);
- check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
+ check_int(info.last_modified_at, >=, t);
+ check_int(info.last_modified_at, <=, time(NULL));
/* Good file info (by handle) */
fd = tr_sys_file_open(path1, TR_SYS_FILE_READ, 0, NULL);
clear_path_info(&info);
check(tr_sys_file_get_info(fd, &info, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_int(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint(info.size, ==, 4);
- check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
+ check_int(info.last_modified_at, >=, t);
+ check_int(info.last_modified_at, <=, time(NULL));
tr_sys_file_close(fd, NULL);
tr_sys_path_remove(path1, NULL);
tr_sys_dir_create(path1, 0, 0777, NULL);
clear_path_info(&info);
check(tr_sys_path_get_info(path1, 0, &info, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
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));
+ check_uint(info.size, !=, (uint64_t)-1);
+ check_int(info.last_modified_at, >=, t);
+ check_int(info.last_modified_at, <=, time(NULL));
tr_sys_path_remove(path1, NULL);
if (create_symlink(path1, path2, false))
{
/* Can't get info of non-existent file/directory */
check(!tr_sys_path_get_info(path1, 0, &info, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
t = time(NULL);
/* Good file info */
clear_path_info(&info);
check(tr_sys_path_get_info(path1, 0, &info, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_int(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint(info.size, ==, 4);
- check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
+ check_int(info.last_modified_at, >=, t);
+ check_int(info.last_modified_at, <=, time(NULL));
/* Good file info (by handle) */
fd = tr_sys_file_open(path1, TR_SYS_FILE_READ, 0, NULL);
clear_path_info(&info);
check(tr_sys_file_get_info(fd, &info, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_int(info.type, ==, TR_SYS_PATH_IS_FILE);
check_uint(info.size, ==, 4);
- check(info.last_modified_at >= t && info.last_modified_at <= time(NULL));
+ check_int(info.last_modified_at, >=, t);
+ check_int(info.last_modified_at, <=, time(NULL));
tr_sys_file_close(fd, NULL);
tr_sys_path_remove(path2, NULL);
tr_sys_dir_create(path2, 0, 0777, NULL);
clear_path_info(&info);
check(tr_sys_path_get_info(path1, 0, &info, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
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));
+ check_uint(info.size, !=, (uint64_t)-1);
+ check_int(info.last_modified_at, >=, t);
+ check_int(info.last_modified_at, <=, time(NULL));
tr_sys_path_remove(path2, NULL);
tr_sys_path_remove(path1, NULL);
/* Non-existent file does not exist */
check(!tr_sys_path_exists(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Create file and see that it exists */
libtest_create_file_with_string_contents(path1, "test");
check(tr_sys_path_exists(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path1, NULL);
/* Create directory and see that it exists */
tr_sys_dir_create(path1, 0, 0777, NULL);
check(tr_sys_path_exists(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path1, NULL);
{
/* Non-existent file does not exist (via symlink) */
check(!tr_sys_path_exists(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Create file and see that it exists (via symlink) */
libtest_create_file_with_string_contents(path2, "test");
check(tr_sys_path_exists(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
/* Create directory and see that it exists (via symlink) */
tr_sys_dir_create(path2, 0, 0777, NULL);
check(tr_sys_path_exists(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
tr_sys_path_remove(path1, NULL);
/* Two non-existent files are not the same */
check(!tr_sys_path_is_same(path1, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Two same files are the same */
libtest_create_file_with_string_contents(path1, "test");
check(tr_sys_path_is_same(path1, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Existent and non-existent files are not the same */
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path2, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Two separate files (even with same content) are not the same */
libtest_create_file_with_string_contents(path2, "test");
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path1, NULL);
/* Two same directories are the same */
tr_sys_dir_create(path1, 0, 0777, NULL);
check(tr_sys_path_is_same(path1, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* File and directory are not the same */
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path2, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
/* Two separate directories are not the same */
tr_sys_dir_create(path2, 0, 0777, NULL);
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path1, NULL);
tr_sys_path_remove(path2, NULL);
{
/* Directory and symlink pointing to it are the same */
check(tr_sys_path_is_same(path1, test_dir, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_path_is_same(test_dir, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Non-existent file and symlink are not the same */
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path2, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Symlinks pointing to different directories are not the same */
create_symlink(path2, "..", true);
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path2, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
/* Symlinks pointing to same directory are the same */
create_symlink(path2, ".", true);
check(tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
/* Directory and symlink pointing to another directory are not the same */
tr_sys_dir_create(path2, 0, 0777, NULL);
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path2, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Symlinks pointing to same directory are the same */
create_symlink(path3, "..", true);
check(tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path1, NULL);
/* File and symlink pointing to directory are not the same */
libtest_create_file_with_string_contents(path1, "test");
check(!tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path3, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path3, NULL);
/* File and symlink pointing to same file are the same */
create_symlink(path3, path1, false);
check(tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_path_is_same(path3, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Symlinks pointing to non-existent files are not the same */
tr_sys_path_remove(path1, NULL);
tr_sys_path_remove(path3, NULL);
create_symlink(path3, "missing", false);
check(!tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path3, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path3, NULL);
/* Symlinks pointing to same non-existent file are not the same */
create_symlink(path3, ".." NATIVE_PATH_SEP "missing", false);
check(!tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path3, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Non-existent file and symlink pointing to non-existent file are not the same */
tr_sys_path_remove(path3, NULL);
check(!tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path3, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
tr_sys_path_remove(path1, NULL);
{
/* File and hardlink to it are the same */
check(tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Two hardlinks to the same file are the same */
create_hardlink(path3, path2);
check(tr_sys_path_is_same(path2, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
check(tr_sys_path_is_same(path1, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path3, NULL);
libtest_create_file_with_string_contents(path3, "test");
create_hardlink(path2, path3);
check(!tr_sys_path_is_same(path1, path2, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_is_same(path2, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path3, NULL);
tr_sys_path_remove(path2, NULL);
if (create_symlink(path2, path1, false) && create_hardlink(path3, path1))
{
check(tr_sys_path_is_same(path2, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
}
else
{
char* tmp;
tmp = tr_sys_path_resolve(path2, &err);
- check(tmp != NULL);
- check(err == NULL);
+ check_str(tmp, !=, NULL);
+ check_ptr(err, ==, NULL);
check(path_contains_no_symlinks(tmp));
tr_free(tmp);
tr_sys_dir_create(path1, 0, 0755, NULL);
tmp = tr_sys_path_resolve(path2, &err);
- check(tmp != NULL);
- check(err == NULL);
+ check_str(tmp, !=, NULL);
+ check_ptr(err, ==, NULL);
check(path_contains_no_symlinks(tmp));
tr_free(tmp);
}
if (data[i].output != NULL)
{
- check(name != NULL);
- check(err == NULL);
+ check_str(name, !=, NULL);
+ check_ptr(err, ==, NULL);
check_str(name, ==, data[i].output);
tr_free(name);
}
else
{
- check(name == NULL);
- check(err != NULL);
+ check_str(name, ==, NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
}
}
check(tr_sys_path_rename(path1, path2, &err));
check(!tr_sys_path_exists(path1, NULL));
check(tr_sys_path_exists(path2, NULL));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Backward rename works */
check(tr_sys_path_rename(path2, path1, &err));
check(tr_sys_path_exists(path1, NULL));
check(!tr_sys_path_exists(path2, NULL));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
/* Another backward rename [of non-existent file] does not work */
check(!tr_sys_path_rename(path2, path1, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
/* Rename to file which couldn't be created does not work */
check(!tr_sys_path_rename(path1, path3, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
/* Rename of non-existent file does not work */
check(!tr_sys_path_rename(path3, path2, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
libtest_create_file_with_string_contents(path2, "test");
/* Renaming file does overwrite existing file */
check(tr_sys_path_rename(path2, path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_dir_create(path2, 0, 0777, NULL);
/* Renaming file does not overwrite existing directory, and vice versa */
check(!tr_sys_path_rename(path1, path2, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
check(!tr_sys_path_rename(path2, path1, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
tr_sys_path_remove(path2, NULL);
/* Rename of symlink works, files stay the same */
check(tr_sys_path_rename(path2, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_exists(path2, NULL));
check(tr_sys_path_exists(path3, NULL));
check(tr_sys_path_is_same(path1, path3, NULL));
/* Rename of hardlink works, files stay the same */
check(tr_sys_path_rename(path2, path3, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_exists(path2, NULL));
check(tr_sys_path_exists(path3, NULL));
check(tr_sys_path_is_same(path1, path3, NULL));
/* Can't remove non-existent file/directory */
check(!tr_sys_path_exists(path1, NULL));
check(!tr_sys_path_remove(path1, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check(!tr_sys_path_exists(path1, NULL));
tr_error_clear(&err);
libtest_create_file_with_string_contents(path1, "test");
check(tr_sys_path_exists(path1, NULL));
check(tr_sys_path_remove(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_exists(path1, NULL));
/* Removing empty directory works */
tr_sys_dir_create(path1, 0, 0777, NULL);
check(tr_sys_path_exists(path1, NULL));
check(tr_sys_path_remove(path1, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(!tr_sys_path_exists(path1, NULL));
/* Removing non-empty directory fails */
check(tr_sys_path_exists(path2, NULL));
check(tr_sys_path_exists(path3, NULL));
check(!tr_sys_path_remove(path2, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check(tr_sys_path_exists(path2, NULL));
check(tr_sys_path_exists(path3, NULL));
tr_error_clear(&err);
/* Can't open non-existent file */
check(!tr_sys_path_exists(path1, NULL));
check(tr_sys_file_open(path1, TR_SYS_FILE_READ, 0600, &err) == TR_BAD_SYS_FILE);
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check(!tr_sys_path_exists(path1, NULL));
tr_error_clear(&err);
check(tr_sys_file_open(path1, TR_SYS_FILE_WRITE, 0600, &err) == TR_BAD_SYS_FILE);
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check(!tr_sys_path_exists(path1, NULL));
tr_error_clear(&err);
#ifdef _WIN32
/* This works on *NIX */
check(tr_sys_file_open(path1, TR_SYS_FILE_READ, 0600, &err) == TR_BAD_SYS_FILE);
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
#endif
check(tr_sys_file_open(path1, TR_SYS_FILE_WRITE, 0600, &err) == TR_BAD_SYS_FILE);
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
tr_sys_path_remove(path1, NULL);
/* Can create non-existent file */
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0640, &err);
- check(fd != TR_BAD_SYS_FILE);
- check(err == NULL);
+ check_int(fd, !=, TR_BAD_SYS_FILE);
+ check_ptr(err, ==, NULL);
tr_sys_file_close(fd, NULL);
check(tr_sys_path_exists(path1, NULL));
check(validate_permissions(path1, 0640));
/* Can open existing file */
check(tr_sys_path_exists(path1, NULL));
fd = tr_sys_file_open(path1, TR_SYS_FILE_READ, 0600, &err);
- check(fd != TR_BAD_SYS_FILE);
- check(err == NULL);
+ check_int(fd, !=, TR_BAD_SYS_FILE);
+ check_ptr(err, ==, NULL);
tr_sys_file_close(fd, NULL);
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE, 0600, &err);
- check(fd != TR_BAD_SYS_FILE);
- check(err == NULL);
+ check_int(fd, !=, TR_BAD_SYS_FILE);
+ check_ptr(err, ==, NULL);
tr_sys_file_close(fd, NULL);
tr_sys_path_remove(path1, NULL);
/* Can't create new file if it already exists */
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE_NEW, 0640, &err);
- check(fd == TR_BAD_SYS_FILE);
- check(err != NULL);
+ check_int(fd, ==, TR_BAD_SYS_FILE);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
tr_sys_path_get_info(path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL);
check_uint(info.size, ==, 4);
tr_sys_path_get_info(path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL);
check_uint(info.size, ==, 4);
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);
+ check_int(fd, !=, TR_BAD_SYS_FILE);
+ check_ptr(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_uint(n, ==, 5);
tr_sys_path_get_info(path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL);
check_uint(info.size, ==, 5);
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);
+ check_int(fd, !=, TR_BAD_SYS_FILE);
+ check_ptr(err, ==, NULL);
tr_sys_file_get_info(fd, &info, NULL);
check_uint(info.size, ==, 0);
tr_sys_file_close(fd, NULL);
fd = tr_sys_file_open(path1, TR_SYS_FILE_READ | TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0600, NULL);
check(tr_sys_file_seek(fd, 0, TR_SEEK_CUR, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 0);
check(tr_sys_file_write(fd, "test", 4, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 4);
check(tr_sys_file_seek(fd, 0, TR_SEEK_CUR, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 4);
check(tr_sys_file_seek(fd, 0, TR_SEEK_SET, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 0);
check(tr_sys_file_read(fd, buf, sizeof(buf), &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 4);
- check_int(memcmp(buf, "test", 4), ==, 0);
+ check_mem(buf, ==, "test", 4);
check(tr_sys_file_seek(fd, -3, TR_SEEK_CUR, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 1);
check(tr_sys_file_write(fd, "E", 1, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 1);
check(tr_sys_file_seek(fd, -2, TR_SEEK_CUR, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 0);
check(tr_sys_file_read(fd, buf, sizeof(buf), &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 4);
- check_int(memcmp(buf, "tEst", 4), ==, 0);
+ check_mem(buf, ==, "tEst", 4);
check(tr_sys_file_seek(fd, 0, TR_SEEK_END, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 4);
check(tr_sys_file_write(fd, " ok", 3, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 3);
check(tr_sys_file_seek(fd, 0, TR_SEEK_SET, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 0);
check(tr_sys_file_read(fd, buf, sizeof(buf), &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 7);
- check_int(memcmp(buf, "tEst ok", 7), ==, 0);
+ check_mem(buf, ==, "tEst ok", 7);
check(tr_sys_file_write_at(fd, "-", 1, 4, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 1);
check(tr_sys_file_read_at(fd, buf, 5, 2, &n, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_uint(n, ==, 5);
- check_int(memcmp(buf, "st-ok", 5), ==, 0);
+ check_mem(buf, ==, "st-ok", 5);
tr_sys_file_close(fd, NULL);
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0600, NULL);
check(tr_sys_file_truncate(fd, 10, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_get_info(fd, &info, NULL);
check_uint(info.size, ==, 10);
check(tr_sys_file_truncate(fd, 20, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_get_info(fd, &info, NULL);
check_uint(info.size, ==, 20);
check(tr_sys_file_truncate(fd, 0, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_get_info(fd, &info, NULL);
check_uint(info.size, ==, 0);
check(tr_sys_file_truncate(fd, 50, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_close(fd, NULL);
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0600, NULL);
check(tr_sys_file_truncate(fd, 25, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_close(fd, NULL);
if (tr_sys_file_preallocate(fd, 50, 0, &err))
{
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_get_info(fd, &info, NULL);
check_uint(info.size, ==, 50);
}
else
{
- check(err != NULL);
+ check_ptr(err, !=, NULL);
fprintf(stderr, "WARNING: [%s] unable to preallocate file (full): %s (%d)\n", __FUNCTION__, err->message, err->code);
tr_error_clear(&err);
}
if (tr_sys_file_preallocate(fd, 500 * 1024 * 1024, TR_SYS_FILE_PREALLOC_SPARSE, &err))
{
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_get_info(fd, &info, NULL);
check_uint(info.size, ==, 500 * 1024 * 1024);
}
else
{
- check(err != NULL);
+ check_ptr(err, !=, NULL);
fprintf(stderr, "WARNING: [%s] unable to preallocate file (sparse): %s (%d)\n", __FUNCTION__, err->message, err->code);
tr_error_clear(&err);
}
fd = tr_sys_file_open(path1, TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, 0600, NULL);
view = tr_sys_file_map_for_reading(fd, 0, 4, &err);
- check(view != NULL);
- check(err == NULL);
+ check_ptr(view, !=, NULL);
+ check_ptr(err, ==, NULL);
- check_int(memcmp(view, "test", 4), ==, 0);
+ check_mem(view, ==, "test", 4);
#ifdef HAVE_UNIFIED_BUFFER_CACHE
tr_sys_file_write_at(fd, "E", 1, 1, NULL, NULL);
- check_int(memcmp(view, "tEst", 4), ==, 0);
+ check_mem(view, ==, "tEst", 4);
#endif
check(tr_sys_file_unmap(view, 4, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_close(fd, NULL);
fd = tr_sys_file_open(path1, TR_SYS_FILE_READ, 0, NULL);
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "a");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "bc");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "def");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "ghij");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, 4, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "klmn");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "o");
check(!tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "o"); /* on EOF, buffer stays unchanged */
tr_sys_file_close(fd, NULL);
fd = tr_sys_file_open(path1, TR_SYS_FILE_READ | TR_SYS_FILE_WRITE | TR_SYS_FILE_TRUNCATE, 0, NULL);
check(tr_sys_file_write_line(fd, "p", &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_file_write_line(fd, "", &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_file_write_line(fd, "qr", &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_file_write_fmt(fd, "s%cu\r\n", &err, 't'));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_file_write_line(fd, "", &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_file_write_line(fd, "", &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_file_write_fmt(fd, "v%sy%d", &err, "wx", 2));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_file_seek(fd, 0, TR_SEEK_SET, NULL, NULL);
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "p");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "qr");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "stu");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "");
check(tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "vwxy2");
check(!tr_sys_file_read_line(fd, buffer, TR_N_ELEMENTS(buffer), &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check_str(buffer, ==, "vwxy2"); /* on EOF, buffer stays unchanged */
tr_sys_file_close(fd, NULL);
/* Can create directory which has parent */
check(tr_sys_dir_create(path1, 0, 0700, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_path_exists(path1, NULL));
check(validate_permissions(path1, 0700));
/* Can't create directory where file already exists */
check(!tr_sys_dir_create(path1, 0, 0700, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
check(!tr_sys_dir_create(path1, TR_SYS_DIR_CREATE_PARENTS, 0700, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
tr_error_clear(&err);
tr_sys_path_remove(path1, NULL);
/* Can't create directory which has no parent */
check(!tr_sys_dir_create(path2, 0, 0700, &err));
- check(err != NULL);
+ check_ptr(err, !=, NULL);
check(!tr_sys_path_exists(path2, NULL));
tr_error_clear(&err);
/* Can create directory with parent directories */
check(tr_sys_dir_create(path2, TR_SYS_DIR_CREATE_PARENTS, 0751, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_path_exists(path1, NULL));
check(tr_sys_path_exists(path2, NULL));
check(validate_permissions(path1, 0751));
/* Can create existing directory (no-op) */
check(tr_sys_dir_create(path1, 0, 0700, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_dir_create(path1, TR_SYS_DIR_CREATE_PARENTS, 0700, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
tr_sys_path_remove(path2, NULL);
tr_sys_path_remove(path1, NULL);
*have1 = *have2 = false;
dd = tr_sys_dir_open(path, &err);
- check(dd != TR_BAD_SYS_DIR);
- check(err == NULL);
+ check_ptr(dd, !=, TR_BAD_SYS_DIR);
+ check_ptr(err, ==, NULL);
while ((name = tr_sys_dir_read_name(dd, &err)) != NULL)
{
- check(err == NULL);
+ check_ptr(err, ==, NULL);
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
{
}
}
- check(err == NULL);
+ check_ptr(err, ==, NULL);
check(tr_sys_dir_close(dd, &err));
- check(err == NULL);
+ check_ptr(err, ==, NULL);
return 0;
}
tr_quark const key = tr_quark_new("key", 3);
err = tr_variantFromJson(&top, in, strlen(in));
- check(err == 0);
+ check_int(err, ==, 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str(str, ==, "Letöltések");
in = "{ \"key\": \"\\u005C\" }";
err = tr_variantFromJson(&top, in, strlen(in));
- check(err == 0);
+ check_int(err, ==, 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str(str, ==, "\\");
*/
in = "{ \"key\": \"Let\\u00f6lt\\u00e9sek\" }";
err = tr_variantFromJson(&top, in, strlen(in));
- check(err == 0);
+ check_int(err, ==, 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str(str, ==, "Letöltések");
tr_variantFree(&top);
}
- check(json != NULL);
- check(strstr(json, "\\u00f6") != NULL);
- check(strstr(json, "\\u00e9") != NULL);
+ check_ptr(json, !=, NULL);
+ check_str(strstr(json, "\\u00f6"), !=, NULL);
+ check_str(strstr(json, "\\u00e9"), !=, NULL);
err = tr_variantFromJson(&top, json, strlen(json));
- check(err == 0);
+ check_int(err, ==, 0);
check(tr_variantIsDict(&top));
check(tr_variantDictFindStr(&top, key, &str, NULL));
check_str(str, ==, "Letöltések");
int64_t i;
int const err = tr_variantFromJson(&top, in, strlen(in));
- check(err == 0);
+ check_int(err, ==, 0);
check(tr_variantIsDict(&top));
- check((headers = tr_variantDictFind(&top, tr_quark_new("headers", 7))) != NULL);
+ check_ptr((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(str, ==, "request");
check(tr_variantDictFindInt(headers, TR_KEY_tag, &i));
check_int(i, ==, 666);
- check((body = tr_variantDictFind(&top, tr_quark_new("body", 4))) != NULL);
+ check_ptr((body = tr_variantDictFind(&top, tr_quark_new("body", 4))), !=, NULL);
check(tr_variantDictFindStr(body, TR_KEY_name, &str, NULL));
check_str(str, ==, "torrent-info");
- check((args = tr_variantDictFind(body, tr_quark_new("arguments", 9))) != NULL);
+ check_ptr((args = tr_variantDictFind(body, tr_quark_new("arguments", 9))), !=, NULL);
check(tr_variantIsDict(args));
- check((ids = tr_variantDictFind(args, TR_KEY_ids)) != NULL);
+ check_ptr((ids = tr_variantDictFind(args, TR_KEY_ids)), !=, NULL);
check(tr_variantIsList(ids));
check_uint(tr_variantListSize(ids), ==, 2);
check(tr_variantGetInt(tr_variantListChild(ids, 0), &i));
top.type = 0;
err = tr_variantFromJson(&top, in, strlen(in));
- check(err != 0);
+ check_int(err, !=, 0);
check(!tr_variantIsDict(&top));
return 0;
char const* str;
int const err = tr_variantFromJson(&top, in, strlen(in));
- check(err == 0);
+ check_int(err, ==, 0);
check(tr_variantDictFindStr(&top, TR_KEY_errorString, &str, NULL));
check_str(str, ==, "torrent not registered with this tracker 6UHsVW'*C");
{
char const* uri;
tr_magnet_info* info;
- int const dec[] =
+ uint8_t const dec[] =
{
210, 53, 64, 16, 163, 202, 74, 222, 91, 116,
39, 187, 9, 58, 98, 163, 137, 159, 243, 129
"&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"
"&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile";
info = tr_magnetParse(uri);
- check(info != NULL);
+ check_ptr(info, !=, NULL);
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(info->webseedCount, ==, 1);
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)
- {
- check(info->hash[i] == dec[i]);
- }
+ check_mem(info->hash, ==, dec, 20);
tr_magnetFree(info);
info = NULL;
check_int(info->webseedCount, ==, 1);
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)
- {
- check(info->hash[i] == dec[i]);
- }
+ check_mem(info->hash, ==, dec, 20);
tr_magnetFree(info);
info = NULL;
/* have tr_makeMetaInfo() build the .torrent file */
torrent_file = tr_strdup_printf("%s.torrent", input_file);
tr_makeMetaInfo(builder, torrent_file, trackers, trackerCount, comment, isPrivate);
- check(isPrivate == builder->isPrivate);
+ check_bool(isPrivate, ==, builder->isPrivate);
check_str(builder->outputFile, ==, torrent_file);
check_str(builder->comment, ==, comment);
check_int(builder->trackerCount, ==, trackerCount);
/* call tr_makeMetaInfo() to build the .torrent file */
torrent_file = tr_strdup_printf("%s.torrent", top);
tr_makeMetaInfo(builder, torrent_file, trackers, trackerCount, comment, isPrivate);
- check(isPrivate == builder->isPrivate);
+ check_bool(isPrivate, ==, builder->isPrivate);
check_str(builder->outputFile, ==, torrent_file);
check_str(builder->comment, ==, comment);
check_int(builder->trackerCount, ==, trackerCount);
the test zero_torrent will be missing its first piece */
tor = libttest_zero_torrent_init(session);
libttest_zero_torrent_populate(tor, false);
- check(tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
+ check_uint(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_uint(tr_torrentStat(tor)->leftUntilDone, ==, tor->info.pieceSize);
*
*/
+#include <memory.h>
#include <stdio.h>
+
#include "transmission.h"
#include "peer-msgs.h"
#include "utils.h"
tr_piece_index_t pieces[] = { 1059, 431, 808, 1217, 287, 376, 1188, 353, 508 };
tr_piece_index_t buf[16];
- for (uint32_t i = 0; i < SHA_DIGEST_LENGTH; ++i)
- {
- infohash[i] = 0xaa;
- }
+ memset(infohash, 0xaa, SHA_DIGEST_LENGTH);
tr_address_from_string(&addr, "80.4.4.200");
numwant = 7;
numgot = tr_generateAllowedSet(buf, numwant, pieceCount, infohash, &addr);
- check(numgot == numwant);
-
- for (uint32_t i = 0; i < numgot; ++i)
- {
- check(buf[i] == pieces[i]);
- }
+ check_uint(numgot, ==, numwant);
+ check_mem(buf, ==, pieces, numgot);
numwant = 9;
numgot = tr_generateAllowedSet(buf, numwant, pieceCount, infohash, &addr);
- check(numgot == numwant);
-
- for (uint32_t i = 0; i < numgot; ++i)
- {
- check(buf[i] == pieces[i]);
- }
+ check_uint(numgot, ==, numwant);
+ check_mem(buf, ==, pieces, numgot);
#endif
str1 = tr_quark_get_string((tr_quark)i, &len1);
str2 = tr_quark_get_string((tr_quark)(i + 1), &len2);
- check(strcmp(str1, str2) < 0);
+ check_str(str1, <, str2);
}
tr_quark const q = tr_quark_new(NULL, TR_BAD_SIZE);
check(tor->info.files[0].is_renamed); /* confirm the file's 'renamed' flag is set */
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 */
+ check_str(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 */
tr_free(tmpstr);
libttest_sync();
loaded = tr_torrentLoadResume(tor, ~0, ctor);
check_str(tr_torrentName(tor), ==, "foobar");
- check((loaded & TR_FR_NAME) != 0);
+ check_uint((loaded & TR_FR_NAME), !=, 0);
/***
**** ...and rename it back again
tr_free(files[1].name);
tor->info.files[1].name = tr_strdup("gabba gabba hey");
loaded = tr_torrentLoadResume(tor, ~0, ctor);
- check((loaded & TR_FR_FILENAMES) != 0);
+ check_uint((loaded & TR_FR_FILENAMES), !=, 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");
/* remove the directory Felidae/Felinae/Felis/catus */
str = tr_torrentFindFile(tor, 1);
- check(str != NULL);
+ check_str(str, !=, NULL);
tr_sys_path_remove(str, NULL);
tr_free(str);
str = tr_torrentFindFile(tor, 2);
- check(str != NULL);
+ check_str(str, !=, NULL);
tr_sys_path_remove(str, NULL);
tmp = tr_sys_path_dirname(str, NULL);
tr_sys_path_remove(tmp, NULL);
tr_rpc_parse_list_str(&top, "6,7", TR_BAD_SIZE);
check(tr_variantIsList(&top));
- check(tr_variantListSize(&top) == 2);
+ check_uint(tr_variantListSize(&top), ==, 2);
check(tr_variantGetInt(tr_variantListChild(&top, 0), &i));
check_int(i, ==, 6);
check(tr_variantGetInt(tr_variantListChild(&top, 1), &i));
tr_rpc_parse_list_str(&top, "1,3-5", TR_BAD_SIZE);
check(tr_variantIsList(&top));
- check(tr_variantListSize(&top) == 4);
+ check_uint(tr_variantListSize(&top), ==, 4);
check(tr_variantGetInt(tr_variantListChild(&top, 0), &i));
check_int(i, ==, 1);
check(tr_variantGetInt(tr_variantListChild(&top, 1), &i));
session = libttest_session_init(NULL);
tor = libttest_zero_torrent_init(session);
- check(tor != NULL);
+ check_ptr(tor, !=, NULL);
tr_variantInitDict(&request, 1);
tr_variantDictAddStr(&request, TR_KEY_method, "session-get");
check(tr_variantIsDict(&response));
check(tr_variantDictFindDict(&response, TR_KEY_arguments, &args));
- check(tr_variantDictFind(args, TR_KEY_alt_speed_down) != NULL);
- check(tr_variantDictFind(args, TR_KEY_alt_speed_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_alt_speed_time_begin) != NULL);
- check(tr_variantDictFind(args, TR_KEY_alt_speed_time_day) != NULL);
- check(tr_variantDictFind(args, TR_KEY_alt_speed_time_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_alt_speed_time_end) != NULL);
- check(tr_variantDictFind(args, TR_KEY_alt_speed_up) != NULL);
- check(tr_variantDictFind(args, TR_KEY_blocklist_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_blocklist_size) != NULL);
- check(tr_variantDictFind(args, TR_KEY_blocklist_url) != NULL);
- check(tr_variantDictFind(args, TR_KEY_cache_size_mb) != NULL);
- check(tr_variantDictFind(args, TR_KEY_config_dir) != NULL);
- check(tr_variantDictFind(args, TR_KEY_dht_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_download_dir) != NULL);
- check(tr_variantDictFind(args, TR_KEY_download_dir_free_space) != NULL);
- check(tr_variantDictFind(args, TR_KEY_download_queue_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_download_queue_size) != NULL);
- check(tr_variantDictFind(args, TR_KEY_encryption) != NULL);
- check(tr_variantDictFind(args, TR_KEY_idle_seeding_limit) != NULL);
- check(tr_variantDictFind(args, TR_KEY_idle_seeding_limit_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_incomplete_dir) != NULL);
- check(tr_variantDictFind(args, TR_KEY_incomplete_dir_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_lpd_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_peer_limit_global) != NULL);
- check(tr_variantDictFind(args, TR_KEY_peer_limit_per_torrent) != NULL);
- check(tr_variantDictFind(args, TR_KEY_peer_port) != NULL);
- check(tr_variantDictFind(args, TR_KEY_peer_port_random_on_start) != NULL);
- check(tr_variantDictFind(args, TR_KEY_pex_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_port_forwarding_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_queue_stalled_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_queue_stalled_minutes) != NULL);
- check(tr_variantDictFind(args, TR_KEY_rename_partial_files) != NULL);
- check(tr_variantDictFind(args, TR_KEY_rpc_version) != NULL);
- check(tr_variantDictFind(args, TR_KEY_rpc_version_minimum) != NULL);
- check(tr_variantDictFind(args, TR_KEY_script_torrent_done_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_script_torrent_done_filename) != NULL);
- check(tr_variantDictFind(args, TR_KEY_seed_queue_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_seed_queue_size) != NULL);
- check(tr_variantDictFind(args, TR_KEY_seedRatioLimit) != NULL);
- check(tr_variantDictFind(args, TR_KEY_seedRatioLimited) != NULL);
- check(tr_variantDictFind(args, TR_KEY_speed_limit_down) != NULL);
- check(tr_variantDictFind(args, TR_KEY_speed_limit_down_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_speed_limit_up) != NULL);
- check(tr_variantDictFind(args, TR_KEY_speed_limit_up_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_start_added_torrents) != NULL);
- check(tr_variantDictFind(args, TR_KEY_trash_original_torrent_files) != NULL);
- check(tr_variantDictFind(args, TR_KEY_units) != NULL);
- check(tr_variantDictFind(args, TR_KEY_utp_enabled) != NULL);
- check(tr_variantDictFind(args, TR_KEY_version) != NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_down), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_begin), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_day), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_end), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_up), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_blocklist_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_blocklist_size), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_blocklist_url), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_cache_size_mb), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_config_dir), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_dht_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_download_dir), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_download_dir_free_space), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_download_queue_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_download_queue_size), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_encryption), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_idle_seeding_limit), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_idle_seeding_limit_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_incomplete_dir), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_incomplete_dir_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_lpd_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_peer_limit_global), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_peer_limit_per_torrent), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_peer_port), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_peer_port_random_on_start), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_pex_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_port_forwarding_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_queue_stalled_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_queue_stalled_minutes), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_rename_partial_files), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_rpc_version), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_rpc_version_minimum), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_script_torrent_done_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_script_torrent_done_filename), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_seed_queue_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_seed_queue_size), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_seedRatioLimit), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_seedRatioLimited), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_down), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_down_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_up), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_up_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_start_added_torrents), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_trash_original_torrent_files), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_units), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_utp_enabled), !=, NULL);
+ check_ptr(tr_variantDictFind(args, TR_KEY_version), !=, NULL);
tr_variantFree(&response);
/* cleanup */
tr_peerIdInit(peer_id);
- check(strlen((char*)peer_id) == PEER_ID_LEN);
- check(memcmp(peer_id, PEERID_PREFIX, 8) == 0);
+ check_uint(strlen((char*)peer_id), ==, PEER_ID_LEN);
+ check_mem(peer_id, ==, PEERID_PREFIX, 8);
for (int j = 8; j < PEER_ID_LEN; ++j)
{
val += strtoul(tmp, NULL, 36);
}
- check(val % 36 == 0);
+ check_int(val % 36, ==, 0);
}
return 0;
check(!tr_session_id_is_local("test"));
session_id = tr_session_id_new();
- check(session_id != NULL);
+ check_ptr(session_id, !=, NULL);
tr_timeUpdate(0);
session_id_str_1 = tr_session_id_get_current(session_id);
- check(session_id_str_1 != NULL);
- check(strlen(session_id_str_1) == 48);
+ check_str(session_id_str_1, !=, NULL);
+ check_uint(strlen(session_id_str_1), ==, 48);
session_id_str_1 = tr_strdup(session_id_str_1);
check(tr_session_id_is_local(session_id_str_1));
check(tr_session_id_is_local(session_id_str_1));
session_id_str_2 = tr_session_id_get_current(session_id);
- check(session_id_str_2 != NULL);
- check(strlen(session_id_str_2) == 48);
- check(strcmp(session_id_str_2, session_id_str_1) == 0);
+ check_str(session_id_str_2, !=, NULL);
+ check_uint(strlen(session_id_str_2), ==, 48);
+ check_str(session_id_str_2, ==, session_id_str_1);
tr_timeUpdate(60 * 60);
check(tr_session_id_is_local(session_id_str_1));
session_id_str_2 = tr_session_id_get_current(session_id);
- check(session_id_str_2 != NULL);
- check(strlen(session_id_str_2) == 48);
- check(strcmp(session_id_str_2, session_id_str_1) != 0);
+ check_str(session_id_str_2, !=, NULL);
+ check_uint(strlen(session_id_str_2), ==, 48);
+ check_str(session_id_str_2, !=, session_id_str_1);
session_id_str_2 = tr_strdup(session_id_str_2);
check(tr_session_id_is_local(session_id_str_2));
check(tr_session_id_is_local(session_id_str_1));
session_id_str_3 = tr_session_id_get_current(session_id);
- check(session_id_str_3 != NULL);
- check(strlen(session_id_str_3) == 48);
- check(strcmp(session_id_str_3, session_id_str_2) != 0);
- check(strcmp(session_id_str_3, session_id_str_1) != 0);
+ check_str(session_id_str_3, !=, NULL);
+ check_uint(strlen(session_id_str_3), ==, 48);
+ check_str(session_id_str_3, !=, session_id_str_2);
+ check_str(session_id_str_3, !=, session_id_str_1);
session_id_str_3 = tr_strdup(session_id_str_3);
check(tr_session_id_is_local(session_id_str_3));
check(!tr_session_id_is_local(session_id_str_2));
check(!tr_session_id_is_local(session_id_str_1));
- tr_free(session_id_str_3);
- tr_free(session_id_str_2);
- tr_free(session_id_str_1);
+ tr_free((char*)session_id_str_3);
+ tr_free((char*)session_id_str_2);
+ tr_free((char*)session_id_str_1);
return 0;
}
while ((c = tr_getopt("summary", argc, argv, options, &optarg)) != TR_OPT_DONE)
{
- check(n < expected_n);
+ check_int(n, <, expected_n);
check_int(c, ==, expected_c[n]);
check_str(optarg, ==, expected_optarg[n]);
++n;
/* strstrip */
in = tr_strdup(" test ");
out = tr_strstrip(in);
- check(in == out);
+ check_ptr(in, ==, out);
check_str(out, ==, "test");
tr_free(in);
/* strstrip */
in = tr_strdup(" test test ");
out = tr_strstrip(in);
- check(in == out);
+ check_ptr(in, ==, out);
check_str(out, ==, "test test");
tr_free(in);
/* strstrip */
in = tr_strdup("test");
out = tr_strstrip(in);
- check(in == out);
+ check_ptr(in, ==, out);
check_str(out, ==, "test");
tr_free(in);
/* this version is not utf-8 (but cp866) */
in = "\x92\xE0\xE3\xA4\xAD\xAE \xA1\xEB\xE2\xEC \x81\xAE\xA3\xAE\xAC";
out = tr_utf8clean(in, 17);
- check(out != NULL);
+ check_ptr(out, !=, NULL);
check(strlen(out) == 17 || strlen(out) == 33);
check(tr_utf8_validate(out, TR_BAD_SIZE, NULL));
tr_free(out);
/* same string, but utf-8 clean */
in = "Трудно быть Богом";
out = tr_utf8clean(in, TR_BAD_SIZE);
- check(out != NULL);
+ check_ptr(out, !=, NULL);
check(tr_utf8_validate(out, TR_BAD_SIZE, NULL));
check_str(out, ==, in);
tr_free(out);
in = "\xF4\x00\x81\x82";
out = tr_utf8clean(in, 4);
- check(out != NULL);
+ check_ptr(out, !=, NULL);
check(strlen(out) == 1 || strlen(out) == 2);
check(tr_utf8_validate(out, TR_BAD_SIZE, NULL));
tr_free(out);
in = "\xF4\x33\x81\x82";
out = tr_utf8clean(in, 4);
- check(out != NULL);
+ check_ptr(out, !=, NULL);
check(strlen(out) == 4 || strlen(out) == 7);
check(tr_utf8_validate(out, TR_BAD_SIZE, NULL));
tr_free(out);
tr_free(numbers);
numbers = tr_parseNumberRange("1-5,3-7,2-6", TR_BAD_SIZE, &count);
- check(count == 7);
- check(numbers != NULL);
+ check_int(count, ==, 7);
+ check_ptr(numbers, !=, NULL);
for (int i = 0; i < count; ++i)
{
numbers = tr_parseNumberRange("1-Hello", TR_BAD_SIZE, &count);
check_int(count, ==, 0);
- check(numbers == NULL);
+ check_ptr(numbers, ==, NULL);
numbers = tr_parseNumberRange("1-", TR_BAD_SIZE, &count);
check_int(count, ==, 0);
- check(numbers == NULL);
+ check_ptr(numbers, ==, NULL);
numbers = tr_parseNumberRange("Hello", TR_BAD_SIZE, &count);
check_int(count, ==, 0);
- check(numbers == NULL);
+ check_ptr(numbers, ==, NULL);
return 0;
}
}
}
- check(highest_low <= lowest_high);
+ check_int(highest_low, <=, lowest_high);
return 0;
}
char const haystack[12] = "abcabcabcabc";
char const needle[3] = "cab";
- check(tr_memmem(haystack, sizeof(haystack), haystack, sizeof(haystack)) == haystack);
- check(tr_memmem(haystack, sizeof(haystack), needle, sizeof(needle)) == haystack + 2);
- check(tr_memmem(needle, sizeof(needle), haystack, sizeof(haystack)) == NULL);
+ check_ptr(tr_memmem(haystack, sizeof(haystack), haystack, sizeof(haystack)), ==, haystack);
+ check_ptr(tr_memmem(haystack, sizeof(haystack), needle, sizeof(needle)), ==, haystack + 2);
+ check_ptr(tr_memmem(needle, sizeof(needle), haystack, sizeof(haystack)), ==, NULL);
return 0;
}
x = tr_env_get_int(test_key, 123);
check_int(x, ==, 123);
s = tr_env_get_string(test_key, NULL);
- check(s == NULL);
+ check_str(s, ==, NULL);
s = tr_env_get_string(test_key, "a");
check_str(s, ==, "a");
tr_free(s);
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int(err, ==, 0);
check_int(val, ==, 64);
- check(buf + 4 == end);
+ check_ptr(end, ==, buf + 4);
/* missing 'e' */
end = NULL;
err = tr_bencParseInt(buf, buf + 3, &end, &val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 888);
- check(end == NULL);
+ check_ptr(end, ==, NULL);
/* empty buffer */
err = tr_bencParseInt(buf, buf + 0, &end, &val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 888);
- check(end == NULL);
+ check_ptr(end, ==, NULL);
/* bad number */
tr_snprintf((char*)buf, sizeof(buf), "i6z4e");
err = tr_bencParseInt(buf, buf + 5, &end, &val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 888);
- check(end == NULL);
+ check_ptr(end, ==, NULL);
/* negative number */
tr_snprintf((char*)buf, sizeof(buf), "i-3e");
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int(err, ==, 0);
check_int(val, ==, -3);
- check(buf + 4 == end);
+ check_ptr(end, ==, buf + 4);
/* zero */
tr_snprintf((char*)buf, sizeof(buf), "i0e");
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int(err, ==, 0);
check_int(val, ==, 0);
- check(buf + 3 == end);
+ check_ptr(end, ==, buf + 3);
/* no leading zeroes allowed */
val = 0;
err = tr_bencParseInt(buf, buf + 4, &end, &val);
check_int(err, ==, EILSEQ);
check_int(val, ==, 0);
- check(NULL == end);
+ check_ptr(end, ==, NULL);
return 0;
}
err = tr_bencParseStr(buf, buf + n, &end, &str, &len);
check_int(err, ==, EILSEQ);
check_uint(len, ==, 0);
- check(str == NULL);
- check(end == NULL);
- check(len == 0);
+ check_ptr(str, ==, NULL);
+ check_ptr(end, ==, NULL);
/* good string */
n = tr_snprintf((char*)buf, sizeof(buf), "4:boat");
err = tr_bencParseStr(buf, buf + n, &end, &str, &len);
check_int(err, ==, 0);
check_uint(len, ==, 4);
- check(strncmp((char const*)str, "boat", len) == 0);
- check(end == buf + 6);
+ check_mem(str, ==, "boat", len);
+ check_ptr(end, ==, buf + 6);
str = NULL;
end = NULL;
len = 0;
err = tr_bencParseStr(buf, buf + (n - 1), &end, &str, &len);
check_int(err, ==, EILSEQ);
check_uint(len, ==, 0);
- check(str == NULL);
- check(end == NULL);
- check(len == 0);
+ check_ptr(str, ==, NULL);
+ check_ptr(end, ==, NULL);
/* empty string */
n = tr_snprintf((char*)buf, sizeof(buf), "0:");
err = tr_bencParseStr(buf, buf + n, &end, &str, &len);
check_int(err, ==, 0);
check_uint(len, ==, 0);
- check(*str == '\0');
- check(end == buf + 2);
+ check_uint(*str, ==, '\0');
+ check_ptr(end, ==, buf + 2);
str = NULL;
end = NULL;
len = 0;
err = tr_bencParseStr(buf, buf + n, &end, &str, &len);
check_int(err, ==, 0);
check_uint(len, ==, 3);
- check(strncmp((char const*)str, "boa", len) == 0);
- check(end == buf + 5);
+ check_mem(str, ==, "boa", len);
+ check_ptr(end, ==, buf + 5);
str = NULL;
end = NULL;
len = 0;
if (!isGood)
{
- check(err != 0);
+ check_int(err, !=, 0);
}
else
{
- check(err == 0);
+ check_int(err, ==, 0);
#if 0
fprintf(stderr, "in: [%s]\n", str);
fprintf(stderr, "out:\n%s", tr_variantToStr(&val, TR_VARIANT_FMT_JSON, NULL));
#endif
- check(end == str + len);
+ check_ptr(end, ==, str + len);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &savedLen);
check_str(saved, ==, str);
check_uint(savedLen, ==, len);
tr_snprintf((char*)buf, sizeof(buf), "i64e");
err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end);
- check(err == 0);
+ check_int(err, ==, 0);
check(tr_variantGetInt(&val, &i));
check_int(i, ==, 64);
- check(end == buf + 4);
+ check_ptr(end, ==, buf + 4);
tr_variantFree(&val);
tr_snprintf((char*)buf, sizeof(buf), "li64ei32ei16ee");
err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end);
- check(err == 0);
- check(end == buf + strlen((char*)buf));
- check(val.val.l.count == 3);
+ check_int(err, ==, 0);
+ check_ptr(end, ==, buf + strlen((char*)buf));
+ check_uint(val.val.l.count, ==, 3);
check(tr_variantGetInt(&val.val.l.vals[0], &i));
check_int(i, ==, 64);
check(tr_variantGetInt(&val.val.l.vals[1], &i));
end = NULL;
tr_snprintf((char*)buf, sizeof(buf), "lllee");
err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end);
- check(err != 0);
- check(end == NULL);
+ check_int(err, !=, 0);
+ check_ptr(end, ==, NULL);
end = NULL;
tr_snprintf((char*)buf, sizeof(buf), "le");
err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end);
- check(err == 0);
- check(end == buf + 2);
+ check_int(err, ==, 0);
+ check_ptr(end, ==, buf + 2);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str(saved, ==, "le");
tr_free(saved);
end = NULL;
tr_snprintf((char*)buf, sizeof(buf), "lld1:bi32e1:ai64eeee");
err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end);
- check(err == 0);
- check(end == buf + strlen((char const*)buf));
- check((child = tr_variantListChild(&val, 0)) != NULL);
- check((child2 = tr_variantListChild(child, 0)) != NULL);
+ check_int(err, ==, 0);
+ check_ptr(end, ==, buf + strlen((char const*)buf));
+ check_ptr((child = tr_variantListChild(&val, 0)), !=, NULL);
+ check_ptr((child2 = tr_variantListChild(child, 0)), !=, NULL);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str(saved, ==, "lld1:ai64e1:bi32eeee");
tr_free(saved);
end = NULL;
tr_snprintf((char*)buf, sizeof(buf), "leee");
err = tr_variantFromBencFull(&val, buf, sizeof(buf), NULL, &end);
- check(err == 0);
- check(end == buf + 2);
+ check_int(err, ==, 0);
+ check_ptr(end, ==, buf + 2);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str(saved, ==, "le");
tr_free(saved);
end = NULL;
tr_snprintf((char*)buf, sizeof(buf), "l1:a1:b1:c");
err = tr_variantFromBencFull(&val, buf, strlen(buf), NULL, &end);
- check(err != 0);
+ check_int(err, !=, 0);
/* incomplete string */
end = NULL;
tr_snprintf((char*)buf, sizeof(buf), "1:");
err = tr_variantFromBencFull(&val, buf, strlen(buf), NULL, &end);
- check(err != 0);
+ check_int(err, !=, 0);
return 0;
}
in[depth * 2] = '\0';
err = tr_variantFromBencFull(&val, in, depth * 2, NULL, &end);
check_int(err, ==, 0);
- check(end == in + depth * 2);
+ check_ptr(end, ==, in + depth * 2);
saved = tr_variantToStr(&val, TR_VARIANT_FMT_BENC, &len);
check_str(saved, ==, in);
tr_free(in);
check(tr_variantDictFindBool(&top, key4, &boolVal));
check(boolVal);
check(tr_variantDictFindInt(&top, key1, &intVal));
- check(intVal == 0);
+ check_int(intVal, ==, 0);
check(tr_variantDictFindInt(&top, key2, &intVal));
- check(intVal == 0);
+ check_int(intVal, ==, 0);
check(tr_variantDictFindInt(&top, key3, &intVal));
- check(intVal != 0);
+ check_int(intVal, !=, 0);
check(tr_variantDictFindInt(&top, key4, &intVal));
- check(intVal != 0);
+ check_int(intVal, !=, 0);
tr_variantFree(&top);
return 0;
benc = tr_variantToStr(&top, TR_VARIANT_FMT_BENC, &len);
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_int(tr_variantFromBencFull(&top2, benc, len, NULL, &end), ==, 0);
+ check_ptr(end, ==, benc + len);
check(tr_variantIsDict(&top2));
check(tr_variantDictFindInt(&top, key_int, &intVal));
check_int(intVal, ==, 1234);
check(tr_variantDictFindBool(&top, key_bool, &boolVal));
- check(boolVal == true);
+ check(boolVal);
check(tr_variantDictFindStr(&top, key_str, &strVal, &strLen));
check_uint(strLen, ==, 16);
check_str(strVal, ==, "this-is-a-string");
ev_base = event_base_new();
wd = create_watchdir(test_dir, &callback, NULL, ev_base);
- check(wd != NULL);
+ check_ptr(wd, !=, NULL);
check(tr_sys_path_is_same(test_dir, tr_watchdir_get_path(wd), NULL));
process_events();
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);
tr_watchdir_t wd = create_watchdir(test_dir, &callback, &wd_data, ev_base);
- check(wd != NULL);
+ check_ptr(wd, !=, NULL);
process_events();
check_ptr(wd_data.dir, ==, NULL);
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);
tr_watchdir_t wd = create_watchdir(test_dir, &callback, &wd_data, ev_base);
- check(wd != NULL);
+ check_ptr(wd, !=, NULL);
process_events();
check_ptr(wd_data.dir, ==, wd);
reset_callback_data(&wd_data, TR_WATCHDIR_ACCEPT);
wd = create_watchdir(test_dir, &callback, &wd_data, ev_base);
- check(wd != NULL);
+ check_ptr(wd, !=, NULL);
process_events();
check_ptr(wd_data.dir, ==, NULL);
reset_callback_data(&wd1_data, TR_WATCHDIR_ACCEPT);
wd1 = create_watchdir(dir1, &callback, &wd1_data, ev_base);
- check(wd1 != NULL);
+ check_ptr(wd1, !=, NULL);
reset_callback_data(&wd2_data, TR_WATCHDIR_ACCEPT);
wd2 = create_watchdir(dir2, &callback, &wd2_data, ev_base);
- check(wd2 != NULL);
+ check_ptr(wd2, !=, NULL);
process_events();
check_ptr(wd1_data.dir, ==, NULL);
reset_callback_data(&wd_data, TR_WATCHDIR_RETRY);
wd = create_watchdir(test_dir, &callback, &wd_data, ev_base);
- check(wd != NULL);
+ check_ptr(wd, !=, NULL);
process_events();
check_ptr(wd_data.dir, ==, NULL);