Commit e5c40065 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

runners/calculator: Fix build with Qalculate of Ubuntu 20.04 LTS

This is the same version KDE Neon provides
parent 60cb17b3
Pipeline #209751 passed with stage
in 6 minutes and 9 seconds
# SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
# SPDX-License-Identifier: BSD-2-Clause
ecm_add_test(calculatorrunnertest.cpp TEST_NAME calculatorrunnertest LINK_LIBRARIES Qt::Test KF5::Runner KF5::KIOCore)
ecm_add_test(calculatorrunnertest.cpp TEST_NAME calculatorrunnertest LINK_LIBRARIES Qt::Test KF5::Runner KF5::KIOCore ${QALCULATE_LIBRARIES})
configure_krunner_test(calculatorrunnertest calculator)
......@@ -7,6 +7,7 @@
#include <KShell>
#include <QMimeData>
#include <QTest>
#include <libqalculate/includes.h>
class CalculatorRunnerTest : public AbstractRunnerTest
{
......@@ -18,7 +19,9 @@ private Q_SLOTS:
void test42();
void testApproximation();
void testQuery_data();
#if QALCULATE_MAJOR_VERSION > 2 || QALCULATE_MINOR_VERSION > 6
void testErrorDetection();
#endif
};
void CalculatorRunnerTest::initTestCase()
......@@ -84,11 +87,13 @@ void CalculatorRunnerTest::test42()
QCOMPARE(manager->matches().constFirst().text(), "42");
}
#if QALCULATE_MAJOR_VERSION > 2 || QALCULATE_MINOR_VERSION > 6
void CalculatorRunnerTest::testErrorDetection()
{
launchQuery("SDL_VIDEODRIVER=");
QVERIFY(manager->matches().isEmpty());
}
#endif
QTEST_MAIN(CalculatorRunnerTest)
......
......@@ -65,6 +65,7 @@ void QalculateEngine::updateResult(KJob *job)
}
}
#if QALCULATE_MAJOR_VERSION > 2 || QALCULATE_MINOR_VERSION > 6
bool has_error()
{
while (CALCULATOR->message()) {
......@@ -100,6 +101,7 @@ bool check_valid_before(const std::string &expression, const EvaluationOptions &
}
return b_valid;
}
#endif
QString QalculateEngine::evaluate(const QString &expression, bool *isApproximate)
{
......@@ -125,9 +127,11 @@ QString QalculateEngine::evaluate(const QString &expression, bool *isApproximate
// to avoid memory overflow for seemingly innocent calculations (Bug 277011)
eo.approximation = APPROXIMATION_APPROXIMATE;
#if QALCULATE_MAJOR_VERSION > 2 || QALCULATE_MINOR_VERSION > 6
if (!check_valid_before(expression.toStdString(), eo)) {
return QString(); // See https://github.com/Qalculate/libqalculate/issues/442
}
#endif
CALCULATOR->setPrecision(16);
MathStructure result = CALCULATOR->calculate(ctext, eo);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment