File indexing completed on 2025-01-26 04:57:21
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "hashcachemanagertest.h" 0008 #include "../hashcachemanager.h" 0009 0010 #include <QStandardPaths> 0011 #include <QTest> 0012 0013 HashCacheManagerTest::HashCacheManagerTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 QStandardPaths::setTestModeEnabled(true); 0017 } 0018 0019 HashCacheManagerTest::~HashCacheManagerTest() = default; 0020 0021 void HashCacheManagerTest::shouldBeUnknowByDefault() 0022 { 0023 WebEngineViewer::HashCacheManager cache; 0024 QCOMPARE(cache.hashStatus(QByteArrayLiteral("foo")), WebEngineViewer::HashCacheManager::Unknown); 0025 } 0026 0027 void HashCacheManagerTest::shouldAddValue_data() 0028 { 0029 QTest::addColumn<QByteArray>("hash"); 0030 QTest::addColumn<uint>("seconds"); 0031 QTest::addColumn<WebEngineViewer::HashCacheManager::UrlStatus>("status"); 0032 uint currentValue = QDateTime::currentDateTimeUtc().toSecsSinceEpoch(); 0033 QTest::newRow("valid") << QByteArrayLiteral("foo") << (currentValue + 2000) << WebEngineViewer::HashCacheManager::UrlOk; 0034 QTest::newRow("malware1validcache") << QByteArrayLiteral("bla") << (currentValue + 2000) << WebEngineViewer::HashCacheManager::MalWare; 0035 QTest::newRow("malware1invalidcache") << QByteArrayLiteral("blu") << (currentValue - 2000) << WebEngineViewer::HashCacheManager::Unknown; 0036 } 0037 0038 void HashCacheManagerTest::shouldAddValue() 0039 { 0040 QFETCH(QByteArray, hash); 0041 QFETCH(uint, seconds); 0042 QFETCH(WebEngineViewer::HashCacheManager::UrlStatus, status); 0043 0044 WebEngineViewer::HashCacheManager cache; 0045 cache.addHashStatus(hash, status, seconds); 0046 QCOMPARE(cache.hashStatus(hash), status); 0047 cache.clearCache(); 0048 } 0049 0050 QTEST_GUILESS_MAIN(HashCacheManagerTest) 0051 0052 #include "moc_hashcachemanagertest.cpp"