File indexing completed on 2024-12-15 04:53:07

0001 /*
0002     This file is part of libkleopatra's test suite.
0003     SPDX-FileCopyrightText: 2023 g10 Code GmbH
0004     SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <Libkleo/Chrono>
0012 #include <Libkleo/ExpiryChecker>
0013 
0014 #include <QTest>
0015 
0016 #include <gpgme++/key.h>
0017 
0018 namespace QTest
0019 {
0020 
0021 inline bool qCompare(const GpgME::Key &key1, const GpgME::Key &key2, const char *actual, const char *expected, const char *file, int line)
0022 {
0023     return qCompare(key1.primaryFingerprint(), key2.primaryFingerprint(), actual, expected, file, line);
0024 }
0025 
0026 template<>
0027 inline char *toString(const Kleo::chrono::days &days)
0028 {
0029     return QTest::toString(days.count() == 1 ? QByteArray{"1 day"} : QByteArray::number(qlonglong{days.count()}) + " days");
0030 }
0031 
0032 // helpers to compare CheckFlags with CheckFlag; the generic template falls back to integer comparison which doesn't give nice value output
0033 inline bool qCompare(const Kleo::ExpiryChecker::CheckFlags &t1, //
0034                      Kleo::ExpiryChecker::CheckFlag t2,
0035                      const char *actual,
0036                      const char *expected,
0037                      const char *file,
0038                      int line)
0039 {
0040     return qCompare(t1, Kleo::ExpiryChecker::CheckFlags{t2}, actual, expected, file, line);
0041 }
0042 inline bool qCompare(Kleo::ExpiryChecker::CheckFlag t1, //
0043                      const Kleo::ExpiryChecker::CheckFlags &t2,
0044                      const char *actual,
0045                      const char *expected,
0046                      const char *file,
0047                      int line)
0048 {
0049     return qCompare(Kleo::ExpiryChecker::CheckFlags{t1}, t2, actual, expected, file, line);
0050 }
0051 
0052 }