From fdd762d0bea2669531decac7f135d199c3159e33 Mon Sep 17 00:00:00 2001 From: august-alt <77973983+august-alt@users.noreply.github.com> Date: Wed, 22 Sep 2021 19:03:46 +0400 Subject: [PATCH] tests: add tests for drives --- .../plugins/preferences/drives/CMakeLists.txt | 28 +++++++++ .../preferences/drives/driveswidgettest.cpp | 60 +++++++++++++++++++ .../preferences/drives/driveswidgettest.h | 36 +++++++++++ 3 files changed, 124 insertions(+) create mode 100644 tests/auto/plugins/preferences/drives/CMakeLists.txt create mode 100644 tests/auto/plugins/preferences/drives/driveswidgettest.cpp create mode 100644 tests/auto/plugins/preferences/drives/driveswidgettest.h diff --git a/tests/auto/plugins/preferences/drives/CMakeLists.txt b/tests/auto/plugins/preferences/drives/CMakeLists.txt new file mode 100644 index 0000000..ef39b64 --- /dev/null +++ b/tests/auto/plugins/preferences/drives/CMakeLists.txt @@ -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 + driveswidgettest.cpp + ../../../../../src/plugins/preferences/drives/driveswidget.cpp + ../../../../../src/plugins/preferences/drives/drivesschema.cpp + ../../../../../src/plugins/preferences/drives/modelbuilder.cpp +) + +set(UI_FORMS + ../../../../../src/plugins/preferences/drives/driveswidget.ui +) + +set(MOC_HEADERS + driveswidgettest.h + ../../../../../src/plugins/preferences/drives/driveswidget.h +) + +qt5_wrap_ui(UI_SOURCES ${UI_FORMS}) +qt5_wrap_cpp(MOC_SOURCES ${MOC_HEADERS}) + +add_executable(driveswidgettest ${SOURCES} ${MOC_SOURCES} ${UI_SOURCES}) +target_link_libraries(driveswidgettest ${GPUI_LIBRARIES} drives-plugin Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test XercesC::XercesC) +add_gpui_test(plugins.driveswidgettest driveswidgettest) diff --git a/tests/auto/plugins/preferences/drives/driveswidgettest.cpp b/tests/auto/plugins/preferences/drives/driveswidgettest.cpp new file mode 100644 index 0000000..fead2c4 --- /dev/null +++ b/tests/auto/plugins/preferences/drives/driveswidgettest.cpp @@ -0,0 +1,60 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2021 BaseALT Ltd. +** +** 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 "driveswidgettest.h" + +#include + +#include "../../../../../src/plugins/preferences/drives/modelbuilder.h" +#include "../../../../../src/plugins/preferences/drives/driveroles.h" +#include "../../../../../src/plugins/preferences/drives/drivesschema.h" +#include "../../../../../src/plugins/preferences/drives/driveswidget.h" + +const std::string dataPath = "../../../../data/"; + +namespace tests { + +void DrivesWidgetTest::show() +{ + std::ifstream file; + + file.open(dataPath + "drives.xml", std::ifstream::in); + if (file.good()) { + auto drives = Drives_(file, ::xsd::cxx::tree::flags::dont_validate); + auto modelBuilder = std::make_unique(); + auto model = modelBuilder->schemaToModel(drives); + + auto selectionModel = std::make_unique(model.get()); + + auto widget = std::make_unique(*model, *selectionModel); + widget->show(); + + selectionModel->setCurrentIndex(model->item(0, 0)->index(), + QItemSelectionModel::Select | QItemSelectionModel::Rows); + + QTest::qWait(10000); + } + + file.close(); +} + +} + +QTEST_MAIN(tests::DrivesWidgetTest) diff --git a/tests/auto/plugins/preferences/drives/driveswidgettest.h b/tests/auto/plugins/preferences/drives/driveswidgettest.h new file mode 100644 index 0000000..9385690 --- /dev/null +++ b/tests/auto/plugins/preferences/drives/driveswidgettest.h @@ -0,0 +1,36 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2021 BaseALT Ltd. +** +** 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_DRIVES_WIDGET_TEST_H +#define GPUI_DRIVES_WIDGET_TEST_H + +#include + +namespace tests { + class DrivesWidgetTest : public QObject + { + Q_OBJECT + + private slots: + void show(); + }; +} + +#endif // GPUI_DRIVES_WIDGET_TEST_H