File indexing completed on 2024-05-12 05:22:34
0001 /* 0002 autotests/hextest.cpp 0003 0004 This file is part of libkleopatra's test suite. 0005 SPDX-FileCopyrightText: 2022 g10 Code GmbH 0006 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include <Libkleo/Hex> 0012 0013 #include <QTest> 0014 0015 using namespace Kleo; 0016 0017 namespace QTest 0018 { 0019 template<> 0020 inline char *toString(const std::string &s) 0021 { 0022 return qstrdup(('"' + s + '"').c_str()); 0023 } 0024 } 0025 0026 class HexTest : public QObject 0027 { 0028 Q_OBJECT 0029 private Q_SLOTS: 0030 void test_hexdecode() 0031 { 0032 QCOMPARE(hexdecode(nullptr), std::string{}); 0033 QCOMPARE(hexdecode(std::string{}), std::string{}); 0034 QCOMPARE(hexdecode(QByteArray{}), QByteArray{}); 0035 0036 QCOMPARE(hexdecode(""), std::string{}); 0037 QCOMPARE(hexdecode(std::string{""}), std::string{}); 0038 QCOMPARE(hexdecode(QByteArray{""}), QByteArray{}); 0039 0040 QCOMPARE(hexdecode("0123456789"), std::string{"0123456789"}); 0041 QCOMPARE(hexdecode(std::string{"0123456789"}), std::string{"0123456789"}); 0042 QCOMPARE(hexdecode(QByteArray{"0123456789"}), QByteArray{"0123456789"}); 0043 0044 QCOMPARE(hexdecode("%20"), std::string{" "}); 0045 QCOMPARE(hexdecode(std::string{"%20"}), std::string{" "}); 0046 QCOMPARE(hexdecode(QByteArray{"%20"}), QByteArray{" "}); 0047 0048 QCOMPARE(hexdecode("+"), std::string{" "}); 0049 QCOMPARE(hexdecode(std::string{"+"}), std::string{" "}); 0050 QCOMPARE(hexdecode(QByteArray{"+"}), QByteArray{" "}); 0051 } 0052 }; 0053 0054 QTEST_MAIN(HexTest) 0055 #include "hextest.moc"