Add optional headers to search request
[qBittorrent.git] / test / testutilsstring.cpp
blob6c1c0c63c5d6b89c5717500762374d5b46e6bad3
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Mike Tzou (Chocobo1)
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.
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.
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.
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.
29 #include <QList>
30 #include <QObject>
31 #include <QTest>
33 #include "base/global.h"
34 #include "base/utils/string.h"
36 namespace
38 class MyString
40 public:
41 MyString(const QString &str)
42 : m_str {str}
46 explicit operator QString() const
48 return m_str;
51 private:
52 QString m_str;
56 class TestUtilsString final : public QObject
58 Q_OBJECT
59 Q_DISABLE_COPY_MOVE(TestUtilsString)
61 public:
62 TestUtilsString() = default;
64 private slots:
65 void testJoinIntoString() const
67 const QList<QString> list1;
68 QCOMPARE(Utils::String::joinIntoString(list1, u","_s), u""_s);
70 const QList<QString> list2 {u"a"_s};
71 QCOMPARE(Utils::String::joinIntoString(list2, u","_s), u"a"_s);
73 const QList<QString> list3 {u"a"_s, u"b"_s};
74 QCOMPARE(Utils::String::joinIntoString(list3, u" , "_s), u"a , b"_s);
76 const QList<MyString> list4 {u"a"_s, u"b"_s, u"cd"_s};
77 QCOMPARE(Utils::String::joinIntoString(list4, u"++"_s), u"a++b++cd"_s);
80 void testSplitCommand() const
82 QCOMPARE(Utils::String::splitCommand({}), {});
83 QCOMPARE(Utils::String::splitCommand(u""_s), {});
84 QCOMPARE(Utils::String::splitCommand(u" "_s), {});
85 QCOMPARE(Utils::String::splitCommand(uR"("")"_s), {uR"("")"_s});
86 QCOMPARE(Utils::String::splitCommand(uR"(" ")"_s), {uR"(" ")"_s});
87 QCOMPARE(Utils::String::splitCommand(u"\"\"\""_s), {u"\"\"\""_s});
88 QCOMPARE(Utils::String::splitCommand(uR"(" """)"_s), {uR"(" """)"_s});
89 QCOMPARE(Utils::String::splitCommand(u" app a b c "_s), QStringList({u"app"_s, u"a"_s, u"b"_s, u"c"_s}));
90 QCOMPARE(Utils::String::splitCommand(u" cmd.exe /d --arg2 \"arg3\" \"\" arg5 \"\"arg6 \"arg7 "_s)
91 , QStringList({u"cmd.exe"_s, u"/d"_s, u"--arg2"_s, u"\"arg3\""_s, u"\"\""_s, u"arg5"_s, u"\"\"arg6"_s, u"\"arg7 "_s}));
95 QTEST_APPLESS_MAIN(TestUtilsString)
96 #include "testutilsstring.moc"