From 4da405e4c7e179d5c16d5290a2588e91a7533908 Mon Sep 17 00:00:00 2001 From: Kumar Kartikay Date: Wed, 26 Feb 2020 03:11:51 +0530 Subject: [PATCH] fix #301584: test for duplicates names in palette adds a test for checking if there are duplicate names in the palettes in the default workspaces and manually removed the duplicate items by making the names more descriptive. --- mtest/CMakeLists.txt | 1 + mtest/mscore/palette/CMakeLists.txt | 24 +++++ mtest/mscore/palette/tst_palette.cpp | 139 +++++++++++++++++++++++++++ mtest/mtest.cpp | 1 + share/workspaces/Advanced.xml | 80 +++++++-------- share/workspaces/Basic.xml | 24 ++--- 6 files changed, 217 insertions(+), 52 deletions(-) create mode 100644 mtest/mscore/palette/CMakeLists.txt create mode 100644 mtest/mscore/palette/tst_palette.cpp diff --git a/mtest/CMakeLists.txt b/mtest/CMakeLists.txt index 9069b9f261b38..f19a223ef0e74 100644 --- a/mtest/CMakeLists.txt +++ b/mtest/CMakeLists.txt @@ -235,6 +235,7 @@ subdirs ( # libmscore/text work in progress... libmscore/utils mscore/workspaces + mscore/palette importmidi capella biab diff --git a/mtest/mscore/palette/CMakeLists.txt b/mtest/mscore/palette/CMakeLists.txt new file mode 100644 index 0000000000000..238be5585ad77 --- /dev/null +++ b/mtest/mscore/palette/CMakeLists.txt @@ -0,0 +1,24 @@ +#============================================================================= +# MuseScore +# Music Composition & Notation +# +# Copyright (C) 2020 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 2. +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +#============================================================================= + +set(TARGET tst_palette) + +set(MTEST_LINK_MSCOREAPP TRUE) + +include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc) diff --git a/mtest/mscore/palette/tst_palette.cpp b/mtest/mscore/palette/tst_palette.cpp new file mode 100644 index 0000000000000..80e602893e85f --- /dev/null +++ b/mtest/mscore/palette/tst_palette.cpp @@ -0,0 +1,139 @@ +//============================================================================= +// MuseScore +// Music Composition & Notation +// +// Copyright (C) 2020 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 2 +// as published by the Free Software Foundation and appearing in +// the file LICENCE.GPL +//============================================================================= + +#include +#include "mtest/testutils.h" +#include "mscore/musescore.h" +#include "mscore/workspace.h" +#include "mscore/palette/palettemodel.h" +#include "mscore/palette/palettetree.h" + +using namespace Ms; + +class TestPaletteModel : public QObject, public MTest + { + Q_OBJECT + + PaletteTreeModel* paletteModel; + QMap> paletteItemNames; + + void initMuseScore(); + void iterateOverModel(QAbstractItemModel *model, QModelIndex parent = QModelIndex()); + void loadPaletteModel(QString name); + + private slots: + void initTestCase(); + void cleanupTestCase(); + + void testDuplicateItemNames_data(); + void testDuplicateItemNames(); + }; + +//--------------------------------------------------------- +// TestPaletteModel::testDuplicateItemNames_data +//--------------------------------------------------------- + +void TestPaletteModel::testDuplicateItemNames_data() + { + QTest::addColumn("workspaceName"); + QTest::addRow("Basic") << "Basic"; + QTest::addRow("Advanced") << "Advanced"; + } + +//--------------------------------------------------------- +// TestPaletteModel::testDuplicateItemNames +//--------------------------------------------------------- + +void TestPaletteModel::testDuplicateItemNames() + { + QFETCH(QString, workspaceName); + loadPaletteModel(workspaceName); + paletteItemNames.clear(); + iterateOverModel(paletteModel); + bool duplicates = false; + qDebug("In %s workspace", qPrintable(workspaceName)); + for (auto name = paletteItemNames.begin(); name != paletteItemNames.end(); ++name) { + if (name.value().size() != 1) { + duplicates = true; + for (auto parent : name.value()) + qDebug("%s (in %s)", qPrintable(name.key()), qPrintable(parent)); + } + } + // make sure there are no duplicates + QVERIFY(!duplicates); + } + +//--------------------------------------------------------- +// TestPaletteModel::iterateOverModel +//--------------------------------------------------------- + +void TestPaletteModel::iterateOverModel(QAbstractItemModel* model, QModelIndex parent) + { + for (int r = 0; r < model->rowCount(parent); ++r) { + QModelIndex index = model->index(r, 0, parent); + QString name = model->data(index).toString(); + QString parentName = model->data(parent).toString(); + + paletteItemNames[name].push_back(parentName); + + if (model->hasChildren(index)) + iterateOverModel(model, index); + } + } + +//--------------------------------------------------------- +// TestPaletteModel::initTestCase +//--------------------------------------------------------- + +void TestPaletteModel::initTestCase() + { + initMuseScore(); + } + +//--------------------------------------------------------- +// TestPaletteModel::loadPaletteModel +//--------------------------------------------------------- + +void TestPaletteModel::loadPaletteModel(QString name) + { + Workspace* w = WorkspacesManager::findByName(name); + paletteModel = new PaletteTreeModel(w->getPaletteTree()); + } + +//--------------------------------------------------------- +// TestPaletteModel::initMuseScore +//--------------------------------------------------------- + +void TestPaletteModel::initMuseScore() + { + qputenv("QML_DISABLE_DISK_CACHE", "true"); + qSetMessagePattern("%{function}: %{message}"); + MScore::noGui = true; + MScore::testMode = true; + initMuseScoreResources(); + QStringList temp; + MuseScore::init(temp); + } + +//--------------------------------------------------------- +// TestPaletteModel::cleanupTestCase +//--------------------------------------------------------- + +void TestPaletteModel::cleanupTestCase() + { + qApp->processEvents(); + delete Ms::mscore; + Ms::mscore = nullptr; + } + +QTEST_MAIN(TestPaletteModel) +#include "tst_palette.moc" diff --git a/mtest/mtest.cpp b/mtest/mtest.cpp index 2bf1c17c069a1..3f480ee31fa53 100644 --- a/mtest/mtest.cpp +++ b/mtest/mtest.cpp @@ -57,6 +57,7 @@ const char* tests[] = { "libmscore/selectionrangedelete/tst_selectionrangedelete", "libmscore/parts/tst_parts", "testscript/tst_runscripts", + "mscore/palette/tst_palette" #endif #if 0 "libmscore/spanners/tst_spanners", // FAIL diff --git a/share/workspaces/Advanced.xml b/share/workspaces/Advanced.xml index 521fa19f9b868..5e02047f342ba 100644 --- a/share/workspaces/Advanced.xml +++ b/share/workspaces/Advanced.xml @@ -403,7 +403,7 @@ - + @@ -998,7 +998,7 @@ noteShapeTriangleRoundWhite - + 22 add-parentheses @@ -1127,7 +1127,7 @@ 0 - + 1 <sym>keyboardPedalPed</sym> @@ -1135,7 +1135,7 @@ 0 - + <sym>keyboardPedalPed</sym> (<sym>keyboardPedalPed</sym>) @@ -1144,28 +1144,28 @@ 0 - + 1 1 0 - + 2 1 0 - + 2 2 0 - + 1 2 @@ -1291,19 +1291,19 @@ double - + 1 start-repeat - + 1 end-repeat - + 1 end-start-repeat @@ -1368,32 +1368,32 @@ 0 - + 1 - + 2 - + 3 - + 4 - + 5 - + gliss. 0 @@ -1403,7 +1403,7 @@ 100 - + gliss. 1 @@ -1589,7 +1589,7 @@ mute - + open @@ -1603,7 +1603,7 @@ 0.65 1 0 - + 1.5 2.66667 @@ -1611,7 +1611,7 @@ metNoteHalfUp = 80 - + 1.5 1.33333 @@ -1619,7 +1619,7 @@ metNoteQuarterUp = 80 - + 1.5 0.666667 @@ -1627,7 +1627,7 @@ metNote8thUp = 80 - + 1.5 4 @@ -1635,7 +1635,7 @@ metNoteHalfUpspacemetAugmentationDot = 80 - + 1.5 2 @@ -1643,7 +1643,7 @@ metNoteQuarterUpspacemetAugmentationDot = 80 - + 1.5 1 @@ -1658,70 +1658,70 @@ Grave - + 1.3 0.833333 Largo - + 1.3 0.875 Lento - + 1.3 1.18333 Adagio - + 1.3 1.53333 Andante - + 1.3 1.9 Moderato - + 1.3 1.93333 Allegretto - + 1.3 2.4 Allegro - + 1.3 2.86667 Vivace - + 1.3 3.11667 Presto - + 1.5 2 @@ -1729,7 +1729,7 @@ metNoteQuarterUp = metNoteQuarterUpspacemetAugmentationDot - + 1.5 2 @@ -1737,7 +1737,7 @@ metNoteQuarterUpspacemetAugmentationDot = metNoteQuarterUp - + 1.5 2 @@ -1745,7 +1745,7 @@ metNoteHalfUp = metNoteQuarterUp - + 1.5 2 @@ -1753,7 +1753,7 @@ metNoteQuarterUp = metNoteHalfUp - + 1.5 2 @@ -1761,7 +1761,7 @@ metNote8thUp = metNote8thUp - + 1.5 2 diff --git a/share/workspaces/Basic.xml b/share/workspaces/Basic.xml index 6fe7b2c77cb43..c81a4e72f3dda 100644 --- a/share/workspaces/Basic.xml +++ b/share/workspaces/Basic.xml @@ -256,7 +256,7 @@ add-brackets - + 22 add-parentheses @@ -418,28 +418,28 @@ 0 - + 1 1 0 - + 2 1 0 - + 2 2 0 - + 1 2 @@ -464,19 +464,19 @@ double - + 1 start-repeat - + 1 end-repeat - + 1 end-start-repeat @@ -585,7 +585,7 @@ 0.65 1 1 - + 1.5 2.66667 @@ -593,7 +593,7 @@ metNoteHalfUp = 80 - + 1.5 1.33333 @@ -601,7 +601,7 @@ metNoteQuarterUp = 80 - + 1.5 0.666667 @@ -609,7 +609,7 @@ metNote8thUp = 80 - + 1.5 2