feat: add shortcuts widget test

This commit is contained in:
august-alt 2021-09-08 19:25:40 +04:00
parent abc1f3c50c
commit a702579964
4 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,28 @@
find_package(Qt5 COMPONENTS Core Gui Widgets Test REQUIRED)
find_package(XercesC REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SOURCES
shortcutswidgettest.cpp
../../../../../src/plugins/preferences/shortcuts/shortcutswidget.cpp
../../../../../src/plugins/preferences/shortcuts/shortcutsschema.cpp
../../../../../src/plugins/preferences/shortcuts/modelbuilder.cpp
)
set(UI_FORMS
../../../../../src/plugins/preferences/shortcuts/shortcutswidget.ui
)
set(MOC_HEADERS
shortcutswidgettest.h
../../../../../src/plugins/preferences/shortcuts/shortcutswidget.h
)
qt5_wrap_ui(UI_SOURCES ${UI_FORMS})
qt5_wrap_cpp(MOC_SOURCES ${MOC_HEADERS})
add_executable(shortcutswidgettest ${SOURCES} ${MOC_SOURCES} ${UI_SOURCES})
target_link_libraries(shortcutswidgettest ${GPUI_LIBRARIES} shortcuts-plugin Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test XercesC::XercesC)
add_gpui_test(plugins.shortcutswidgettest shortcutswidgettest)

View File

@ -0,0 +1,61 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** This program 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.
**
** 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 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 "shortcutswidgettest.h"
#include <fstream>
#include "../../../../../src/plugins/preferences/shortcuts/modelbuilder.h"
#include "../../../../../src/plugins/preferences/shortcuts/shortcutroles.h"
#include "../../../../../src/plugins/preferences/shortcuts/shortcutsschema.h"
#include "../../../../../src/plugins/preferences/shortcuts/shortcutswidget.h"
const std::string dataPath = "../../../../data/";
namespace tests {
void ShortcutsWidgetTest::show()
{
std::ifstream file;
file.open (dataPath + "shortcuts.xml", std::ifstream::in);
if (file.good()) {
auto shortcuts = Shortcuts_(file, ::xsd::cxx::tree::flags::dont_validate);
auto modelBuilder = std::make_unique<gpui::ModelBuilder>();
auto model = modelBuilder->schemaToModel(shortcuts);
auto selectionModel = std::make_unique<QItemSelectionModel>(model.get());
auto widget = std::make_unique<gpui::ShortcutsWidget>(*model, *selectionModel);
widget->show();
selectionModel->setCurrentIndex(model->item(0, 0)->index(),
QItemSelectionModel::Select | QItemSelectionModel::Rows);
QTest::qWait(10000);
}
file.close();
}
}
QTEST_MAIN(tests::ShortcutsWidgetTest)

View File

@ -0,0 +1,36 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** This program 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.
**
** 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 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.
**
***********************************************************************************************************************/
#ifndef GPUI_SHORTCUTS_WIDGET_TEST_H
#define GPUI_SHORTCUTS_WIDGET_TEST_H
#include <QtTest>
namespace tests {
class ShortcutsWidgetTest : public QObject
{
Q_OBJECT
private slots:
void show();
};
}
#endif // GPUI_SHORTCUTS_WIDGET_TEST_H

25
tests/data/shortcuts.xml Executable file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Shortcuts clsid="{872ECB34-B2EC-401b-A585-D32574AA90EE}">
<Shortcut clsid="{4F2F7C55-2790-433e-8127-0739D1CFA327}"
name="Firefox"
status="Firefox"
image="0"
changed="2020-05-13 15:37:47"
uid="{EA9BCB22-CD0C-47B2-B550-D812414DEE6B}"
userContext="0"
bypassErrors="1">
<Properties pidl=""
targetType="URL"
action="R"
comment="Test comment"
shortcutKey="0"
startIn="/usr/bin/"
arguments="--no-remote"
iconIndex="0"
targetPath="/usr/bin/firefox"
iconPath="system-file-manager"
window=""
shortcutPath="%DesktopDir%\Firefox" />
<Filters/>
</Shortcut>
</Shortcuts>