File indexing completed on 2024-04-21 03:58:29

0001 /*
0002  *   SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org>
0003  *
0004  *   SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "currencytableinittest.h"
0008 #include <QStandardPaths>
0009 #include <cmath>
0010 
0011 using namespace KUnitConversion;
0012 
0013 void CurrencyTableInitTest::testCategoryInit()
0014 {
0015     QStandardPaths::setTestModeEnabled(true);
0016     const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml");
0017 
0018     QVERIFY(QFile::exists(QLatin1String(":/currency.xml")));
0019     if (QFile::exists(cache)) {
0020         QFile::remove(cache);
0021     }
0022     // note: copy of file updates the file's modified timestamp and thus file is seen as recently downloaded file
0023     QVERIFY(QFile::copy(QLatin1String(":/currency.xml"), cache));
0024 
0025     Converter c;
0026     Value input = Value(1000, Eur);
0027     Value v = c.convert(input, QStringLiteral("$"));
0028     qDebug() << "converted value to:" << v.number();
0029     QVERIFY(v.isValid());
0030     QVERIFY(!std::isnan(v.number()));
0031 }
0032 
0033 QTEST_MAIN(CurrencyTableInitTest)
0034 
0035 #include "moc_currencytableinittest.cpp"