Fixed tests

This commit is contained in:
Eism 2021-10-18 16:23:02 +02:00
parent 2dc5376d1e
commit fad1cf4d8c
10 changed files with 162 additions and 1 deletions

View file

@ -24,6 +24,9 @@
#include "modularity/imoduleexport.h"
class QObject;
class QEvent;
namespace mu::framework {
class IApplication : MODULE_EXPORT_INTERFACE
{
@ -39,6 +42,8 @@ public:
virtual void setRunMode(const RunMode& mode) = 0;
virtual RunMode runMode() const = 0;
virtual bool noGui() const = 0;
virtual bool notify(QObject* object, QEvent* event) = 0;
};
}

View file

@ -21,6 +21,8 @@
*/
#include "application.h"
#include <QApplication>
using namespace mu::framework;
void Application::setRunMode(const RunMode& mode)
@ -41,3 +43,8 @@ bool Application::noGui() const
}
return false;
}
bool Application::notify(QObject* object, QEvent* event)
{
return qApp->notify(object, event);
}

View file

@ -35,6 +35,8 @@ public:
RunMode runMode() const override;
bool noGui() const override;
bool notify(QObject* object, QEvent* event) override;
private:
RunMode m_runMode = RunMode::Editor;

View file

@ -24,6 +24,7 @@ set(MODULE_TEST_SRC
${CMAKE_CURRENT_LIST_DIR}/uri_tests.cpp
${CMAKE_CURRENT_LIST_DIR}/val_tests.cpp
${CMAKE_CURRENT_LIST_DIR}/logremover_tests.cpp
${CMAKE_CURRENT_LIST_DIR}/mocks/applicationmock.h
)
include(${PROJECT_SOURCE_DIR}/src/framework/testing/gtest.cmake)

View file

@ -0,0 +1,41 @@
/*
* 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/>.
*/
#ifndef MU_FRAMEWORK_APPLICATIONMOCK_H
#define MU_FRAMEWORK_APPLICATIONMOCK_H
#include <gmock/gmock.h>
#include "framework/global/iapplication.h"
namespace mu::framework {
class ApplicationMock : public IApplication
{
public:
MOCK_METHOD(void, setRunMode, (const RunMode&), (override));
MOCK_METHOD(RunMode, runMode, (), (const, override));
MOCK_METHOD(bool, noGui, (), (const, override));
MOCK_METHOD(bool, notify, (QObject*, QEvent*), (override));
};
}
#endif // MU_FRAMEWORK_APPLICATIONMOCK_H

View file

@ -357,7 +357,7 @@ void NavigationController::navigateTo(NavigationController::NavigationType type)
//! HACK: it needs for canceling reading the name of previous control on accessibility
QKeyEvent* keyEvent = new QKeyEvent(QEvent::Type::KeyPress, Qt::Key_Cancel, Qt::KeyboardModifier::NoModifier, 0, 1, 0);
QCoreApplicationPrivate::setEventSpontaneous(keyEvent, true);
qApp->notify(mainWindow()->qWindow(), keyEvent);
application()->notify(mainWindow()->qWindow(), keyEvent);
#endif
switch (type) {

View file

@ -31,6 +31,7 @@
#include "actions/actionable.h"
#include "async/asyncable.h"
#include "global/iinteractive.h"
#include "global/iapplication.h"
#include "../imainwindow.h"
namespace mu::ui {
@ -38,6 +39,7 @@ class NavigationController : public QObject, public INavigationController, publi
{
INJECT(ui, actions::IActionsDispatcher, dispatcher)
INJECT(ui, framework::IInteractive, interactive)
INJECT(ui, framework::IApplication, application)
INJECT(ui, IMainWindow, mainWindow)
public:

View file

@ -24,6 +24,7 @@ set(MODULE_TEST_SRC
${CMAKE_CURRENT_LIST_DIR}/environment.cpp
${CMAKE_CURRENT_LIST_DIR}/navigationcontroller_tests.cpp
${CMAKE_CURRENT_LIST_DIR}/mocks/navigationmocks.h
${CMAKE_CURRENT_LIST_DIR}/mocks/mainwindowprovidermock.h
)
set(MODULE_TEST_LINK

View file

@ -0,0 +1,49 @@
/*
* 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/>.
*/
#ifndef MU_UI_MAINWINDOWPROVIDERMOCK_H
#define MU_UI_MAINWINDOWPROVIDERMOCK_H
#include <gmock/gmock.h>
#include "framework/ui/imainwindow.h"
namespace mu::ui {
class MainWindowProviderMock : public IMainWindow
{
public:
MOCK_METHOD(QWindow*, qWindow, (), (const, override));
MOCK_METHOD(QWindow*, topWindow, (), (const, override));
MOCK_METHOD(void, pushWindow, (QWindow*), (override));
MOCK_METHOD(void, popWindow, (QWindow*), (override));
MOCK_METHOD(void, requestShowOnBack, (), (override));
MOCK_METHOD(void, requestShowOnFront, (), (override));
MOCK_METHOD(bool, isFullScreen, (), (const, override));
MOCK_METHOD(void, toggleFullScreen, (), (override));
MOCK_METHOD(const QScreen*, screen, (), (const, override));
};
}
#endif // MU_UI_MAINWINDOWPROVIDERMOCK_H

View file

@ -24,16 +24,24 @@
#include <vector>
#include <map>
#include <QWindow>
#include <QKeyEvent>
#include "ui/internal/navigationcontroller.h"
#include "actions/internal/actionsdispatcher.h"
#include "mocks/navigationmocks.h"
#include "mocks/mainwindowprovidermock.h"
#include "global/tests/mocks/applicationmock.h"
#include "log.h"
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::NiceMock;
using ::testing::_;
using ::testing::SaveArgPointee;
using ::testing::DoAll;
using namespace mu;
using namespace mu::ui;
@ -45,6 +53,8 @@ public:
struct Env {
NavigationController controller;
std::shared_ptr<actions::IActionsDispatcher> dispatcher;
std::shared_ptr<MainWindowProviderMock> mainWindow;
std::shared_ptr<framework::ApplicationMock> application;
//! NOTE Garbage and references
std::vector<INavigation::Index> idxsRefs;
@ -56,6 +66,12 @@ public:
controller.init();
mainWindow = std::make_shared<MainWindowProviderMock>();
controller.setmainWindow(mainWindow);
application = std::make_shared<framework::ApplicationMock>();
controller.setapplication(application);
idxsRefs.reserve(10000);
}
};
@ -181,6 +197,27 @@ public:
}
}
}
QEvent expectSendingEventOnNavigation(Env& env)
{
QEvent event(QEvent::None);
#ifdef Q_OS_LINUX
//! For Linux it needs to send spontanous event for canceling reading the name of previous control on accessibility
QWindow* window = new QWindow();
EXPECT_CALL(*env.mainWindow, qWindow()).WillOnce(Return(window));
EXPECT_CALL(*env.application, notify(window, _)).WillOnce(DoAll(SaveArgPointee<1>(&event), Return(true)));
#endif
return event;
}
void checkSendingEventOnNavigation(const QEvent& event)
{
#ifdef Q_OS_LINUX
EXPECT_TRUE(event.spontaneous());
#endif
}
};
TEST_F(NavigationControllerTests, FirstActiveOnNextSection)
@ -204,9 +241,13 @@ TEST_F(NavigationControllerTests, FirstActiveOnNextSection)
//! CHECK The second section must not be activated
EXPECT_CALL(*sect2->section, setActive(true)).Times(0);
QEvent event = expectSendingEventOnNavigation(env);
//! DO Send action `nav-next-section` (usually F6)
env.dispatcher->dispatch("nav-next-section");
checkSendingEventOnNavigation(event);
delete sect1;
delete sect2;
}
@ -232,9 +273,13 @@ TEST_F(NavigationControllerTests, FirstActiveOnNextPanel)
//! CHECK The second section must not be activated
EXPECT_CALL(*sect2->section, setActive(true)).Times(0);
QEvent event = expectSendingEventOnNavigation(env);
//! DO Send action `nav-next-section` (usually Tab)
env.dispatcher->dispatch("nav-next-panel");
checkSendingEventOnNavigation(event);
delete sect1;
delete sect2;
}
@ -260,9 +305,13 @@ TEST_F(NavigationControllerTests, FirstActiveOnPrevSection)
//! CHECK The first section must not be activated
EXPECT_CALL(*sect1->section, setActive(true)).Times(0);
QEvent event = expectSendingEventOnNavigation(env);
//! DO Send action `nav-next-section` (usually Shift+F6)
env.dispatcher->dispatch("nav-prev-section");
checkSendingEventOnNavigation(event);
delete sect1;
delete sect2;
}
@ -288,9 +337,13 @@ TEST_F(NavigationControllerTests, FirstActiveOnPrevPanel)
//! CHECK The first section must not be activated
EXPECT_CALL(*sect1->section, setActive(true)).Times(0);
QEvent event = expectSendingEventOnNavigation(env);
//! DO Send action `nav-next-section` (usually Shift+Tab)
env.dispatcher->dispatch("nav-prev-panel");
checkSendingEventOnNavigation(event);
delete sect1;
delete sect2;
}