diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
commit | 145364a8af6a1fec06556221e66d4b724a62fc9a (patch) | |
tree | 53bd71a544008c518034f208d64c932dc2883f50 /src/test | |
download | rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip |
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/accidentals.cpp | 88 | ||||
-rw-r--r-- | src/test/dummy.cpp | 6 | ||||
-rw-r--r-- | src/test/segmenttransposecommand.cpp | 161 | ||||
-rw-r--r-- | src/test/transpose.cpp | 154 |
4 files changed, 409 insertions, 0 deletions
diff --git a/src/test/accidentals.cpp b/src/test/accidentals.cpp new file mode 100644 index 0000000..90d929b --- /dev/null +++ b/src/test/accidentals.cpp @@ -0,0 +1,88 @@ +// -*- c-basic-offset: 4 -*- + +#include "NotationTypes.h" + +using namespace Rosegarden; +using std::cout; + +// Unit test-ish tests for resolving accidentals +// +// Returns -1 (or crashes :)) on error, 0 on success +int assertHasAccidental(Pitch &pitch, + const Accidental& accidental, const Key& key) +{ + Accidental calculatedAccidental = + pitch.getAccidental(key); + + std::cout << "Got " << calculatedAccidental << " for pitch " << pitch.getPerformancePitch() << " in key " << key.getName() << std::endl; + + if (calculatedAccidental != accidental) { + std::cout << "Expected " << accidental << std::endl; + return -1; + } + return 0; +} + +int testBInEMinor() +{ + // a B, also in E minor, has no accidental + Pitch testPitch(59 % 12); + return assertHasAccidental(testPitch, + Accidentals::NoAccidental, Key("E minor")); +} + +/** + * + */ +int testFInBMinor() +{ + Pitch testPitch(77); + return assertHasAccidental(testPitch, + Accidentals::NoAccidental, Key("B minor")); +} + +int testInvalidSuggestion() +{ + // If we specify an invalid suggestion, + // getAccidental() should be robust against that. + Pitch testPitch = Pitch(59, Accidentals::Sharp); + return assertHasAccidental(testPitch, + Accidentals::NoAccidental, Key("E minor")); +} + +int testBbinBb() +{ + Pitch testPitch = Pitch(10, Accidentals::NoAccidental); + Accidental accidental = testPitch.getAccidental(Key("Bb major")); + std::cout << "Bb accidental: " << accidental << std::endl; + if (accidental != Accidentals::Flat) + { + return -1; + } + return 0; +} + +// Verifies that the height on staff for pitch 61 using flats is -1, not -2 +int testDesHeight() +{ + bool useSharps = false; + + Pitch pitch(61); + int h = pitch.getHeightOnStaff(Clef(Clef::Treble, 0), useSharps); + + if (h != -1) + { + std::cerr << "Error in testDesHeight: expected height -1, got " << h << std::endl; + return -1; + } + return 0; +} + +int test_accidentals(int argc, char **argv) +{ + return testBInEMinor() + + testFInBMinor() + + testInvalidSuggestion() + + testBbinBb() + + testDesHeight(); +} diff --git a/src/test/dummy.cpp b/src/test/dummy.cpp new file mode 100644 index 0000000..66806a0 --- /dev/null +++ b/src/test/dummy.cpp @@ -0,0 +1,6 @@ +/** dummy unittest to test the unittesting system */ +int test_dummy (int argc, char** argv) +{ + // Always succeed + return 0; +} diff --git a/src/test/segmenttransposecommand.cpp b/src/test/segmenttransposecommand.cpp new file mode 100644 index 0000000..0025529 --- /dev/null +++ b/src/test/segmenttransposecommand.cpp @@ -0,0 +1,161 @@ +// -*- c-basic-offset: 4 -*- + +#include "commands/segment/SegmentTransposeCommand.h" +#include "base/NotationTypes.h" +#include "base/Segment.h" +#include "base/Selection.h" + +using namespace Rosegarden; +using std::cout; + +/** + * Bb in Bb major became E# in F major, due to segment + * transposition + * + * Should be F + */ +int testSegmentBbtoF() +{ + Segment * segment1 = new Segment(); + Note * n = new Note(Note::QuarterNote); + Event * bes = n->getAsNoteEvent(1, 10); + segment1->insert(bes); + segment1->insert(Key("Bb major").getAsEvent(0)); + SegmentTransposeCommand * mockCommand = + new SegmentTransposeCommand(*segment1, + true, -3, -5, true); + mockCommand->execute(); + + EventSelection m_selection(*segment1, segment1->getStartTime(), segment1->getEndMarkerTime()); + EventSelection::eventcontainer::iterator i; + for (i = m_selection.getSegmentEvents().begin(); + i != m_selection.getSegmentEvents().end(); ++i) { + if ((*i)->isa(Note::EventType)) { + Pitch resultPitch(**i); + std::cout << "Resulting pitch is: " << resultPitch.getPerformancePitch() << std::endl; + std::cout << "accidental: " << resultPitch.getDisplayAccidental(Key("F major")) << std::endl; + std::cout << "DisplayAccidental: " << resultPitch.getDisplayAccidental(Key("F major")) << std::endl; + if (resultPitch.getDisplayAccidental(Key("F major")) != Accidentals::NoAccidental) + { + return -1; + } + } + } + + return 0; +} + +/** + * G# in E major became Bb in F major, due to segment + * transposition (by using the 'segment transposition' combobox) + * + * Should be A# + */ +int testGistoAis() +{ + Segment * segment1 = new Segment(); + Note * n = new Note(Note::QuarterNote); + Event * gis = n->getAsNoteEvent(1, 8); + segment1->insert(gis); + segment1->insert(Key("E major").getAsEvent(0)); + SegmentTransposeCommand * mockCommand = + new SegmentTransposeCommand(*segment1, + true, 1, 2, true); + mockCommand->execute(); + + EventSelection m_selection(*segment1, segment1->getStartTime(), segment1->getEndMarkerTime()); + EventSelection::eventcontainer::iterator i; + for (i = m_selection.getSegmentEvents().begin(); + i != m_selection.getSegmentEvents().end(); ++i) { + if ((*i)->isa(Note::EventType)) { + Pitch resultPitch(**i); + std::cout << "Resulting pitch is: " << resultPitch.getPerformancePitch() << std::endl; + std::cout << "accidental: " << resultPitch.getDisplayAccidental(Key("F# major")) << std::endl; + std::cout << "DisplayAccidental: " << resultPitch.getDisplayAccidental(Key("F# major")) << std::endl; + if (resultPitch.getDisplayAccidental(Key("F# major")) != Accidentals::NoAccidental) + { + std::cout << "Gis in E major does not become A#-in-F#-major (no-accidental) when transposed upwards by a small second" << std::endl; + return -1; + } + } + } + + return 0; +} + +/** + * A C# in the key of C# major somehow became a B# in the key of C + */ +int testSegmentCisToC() +{ + Segment * segment1 = new Segment(); + Note * n = new Note(Note::QuarterNote); + Event * cis = n->getAsNoteEvent(1, 13); + segment1->insert(cis); + segment1->insert(Key("C# major").getAsEvent(0)); + SegmentTransposeCommand * mockCommand = + new SegmentTransposeCommand(*segment1, + true, 0, -1, true); + mockCommand->execute(); + + EventSelection m_selection(*segment1, segment1->getStartTime(), segment1->getEndMarkerTime()); + EventSelection::eventcontainer::iterator i; + for (i = m_selection.getSegmentEvents().begin(); + i != m_selection.getSegmentEvents().end(); ++i) { + if ((*i)->isa(Note::EventType)) { + Pitch resultPitch(**i); + std::cout << "Resulting pitch is: " << resultPitch.getPerformancePitch() << std::endl; + std::cout << "accidental: " << resultPitch.getDisplayAccidental(Key("C major")) << std::endl; + std::cout << "DisplayAccidental: " << resultPitch.getDisplayAccidental(Key("C major")) << std::endl; + if (resultPitch.getDisplayAccidental(Key("C major")) != Accidentals::NoAccidental) + { + std::cout << "C# in C# major does not lose accidental when transposed downwards by 1 semitone" << std::endl; + return -1; + } + } + } + + return 0; +} + +int testUndo() +{ + Segment * segment1 = new Segment(); + Segment * segment2 = new Segment(); + + // transpose once + SegmentTransposeCommand * mockCommand1a = + new SegmentTransposeCommand(*segment1, + true, -1, -2, true); + mockCommand1a->execute(); + SegmentTransposeCommand * mockCommand1b = + new SegmentTransposeCommand(*segment2, + true, -1, -2, true); + mockCommand1b->execute(); + + // transpose twice + SegmentTransposeCommand * mockCommand2a = + new SegmentTransposeCommand(*segment1, + true, -1, -2, true); + mockCommand2a->execute(); + SegmentTransposeCommand * mockCommand2b = + new SegmentTransposeCommand(*segment2, + true, -1, -2, true); + mockCommand2b->execute(); + + mockCommand2b->unexecute(); + mockCommand2a->unexecute(); + mockCommand1b->unexecute(); + mockCommand1a->unexecute(); + + return 0; +} + +int test_segmenttransposecommand(int argc, char** argv) +{ + return + testGistoAis() + + testSegmentCisToC() + + testUndo() + + testSegmentBbtoF(); +} diff --git a/src/test/transpose.cpp b/src/test/transpose.cpp new file mode 100644 index 0000000..a4198b3 --- /dev/null +++ b/src/test/transpose.cpp @@ -0,0 +1,154 @@ +// -*- c-basic-offset: 4 -*- +// + +#include "NotationTypes.h" +#include "gui/dialogs/IntervalDialog.h" + +using namespace Rosegarden; +using std::cout; + +// Unit test-ish tests for transposition. +// +// Returns -1 (or crashes :)) on error, 0 on success + +/** + * should be in Pitch eventually + */ +int testAisDisplayAccidentalInCmaj() +{ + Pitch ais(70, Accidentals::Sharp); + Key cmaj ("C major"); + Accidental accidental = ais.getDisplayAccidental(cmaj); + if (accidental != Accidentals::Sharp) + { + std::cout << "Accidental for A# in Cmaj was " << accidental << " instead of expected Sharp" << std::endl; + return -1; + } + + return 0; +} + +/** + * transpose an C# down by an augmented prime in C# major, should yield a C (in C major) + */ +int testCisToC() +{ + std::cout << "Testing transposing C# to C... "; + + Pitch cis(73, Accidentals::Sharp); + Pitch result = cis.transpose(Key("C# major"), -1, 0); + + Accidental resultAccidental = result.getAccidental(Key("C major")); + int resultPitch = result.getPerformancePitch(); + if (resultAccidental != Accidentals::NoAccidental || resultPitch != 72) + { + std::cout << "Transposing C# down by an augmented prime didn't yield C, but " << result.getNoteName(Key("C major")) << resultAccidental << std::endl; + return -1; + } + + return 0; +} + +/** + * transpose an A# up by a major second, should + * yield a B# (as C would be a minor triad) + */ +int testAisToBis() +{ + std::cout << "Testing transposing A# to B#... "; + Pitch ais(70, Accidentals::Sharp); + Key cmaj ("C major"); + + Pitch result = ais.transpose(cmaj, 2, 1); + + Accidental resultAccidental = result.getAccidental(cmaj); + int resultPitch = result.getPerformancePitch(); + if (resultAccidental != Accidentals::Sharp || resultPitch != 72) + { + std::cout << "Transposing A# up by a major second didn't yield B#, but " << result.getNoteName(cmaj) << resultAccidental << std::endl; + return -1; + } + std::cout << "Success" << std::endl; + + return 0; +} + +/** + * Transpose G to D in the key of D major. + */ +int testGToD() +{ + std::cout << "Testing transposing G to D... "; + Pitch g(67, Accidentals::Natural); + Key* dmaj = new Key("D major"); + + Pitch result = g.transpose(*dmaj, 7, 4); + + Accidental resultAccidental = result.getAccidental(*dmaj); + int resultPitch = result.getPerformancePitch(); + if (resultAccidental != Accidentals::NoAccidental || resultPitch != 74) + { + std::cout << "Transposing G up by a fifth didn't yield D, but " << result.getNoteName(*dmaj) << resultAccidental << std::endl; + return -1; + } + std::cout << "Success" << std::endl; + return 0; +} + +int testTransposeBbToF() +{ + Pitch bb(70, Accidentals::Flat); + Key besmaj("Bb major"); + Pitch result = bb.transpose(besmaj, -5, -3); + + Accidental resultAccidental = result.getAccidental(besmaj); + int resultPitch = result.getPerformancePitch(); + if (resultAccidental != Accidentals::NoAccidental || resultPitch != 65) + { + return -1; + } + return 0; +} + +int testIntervalString(int steps, int semitones, QString expectedString) +{ + QString text = IntervalDialog::getIntervalName(steps, semitones); + if (text != expectedString) { + std::cout << "When converting the interval " << steps << "," << semitones << " to string, expected '" << expectedString << "' but got '" << text << "'" << std::endl; + return -1; + } + return 0; +} + +int testIntervalToString() +{ + return testIntervalString(1,1,"up a minor second") + + testIntervalString(0,0,"a perfect unison") + + testIntervalString(0,1,"up an augmented unison") + + testIntervalString(7,12,"up 1 octave") + + testIntervalString(7,13,"up an augmented octave"); + + QString text = IntervalDialog::getIntervalName(1, 1); + std::cout << "Minor second: " << text << std::endl; + + text = IntervalDialog::getIntervalName(0, 0); + std::cout << "Perfect unison: " << text << std::endl; + text = IntervalDialog::getIntervalName(0, 1); + std::cout << "Augmented unison: " << text << std::endl; + text = IntervalDialog::getIntervalName(7, 12); + std::cout << "1 octave: " << text << std::endl; + text = IntervalDialog::getIntervalName(7, 13); + std::cout << "Octave and augmented unison: " << text << std::endl; + return 0; +} + +int test_transpose(int argc, char **argv) +{ + return testAisDisplayAccidentalInCmaj() + + testAisToBis() + + testGToD() + + testTransposeBbToF() + + testIntervalToString() + + testCisToC(); + +} |