1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 16:24:02 +00:00
transmission/tests/libtransmission/magnet-test.cc
Charles Kerr ce51f1adbf
refactor: work around msvc constxpr std::array bug (#1429)
The tests FTBFS on the latest version of MSVC because it has a regression
that crashes the compiler when it sees a constexpr std::array. This commit
can be reverted when MSVC releases a fix.

https://developercommunity.visualstudio.com/content/problem/1139953/167-regression-auto-constexpr-with-deduced-array-i.html
2020-09-07 19:33:36 -05:00

54 lines
1.8 KiB
C++

/*
* This file Copyright (C) 2010-2014 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#include "transmission.h"
#include "magnet.h"
#include "utils.h"
#include "gtest/gtest.h"
#include <array>
TEST(Magnet, magnetParse)
{
auto const expected_hash = std::array<uint8_t, SHA_DIGEST_LENGTH>{
210, 53, 64, 16, 163, 202, 74, 222, 91, 116,
39, 187, 9, 58, 98, 163, 137, 159, 243, 129
};
char const* const uri_hex =
"magnet:?xt=urn:btih:"
"d2354010a3ca4ade5b7427bb093a62a3899ff381"
"&dn=Display%20Name"
"&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
"&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce"
"&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile";
char const* const uri_base32 =
"magnet:?xt=urn:btih:"
"2I2UAEFDZJFN4W3UE65QSOTCUOEZ744B"
"&dn=Display%20Name"
"&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"
"&ws=http%3A%2F%2Fserver.webseed.org%2Fpath%2Fto%2Ffile"
"&tr=http%3A%2F%2Ftracker.opentracker.org%2Fannounce";
for (auto const& uri : { uri_hex, uri_base32 })
{
auto* info = tr_magnetParse(uri);
EXPECT_NE(nullptr, info);
EXPECT_EQ(2, info->trackerCount);
EXPECT_STREQ("http://tracker.openbittorrent.com/announce", info->trackers[0]);
EXPECT_STREQ("http://tracker.opentracker.org/announce", info->trackers[1]);
EXPECT_EQ(1, info->webseedCount);
EXPECT_STREQ("http://server.webseed.org/path/to/file", info->webseeds[0]);
EXPECT_STREQ("Display Name", info->displayName);
EXPECT_EQ(expected_hash.size(), sizeof(info->hash));
EXPECT_EQ(0, memcmp(info->hash, expected_hash.data(), expected_hash.size()));
tr_magnetFree(info);
}
}