Skip to content

Commit

Permalink
add tests for incorrect measure sequences in systems
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatters1 committed Feb 11, 2025
1 parent 170a16f commit 571c416
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/mnxvalidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ static void validateScores(const MnxValidateContext& context)
}
}
}
std::optional<size_t> lastSystemMeasure;
bool isFirstSystem = true;
if (auto pages = score.pages()) {
for (const auto page : pages.value()) {
size_t x = page.calcArrayIndex();
Expand All @@ -360,19 +362,32 @@ static void validateScores(const MnxValidateContext& context)
size_t y = system.calcArrayIndex();
if (const auto layout = system.layout()) {
if (!context.getLayoutIndex(layout.value(), "System[" + std::to_string(y)
+ "] in page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
+ "] on page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
valid = false;
}
}
if (!context.getMeasureIndex(system.measure(), "System[" + std::to_string(y)
+ "] in page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
auto currentSystemMeasure = context.getMeasureIndex(system.measure(), "System[" + std::to_string(y)
+ "] on page[" + std::to_string(x) + "] in score \"" + score.name() + "\"");
if (!currentSystemMeasure) {
valid = false;
} else if (isFirstSystem && currentSystemMeasure.value() > 0) {
context.logMessage(LogMsg() << "The first system in score \"" << score.name()
<< "\" starts after the first measure.", LogSeverity::Error);
}
isFirstSystem = false;
if (lastSystemMeasure && currentSystemMeasure <= lastSystemMeasure) {
std::string msg = currentSystemMeasure < lastSystemMeasure
? " starts before"
: " starts on the same measure as";
context.logMessage(LogMsg() << "System[" << y << "] on page[" << x << "] in score \"" << score.name() << "\""
<< msg << " previous system.", LogSeverity::Error);
}
lastSystemMeasure = currentSystemMeasure;
if (const auto layoutChanges = system.layoutChanges()) {
for (const auto layoutChange : layoutChanges.value()) {
size_t z = layoutChange.calcArrayIndex();
if (!context.getLayoutIndex(layoutChange.layout(), "Layout change[" + std::to_string(z) + "] in system[" + std::to_string(y)
+ "] in page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
+ "] on page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
valid = false;
}
/// @todo validate location.bar
Expand Down
37 changes: 37 additions & 0 deletions tests/data/inputs/errors/score_system_bad_start.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"mnx": {
"version": 1
},
"global": {
"measures": [
{
"index": 2
},
{},
{},
{},
{}
]
},
"parts": [],
"scores": [
{
"name": "Score",
"pages": [
{
"systems": [
{
"measure": 2
},
{
"measure": 4
},
{
"measure": 3
}
]
}
]
}
]
}
34 changes: 34 additions & 0 deletions tests/data/inputs/errors/score_system_bad_start2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"mnx": {
"version": 1
},
"global": {
"measures": [
{
"index": 2
},
{},
{},
{},
{}
]
},
"parts": [],
"scores": [
{
"name": "Score",
"pages": [
{
"systems": []
},
{
"systems": [
{
"measure": 3
}
]
}
]
}
]
}
22 changes: 21 additions & 1 deletion tests/test_scores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,27 @@ TEST(Scores, InvalidSystemStartMeasure)
setupTestDataPaths();
std::filesystem::path inputPath = getInputPath() / "errors" / "score_system_bad_measure.json";
ArgList args = { MNXVALIDATE_NAME, inputPath.u8string(), "--no-log" };
checkStderr({ std::string("score_system_bad_measure.json"), "System[0] in page[0] in score \"Score\" references non-existent measure 1" }, [&]() {
checkStderr({ std::string("score_system_bad_measure.json"), "System[0] on page[0] in score \"Score\" references non-existent measure 1" }, [&]() {
EXPECT_NE(mnxValidateTestMain(args.argc(), args.argv()), 0) << "validate " << inputPath.u8string();
});
}

TEST(Scores, InvalidSystemMeasureSequence)
{
setupTestDataPaths();
std::filesystem::path inputPath = getInputPath() / "errors" / "score_system_bad_start.json";
ArgList args = { MNXVALIDATE_NAME, inputPath.u8string(), "--no-log" };
checkStderr({ std::string("score_system_bad_start.json"), "System[2] on page[0] in score \"Score\" starts before previous system" }, [&]() {
EXPECT_NE(mnxValidateTestMain(args.argc(), args.argv()), 0) << "validate " << inputPath.u8string();
});
}

TEST(Scores, InvalidSystemMeasureSequence2)
{
setupTestDataPaths();
std::filesystem::path inputPath = getInputPath() / "errors" / "score_system_bad_start2.json";
ArgList args = { MNXVALIDATE_NAME, inputPath.u8string(), "--no-log" };
checkStderr({ std::string("score_system_bad_start2.json"), "The first system in score \"Score\" starts after the first measure" }, [&]() {
EXPECT_NE(mnxValidateTestMain(args.argc(), args.argv()), 0) << "validate " << inputPath.u8string();
});
}

0 comments on commit 571c416

Please sign in to comment.