File indexing completed on 2025-01-05 04:35:07

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "qztools.h"
0019 #include "mainapplication.h"
0020 
0021 #include <iostream>
0022 #include <QLibrary>
0023 #include <QtTest/QTest>
0024 
0025 int main(int argc, char **argv)
0026 {
0027     if (argc != 2) {
0028         std::cerr << "pyfalkontestrunner [test.py]" << std::endl;
0029         return 1;
0030     }
0031 
0032     QzTools::removeRecursively(QDir::tempPath() + QSL("/Falkon-test"));
0033     MainApplication::setTestModeEnabled(true);
0034     MainApplication app(argc, argv);
0035 
0036 #if defined(Q_OS_MACOS)
0037     const QString suffix = QSL("dylib");
0038 #elif defined(Q_OS_UNIX)
0039     const QString suffix = QSL("so");
0040 #elif defined(Q_OS_WIN)
0041     const QString suffix = QSL("dll");
0042 #endif
0043 
0044     QLibrary library(QFINDTESTDATA(QSL("plugins/PyFalkon.") + suffix));
0045     library.setLoadHints(QLibrary::ExportExternalSymbolsHint);
0046     if (!library.load()) {
0047         std::cerr << qPrintable(library.errorString()) << std::endl;
0048         return 2;
0049     }
0050 
0051     auto run_script = (bool(*)(const QByteArray&)) library.resolve("pyfalkon_run_script");
0052     if (!run_script) {
0053         return 3;
0054     }
0055 
0056     QFile file(app.arguments().at(1));
0057     if (!file.open(QFile::ReadOnly)) {
0058         std::cerr << "Failed to open " << qPrintable(file.fileName()) << " for reading" << std::endl;
0059         return 4;
0060     }
0061 
0062     if (!run_script(file.readAll())) {
0063         return 5;
0064     }
0065 
0066     return 0;
0067 }