diff --git a/CMakeLists.txt b/CMakeLists.txt index 912e9d6..b924c3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,84 +1,90 @@ cmake_minimum_required(VERSION 3.0) set(KF5_VERSION "5.51.0") # handled by release scripts set(KF5_DEP_VERSION "5.50.0") # handled by release scripts project(KUnitConversion VERSION ${KF5_VERSION}) include(FeatureSummary) find_package(ECM 5.50.0 NO_MODULE) set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules") feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) set(REQUIRED_QT_VERSION 5.8.0) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Network) include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMAddQch) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") ecm_setup_version(PROJECT VARIABLE_PREFIX KUNITCONVERSION VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kunitconversion_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5UnitConversionConfigVersion.cmake" SOVERSION 5) find_package(KF5I18n ${KF5_DEP_VERSION} REQUIRED) -#remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) add_definitions(-DTRANSLATION_DOMAIN=\"kunitconversion5\") if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ki18n_install(po) endif() +add_definitions(-DQT_NO_CAST_FROM_ASCII) +add_definitions(-DQT_NO_CAST_TO_ASCII) +add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) +add_definitions(-DQT_NO_URL_CAST_FROM_STRING) +add_definitions(-DQT_USE_QSTRINGBUILDER) +#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) + add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(autotests) endif() # create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5UnitConversion") if (BUILD_QCH) ecm_install_qch_export( TARGETS KF5UnitConversion_QCH FILE KF5UnitConversionQchTargets.cmake DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KF5UnitConversionQchTargets.cmake\")") endif() include(CMakePackageConfigHelpers) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5UnitConversionConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5UnitConversionConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5UnitConversionConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5UnitConversionConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5UnitConversionTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5UnitConversionTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kunitconversion_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/autotests/convertertest.cpp b/autotests/convertertest.cpp index 9482214..a31d81b 100644 --- a/autotests/convertertest.cpp +++ b/autotests/convertertest.cpp @@ -1,107 +1,107 @@ /* * Copyright (C) 2009 Petri Damstén * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "convertertest.h" #include #include #include #include using namespace KUnitConversion; void ConverterTest::initTestCase() { - QStandardPaths::enableTestMode(true); + QStandardPaths::setTestModeEnabled(true); // Remove currency cache to force a download const QString cache = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/libkunitconversion/currency.xml"); QFile::remove(cache); } void ConverterTest::testCategory() { Converter c; QCOMPARE(c.categoryForUnit(QStringLiteral("km")).id(), LengthCategory); QCOMPARE(c.category(QStringLiteral("Length")).id(), LengthCategory); QCOMPARE(c.category(LengthCategory).name(), QStringLiteral("Length")); QVERIFY(c.categories().size() > 0); } void ConverterTest::testUnits() { Converter c; QCOMPARE(c.unit(QStringLiteral("km")).symbol(), QStringLiteral("km")); QCOMPARE(c.unit(Kilogram).symbol(), QStringLiteral("kg")); } void ConverterTest::testConvert() { Converter c; Value v = c.convert(Value(3.14, Kilometer), QStringLiteral("m")); QCOMPARE(v.number(), 3140.0); v = c.convert(v, QStringLiteral("cm")); QCOMPARE(v.number(), 314000.0); v = c.convert(v, c.category(LengthCategory).defaultUnit()); QCOMPARE(v.number(), 3140.0); } void ConverterTest::testInvalid() { Converter c; QCOMPARE(c.categoryForUnit(QStringLiteral("does not exist")).id(), InvalidCategory); QCOMPARE(c.unit(QStringLiteral("does not exist")).symbol(), QString()); QCOMPARE(c.category(QStringLiteral("does not exist")).name(), QString()); } class CurrencyTestThread : public QThread { public: CurrencyTestThread(Converter &c) : m_c(c) {} void run() override { Value input = Value(1000, Eur); Value v = m_c.convert(input, QStringLiteral("$")); number = v.number(); } int number; Converter &m_c; }; void ConverterTest::testCurrency() { Converter c; // 2 threads is enough for tsan to notice races, let's not hammer the website with more concurrent requests const int numThreads = 2; QVector threads; threads.resize(numThreads); for (int i = 0; i < numThreads; ++i) { threads[i] = new CurrencyTestThread(c); } for (int i = 0; i < numThreads; ++i) { threads[i]->start(); } for (int i = 0; i < numThreads; ++i) { threads[i]->wait(); QVERIFY(threads.at(i)->number > 100); } qDeleteAll(threads); } QTEST_MAIN(ConverterTest)