|
| 1 | +/* |
| 2 | + * Bittorrent Client using Qt and libtorrent. |
| 3 | + * Copyright (C) 2026 Andy Ye |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU General Public License |
| 7 | + * as published by the Free Software Foundation; either version 2 |
| 8 | + * of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | + * |
| 19 | + * In addition, as a special exception, the copyright holders give permission to |
| 20 | + * link this program with the OpenSSL project's "OpenSSL" library (or with |
| 21 | + * modified versions of it that use the same license as the "OpenSSL" library), |
| 22 | + * and distribute the linked executables. You must obey the GNU General Public |
| 23 | + * License in all respects for all of the code used other than "OpenSSL". If you |
| 24 | + * modify file(s), you may extend this exception to your version of the file(s), |
| 25 | + * but you are not obligated to do so. If you do not wish to do so, delete this |
| 26 | + * exception statement from your version. |
| 27 | + */ |
| 28 | + |
| 29 | +#include <QObject> |
| 30 | +#include <QTest> |
| 31 | + |
| 32 | +#include "base/bittorrent/torrentdescriptor.h" |
| 33 | +#include "base/bittorrent/trackerentry.h" |
| 34 | +#include "base/global.h" |
| 35 | + |
| 36 | +class TestBittorrentTorrentDescriptor final : public QObject |
| 37 | +{ |
| 38 | + Q_OBJECT |
| 39 | + Q_DISABLE_COPY_MOVE(TestBittorrentTorrentDescriptor) |
| 40 | + |
| 41 | +public: |
| 42 | + TestBittorrentTorrentDescriptor() = default; |
| 43 | + |
| 44 | +private slots: |
| 45 | + void testParseMagnetFiltersUnsupportedTrackers() const |
| 46 | + { |
| 47 | + const QString magnet = |
| 48 | + u"magnet:?xt=urn:btih:c58645e2e922428dceb1f98f51ffa424810570f0" |
| 49 | + "&tr=http%3A%2F%2Ftracker.example.com%2Fannounce" |
| 50 | + "&tr=udp%3A%2F%2Ftracker.example.com%3A1337%2Fannounce" |
| 51 | + "&tr=%3C!DOCTYPE%20html%3E%3Chtml%3E" |
| 52 | + "&tr=ftp%3A%2F%2Ftracker.example.com%2Fannounce" |
| 53 | + "&tr=313131"_s; |
| 54 | + |
| 55 | + const auto parseResult = BitTorrent::TorrentDescriptor::parse(magnet); |
| 56 | + QVERIFY(parseResult); |
| 57 | + |
| 58 | + const QList<BitTorrent::TrackerEntry> trackers = parseResult.value().trackers(); |
| 59 | + QCOMPARE(trackers.size(), 2); |
| 60 | + QCOMPARE(trackers.at(0).url, u"http://tracker.example.com/announce"_s); |
| 61 | + QCOMPARE(trackers.at(1).url, u"udp://tracker.example.com:1337/announce"_s); |
| 62 | + |
| 63 | + const lt::add_torrent_params &nativeParams = parseResult.value().ltAddTorrentParams(); |
| 64 | + QCOMPARE(nativeParams.trackers.size(), 2); |
| 65 | + QCOMPARE(nativeParams.tracker_tiers.size(), 2); |
| 66 | + } |
| 67 | +}; |
| 68 | + |
| 69 | +QTEST_APPLESS_MAIN(TestBittorrentTorrentDescriptor) |
| 70 | +#include "testbittorrenttorrentdescriptor.moc" |
0 commit comments