moved capella mtest

This commit is contained in:
Igor Korsukov 2021-01-26 10:01:21 +02:00
parent 4fc645e81e
commit 41d47a0174
62 changed files with 251 additions and 40 deletions

View file

@ -1,16 +0,0 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
#
# Copyright (C) 2012 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
#=============================================================================
subdirs(
io
)

View file

@ -1,15 +0,0 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
#
# Copyright (C) 2013 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_capella_io)
include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc)

View file

@ -76,6 +76,7 @@ if (BUILD_UNIT_TESTS)
add_subdirectory(importexport/bb/tests)
add_subdirectory(importexport/braille/tests)
add_subdirectory(importexport/bww/tests)
add_subdirectory(importexport/capella/tests)
add_subdirectory(importexport/musicxml/tests)
endif(BUILD_UNIT_TESTS)

View file

@ -0,0 +1,37 @@
#=============================================================================
# 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(MODULE_TEST iex_capella_tests)
set(MODULE_TEST_SRC
${CMAKE_CURRENT_LIST_DIR}/environment.cpp
${CMAKE_CURRENT_LIST_DIR}/testbase.cpp
${CMAKE_CURRENT_LIST_DIR}/testbase.h
${CMAKE_CURRENT_LIST_DIR}/tst_capella_io.cpp
)
set(MODULE_TEST_LINK
libmscore
fonts
iex_capella
)
set(MODULE_TEST_DATA_ROOT ${CMAKE_CURRENT_LIST_DIR})
include(${PROJECT_SOURCE_DIR}/src/framework/testing/qtest.cmake)

View file

@ -0,0 +1,32 @@
//=============================================================================
// 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.
//=============================================================================
#include "testing/environment.h"
#include "log.h"
#include "framework/fonts/fontsmodule.h"
static mu::testing::SuiteEnvironment importexport_se(
{
new mu::fonts::FontsModule(), // needs for libmscore
},
[]() {
LOGI() << "braille tests suite post init";
}
);

View file

@ -0,0 +1,124 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2012-2013 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 LICENCE.GPL
//=============================================================================
#include "testbase.h"
#include <QtTest/QtTest>
#include <QTextStream>
#include "config.h"
#include "libmscore/score.h"
#include "libmscore/instrtemplate.h"
#include "libmscore/musescoreCore.h"
namespace Ms {
extern Score::FileError importCapella(MasterScore*, const QString& name);
extern Score::FileError importCapXml(MasterScore*, const QString& name);
}
namespace Ms {
MTest::MTest()
{
MScore::testMode = true;
}
MasterScore* MTest::readScore(const QString& name)
{
QString path = root + "/" + name;
MasterScore* score = new MasterScore(mscore->baseStyle());
QFileInfo fi(path);
score->setName(fi.completeBaseName());
QString csl = fi.suffix().toLower();
ScoreLoad sl;
Score::FileError rv;
if (csl == "mscz" || csl == "mscx") {
rv = score->loadMsc(path, false);
} else if (csl == "cap") {
rv = importCapella(score, path);
score->setMetaTag("originalFormat", csl);
} else if (csl == "capx") {
rv = importCapXml(score, path);
score->setMetaTag("originalFormat", csl);
} else {
rv = Score::FileError::FILE_UNKNOWN_TYPE;
}
if (rv != Score::FileError::FILE_NO_ERROR) {
QWARN(qPrintable(QString("readScore: cannot load <%1> type <%2>\n").arg(path).arg(csl)));
delete score;
score = 0;
} else {
for (Score* s : score->scoreList()) {
s->doLayout();
}
}
return score;
}
bool MTest::saveScore(Score* score, const QString& name) const
{
QFileInfo fi(name);
// MScore::testMode = true;
return score->Score::saveFile(fi);
}
bool MTest::compareFilesFromPaths(const QString& f1, const QString& f2)
{
QString cmd = "diff";
QStringList args;
args.append("-u");
args.append("--strip-trailing-cr");
args.append(f2);
args.append(f1);
QProcess p;
qDebug() << "Running " << cmd << " with arg1: " << QFileInfo(f2).fileName() << " and arg2: "
<< QFileInfo(f1).fileName();
p.start(cmd, args);
if (!p.waitForFinished() || p.exitCode()) {
QByteArray ba = p.readAll();
//qDebug("%s", qPrintable(ba));
//qDebug(" <diff -u %s %s failed", qPrintable(compareWith),
// qPrintable(QString(root + "/" + saveName)));
QTextStream outputText(stdout);
outputText << QString(ba);
outputText << QString(" <diff -u %1 %2 failed").arg(f2).arg(f1);
return false;
}
return true;
}
bool MTest::compareFiles(const QString& saveName, const QString& compareWith) const
{
return compareFilesFromPaths(saveName, root + "/" + compareWith);
}
bool MTest::saveCompareScore(Score* score, const QString& saveName, const QString& compareWith) const
{
if (!saveScore(score, saveName)) {
return false;
}
return compareFiles(saveName, compareWith);
}
void MTest::initMTest(const QString& rootDir)
{
MScore::noGui = true;
mscore = new MScore;
new MuseScoreCore;
mscore->init();
root = rootDir;
loadInstrumentTemplates(":/instruments.xml");
}
}

View file

@ -0,0 +1,49 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2012 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 LICENCE.GPL
//=============================================================================
#ifndef __TESTUTILS_H__
#define __TESTUTILS_H__
#include "libmscore/element.h"
namespace Ms {
class MScore;
class MasterScore;
class Score;
//---------------------------------------------------------
// MTest
//---------------------------------------------------------
class MTest
{
protected:
Ms::MScore* mscore;
QString root; // root path of test source
MTest();
Ms::MasterScore* readScore(const QString& name);
bool saveScore(Ms::Score*, const QString& name) const;
bool compareFiles(const QString& saveName, const QString& compareWith) const;
bool saveCompareScore(Ms::Score*, const QString& saveName, const QString& compareWith) const;
void initMTest(const QString& root);
public:
static bool compareFilesFromPaths(const QString& f1, const QString& f2);
};
}
void initMuseScoreResources();
#endif

View file

@ -10,12 +10,11 @@
// the file LICENCE.GPL
//=============================================================================
#include <QtTest/QtTest>
#include "mtest/testutils.h"
#include "testing/qtestsuite.h"
#include "testbase.h"
#include "libmscore/score.h"
#include "mscore/preferences.h"
#define DIR QString("capella/io/")
static const QString CAPELLA_DIR("data/");
using namespace Ms;
@ -73,7 +72,7 @@ private slots:
void TestCapellaIO::initTestCase()
{
initMTest();
initMTest(QString(iex_capella_tests_DATA_ROOT));
}
//---------------------------------------------------------
@ -83,10 +82,10 @@ void TestCapellaIO::initTestCase()
void TestCapellaIO::capReadTest(const char* file)
{
MasterScore* score = readScore(DIR + file + ".cap");
MasterScore* score = readScore(CAPELLA_DIR + file + ".cap");
QVERIFY(score);
QVERIFY(saveCompareScore(score, QString("%1.cap.mscx").arg(file),
DIR + QString("%1.cap-ref.mscx").arg(file)));
CAPELLA_DIR + QString("%1.cap-ref.mscx").arg(file)));
delete score;
}
@ -97,10 +96,10 @@ void TestCapellaIO::capReadTest(const char* file)
void TestCapellaIO::capxReadTest(const char* file)
{
MasterScore* score = readScore(DIR + file + ".capx");
MasterScore* score = readScore(CAPELLA_DIR + file + ".capx");
QVERIFY(score);
QVERIFY(saveCompareScore(score, QString("%1.capx.mscx").arg(file),
DIR + QString("%1.capx-ref.mscx").arg(file)));
CAPELLA_DIR + QString("%1.capx-ref.mscx").arg(file)));
delete score;
}