diff options
author | Andreas Sturmlechner <asturm@gentoo.org> | 2021-08-30 19:56:11 +0200 |
---|---|---|
committer | Andreas Sturmlechner <asturm@gentoo.org> | 2021-08-30 19:57:04 +0200 |
commit | 023672ffe5fabfe84fded3a555312764ca3894c0 (patch) | |
tree | bab66b8b9774b529b00b4370abfa673bd33aa53f /kde-frameworks | |
parent | x11-wm/i3: Add myself as maintainer (diff) | |
download | gentoo-023672ffe5fabfe84fded3a555312764ca3894c0.tar.gz gentoo-023672ffe5fabfe84fded3a555312764ca3894c0.tar.bz2 gentoo-023672ffe5fabfe84fded3a555312764ca3894c0.zip |
kde-frameworks/kunitconversion: Fix currency runner
Upstream commits:
6e41104426a3ae59bcb90be708abcc3092155436
2a57f9d1c6b2f8d9e2babcdaca66f1cf2a3c5849
KDE-bug: https://bugs.kde.org/show_bug.cgi?id=441337
Package-Manager: Portage-3.0.22, Repoman-3.0.3
Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
Diffstat (limited to 'kde-frameworks')
3 files changed, 359 insertions, 0 deletions
diff --git a/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-24h-currency-sync.patch b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-24h-currency-sync.patch new file mode 100644 index 000000000000..056a2e8b1e5b --- /dev/null +++ b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-24h-currency-sync.patch @@ -0,0 +1,91 @@ +From 6e41104426a3ae59bcb90be708abcc3092155436 Mon Sep 17 00:00:00 2001 +From: Andreas Cord-Landwehr <cordlandwehr@kde.org> +Date: Tue, 24 Aug 2021 21:06:47 +0200 +Subject: [PATCH] Fix automatic currency file sync after 24h + +Conversion plugin in Krunner depends on automatic refresh of currency +table. std::call_once does not work there, because process is never +stopped. + +BUG: 441337 +--- + autotests/convertertest.cpp | 16 ++++++++++++++++ + autotests/convertertest.h | 6 ++++++ + src/currency.cpp | 9 ++++++--- + 3 files changed, 28 insertions(+), 3 deletions(-) + +diff --git a/autotests/convertertest.cpp b/autotests/convertertest.cpp +index aa0ccae..e36b7fe 100644 +--- a/autotests/convertertest.cpp ++++ b/autotests/convertertest.cpp +@@ -8,9 +8,11 @@ + #include <QStandardPaths> + #include <QThread> + #include <QVector> ++#include <currency_p.h> + #include <kunitconversion/unitcategory.h> + + using namespace KUnitConversion; ++using namespace std::chrono_literals; + + void ConverterTest::initTestCase() + { +@@ -113,4 +115,18 @@ void ConverterTest::testCurrency() + qDeleteAll(threads); + } + ++void ConverterTest::testCurrencyConversionTableUpdate() ++{ ++ const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml"); ++ ++ // Missing conversion table must lead to update of table ++ // note that this is the same code path as for last modified updates ++ QFile::remove(cache); ++ QVERIFY(Currency::lastConversionTableUpdate().isNull()); ++ Converter c; ++ Value input = Value(1000, Eur); ++ Value v = c.convert(input, QStringLiteral("$")); ++ QVERIFY(!Currency::lastConversionTableUpdate().isNull()); ++} ++ + QTEST_MAIN(ConverterTest) +diff --git a/autotests/convertertest.h b/autotests/convertertest.h +index 21d5213..d3d6303 100644 +--- a/autotests/convertertest.h ++++ b/autotests/convertertest.h +@@ -23,6 +23,12 @@ private Q_SLOTS: + void testConvert(); + void testInvalid(); + void testCurrency(); ++ /** ++ * Checks that conversion tables are updated after timeout ++ * ++ * Regression test for https://bugs.kde.org/show_bug.cgi?id=441337 ++ */ ++ void testCurrencyConversionTableUpdate(); + }; + + #endif // CONVERTERTEST_H +diff --git a/src/currency.cpp b/src/currency.cpp +index 038e928..ead7ce5 100644 +--- a/src/currency.cpp ++++ b/src/currency.cpp +@@ -745,9 +745,12 @@ void CurrencyCategoryPrivate::syncConversionTable(std::chrono::seconds updateSki + Value CurrencyCategoryPrivate::convert(const Value &value, const Unit &to) + { + // TODO KF6 remove this blocking call and change behavior that explicit call to syncConversionTable is mandatory before +- // right now, if a sync is performed at application start, then this call will not block anymore for 24 hours +- static std::once_flag updateFlag; +- std::call_once(updateFlag, &CurrencyCategoryPrivate::syncConversionTable, this, 24h); ++ // first access to converted data, also to make syncs more explicit ++ static QMutex updateFlag; ++ { ++ QMutexLocker locker(&updateFlag); ++ CurrencyCategoryPrivate::syncConversionTable(24h); ++ } + + Value v = UnitCategoryPrivate::convert(value, to); + return v; +-- +GitLab + diff --git a/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-currency-values-init.patch b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-currency-values-init.patch new file mode 100644 index 000000000000..01ee8a6fa575 --- /dev/null +++ b/kde-frameworks/kunitconversion/files/kunitconversion-5.85.0-fix-currency-values-init.patch @@ -0,0 +1,235 @@ +From 2a57f9d1c6b2f8d9e2babcdaca66f1cf2a3c5849 Mon Sep 17 00:00:00 2001 +From: Andreas Cord-Landwehr <cordlandwehr@kde.org> +Date: Sat, 28 Aug 2021 11:42:06 +0200 +Subject: [PATCH] Fix initialization of currency values + +If there is already a recent currency.xml file provided then use this to +initialize the currency converter. + +BUG: 441337 +--- + autotests/CMakeLists.txt | 8 ++++ + autotests/currencytableinittest.cpp | 33 +++++++++++++++ + autotests/currencytableinittest.h | 26 ++++++++++++ + autotests/currencytableinittest/currency.xml | 43 ++++++++++++++++++++ + autotests/currencytableinittest/data.qrc | 5 +++ + autotests/valuetest.cpp | 6 +++ + src/currency.cpp | 10 +++-- + 7 files changed, 128 insertions(+), 3 deletions(-) + create mode 100644 autotests/currencytableinittest.cpp + create mode 100644 autotests/currencytableinittest.h + create mode 100644 autotests/currencytableinittest/currency.xml + create mode 100644 autotests/currencytableinittest/data.qrc + +diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt +index ec457a5..8225bf2 100644 +--- a/autotests/CMakeLists.txt ++++ b/autotests/CMakeLists.txt +@@ -8,3 +8,11 @@ ecm_add_tests( + convertertest.cpp + LINK_LIBRARIES KF5::UnitConversion KF5::I18n Qt5::Test + ) ++ ++qt5_add_resources(CURRENCY_TEST_RESOURCES currencytableinittest/data.qrc) ++ecm_add_test( ++ currencytableinittest.cpp ++ ${CURRENCY_TEST_RESOURCES} ++ TEST_NAME currencytableinittest ++ LINK_LIBRARIES KF5::UnitConversion KF5::I18n Qt5::Test ++) +diff --git a/autotests/currencytableinittest.cpp b/autotests/currencytableinittest.cpp +new file mode 100644 +index 0000000..c83709a +--- /dev/null ++++ b/autotests/currencytableinittest.cpp +@@ -0,0 +1,33 @@ ++/* ++ * SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org> ++ * ++ * SPDX-License-Identifier: LGPL-2.0-or-later ++ */ ++ ++#include "currencytableinittest.h" ++#include <QStandardPaths> ++#include <cmath> ++ ++using namespace KUnitConversion; ++ ++void CurrencyTableInitTest::testCategoryInit() ++{ ++ QStandardPaths::setTestModeEnabled(true); ++ const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml"); ++ ++ QVERIFY(QFile::exists(QLatin1String(":/currency.xml"))); ++ if (QFile::exists(cache)) { ++ QFile::remove(cache); ++ } ++ // note: copy of file updates the file's modified timestamp and thus file is seen as recently downloaded file ++ QVERIFY(QFile::copy(QLatin1String(":/currency.xml"), cache)); ++ ++ Converter c; ++ Value input = Value(1000, Eur); ++ Value v = c.convert(input, QStringLiteral("$")); ++ qDebug() << "converted value to:" << v.number(); ++ QVERIFY(v.isValid()); ++ QVERIFY(!std::isnan(v.number())); ++} ++ ++QTEST_MAIN(CurrencyTableInitTest) +diff --git a/autotests/currencytableinittest.h b/autotests/currencytableinittest.h +new file mode 100644 +index 0000000..0b835d0 +--- /dev/null ++++ b/autotests/currencytableinittest.h +@@ -0,0 +1,26 @@ ++/* ++ * SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org> ++ * ++ * SPDX-License-Identifier: LGPL-2.0-or-later ++ */ ++ ++#ifndef CURRENCYTABLEINIT_TEST_H ++#define CURRENCYTABLEINIT_TEST_H ++ ++#include <QObject> ++#include <QTest> ++#include <kunitconversion/converter.h> ++ ++using namespace KUnitConversion; ++ ++class CurrencyTableInitTest : public QObject ++{ ++ Q_OBJECT ++private Q_SLOTS: ++ /** ++ * Check that the currency converter is correctly initialized when currency.xml is recent and available ++ */ ++ void testCategoryInit(); ++}; ++ ++#endif +diff --git a/autotests/currencytableinittest/currency.xml b/autotests/currencytableinittest/currency.xml +new file mode 100644 +index 0000000..dca42d5 +--- /dev/null ++++ b/autotests/currencytableinittest/currency.xml +@@ -0,0 +1,43 @@ ++<?xml version="1.0" encoding="UTF-8"?> ++<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"> ++ <gesmes:subject>Reference rates</gesmes:subject> ++ <gesmes:Sender> ++ <gesmes:name>European Central Bank</gesmes:name> ++ </gesmes:Sender> ++ <Cube> ++ <Cube time='2021-08-24'> ++ <Cube currency='USD' rate='1.1740'/> ++ <Cube currency='JPY' rate='128.74'/> ++ <Cube currency='BGN' rate='1.9558'/> ++ <Cube currency='CZK' rate='25.533'/> ++ <Cube currency='DKK' rate='7.4370'/> ++ <Cube currency='GBP' rate='0.85578'/> ++ <Cube currency='HUF' rate='349.69'/> ++ <Cube currency='PLN' rate='4.5792'/> ++ <Cube currency='RON' rate='4.9280'/> ++ <Cube currency='SEK' rate='10.2090'/> ++ <Cube currency='CHF' rate='1.0711'/> ++ <Cube currency='ISK' rate='150.00'/> ++ <Cube currency='NOK' rate='10.4003'/> ++ <Cube currency='HRK' rate='7.4938'/> ++ <Cube currency='RUB' rate='86.7484'/> ++ <Cube currency='TRY' rate='9.8836'/> ++ <Cube currency='AUD' rate='1.6203'/> ++ <Cube currency='BRL' rate='6.2681'/> ++ <Cube currency='CAD' rate='1.4822'/> ++ <Cube currency='CNY' rate='7.6042'/> ++ <Cube currency='HKD' rate='9.1448'/> ++ <Cube currency='IDR' rate='16897.00'/> ++ <Cube currency='ILS' rate='3.7789'/> ++ <Cube currency='INR' rate='87.0625'/> ++ <Cube currency='KRW' rate='1369.00'/> ++ <Cube currency='MXN' rate='23.8606'/> ++ <Cube currency='MYR' rate='4.9525'/> ++ <Cube currency='NZD' rate='1.6893'/> ++ <Cube currency='PHP' rate='58.783'/> ++ <Cube currency='SGD' rate='1.5918'/> ++ <Cube currency='THB' rate='38.595'/> ++ <Cube currency='ZAR' rate='17.6902'/> ++ </Cube> ++ </Cube> ++</gesmes:Envelope> +\ No newline at end of file +diff --git a/autotests/currencytableinittest/data.qrc b/autotests/currencytableinittest/data.qrc +new file mode 100644 +index 0000000..19f9d69 +--- /dev/null ++++ b/autotests/currencytableinittest/data.qrc +@@ -0,0 +1,5 @@ ++<RCC> ++ <qresource prefix="/"> ++ <file>currency.xml</file> ++ </qresource> ++</RCC> +diff --git a/autotests/valuetest.cpp b/autotests/valuetest.cpp +index 0b348d7..53be1b7 100644 +--- a/autotests/valuetest.cpp ++++ b/autotests/valuetest.cpp +@@ -55,6 +55,12 @@ void ValueTest::testInvalid() + + void ValueTest::testCurrencyNotDownloaded() + { ++ // ensure that no local conversion table is available ++ const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml"); ++ if (!QFile::exists(cache)) { ++ QFile::remove(cache); ++ } ++ + auto pounds = Value(100, Gbp); + auto eur = pounds.convertTo(Eur); + QVERIFY(!eur.isValid()); +diff --git a/src/currency.cpp b/src/currency.cpp +index ead7ce5..43161e2 100644 +--- a/src/currency.cpp ++++ b/src/currency.cpp +@@ -47,6 +47,7 @@ public: + Value convert(const Value &value, const Unit &toUnit) override; + bool hasOnlineConversionTable() const override; + void syncConversionTable(std::chrono::seconds updateSkipSeconds) override; ++ bool m_initialized{false}; //!< indicates if units are prepared from currency table + }; + + bool CurrencyCategoryPrivate::hasOnlineConversionTable() const +@@ -668,12 +669,12 @@ QDateTime Currency::lastConversionTableUpdate() + void CurrencyCategoryPrivate::syncConversionTable(std::chrono::seconds updateSkipPeriod) + { + // sync call is expected to be guarded as being called only once +- auto updateCurrencyConversionTable = [this](const QString &cachePath) { ++ auto updateCurrencyConversionTable = [this](const QString &cachePath, bool performNetworkSync) { + qCDebug(LOG_KUNITCONVERSION) << "currency conversion table sync started"; + static QMutex mutex; + QMutexLocker locker(&mutex); + bool updateError{false}; +- if (isConnected()) { ++ if (performNetworkSync && isConnected()) { + // Bug 345750: QNetworkReply does not work without an event loop and doesn't implement waitForReadyRead() + QEventLoop loop; + QNetworkAccessManager manager; +@@ -733,12 +734,15 @@ void CurrencyCategoryPrivate::syncConversionTable(std::chrono::seconds updateSki + } + } + } ++ m_initialized = !updateError; + return !updateError; + }; + + QFileInfo info(cacheLocation()); + if (!info.exists() || info.lastModified().secsTo(QDateTime::currentDateTime()) > updateSkipPeriod.count()) { +- updateCurrencyConversionTable(cacheLocation()); ++ updateCurrencyConversionTable(cacheLocation(), true); ++ } else if (!m_initialized) { ++ updateCurrencyConversionTable(cacheLocation(), false); + } + } + +-- +GitLab + diff --git a/kde-frameworks/kunitconversion/kunitconversion-5.85.0-r1.ebuild b/kde-frameworks/kunitconversion/kunitconversion-5.85.0-r1.ebuild new file mode 100644 index 000000000000..1a8a5753d916 --- /dev/null +++ b/kde-frameworks/kunitconversion/kunitconversion-5.85.0-r1.ebuild @@ -0,0 +1,33 @@ +# Copyright 1999-2021 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +PVCUT=$(ver_cut 1-2) +QTMIN=5.15.2 +inherit ecm kde.org + +DESCRIPTION="Framework for converting units" +LICENSE="LGPL-2+" +KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~riscv ~x86" +IUSE="" + +DEPEND=" + >=dev-qt/qtnetwork-${QTMIN}:5 + =kde-frameworks/ki18n-${PVCUT}*:5 +" +RDEPEND="${DEPEND}" + +PATCHES=( # KDE-bug 441337 + "${FILESDIR}"/${P}-fix-24h-currency-sync.patch + "${FILESDIR}"/${P}-fix-currency-values-init.patch +) + +src_test() { + # bug 623938 - needs internet connection + local myctestargs=( + -E "(convertertest)" + ) + + LC_NUMERIC="C" ecm_src_test # bug 694804 +} |