refactor: re-enable some clang tidy warnings in tests (#4170)

This commit is contained in:
Charles Kerr 2022-11-14 14:16:29 -06:00 committed by GitHub
parent bde1359d5d
commit 8df26dd2fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 158 additions and 229 deletions

View File

@ -3,59 +3,28 @@
# cleaned up yet. Pull requests welcomed.
Checks: >
bugprone-*,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
-bugprone-unchecked-optional-access,
cert-*,
-cert-dcl50-cpp,
-cert-err33-c,
-cert-err58-cpp,
clang-analyzer-optin*,
-clang-diagnostic-c++98*,
-clang-diagnostic-global-constructors,
-clang-diagnostic-missing-prototypes,
-clang-diagnostic-nonportable-system-include-path,
-clang-diagnostic-old-style-cast,
-clang-diagnostic-shorten-64-to-32,
-clang-diagnostic-sign-compare,
-clang-diagnostic-sign-conversion,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-const-cast,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-static-cast-downcast,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-special-member-functions,
google-readability-*,
-google-readability-casting,
google-runtime-operator,
hicpp-*,
-hicpp-multiway-paths-covered,
-hicpp-no-array-decay,
-hicpp-signed-bitwise,
-hicpp-special-member-functions,
-hicpp-vararg,
misc-*,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-concat-nested-namespaces,
-modernize-raw-string-literal,
-modernize-return-braced-init-list,
-modernize-use-trailing-return-type,
performance-*,
-performance-no-int-to-ptr,
readability-*,
-readability-function-cognitive-complexity,
-readability-identifier-length,

View File

@ -90,7 +90,7 @@ protected:
static void expectEqual(tr_scrape_request const& expected, std::vector<tr_sha1_digest_t> const& actual)
{
EXPECT_EQ(expected.info_hash_count, std::size(actual));
for (size_t i = 0; i < std::min(size_t(expected.info_hash_count), std::size(actual)); ++i)
for (size_t i = 0; i < std::min(static_cast<size_t>(expected.info_hash_count), std::size(actual)); ++i)
{
EXPECT_EQ(expected.info_hash[i], actual[i]);
}

View File

@ -31,7 +31,7 @@ TEST(Bitfield, count)
}
int begin = tr_rand_int_weak(bit_count);
int end;
int end = 0;
do
{
end = tr_rand_int_weak(bit_count);

View File

@ -15,13 +15,13 @@ using BlockInfoTest = ::testing::Test;
TEST_F(BlockInfoTest, fieldsAreSet)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024 } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 4U };
static auto constexpr TotalSize = PieceSize * PieceCount;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 4;
uint64_t constexpr TotalSize = PieceSize * PieceCount;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
EXPECT_EQ(ExpectedBlockSize, info.blockSize(info.blockCount() - 1));
@ -40,13 +40,13 @@ TEST_F(BlockInfoTest, fieldsAreSet)
TEST_F(BlockInfoTest, handlesOddSize)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024U } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 5U };
static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 5;
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
EXPECT_EQ(1U, info.blockSize(info.blockCount() - 1));
@ -58,13 +58,13 @@ TEST_F(BlockInfoTest, handlesOddSize)
TEST_F(BlockInfoTest, pieceSize)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024U } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 5U };
static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 5;
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
EXPECT_EQ(PieceSize, info.pieceSize(info.pieceCount() - 2));
@ -73,13 +73,13 @@ TEST_F(BlockInfoTest, pieceSize)
TEST_F(BlockInfoTest, blockSize)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024U } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 5U };
static auto constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 5;
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
EXPECT_EQ(ExpectedBlockSize, info.blockSize(info.blockCount() - 2));
@ -88,13 +88,13 @@ TEST_F(BlockInfoTest, blockSize)
TEST_F(BlockInfoTest, blockSpanForPiece)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024U } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 5U };
static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 5;
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
EXPECT_EQ(0U, info.blockSpanForPiece(0).begin);
@ -112,13 +112,13 @@ TEST_F(BlockInfoTest, blockSpanForPiece)
TEST_F(BlockInfoTest, blockLoc)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024U } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 5U };
static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 5;
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
// begin
@ -144,13 +144,13 @@ TEST_F(BlockInfoTest, blockLoc)
TEST_F(BlockInfoTest, pieceLoc)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024U } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 5U };
static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 5;
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
// begin
@ -192,13 +192,13 @@ TEST_F(BlockInfoTest, pieceLoc)
TEST_F(BlockInfoTest, byteLoc)
{
auto info = tr_block_info{};
static auto constexpr ExpectedBlockSize = uint64_t{ 1024U } * 16U;
static auto constexpr ExpectedBlocksPerPiece = uint64_t{ 4U };
static auto constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
static auto constexpr PieceCount = uint64_t{ 5U };
static auto constexpr TotalSize = PieceSize * (PieceCount - 1U) + 1U;
uint64_t constexpr ExpectedBlockSize = 1024 * 16;
uint64_t constexpr ExpectedBlocksPerPiece = 4;
uint64_t constexpr PieceSize = ExpectedBlockSize * ExpectedBlocksPerPiece;
uint64_t constexpr PieceCount = 5;
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
auto info = tr_block_info{};
info.initSizes(TotalSize, PieceSize);
auto loc = info.byteLoc(0);

View File

@ -17,10 +17,7 @@
#include "test-fixtures.h"
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
class BlocklistTest : public SessionTest
@ -126,6 +123,4 @@ TEST_F(BlocklistTest, updating)
// cleanup
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -31,7 +31,7 @@ struct TestTorrent : public tr_completion::torrent_view
}
};
auto constexpr BlockSize = uint64_t{ 16 * 1024 };
auto constexpr BlockSize = uint64_t{ 16 } * 1024U;
} // namespace
@ -278,7 +278,7 @@ TEST_F(CompletionTest, leftUntilDone)
// check that dnd-flagging a piece we DON'T already have adjusts by block_info.pieceSize()
torrent.dnd_pieces.insert(1);
completion.invalidateSizeWhenDone();
EXPECT_EQ(block_info.totalSize() - block_info.pieceSize() * 2, completion.leftUntilDone());
EXPECT_EQ(block_info.totalSize() - block_info.pieceSize() * uint64_t{ 2U }, completion.leftUntilDone());
torrent.dnd_pieces.clear();
completion.invalidateSizeWhenDone();
@ -323,7 +323,7 @@ TEST_F(CompletionTest, sizeWhenDone)
torrent.dnd_pieces.insert(i);
}
completion.invalidateSizeWhenDone();
EXPECT_EQ(block_info.totalSize() - 16 * block_info.pieceSize(), completion.sizeWhenDone());
EXPECT_EQ(block_info.totalSize() - uint64_t{ 16U } * block_info.pieceSize(), completion.sizeWhenDone());
}
TEST_F(CompletionTest, createPieceBitfield)
@ -349,7 +349,7 @@ TEST_F(CompletionTest, createPieceBitfield)
// serialize it to a raw bitfield, read it back into a bitfield,
// and test that the new bitfield matches
auto const pieces_raw_bitfield = completion.createPieceBitfield();
tr_bitfield pieces{ size_t(block_info.pieceCount()) };
tr_bitfield pieces{ size_t{ block_info.pieceCount() } };
pieces.setRaw(std::data(pieces_raw_bitfield), std::size(pieces_raw_bitfield));
for (uint64_t i = 0; i < block_info.pieceCount(); ++i)
{

View File

@ -13,10 +13,7 @@
#include "test-fixtures.h"
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
class CopyTest : public SandboxedTest
@ -86,6 +83,4 @@ TEST_F(CopyTest, copy)
testImpl(filename1, filename2, random_file_length);
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -142,12 +142,12 @@ TEST(Crypto, ssha1)
std::string_view ssha1;
};
auto constexpr Tests = std::array<LocalTest, 2>{ {
static auto constexpr Tests = std::array<LocalTest, 2>{ {
{ "test"sv, "{15ad0621b259a84d24dcd4e75b09004e98a3627bAMbyRHJy"sv },
{ "QNY)(*#$B)!_X$B !_B#($^!)*&$%CV!#)&$C!@$(P*)"sv, "{10e2d7acbb104d970514a147cd16d51dfa40fb3c0OSwJtOL"sv },
} };
auto constexpr HashCount = size_t{ 4 * 1024 };
static auto constexpr HashCount = size_t{ 4U } * 1024U;
for (auto const& [plain_text, ssha1] : Tests)
{
@ -266,14 +266,14 @@ TEST(Crypto, base64)
auto buf = std::string{};
for (size_t j = 0; j < i; ++j)
{
buf += char(tr_rand_int_weak(256));
buf += static_cast<char>(tr_rand_int_weak(256));
}
EXPECT_EQ(buf, tr_base64_decode(tr_base64_encode(buf)));
buf = std::string{};
for (size_t j = 0; j < i; ++j)
{
buf += char(1 + tr_rand_int_weak(255));
buf += static_cast<char>(1 + tr_rand_int_weak(255));
}
EXPECT_EQ(buf, tr_base64_decode(tr_base64_encode(buf)));
}

View File

@ -39,10 +39,7 @@
using namespace std::literals;
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
class FileTest : public SessionTest
@ -113,7 +110,7 @@ protected:
slash_pos = p + strlen(p) - 1;
}
auto const path_part = std::string{ path, size_t(slash_pos - path + 1) };
auto const path_part = std::string{ path, static_cast<size_t>(slash_pos - path + 1) };
auto const info = tr_sys_path_get_info(path_part, TR_SYS_PATH_NO_FOLLOW);
if (!info || (!info->isFile() && !info->isFolder()))
{
@ -178,9 +175,14 @@ protected:
EXPECT_NE(TR_BAD_SYS_DIR, dd);
EXPECT_EQ(nullptr, err) << *err;
char const* name;
while ((name = tr_sys_dir_read_name(dd, &err)) != nullptr)
for (;;)
{
char const* name = tr_sys_dir_read_name(dd, &err);
if (name == nullptr)
{
break;
}
EXPECT_EQ(nullptr, err) << *err;
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
@ -295,7 +297,7 @@ TEST_F(FileTest, getInfo)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run symlink tests\n", __FUNCTION__);
}
}
@ -394,7 +396,7 @@ TEST_F(FileTest, pathExists)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run symlink tests\n", __FUNCTION__);
}
}
@ -591,7 +593,7 @@ TEST_F(FileTest, pathIsSame)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run symlink tests\n", __FUNCTION__);
}
path3.assign(test_dir, "/c"sv);
@ -631,7 +633,7 @@ TEST_F(FileTest, pathIsSame)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run hardlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run symlink tests\n", __FUNCTION__);
}
if (createSymlink(path2, path1, false) && createHardlink(path3, path1))
@ -641,7 +643,7 @@ TEST_F(FileTest, pathIsSame)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run combined symlink and hardlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run combined symlink and hardlink tests\n", __FUNCTION__);
}
tr_sys_path_remove(path3);
@ -678,7 +680,7 @@ TEST_F(FileTest, pathResolve)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run symlink tests\n", __FUNCTION__);
}
tr_sys_path_remove(path2);
@ -948,7 +950,7 @@ TEST_F(FileTest, pathRename)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run symlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run symlink tests\n", __FUNCTION__);
}
if (createHardlink(path2, path1))
@ -969,7 +971,7 @@ TEST_F(FileTest, pathRename)
}
else
{
fprintf(stderr, "WARNING: [%s] unable to run hardlink tests\n", __FUNCTION__);
fmt::print(stderr, "WARNING: [{:s}] unable to run hardlink tests\n", __FUNCTION__);
}
tr_sys_path_remove(path1);
@ -1237,7 +1239,12 @@ TEST_F(FileTest, filePreallocate)
else
{
EXPECT_NE(nullptr, err);
fprintf(stderr, "WARNING: [%s] unable to preallocate file (full): %s (%d)\n", __FUNCTION__, err->message, err->code);
fmt::print(
stderr,
"WARNING: [{:s}] unable to preallocate file (full): {:s} ({:d})\n",
__FUNCTION__,
err->message,
err->code);
tr_error_clear(&err);
}
@ -1247,7 +1254,7 @@ TEST_F(FileTest, filePreallocate)
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0600);
prealloc_size = 500 * 1024 * 1024;
prealloc_size = size_t{ 500U } * 1024U * 1024U;
if (tr_sys_file_preallocate(fd, prealloc_size, TR_SYS_FILE_PREALLOC_SPARSE, &err))
{
EXPECT_EQ(nullptr, err) << *err;
@ -1258,7 +1265,12 @@ TEST_F(FileTest, filePreallocate)
else
{
EXPECT_NE(nullptr, err) << *err;
fprintf(stderr, "WARNING: [%s] unable to preallocate file (sparse): %s (%d)\n", __FUNCTION__, err->message, err->code);
fmt::print(
stderr,
"WARNING: [{:s}] unable to preallocate file (sparse): {:s} ({:d})\n",
__FUNCTION__,
err->message,
err->code);
tr_error_clear(&err);
}
@ -1341,8 +1353,8 @@ TEST_F(FileTest, dirRead)
auto const path1 = tr_pathbuf{ test_dir, "/a"sv };
auto const path2 = tr_pathbuf{ test_dir, "/b"sv };
bool have1;
bool have2;
auto have1 = bool{};
auto have2 = bool{};
testDirReadImpl(test_dir, &have1, &have2);
EXPECT_FALSE(have1);
EXPECT_FALSE(have2);
@ -1403,6 +1415,4 @@ TEST_F(FileTest, dirOpen)
EXPECT_EQ(nullptr, err) << *err;
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -39,8 +39,8 @@ protected:
auto n = int{};
tr_optind = 1;
int c;
char const* argstr;
auto c = int{};
char const* argstr = nullptr;
while ((c = tr_getopt("summary", argc, argv, Options.data(), &argstr)) != TR_OPT_DONE)
{
EXPECT_LT(n, expected_n);

View File

@ -27,9 +27,7 @@ using namespace std::literals;
#define LOCAL_SOCKETPAIR_AF AF_UNIX
#endif
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
auto constexpr MaxWaitMsec = int{ 5000 };
@ -428,5 +426,4 @@ TEST_F(HandshakeTest, outgoingEncrypted)
evutil_closesocket(sock);
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -142,7 +142,7 @@ TEST_P(JSONTest, test1)
EXPECT_TRUE(tr_variantFromBuf(&top, TR_VARIANT_PARSE_JSON | TR_VARIANT_PARSE_INPLACE, in));
auto sv = std::string_view{};
int64_t i;
auto i = int64_t{};
EXPECT_TRUE(tr_variantIsDict(&top));
auto* headers = tr_variantDictFind(&top, tr_quark_new("headers"sv));
EXPECT_NE(nullptr, headers);

View File

@ -19,9 +19,7 @@
using namespace std::literals;
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
using LpdTest = SessionTest;
@ -37,8 +35,6 @@ public:
{
}
~MyMediator() override = default;
[[nodiscard]] tr_port port() const override
{
return port_;
@ -208,5 +204,4 @@ TEST_F(LpdTest, DoesNotReannounceTooSoon)
}
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -17,11 +17,11 @@ using namespace std::literals;
TEST(MagnetMetainfo, magnetParse)
{
auto constexpr ExpectedHash = tr_sha1_digest_t{ std::byte(210), std::byte(53), std::byte(64), std::byte(16),
std::byte(163), std::byte(202), std::byte(74), std::byte(222),
std::byte(91), std::byte(116), std::byte(39), std::byte(187),
std::byte(9), std::byte(58), std::byte(98), std::byte(163),
std::byte(137), std::byte(159), std::byte(243), std::byte(129) };
auto constexpr ExpectedHash = tr_sha1_digest_t{ std::byte{ 210 }, std::byte{ 53 }, std::byte{ 64 }, std::byte{ 16 },
std::byte{ 163 }, std::byte{ 202 }, std::byte{ 74 }, std::byte{ 222 },
std::byte{ 91 }, std::byte{ 116 }, std::byte{ 39 }, std::byte{ 187 },
std::byte{ 9 }, std::byte{ 58 }, std::byte{ 98 }, std::byte{ 163 },
std::byte{ 137 }, std::byte{ 159 }, std::byte{ 243 }, std::byte{ 129 } };
auto constexpr UriHex =
"magnet:?xt=urn:btih:"

View File

@ -26,10 +26,7 @@
using namespace std::literals;
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
class MakemetaTest : public SandboxedTest
@ -219,6 +216,4 @@ TEST_F(MakemetaTest, singleFile)
testBuilder(builder);
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -22,10 +22,7 @@
using namespace std::literals;
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
auto constexpr MaxWaitMsec = 5000;
@ -190,6 +187,4 @@ TEST_F(MoveTest, setLocation)
tr_torrentRemove(tor, true, nullptr, nullptr);
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -30,7 +30,7 @@ TEST_F(PeerMgrActiveRequestsTest, requestsAreNotAddedTwice)
auto const block = tr_block_index_t{ 100 };
auto const peer = static_cast<tr_peer*>(nullptr);
auto const when = time_t(0);
auto const when = time_t{};
EXPECT_TRUE(requests.add(block, peer, when));
EXPECT_FALSE(requests.add(block, peer, when));
EXPECT_FALSE(requests.add(block, peer, when));
@ -62,7 +62,7 @@ TEST_F(PeerMgrActiveRequestsTest, requestsAreRemoved)
auto const block = tr_block_index_t{ 100 };
auto const peer = static_cast<tr_peer*>(nullptr);
auto const when = time_t(0);
auto const when = time_t{};
EXPECT_TRUE(requests.add(block, peer, when));
EXPECT_EQ(1U, requests.count(block));
@ -86,7 +86,7 @@ TEST_F(PeerMgrActiveRequestsTest, peersAreRemoved)
auto const block = tr_block_index_t{ 100 };
auto const peer = static_cast<tr_peer*>(nullptr);
auto const when = time_t(0);
auto const when = time_t{};
// setup: add a request
EXPECT_TRUE(requests.add(block, peer, when));

View File

@ -18,7 +18,7 @@ protected:
template<typename T>
std::string quarkGetString(T i)
{
return std::string{ tr_quark_get_string_view(tr_quark(i)) };
return std::string{ tr_quark_get_string_view(tr_quark{ i }) };
}
};

View File

@ -22,10 +22,7 @@
using namespace std::literals;
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
class RenameTest : public SessionTest
@ -435,7 +432,7 @@ TEST_F(RenameTest, partialFile)
auto constexpr PieceCount = uint32_t{ 33 };
auto constexpr PieceSize = uint32_t{ 32768 };
auto constexpr Length = std::array<uint32_t, 3>{ 1048576, 4096, 512 };
auto constexpr TotalSize = uint64_t(Length[0]) + Length[1] + Length[2];
auto constexpr TotalSize = uint64_t{ Length[0] } + Length[1] + Length[2];
/***
**** create our test torrent with an incomplete .part file
@ -484,6 +481,4 @@ TEST_F(RenameTest, partialFile)
torrentRemoveAndWait(tor, 0);
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -17,17 +17,14 @@
using namespace std::literals;
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
using RpcTest = SessionTest;
TEST_F(RpcTest, list)
{
int64_t i;
auto i = int64_t{};
auto sv = std::string_view{};
tr_variant top;
@ -89,7 +86,7 @@ TEST_F(RpcTest, sessionGet)
tr_variantClear(&request);
EXPECT_TRUE(tr_variantIsDict(&response));
tr_variant* args;
tr_variant* args = nullptr;
EXPECT_TRUE(tr_variantDictFindDict(&response, TR_KEY_arguments, &args));
// what we expected
@ -157,9 +154,9 @@ TEST_F(RpcTest, sessionGet)
// what we got
std::set<tr_quark> actual_keys;
tr_quark key;
tr_variant* val;
size_t n = 0;
auto key = tr_quark{};
tr_variant* val = nullptr;
auto n = size_t{};
while ((tr_variantDictChild(args, n++, &key, &val)))
{
actual_keys.insert(key);
@ -188,6 +185,4 @@ TEST_F(RpcTest, sessionGet)
tr_torrentRemove(tor, false, nullptr, nullptr);
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -25,8 +25,6 @@ protected:
class MockMediator final : public tr_session_alt_speeds::Mediator
{
public:
~MockMediator() override = default;
void isActiveChanged(bool is_active, ChangeReason reason) override
{
changelog_.emplace_back(is_active, reason, time());

View File

@ -252,7 +252,7 @@ TEST_F(SessionTest, sessionId)
EXPECT_TRUE(tr_session_id::isLocal(session_id_str_2));
EXPECT_TRUE(tr_session_id::isLocal(session_id_str_1));
current_time_mock::set(3600U * 2U);
current_time_mock::set(7200U);
EXPECT_TRUE(tr_session_id::isLocal(session_id_str_2));
EXPECT_TRUE(tr_session_id::isLocal(session_id_str_1));
@ -265,7 +265,7 @@ TEST_F(SessionTest, sessionId)
EXPECT_TRUE(tr_session_id::isLocal(session_id_str_2));
EXPECT_FALSE(tr_session_id::isLocal(session_id_str_1));
current_time_mock::set(60U * 60U * 10U);
current_time_mock::set(36000U);
EXPECT_TRUE(tr_session_id::isLocal(session_id_str_3));
EXPECT_TRUE(tr_session_id::isLocal(session_id_str_2));
EXPECT_FALSE(tr_session_id::isLocal(session_id_str_1));

View File

@ -24,10 +24,7 @@
#define setenv(key, value, unused) SetEnvironmentVariableA(key, value)
#endif
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
std::string getTestProgramPath(std::string const& filename)
@ -296,6 +293,4 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values( //
getTestProgramPath("subprocess-test"))));
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -15,9 +15,7 @@
#include "test-fixtures.h"
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
using TorrentMagnetTest = SessionTest;
@ -55,5 +53,4 @@ TEST_F(TorrentMagnetTest, getMetadataPiece)
EXPECT_EQ(tor->pieceHash(0), torrent_metainfo.pieceHash(0));
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -19,9 +19,7 @@
using namespace std::literals;
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
using TorrentMetainfoTest = SessionTest;
@ -261,5 +259,4 @@ TEST_F(TorrentMetainfoTest, parseBencOOBWrite)
EXPECT_FALSE(tm.parseBenc(tr_base64_decode("ZGg0OmluZm9kNjpwaWVjZXMzOkFpzQ==")));
}
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test

View File

@ -5,6 +5,7 @@
#include <set>
#include <string_view>
#include <vector>
#include "transmission.h"
@ -20,10 +21,13 @@ using TorrentsTest = ::testing::Test;
TEST_F(TorrentsTest, simpleTests)
{
auto constexpr* const TorrentFile = LIBTRANSMISSION_TEST_ASSETS_DIR "/Android-x86 8.1 r6 iso.torrent";
auto owned = std::vector<std::unique_ptr<tr_torrent>>{};
auto tm = tr_torrent_metainfo{};
EXPECT_TRUE(tm.parseTorrentFile(TorrentFile));
auto* tor = new tr_torrent(std::move(tm));
EXPECT_NE(nullptr, tor);
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
auto* const tor = owned.back().get();
auto torrents = tr_torrents{};
EXPECT_TRUE(std::empty(torrents));
@ -47,7 +51,6 @@ TEST_F(TorrentsTest, simpleTests)
// cleanup
torrents.remove(tor, time(nullptr));
delete tor;
}
TEST_F(TorrentsTest, rangedLoop)
@ -57,6 +60,7 @@ TEST_F(TorrentsTest, rangedLoop)
"ubuntu-18.04.6-desktop-amd64.iso.torrent"sv,
"ubuntu-20.04.4-desktop-amd64.iso.torrent"sv };
auto owned = std::vector<std::unique_ptr<tr_torrent>>{};
auto torrents = tr_torrents{};
auto torrents_set = std::set<tr_torrent const*>{};
@ -65,7 +69,9 @@ TEST_F(TorrentsTest, rangedLoop)
auto const path = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, '/', name };
auto tm = tr_torrent_metainfo{};
EXPECT_TRUE(tm.parseTorrentFile(path));
auto* const tor = new tr_torrent{ std::move(tm) };
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
auto* const tor = owned.back().get();
tor->unique_id_ = torrents.add(tor);
EXPECT_EQ(tor, torrents.get(tor->id()));
torrents_set.insert(tor);
@ -74,10 +80,8 @@ TEST_F(TorrentsTest, rangedLoop)
for (auto* const tor : torrents)
{
EXPECT_EQ(1U, torrents_set.erase(tor));
delete tor;
}
EXPECT_EQ(0U, std::size(torrents_set));
EXPECT_EQ(0U, std::size(torrents_set));
}
TEST_F(TorrentsTest, removedSince)
@ -87,6 +91,7 @@ TEST_F(TorrentsTest, removedSince)
"ubuntu-18.04.6-desktop-amd64.iso.torrent"sv,
"ubuntu-20.04.4-desktop-amd64.iso.torrent"sv };
auto owned = std::vector<std::unique_ptr<tr_torrent>>{};
auto torrents = tr_torrents{};
auto torrents_v = std::vector<tr_torrent const*>{};
torrents_v.reserve(std::size(Filenames));
@ -96,7 +101,10 @@ TEST_F(TorrentsTest, removedSince)
{
auto const path = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, '/', name };
auto tm = tr_torrent_metainfo{};
auto* const tor = new tr_torrent{ std::move(tm) };
EXPECT_TRUE(tm.parseTorrentFile(path));
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
auto* const tor = owned.back().get();
tor->unique_id_ = torrents.add(tor);
torrents_v.push_back(tor);
}
@ -119,6 +127,4 @@ TEST_F(TorrentsTest, removedSince)
EXPECT_EQ(remove, torrents.removedSince(200));
remove = { torrents_v[0]->id(), torrents_v[1]->id(), torrents_v[2]->id(), torrents_v[3]->id() };
EXPECT_EQ(remove, torrents.removedSince(50));
std::for_each(std::begin(torrents_v), std::end(torrents_v), [](auto* tor) { delete tor; });
}

View File

@ -212,7 +212,7 @@ TEST_F(VariantTest, parse)
auto benc = "i64e"sv;
auto i = int64_t{};
auto val = tr_variant{};
char const* end;
char const* end = nullptr;
auto ok = tr_variantFromBuf(&val, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, benc, &end);
EXPECT_TRUE(ok);
EXPECT_TRUE(tr_variantGetInt(&val, &i));
@ -296,7 +296,7 @@ TEST_F(VariantTest, bencSortWhenSerializing)
auto constexpr ExpectedOut = "lld1:ai64e1:bi32eeee"sv;
tr_variant val;
char const* end;
char const* end = nullptr;
auto const ok = tr_variantFromBuf(&val, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, In, &end);
EXPECT_TRUE(ok);
EXPECT_EQ(std::data(In) + std::size(In), end);
@ -311,7 +311,7 @@ TEST_F(VariantTest, bencMalformedTooManyEndings)
auto constexpr ExpectedOut = "le"sv;
tr_variant val;
char const* end;
char const* end = nullptr;
auto const ok = tr_variantFromBuf(&val, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, In, &end);
EXPECT_TRUE(ok);
EXPECT_EQ(std::data(In) + std::size(ExpectedOut), end);
@ -395,7 +395,7 @@ TEST_F(VariantTest, merge)
tr_variantMergeDicts(&dest, /*const*/ &src);
int64_t i;
auto i = int64_t{};
EXPECT_TRUE(tr_variantDictFindInt(&dest, i1, &i));
EXPECT_EQ(1, i);
EXPECT_TRUE(tr_variantDictFindInt(&dest, i2, &i));
@ -425,7 +425,7 @@ TEST_F(VariantTest, stackSmash)
std::string const in = std::string(Depth, 'l') + std::string(Depth, 'e');
// confirm that it fails instead of crashing
char const* end;
char const* end = nullptr;
tr_variant val;
tr_error* error = nullptr;
auto ok = tr_variantFromBuf(&val, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, in, &end, &error);
@ -443,7 +443,7 @@ TEST_F(VariantTest, boolAndIntRecast)
auto const key3 = tr_quark_new("key3"sv);
auto const key4 = tr_quark_new("key4"sv);
tr_variant top;
auto top = tr_variant{};
tr_variantInitDict(&top, 10);
tr_variantDictAddBool(&top, key1, false);
tr_variantDictAddBool(&top, key2, 0); // NOLINT modernize-use-bool-literals
@ -451,7 +451,7 @@ TEST_F(VariantTest, boolAndIntRecast)
tr_variantDictAddInt(&top, key4, 1);
// confirm we can read both bools and ints as bools
bool b;
auto b = bool{};
EXPECT_TRUE(tr_variantDictFindBool(&top, key1, &b));
EXPECT_FALSE(b);
EXPECT_TRUE(tr_variantDictFindBool(&top, key2, &b));
@ -462,7 +462,7 @@ TEST_F(VariantTest, boolAndIntRecast)
EXPECT_TRUE(b);
// confirm we can read both bools and ints as ints
int64_t i;
auto i = int64_t{};
EXPECT_TRUE(tr_variantDictFindInt(&top, key1, &i));
EXPECT_EQ(0, i);
EXPECT_TRUE(tr_variantDictFindInt(&top, key2, &i));

View File

@ -36,10 +36,7 @@ static auto constexpr RetryDuration = 100ms;
static auto constexpr ProcessEventsTimeout = 300ms;
static_assert(ProcessEventsTimeout > GenericRescanInterval);
namespace libtransmission
{
namespace test
namespace libtransmission::test
{
enum class WatchMode
@ -259,6 +256,4 @@ INSTANTIATE_TEST_SUITE_P( //
WatchMode::NATIVE,
WatchMode::GENERIC));
} // namespace test
} // namespace libtransmission
} // namespace libtransmission::test