-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
9eec241
commit 4da405e
Showing
6 changed files
with
217 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.