Warning, file /utilities/basket/src/tests/toolstest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2014 Gleb Baryshev <gleb.baryshev@gmail.com> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include <QObject> 0007 #include <QtTest/QtTest> 0008 0009 #include <tools.h> 0010 0011 class ToolsTest : public QObject 0012 { 0013 Q_OBJECT 0014 private Q_SLOTS: 0015 void testHtmlToText(); 0016 0017 private: 0018 bool readAll(QString fileName, QString &text); 0019 }; 0020 0021 QTEST_MAIN(ToolsTest) 0022 0023 void ToolsTest::testHtmlToText() 0024 { 0025 // Test the function on files from htmltotext/ 0026 0027 for (int i = 1; i <= 5; i++) { 0028 QString html, text; 0029 QString basename = QFINDTESTDATA("htmltotext/"); 0030 QVERIFY2(QDir(basename).exists(), "Test data file not found"); 0031 basename += QString::number(i); 0032 0033 if (readAll(basename + ".html", html) && readAll(basename + ".txt", text)) 0034 QCOMPARE(Tools::htmlToText(html), text); 0035 } 0036 } 0037 0038 bool ToolsTest::readAll(QString fileName, QString &text) 0039 { 0040 QFile f(fileName); 0041 if (!f.open(QFile::ReadOnly | QFile::Text)) { 0042 QWARN(QString("Failed to open data file %1 - skipping").arg(fileName).toUtf8()); 0043 return false; 0044 } 0045 QTextStream filestream(&f); 0046 text = filestream.readAll(); 0047 return true; 0048 } 0049 0050 #include "toolstest.moc"