Skip to content

Commit

Permalink
Merge pull request #25595 from Eism/update_framework_for_tests
Browse files Browse the repository at this point in the history
A few changes to allow testing of controllers
  • Loading branch information
Eism authored Nov 21, 2024
2 parents fe94f60 + d0ce51f commit 713085e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/framework/actions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ set(MODULE_SRC
)

setup_module()

if (MUSE_MODULE_ACTIONS_TESTS)
add_subdirectory(tests)
endif()
33 changes: 33 additions & 0 deletions src/framework/actions/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: GPL-3.0-only
# MuseScore-CLA-applies
#
# MuseScore
# Music Composition & Notation
#
# Copyright (C) 2021 MuseScore BVBA and others
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# 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, see <https://www.gnu.org/licenses/>.

set(MODULE_TEST muse_actions_tests)

set(MODULE_TEST_SRC
${CMAKE_CURRENT_LIST_DIR}/mocks/actionsdispatchermock.h
)

set(MODULE_TEST_LINK
muse::actions
)

set(MODULE_TEST_DATA_ROOT ${CMAKE_CURRENT_LIST_DIR})

include(SetupGTest)
40 changes: 40 additions & 0 deletions src/framework/actions/tests/mocks/actionsdispatchermock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once

#include <gmock/gmock.h>

#include "actions/iactionsdispatcher.h"

namespace muse::actions {
class ActionsDispatcherMock : public IActionsDispatcher
{
public:
MOCK_METHOD(void, dispatch, (const ActionCode&), (override));
MOCK_METHOD(void, dispatch, (const ActionCode&, const ActionData&), (override));

MOCK_METHOD(void, unReg, (Actionable*), (override));
MOCK_METHOD(void, reg, (Actionable*, const ActionCode&, const ActionCallBackWithNameAndData&), (override));
MOCK_METHOD(bool, isReg, (Actionable*), (const, override));
MOCK_METHOD(ActionCodeList, actionList, (), (const, override));
};
}
2 changes: 2 additions & 0 deletions src/framework/global/iapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class IApplication : MODULE_EXPORT_INTERFACE
#ifndef NO_QT_SUPPORT
virtual QWindow* focusWindow() const = 0;
virtual bool notify(QObject* object, QEvent* event) = 0;

virtual Qt::KeyboardModifiers keyboardModifiers() const = 0;
#endif
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/framework/global/internal/baseapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ bool BaseApplication::notify(QObject* object, QEvent* event)
return qApp->notify(object, event);
}

Qt::KeyboardModifiers BaseApplication::keyboardModifiers() const
{
return QApplication::keyboardModifiers();
}

#endif

void BaseApplication::restart()
Expand Down
2 changes: 2 additions & 0 deletions src/framework/global/internal/baseapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class BaseApplication : public IApplication
#ifndef NO_QT_SUPPORT
QWindow* focusWindow() const override;
bool notify(QObject* object, QEvent* event) override;

Qt::KeyboardModifiers keyboardModifiers() const override;
#endif

protected:
Expand Down
5 changes: 4 additions & 1 deletion src/framework/global/tests/mocks/applicationmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ class ApplicationMock : public IApplication
MOCK_METHOD(RunMode, runMode, (), (const, override));
MOCK_METHOD(bool, noGui, (), (const, override));

#ifndef NO_QT_SUPPORT
MOCK_METHOD(QWindow*, focusWindow, (), (const, override));

MOCK_METHOD(bool, notify, (QObject*, QEvent*), (override));

MOCK_METHOD(Qt::KeyboardModifiers, keyboardModifiers, (), (const, override));
#endif

MOCK_METHOD(void, perform, (), (override));
MOCK_METHOD(void, finish, (), (override));
MOCK_METHOD(void, restart, (), (override));
Expand Down

0 comments on commit 713085e

Please sign in to comment.