Skip to content

Commit 571c416

Browse files
committed
add tests for incorrect measure sequences in systems
1 parent 170a16f commit 571c416

File tree

4 files changed

+111
-5
lines changed

4 files changed

+111
-5
lines changed

src/mnxvalidate.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ static void validateScores(const MnxValidateContext& context)
348348
}
349349
}
350350
}
351+
std::optional<size_t> lastSystemMeasure;
352+
bool isFirstSystem = true;
351353
if (auto pages = score.pages()) {
352354
for (const auto page : pages.value()) {
353355
size_t x = page.calcArrayIndex();
@@ -360,19 +362,32 @@ static void validateScores(const MnxValidateContext& context)
360362
size_t y = system.calcArrayIndex();
361363
if (const auto layout = system.layout()) {
362364
if (!context.getLayoutIndex(layout.value(), "System[" + std::to_string(y)
363-
+ "] in page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
365+
+ "] on page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
364366
valid = false;
365367
}
366368
}
367-
if (!context.getMeasureIndex(system.measure(), "System[" + std::to_string(y)
368-
+ "] in page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
369+
auto currentSystemMeasure = context.getMeasureIndex(system.measure(), "System[" + std::to_string(y)
370+
+ "] on page[" + std::to_string(x) + "] in score \"" + score.name() + "\"");
371+
if (!currentSystemMeasure) {
369372
valid = false;
373+
} else if (isFirstSystem && currentSystemMeasure.value() > 0) {
374+
context.logMessage(LogMsg() << "The first system in score \"" << score.name()
375+
<< "\" starts after the first measure.", LogSeverity::Error);
370376
}
377+
isFirstSystem = false;
378+
if (lastSystemMeasure && currentSystemMeasure <= lastSystemMeasure) {
379+
std::string msg = currentSystemMeasure < lastSystemMeasure
380+
? " starts before"
381+
: " starts on the same measure as";
382+
context.logMessage(LogMsg() << "System[" << y << "] on page[" << x << "] in score \"" << score.name() << "\""
383+
<< msg << " previous system.", LogSeverity::Error);
384+
}
385+
lastSystemMeasure = currentSystemMeasure;
371386
if (const auto layoutChanges = system.layoutChanges()) {
372387
for (const auto layoutChange : layoutChanges.value()) {
373388
size_t z = layoutChange.calcArrayIndex();
374389
if (!context.getLayoutIndex(layoutChange.layout(), "Layout change[" + std::to_string(z) + "] in system[" + std::to_string(y)
375-
+ "] in page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
390+
+ "] on page[" + std::to_string(x) + "] in score \"" + score.name() + "\"")) {
376391
valid = false;
377392
}
378393
/// @todo validate location.bar
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"mnx": {
3+
"version": 1
4+
},
5+
"global": {
6+
"measures": [
7+
{
8+
"index": 2
9+
},
10+
{},
11+
{},
12+
{},
13+
{}
14+
]
15+
},
16+
"parts": [],
17+
"scores": [
18+
{
19+
"name": "Score",
20+
"pages": [
21+
{
22+
"systems": [
23+
{
24+
"measure": 2
25+
},
26+
{
27+
"measure": 4
28+
},
29+
{
30+
"measure": 3
31+
}
32+
]
33+
}
34+
]
35+
}
36+
]
37+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"mnx": {
3+
"version": 1
4+
},
5+
"global": {
6+
"measures": [
7+
{
8+
"index": 2
9+
},
10+
{},
11+
{},
12+
{},
13+
{}
14+
]
15+
},
16+
"parts": [],
17+
"scores": [
18+
{
19+
"name": "Score",
20+
"pages": [
21+
{
22+
"systems": []
23+
},
24+
{
25+
"systems": [
26+
{
27+
"measure": 3
28+
}
29+
]
30+
}
31+
]
32+
}
33+
]
34+
}

tests/test_scores.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,27 @@ TEST(Scores, InvalidSystemStartMeasure)
9494
setupTestDataPaths();
9595
std::filesystem::path inputPath = getInputPath() / "errors" / "score_system_bad_measure.json";
9696
ArgList args = { MNXVALIDATE_NAME, inputPath.u8string(), "--no-log" };
97-
checkStderr({ std::string("score_system_bad_measure.json"), "System[0] in page[0] in score \"Score\" references non-existent measure 1" }, [&]() {
97+
checkStderr({ std::string("score_system_bad_measure.json"), "System[0] on page[0] in score \"Score\" references non-existent measure 1" }, [&]() {
98+
EXPECT_NE(mnxValidateTestMain(args.argc(), args.argv()), 0) << "validate " << inputPath.u8string();
99+
});
100+
}
101+
102+
TEST(Scores, InvalidSystemMeasureSequence)
103+
{
104+
setupTestDataPaths();
105+
std::filesystem::path inputPath = getInputPath() / "errors" / "score_system_bad_start.json";
106+
ArgList args = { MNXVALIDATE_NAME, inputPath.u8string(), "--no-log" };
107+
checkStderr({ std::string("score_system_bad_start.json"), "System[2] on page[0] in score \"Score\" starts before previous system" }, [&]() {
108+
EXPECT_NE(mnxValidateTestMain(args.argc(), args.argv()), 0) << "validate " << inputPath.u8string();
109+
});
110+
}
111+
112+
TEST(Scores, InvalidSystemMeasureSequence2)
113+
{
114+
setupTestDataPaths();
115+
std::filesystem::path inputPath = getInputPath() / "errors" / "score_system_bad_start2.json";
116+
ArgList args = { MNXVALIDATE_NAME, inputPath.u8string(), "--no-log" };
117+
checkStderr({ std::string("score_system_bad_start2.json"), "The first system in score \"Score\" starts after the first measure" }, [&]() {
98118
EXPECT_NE(mnxValidateTestMain(args.argc(), args.argv()), 0) << "validate " << inputPath.u8string();
99119
});
100120
}

0 commit comments

Comments
 (0)