Skip to content

Commit

Permalink
fix #301584: test for duplicates names in palette
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krkartikay committed Mar 4, 2020
1 parent 9eec241 commit 4da405e
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 52 deletions.
1 change: 1 addition & 0 deletions mtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ subdirs (
# libmscore/text work in progress...
libmscore/utils
mscore/workspaces
mscore/palette
importmidi
capella
biab
Expand Down
24 changes: 24 additions & 0 deletions mtest/mscore/palette/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
139 changes: 139 additions & 0 deletions mtest/mscore/palette/tst_palette.cpp
Original file line number Diff line number Diff line change
@@ -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 <QtTest/QtTest>
#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<QString, vector<QString>> 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<QString>("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"
1 change: 1 addition & 0 deletions mtest/mtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4da405e

Please sign in to comment.