mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-14 09:14:14 +02:00
eab557d9af
The first test that runs a real QETApp, offscreen (qetapptest.h): it links qelectrotech_objects, keeps its settings, configuration and data in a temporary folder, and triggers the editor's own actions. tst_rotateselectionimage covers #1413: Space ("rotate_selection") turns a picture's rotationAngle, not QGraphicsItem's rotation, in place, and a picture read back from its XML has the angle; undo and redo, twice; and a group turn ("rotate_group_selection") moves each picture's pivot a quarter turn around the group's centre. All three fail with the code from before #1413. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
3.3 KiB
C++
113 lines
3.3 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech 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 General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef QETAPPTEST_H
|
|
#define QETAPPTEST_H
|
|
|
|
/**
|
|
For tests that need the application around the class they test: a
|
|
folio, the view showing it, the editor window and its actions. They
|
|
link the application's own code (see qet_add_app_test() in
|
|
CMakeLists.txt) and run a real QETApp, offscreen, with its settings,
|
|
configuration and data in a folder of their own.
|
|
*/
|
|
|
|
#include "diagram.h"
|
|
#include "diagramview.h"
|
|
#include "qetapp.h"
|
|
#include "qetarguments.h"
|
|
#include "qetdiagrameditor.h"
|
|
|
|
#include <QAction>
|
|
#include <QApplication>
|
|
#include <QCoreApplication>
|
|
#include <QSettings>
|
|
#include <QTemporaryDir>
|
|
#include <QtTest>
|
|
|
|
namespace QetAppTest {
|
|
|
|
/// The editor window QETApp opened at start.
|
|
inline QETDiagramEditor *editor()
|
|
{
|
|
const QList<QETDiagramEditor *> editors = QETApp::diagramEditors();
|
|
return editors.isEmpty() ? nullptr : editors.first();
|
|
}
|
|
|
|
/// The view of the folio shown in the editor, after a new project of one
|
|
/// folio if the editor has none open.
|
|
inline DiagramView *view()
|
|
{
|
|
QETDiagramEditor *e = editor();
|
|
if (!e)
|
|
return nullptr;
|
|
if (!e->findChild<DiagramView *>())
|
|
e->newProject();
|
|
return e->findChild<DiagramView *>();
|
|
}
|
|
|
|
inline Diagram *diagram()
|
|
{
|
|
DiagramView *v = view();
|
|
return v ? v->diagram() : nullptr;
|
|
}
|
|
|
|
/// The editor's action whose data() is @p name, as the menus, the
|
|
/// toolbar and the keyboard shortcut trigger it ("rotate_selection" is
|
|
/// Space).
|
|
inline QAction *action(const QString &name)
|
|
{
|
|
QETDiagramEditor *e = editor();
|
|
if (!e)
|
|
return nullptr;
|
|
for (QAction *a : e->findChildren<QAction *>())
|
|
if (a->data().toString() == name)
|
|
return a;
|
|
return nullptr;
|
|
}
|
|
|
|
/// Run @p test inside a QETApp whose settings, configuration and data
|
|
/// live in a temporary folder, so that no test reads or changes the
|
|
/// user's own.
|
|
template <typename Test>
|
|
int run(int argc, char **argv)
|
|
{
|
|
QApplication app(argc, argv);
|
|
QCoreApplication::setOrganizationName("QElectroTech");
|
|
QCoreApplication::setApplicationName("QElectroTech");
|
|
QTemporaryDir home;
|
|
if (!home.isValid())
|
|
return 1;
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, home.filePath("settings"));
|
|
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, home.filePath("settings"));
|
|
QETApp::applyDirectoryArguments(QETArguments(QList<QString>{
|
|
"--config-dir=" + home.filePath("config"),
|
|
"--data-dir=" + home.filePath("data")}));
|
|
QETApp qetapp;
|
|
QCoreApplication::processEvents();
|
|
Test test;
|
|
return QTest::qExec(&test, argc, argv);
|
|
}
|
|
|
|
} // namespace QetAppTest
|
|
|
|
#define QET_APP_TEST_MAIN(Test) \
|
|
int main(int argc, char **argv) { return QetAppTest::run<Test>(argc, argv); }
|
|
|
|
#endif
|