-
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.
Add test for tree model consistency & make it pass
- Loading branch information
1 parent
48d860c
commit 0990831
Showing
6 changed files
with
171 additions
and
8 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
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,16 @@ | ||
#============================================================================= | ||
# MuseScore | ||
# Music Composition & Notation | ||
# | ||
# Copyright (C) 2011 Werner Schweer | ||
# | ||
# 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 LICENSE.GPL | ||
#============================================================================= | ||
|
||
set(TARGET tst_tree_model) | ||
|
||
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,109 @@ | ||
//============================================================================= | ||
// 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 "libmscore/score.h" | ||
|
||
#define DIR QString("libmscore/layout_elements") | ||
|
||
using namespace Ms; | ||
|
||
//--------------------------------------------------------- | ||
// TestTreeModel | ||
/// Ensures that the tree model is consistent. Starting | ||
/// from Score each element in the tree should have the | ||
/// correct parent element, the one whose children list | ||
/// it appears in. | ||
//--------------------------------------------------------- | ||
|
||
class TestTreeModel : public QObject, public MTest | ||
{ | ||
Q_OBJECT | ||
|
||
MasterScore * score; | ||
void beam(const char* path); | ||
void tstTree(QString file); | ||
void traverseTree(ScoreElement* element); | ||
|
||
QString elementToText(ScoreElement* element); | ||
|
||
private slots: | ||
void initTestCase(); | ||
void tstTreeElements() { tstTree("tree_elements.mscx"); } | ||
void tstTreeTablature() { tstTree("tree_elements_tab.mscx"); } | ||
void tstTreeMoonlight() { tstTree("moonlight.mscx"); } | ||
void tstTreeGoldberg() { tstTree("goldberg.mscx"); } | ||
}; | ||
|
||
//--------------------------------------------------------- | ||
// initTestCase | ||
//--------------------------------------------------------- | ||
|
||
void TestTreeModel::initTestCase() | ||
{ | ||
initMTest(); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// tstTree | ||
//--------------------------------------------------------- | ||
|
||
void TestTreeModel::tstTree(QString file) | ||
{ | ||
MasterScore* score = readScore(DIR + file); | ||
traverseTree(score); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// traverseTree | ||
/// Checks whether parent element of current element is | ||
/// correct, then recursively checks all children. | ||
//--------------------------------------------------------- | ||
|
||
void TestTreeModel::traverseTree(ScoreElement* element) | ||
{ | ||
for (ScoreElement* child : (*element)) { | ||
if (child) { | ||
// if parent is not correct print some logging info and exit | ||
if (element->treeParent() != parent) { | ||
qDebug() << "Element does not have correct parent!"; | ||
qDebug() << "Element name: " << elementToText(element); | ||
qDebug() << "Parent in tree model: " << elementToText(element->treeParent()); | ||
qDebug() << "Expected parent: " << elementToText(parent); | ||
} | ||
QCOMPARE(element->treeParent(), parent); | ||
|
||
// recursively apply to the rest of the tree | ||
traverseTree(child); | ||
} | ||
} | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// elementToText | ||
/// for printing debug info about any element | ||
//--------------------------------------------------------- | ||
|
||
QString TestTreeModel::elementToText(ScoreElement* element){ | ||
if (element == nullptr) { | ||
return "nullptr"; | ||
} | ||
if (element->isElement()){ | ||
return QString(toElement(element)->name()) + " (" + toElement(element)->accessibleInfo() + ")"; | ||
} | ||
return element->userName(); | ||
} | ||
|
||
|
||
QTEST_MAIN(TestTreeModel) | ||
#include "tst_tree_model.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