1 /* -*- Mode: c++ -*- */
2 /***************************************************************************
3  *            midimapparsertest.cc
4  *
5  *  Wed Jul 25 20:37:23 CEST 2018
6  *  Copyright 2018 Bent Bisballe Nyeng
7  *  deva@aasimon.org
8  ****************************************************************************/
9 
10 /*
11  *  This file is part of DrumGizmo.
12  *
13  *  DrumGizmo is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU Lesser General Public License as published by
15  *  the Free Software Foundation; either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  DrumGizmo is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU Lesser General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Lesser General Public License
24  *  along with DrumGizmo; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
26  */
27 #include <uunit.h>
28 
29 #include <midimapparser.h>
30 
31 #include "scopedfile.h"
32 
33 class MidimapParserTest
34 	: public uUnit
35 {
36 public:
MidimapParserTest()37 	MidimapParserTest()
38 	{
39 		uUNIT_TEST(MidimapParserTest::test);
40 		uUNIT_TEST(MidimapParserTest::invalid);
41 	}
42 
test()43 	void test()
44 	{
45 		ScopedFile scoped_file(
46 			"<?xml version='1.0' encoding='UTF-8'?>\n" \
47 			"<midimap>\n" \
48 			"	<map note=\"54\" instr=\"Crash_left_tip\"/>\n" \
49 			"	<map note=\"60\" instr=\"Crash_left_whisker\"/>\n" \
50 			"	<map note=\"55\" instr=\"Crash_right_tip\"/>\n" \
51 			"	<map note=\"62\" instr=\"Crash_right_whisker\"/>\n" \
52 			"	<map note=\"56\" instr=\"Hihat_closed\"/>\n" \
53 			"</midimap>");
54 
55 		MidiMapParser parser;
56 		uUNIT_ASSERT(parser.parseFile(scoped_file.filename()));
57 
58 		uUNIT_ASSERT(parser.midimap.find(54) != parser.midimap.end());
59 		uUNIT_ASSERT(parser.midimap.find(60) != parser.midimap.end());
60 		uUNIT_ASSERT(parser.midimap.find(55) != parser.midimap.end());
61 		uUNIT_ASSERT(parser.midimap.find(62) != parser.midimap.end());
62 		uUNIT_ASSERT(parser.midimap.find(56) != parser.midimap.end());
63 
64 		uUNIT_ASSERT_EQUAL(std::string("Crash_left_tip"), parser.midimap[54]);
65 		uUNIT_ASSERT_EQUAL(std::string("Crash_left_whisker"), parser.midimap[60]);
66 		uUNIT_ASSERT_EQUAL(std::string("Crash_right_tip"), parser.midimap[55]);
67 		uUNIT_ASSERT_EQUAL(std::string("Crash_right_whisker"), parser.midimap[62]);
68 		uUNIT_ASSERT_EQUAL(std::string("Hihat_closed"), parser.midimap[56]);
69 	}
70 
invalid()71 	void invalid()
72 	{
73 		ScopedFile scoped_file(
74 			"<?xml version='1.0' encoding='UTF-8'?>\n" \
75 			"<midimap\n" \
76 			"	<map note=\"54\" instr=\"Crash_left_tip\"/>\n" \
77 			"	<map note=\"60\" instr=\"Crash_left_whisker\"/>\n" \
78 			"	<map note=\"55\" instr=\"Crash_right_tip\"/>\n" \
79 			"	<map note=\"62\" instr=\"Crash_right_whisker\"/>\n" \
80 			"	<map note=\"56\" instr=\"Hihat_closed\"/>\n" \
81 			"</midimap>");
82 
83 		MidiMapParser parser;
84 		uUNIT_ASSERT(!parser.parseFile(scoped_file.filename()));
85 	}
86 };
87 
88 // Registers the fixture into the 'registry'
89 static MidimapParserTest test;
90