From b4900025e20e9268f92bc3f7b8f810222453f735 Mon Sep 17 00:00:00 2001 From: Adam Higerd Date: Sat, 2 Jul 2022 11:12:12 -0500 Subject: [PATCH] break up test suites, fix index mapping issue --- src/platform/qt/CMakeLists.txt | 33 ++++++++++++------- src/platform/qt/library/LibraryController.cpp | 7 ++++ src/platform/qt/test/library.cpp | 4 +-- src/platform/qt/test/main.cpp | 19 ----------- src/platform/qt/test/spanset.cpp | 5 ++- src/platform/qt/test/suite.h | 23 ------------- 6 files changed, 32 insertions(+), 59 deletions(-) delete mode 100644 src/platform/qt/test/main.cpp delete mode 100644 src/platform/qt/test/suite.h diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index d08356c8871..9c193ceaf05 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -188,6 +188,10 @@ set(GB_SRC GBOverride.cpp PrinterView.cpp) +set(TEST_QT_spanset_SRC + test/spanset.cpp + utils.cpp) + set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libqt5widgets5") set(AUDIO_SRC) @@ -241,6 +245,12 @@ if(USE_SQLITE3) library/LibraryController.cpp library/LibraryEntry.cpp library/LibraryModel.cpp) + + set(TEST_QT_library_SRC + library/LibraryEntry.cpp + library/LibraryModel.cpp + test/library.cpp + utils.cpp) endif() if(USE_DISCORD_RPC) @@ -486,18 +496,17 @@ if(BUILD_SUITE) enable_testing() find_package(${QT}Test) if(${QT}Test_FOUND) - set(TEST_SRC - library/LibraryEntry.cpp - library/LibraryModel.cpp - test/library.cpp - test/main.cpp - test/spanset.cpp - utils.cpp - ) - add_executable(test-platform-qt WIN32 ${TEST_SRC}) - target_link_libraries(test-platform-qt ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${QT}::Test) - set_target_properties(test-platform-qt PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES};${OS_DEFINES};${QT_DEFINES}" COMPILE_OPTIONS "${FEATURE_FLAGS}") - add_test(platform-qt test-platform-qt) + get_property(ALL_TESTS DIRECTORY PROPERTY VARIABLES) + list(FILTER ALL_TESTS INCLUDE REGEX "^TEST_QT_.*_SRC$") + foreach(TEST_SRC ${ALL_TESTS}) + string(REGEX REPLACE "^TEST_QT_(.*)_SRC$" "\\1" TEST_NAME ${TEST_SRC}) + message("TEST_NAME=${TEST_NAME}") + message("TEST_SRC=${${TEST_SRC}}") + add_executable(test-qt-${TEST_NAME} WIN32 ${${TEST_SRC}}) + target_link_libraries(test-qt-${TEST_NAME} ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${QT}::Test) + set_target_properties(test-qt-${TEST_NAME} PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES};${OS_DEFINES};${QT_DEFINES}" COMPILE_OPTIONS "${FEATURE_FLAGS}") + add_test(platform-qt-${TEST_NAME} test-qt-${TEST_NAME}) + endforeach() else() message("${QT}Test not found") endif() diff --git a/src/platform/qt/library/LibraryController.cpp b/src/platform/qt/library/LibraryController.cpp index adebb531a42..aa22a20ee58 100644 --- a/src/platform/qt/library/LibraryController.cpp +++ b/src/platform/qt/library/LibraryController.cpp @@ -120,6 +120,13 @@ void LibraryController::selectEntry(const QString& fullpath) { return; } QModelIndex index = m_libraryModel->index(fullpath); + + // If the model is proxied in the current view, map the index to the proxy + QAbstractProxyModel* proxy = qobject_cast(m_currentView->model()); + if (proxy) { + index = proxy->mapFromSource(index); + } + if (index.isValid()) { m_currentView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current); } diff --git a/src/platform/qt/test/library.cpp b/src/platform/qt/test/library.cpp index 14819dea6a9..2cda06694fb 100644 --- a/src/platform/qt/test/library.cpp +++ b/src/platform/qt/test/library.cpp @@ -3,7 +3,6 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "suite.h" #include "platform/qt/library/LibraryModel.h" #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) @@ -11,6 +10,7 @@ #endif #include +#include #define FIND_GBA_ROW(gba, gb) \ int gba = findGBARow(); \ @@ -196,5 +196,5 @@ private slots: } }; -M_REGISTER_QT_TEST(LibraryModelTest) +QTEST_MAIN(LibraryModelTest) #include "library.moc" diff --git a/src/platform/qt/test/main.cpp b/src/platform/qt/test/main.cpp deleted file mode 100644 index 28a42241599..00000000000 --- a/src/platform/qt/test/main.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (c) 2013-2022 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "suite.h" - -QList registeredTests; - -int main(int argc, char** argv) { - int err = 0; - for (TestRegistrar* test : registeredTests) { - int result = test->main(argc, argv); - if (result && !err) { - err = result; - } - } - return err; -} diff --git a/src/platform/qt/test/spanset.cpp b/src/platform/qt/test/spanset.cpp index 0391a72fd7a..45a2a1e2551 100644 --- a/src/platform/qt/test/spanset.cpp +++ b/src/platform/qt/test/spanset.cpp @@ -3,10 +3,9 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "suite.h" #include "platform/qt/utils.h" -#include +#include using namespace QGBA; @@ -58,5 +57,5 @@ private slots: } }; -M_REGISTER_QT_TEST(SpanSetTest) +QTEST_APPLESS_MAIN(SpanSetTest) #include "spanset.moc" diff --git a/src/platform/qt/test/suite.h b/src/platform/qt/test/suite.h deleted file mode 100644 index 6aae5f7e051..00000000000 --- a/src/platform/qt/test/suite.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (c) 2013-2022 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#pragma once - -#define QT_NO_OPENGL - -#include -#include - -struct TestRegistrar { - virtual int main(int argc, char** argv) = 0; -}; - -extern QList registeredTests; - -#define M_REGISTER_QT_TEST(Class) \ - static struct Class ## Registrar : TestRegistrar { \ - QTEST_MAIN(Class) \ - Class ## Registrar() { registeredTests << this; } \ - } registrar_ ## Class;