diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index fc7416a..f906f06 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,152 +1,167 @@ find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test) +find_package(PythonInterp) +set_package_properties(PythonInterp PROPERTIES DESCRIPTION "Python Interpreter" + URL "https://www.python.org" TYPE OPTIONAL + PURPOSE "Python interpreter is needed to execute test for external extractors or writers") + remove_definitions(-DQT_NO_CAST_FROM_ASCII) configure_file(indexerextractortestsconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/indexerextractortestsconfig.h @ONLY) set(indexerextractor_SRCS indexerextractortests.cpp ../src/extractors/plaintextextractor.cpp ) ecm_add_test(${indexerextractor_SRCS} TEST_NAME "indexextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # Office # if(KF5Archive_FOUND) ecm_add_test(odfextractortest.cpp ../src/extractors/odfextractor.cpp TEST_NAME "odfextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData KF5::Archive ) endif() if(KF5Archive_FOUND) ecm_add_test(office2007extractortest.cpp ../src/extractors/office2007extractor.cpp TEST_NAME "officeextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData KF5::Archive ) endif() # # Poppler # if(Poppler_Qt5_FOUND) ecm_add_test(popplerextractortest.cpp ../src/extractors/popplerextractor.cpp TEST_NAME "popplerextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData Poppler::Qt5 ) endif() # # EPub # if(EPUB_FOUND) include_directories(${EPUB_INCLUDE_DIR}) ecm_add_test(epubextractortest.cpp ../src/extractors/epubextractor.cpp TEST_NAME "epubextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${EPUB_LIBRARIES} ) endif() # # Mobi # if (QMOBIPOCKET_FOUND) include_directories(${QMOBIPOCKET_INCLUDE_DIR}) ecm_add_test(mobiextractortest.cpp ../src/extractors/mobiextractor.cpp TEST_NAME "mobiextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${QMOBIPOCKET_LIBRARIES} ) endif() # # Property Info # ecm_add_test(propertyinfotest.cpp TEST_NAME "propertyinfotest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # Exiv2 # if(EXIV2_FOUND) include_directories(${EXIV2_INCLUDE_DIR}) kde_enable_exceptions() ecm_add_test(exiv2extractortest.cpp ../src/extractors/exiv2extractor.cpp TEST_NAME "exiv2extractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${EXIV2_LIBRARIES} ) endif() # # TagLib # if(TAGLIB_FOUND) include_directories(${TAGLIB_INCLUDES}) kde_enable_exceptions() ecm_add_test(taglibextractortest.cpp ../src/extractors/taglibextractor.cpp TEST_NAME "taglibextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) endif() # # QtMultimedia # if(NOT TAGLIB_FOUND AND Qt5Multimedia_FOUND) kde_enable_exceptions() ecm_add_test(qtmultimediaextractortest.cpp ../src/extractors/qtmultimediaextractor.cpp TEST_NAME "qtmultimediaextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData Qt5::Multimedia ) endif() -ecm_add_test(externalextractortest.cpp ../src/externalextractor.cpp - TEST_NAME "externalextractortest" - LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n -) +if(PYTHONINTERP_FOUND) + configure_file(samplefiles/testexternalextractor/main.py samplefiles/testexternalextractor/main.py) + configure_file(samplefiles/testexternalextractor/manifest.json samplefiles/testexternalextractor/manifest.json COPYONLY) + + ecm_add_test(externalextractortest.cpp ../src/externalextractor.cpp + TEST_NAME "externalextractortest" + LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n + ) +endif() # # Collection # set(extractorcollection_SRCS extractorcollectiontest.cpp ) ecm_add_test(${extractorcollection_SRCS} TEST_NAME "extractorcollectiontest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) ################ # Writer tests # ################ # # TagLib # if(TAGLIB_FOUND) include_directories(${TAGLIB_INCLUDES}) kde_enable_exceptions() ecm_add_test(taglibwritertest.cpp ../src/writers/taglibwriter.cpp TEST_NAME "taglibwritertest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) endif() -ecm_add_test(externalwritertest.cpp ../src/externalwriter.cpp - TEST_NAME "externalwritertest" - LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n -) +if(PYTHONINTERP_FOUND) + configure_file(samplefiles/testexternalwriter/main.py samplefiles/testexternalwriter/main.py) + configure_file(samplefiles/testexternalwriter/manifest.json samplefiles/testexternalwriter/manifest.json COPYONLY) + + ecm_add_test(externalwritertest.cpp ../src/externalwriter.cpp + TEST_NAME "externalwritertest" + LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n + ) +endif() diff --git a/autotests/externalextractortest.cpp b/autotests/externalextractortest.cpp index e24b170..7e8661d 100644 --- a/autotests/externalextractortest.cpp +++ b/autotests/externalextractortest.cpp @@ -1,55 +1,55 @@ /* * * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "externalextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "externalextractor.h" #include "config-kfilemetadata.h" #include #include #include #include using namespace KFileMetaData; QString ExternalExtractorTest::testFilePath(const QString& fileName) const { - return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; + return QLatin1String(INDEXER_TESTS_SAMPLE_CONFIGURED_FILES_PATH) + QDir::separator() + fileName; } void ExternalExtractorTest::test() { QTemporaryFile file; file.open(); file.write("Hello"); file.close(); QScopedPointer plugin(new ExternalExtractor( testFilePath("testexternalextractor") )); SimpleExtractionResult result(file.fileName(), "application/text"); plugin->extract(&result); QCOMPARE(result.text(), QStringLiteral("Hello ")); } QTEST_GUILESS_MAIN(ExternalExtractorTest) diff --git a/autotests/externalwritertest.cpp b/autotests/externalwritertest.cpp index 9edd392..65f6bbf 100644 --- a/autotests/externalwritertest.cpp +++ b/autotests/externalwritertest.cpp @@ -1,53 +1,53 @@ /* * * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "externalwritertest.h" #include "writedata.h" #include "indexerextractortestsconfig.h" #include "externalwriter.h" #include "config-kfilemetadata.h" #include #include #include #include using namespace KFileMetaData; QString ExternalWriterTest::testFilePath(const QString& fileName) const { - return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; + return QLatin1String(INDEXER_TESTS_SAMPLE_CONFIGURED_FILES_PATH) + QDir::separator() + fileName; } void ExternalWriterTest::test() { QTemporaryFile file; QScopedPointer plugin( new ExternalWriter(testFilePath("testexternalwriter") )); file.open(); WriteData data(file.fileName(), "application/text"); plugin->write(data); QCOMPARE(QString(file.readAll()), QStringLiteral("{}")); } QTEST_GUILESS_MAIN(ExternalWriterTest) diff --git a/autotests/indexerextractortestsconfig.h.in b/autotests/indexerextractortestsconfig.h.in index 0ef657d..ff61470 100644 --- a/autotests/indexerextractortestsconfig.h.in +++ b/autotests/indexerextractortestsconfig.h.in @@ -1,27 +1,28 @@ /* This file is part of the Nepomuk KDE project. Copyright (C) 2013 David Edmundson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef INDEXEREXTRACTORTESTSCONFIG_H #define INDEXEREXTRACTORTESTSCONFIG_H #define INDEXER_TESTS_SAMPLE_FILES_PATH "@CMAKE_CURRENT_SOURCE_DIR@/samplefiles" +#define INDEXER_TESTS_SAMPLE_CONFIGURED_FILES_PATH "@CMAKE_CURRENT_BINARY_DIR@/samplefiles" #endif diff --git a/autotests/samplefiles/testexternalextractor/main.py b/autotests/samplefiles/testexternalextractor/main.py index b3e7631..1602dc0 100755 --- a/autotests/samplefiles/testexternalextractor/main.py +++ b/autotests/samplefiles/testexternalextractor/main.py @@ -1,23 +1,23 @@ -#!/usr/bin/env python +#!@PYTHON_EXECUTABLE@ import sys import json extractor_data = json.loads(sys.stdin.read()) def extract(): path = extractor_data.get('path') mimetype = extractor_data.get('mimetype') doc = open(path) return_value = {} return_value['properties'] = {} return_value['properties']['text'] = doc.read() return_value['status'] = 'OK' return_value['error'] = '' print(json.dumps(return_value)) if __name__ == "__main__": extract() diff --git a/autotests/samplefiles/testexternalwriter/main.py b/autotests/samplefiles/testexternalwriter/main.py index 4c46980..a44adfc 100755 --- a/autotests/samplefiles/testexternalwriter/main.py +++ b/autotests/samplefiles/testexternalwriter/main.py @@ -1,23 +1,23 @@ -#!/usr/bin/env python +#!@PYTHON_EXECUTABLE@ import sys import json writer_data = json.loads(sys.stdin.read()) def write(): path = writer_data.get('path') mimetype = writer_data.get('mimetype', '') properties = writer_data.get('properties', '') output = open(path, 'w') output.write(json.dumps(properties)) return_status = {} return_status['status'] = 'OK' return_status['error'] = '' print(json.dumps(return_status)) if __name__ == "__main__": write()