Skip to content

Commit

Permalink
Added unit test and actualised existing
Browse files Browse the repository at this point in the history
  • Loading branch information
Eism committed Jan 11, 2024
1 parent d5cba99 commit 828ee4b
Show file tree
Hide file tree
Showing 14 changed files with 1,092 additions and 125 deletions.
4 changes: 4 additions & 0 deletions src/notation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ set(MODULE_LINK
ui
)

if (MUE_BUILD_UNIT_TESTS)
add_subdirectory(tests)
endif()

if (NOT MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy")
endif (NOT MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
Expand Down
5 changes: 5 additions & 0 deletions src/notation/inotationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class INotationInteraction
{
notation::EngravingItem* element = nullptr;
notation::Staff* staff = nullptr;

bool operator ==(const HitElementContext& other) const
{
return element == other.element && staff == other.staff;
}
};

virtual const HitElementContext& hitElementContext() const = 0;
Expand Down
22 changes: 19 additions & 3 deletions src/notation/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,29 @@
# 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 notation_test)
set(MODULE_TEST notation_tests)

set(MODULE_TEST_SRC
${PROJECT_SOURCE_DIR}/src/engraving/tests/utils/scorerw.cpp
${PROJECT_SOURCE_DIR}/src/engraving/tests/utils/scorerw.h

${CMAKE_CURRENT_LIST_DIR}/mocks/msczreadermock.h
${CMAKE_CURRENT_LIST_DIR}/mocks/notationconfigurationmock.h
${CMAKE_CURRENT_LIST_DIR}/mocks/notationinteractionmock.h
${CMAKE_CURRENT_LIST_DIR}/mocks/notationselectionmock.h
${CMAKE_CURRENT_LIST_DIR}/mocks/controlledviewmock.h

${CMAKE_CURRENT_LIST_DIR}/environment.cpp
${CMAKE_CURRENT_LIST_DIR}/notationviewinputcontroller_tests.cpp
)

set(MODULE_TEST_LINK
fonts
engraving
notation
)

set(MODULE_TEST_LINK notation)
set(MODULE_TEST_DATA_ROOT ${CMAKE_CURRENT_LIST_DIR})

include(${PROJECT_SOURCE_DIR}/framework/utests_base/utests_base.cmake)
include(${PROJECT_SOURCE_DIR}/src/framework/testing/gtest.cmake)

191 changes: 191 additions & 0 deletions src/notation/tests/data/test.mscx
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="3.01">
<Score>
<Division>480</Division>
<Style>
<Spatium>1.76389</Spatium>
</Style>
<showInvisible>1</showInvisible>
<showUnprintable>1</showUnprintable>
<showFrames>1</showFrames>
<showMargins>0</showMargins>
<metaTag name="arranger"></metaTag>
<metaTag name="composer"></metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle">Test</metaTag>
<Part>
<Staff id="1">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
</Staff>
<trackName>Voice</trackName>
<Instrument>
<trackName>Voice</trackName>
<minPitchP>36</minPitchP>
<maxPitchP>94</maxPitchP>
<minPitchA>40</minPitchA>
<maxPitchA>79</maxPitchA>
<Articulation>
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="staccato">
<velocity>100</velocity>
<gateTime>85</gateTime>
</Articulation>
<Articulation name="tenuto">
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="sforzato">
<velocity>120</velocity>
<gateTime>100</gateTime>
</Articulation>
<Channel>
</Channel>
</Instrument>
</Part>
<Part>
<Staff id="2">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
</Staff>
<trackName>Voice</trackName>
<Instrument>
<longName>Voice</longName>
<shortName>Vo.</shortName>
<trackName>Voice</trackName>
<minPitchP>36</minPitchP>
<maxPitchP>94</maxPitchP>
<minPitchA>40</minPitchA>
<maxPitchA>79</maxPitchA>
<instrumentId>voice.vocals</instrumentId>
<Articulation>
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="staccatissimo">
<velocity>100</velocity>
<gateTime>33</gateTime>
</Articulation>
<Articulation name="staccato">
<velocity>100</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="portato">
<velocity>100</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="tenuto">
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="marcato">
<velocity>120</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="sforzato">
<velocity>120</velocity>
<gateTime>100</gateTime>
</Articulation>
<Channel>
<program value="52"/>
</Channel>
</Instrument>
</Part>
<Staff id="1">
<VBox>
<height>10</height>
<Text>
<style>title</style>
<text>Test</text>
</Text>
<Text>
<style>subtitle</style>
<text>Split Measure+Slur</text>
</Text>
</VBox>
<Measure>
<voice>
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
<durationType>quarter</durationType>
<Spanner type="Slur">
<Slur>
</Slur>
<next>
<location>
<fractions>3/4</fractions>
</location>
</next>
</Spanner>
<Note>
<pitch>60</pitch>
<tpc>14</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>62</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>64</pitch>
<tpc>18</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Spanner type="Slur">
<prev>
<location>
<fractions>-3/4</fractions>
</location>
</prev>
</Spanner>
<Note>
<pitch>65</pitch>
<tpc>13</tpc>
</Note>
</Chord>
<BarLine>
<subtype>end</subtype>
</BarLine>
</voice>
</Measure>
</Staff>
<Staff id="2">
<Measure>
<voice>
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
</TimeSig>
<Rest>
<durationType>measure</durationType>
<duration>4/4</duration>
</Rest>
</voice>
</Measure>
</Staff>
</Score>
</museScore>
51 changes: 51 additions & 0 deletions src/notation/tests/environment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2024 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/>.
*/

#include "testing/environment.h"

#include "fonts/fontsmodule.h"
#include "draw/drawmodule.h"
#include "engraving/engravingmodule.h"
#include "engraving/tests/utils/scorerw.h"

#include "engraving/dom/instrtemplate.h"
#include "engraving/dom/mscore.h"

static mu::testing::SuiteEnvironment importexport_se(
{
new mu::draw::DrawModule(),
new mu::fonts::FontsModule(), // needs for engraving
new mu::engraving::EngravingModule()
},
nullptr,
[]() {
LOGI() << "notation tests suite post init";

mu::engraving::ScoreRW::setRootPath(mu::String::fromUtf8(notation_tests_DATA_ROOT));

mu::engraving::MScore::testMode = true;
mu::engraving::MScore::testWriteStyleToScore = false;
mu::engraving::MScore::noGui = true;

mu::engraving::loadInstrumentTemplates(":/data/instruments.xml");
}
);
39 changes: 27 additions & 12 deletions src/notation/tests/mocks/controlledviewmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,44 @@

#include "notation/view/notationviewinputcontroller.h"

namespace mu {
namespace notation {
namespace mu::notation {
class ControlledViewMock : public IControlledView
{
public:

MOCK_METHOD(qreal, width, (), (const, override));
MOCK_METHOD(qreal, height, (), (const, override));
MOCK_METHOD(qreal, scale, (), (const, override));
MOCK_METHOD(QPoint, toLogical, (const QPoint& p), (const, override));

MOCK_METHOD(void, moveCanvas, (int dx, int dy), (override));
MOCK_METHOD(void, scrollVertical, (int dy), (override));
MOCK_METHOD(void, scrollHorizontal, (int dx), (override));
MOCK_METHOD(void, setZoom, (int, const QPoint&), (override));
MOCK_METHOD(PointF, viewportTopLeft, (), (const, override));

MOCK_METHOD(bool, moveCanvas, (qreal, qreal), (override));
MOCK_METHOD(void, moveCanvasHorizontal, (qreal), (override));
MOCK_METHOD(void, moveCanvasVertical, (qreal), (override));

MOCK_METHOD(RectF, notationContentRect, (), (const, override));
MOCK_METHOD(qreal, currentScaling, (), (const, override));
MOCK_METHOD(void, setScaling, (qreal, const PointF&, bool), (override));

MOCK_METHOD(PointF, toLogical, (const PointF&), (const, override));
MOCK_METHOD(PointF, toLogical, (const QPointF&), (const, override));
MOCK_METHOD(PointF, fromLogical, (const PointF&), (const, override));
MOCK_METHOD(RectF, fromLogical, (const RectF&), (const, override));

MOCK_METHOD(bool, isNoteEnterMode, (), (const, override));
MOCK_METHOD(void, showShadowNote, (const QPointF& pos), (override));
MOCK_METHOD(void, showShadowNote, (const PointF&), (override));

MOCK_METHOD(void, showContextMenu, (const ElementType&, const QPointF&), (override));
MOCK_METHOD(void, hideContextMenu, (), (override));

MOCK_METHOD(INotationInteraction*, notationInteraction, (), (const, override));
MOCK_METHOD(INotationPlayback*, notationPlayback, (), (const, override));
MOCK_METHOD(void, showElementPopup, (const ElementType&, const RectF&), (override));
MOCK_METHOD(void, hideElementPopup, (), (override));
MOCK_METHOD(void, toggleElementPopup, (const ElementType&, const RectF&), (override));

MOCK_METHOD(INotationInteractionPtr, notationInteraction, (), (const, override));
MOCK_METHOD(INotationPlaybackPtr, notationPlayback, (), (const, override));

MOCK_METHOD(QQuickItem*, asItem, (), (override));
};
}
}

#endif // MU_NOTATION_CONTROLLEDVIEWMOCK_H
Loading

0 comments on commit 828ee4b

Please sign in to comment.