1 /*
2 Copyright (C) 2008-2021, Pedro Lopez-Cabanillas <plcl@users.sf.net>
3
4 This file is part of the Drumstick project, see https://sf.net/p/drumstick
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <QString>
21 #include <QtTest>
22 #include <drumstick/alsaevent.h>
23
24 using namespace drumstick::ALSA;
25
26 class AlsaTest1 : public QObject
27 {
28 Q_OBJECT
29
30 public:
31 AlsaTest1();
32
33 private Q_SLOTS:
34 void testEvents();
35 };
36
37 AlsaTest1::AlsaTest1() = default;
38
testEvents()39 void AlsaTest1::testEvents()
40 {
41 NoteEvent note(0, 60, 100, 120);
42 QCOMPARE(note.getChannel(), 0);
43 QCOMPARE(note.getKey(), 60);
44 QCOMPARE(note.getVelocity(), 100);
45 QCOMPARE(note.getDuration(), 120uL);
46
47 NoteOnEvent noteOn(1, 60, 100);
48 QCOMPARE(noteOn.getChannel(), 1);
49 QCOMPARE(noteOn.getKey(), 60);
50 QCOMPARE(noteOn.getVelocity(), 100);
51
52 NoteOffEvent noteOff(2, 60, 0);
53 QCOMPARE(noteOff.getChannel(), 2);
54 QCOMPARE(noteOff.getKey(), 60);
55 QCOMPARE(noteOff.getVelocity(), 0);
56
57 ControllerEvent ctl(3, 33, 66);
58 QCOMPARE(ctl.getChannel(), 3);
59 QCOMPARE(ctl.getParam(), 33u);
60 QCOMPARE(ctl.getValue(), 66);
61
62 ProgramChangeEvent pgm(4, 123);
63 QCOMPARE(pgm.getChannel(), 4);
64 QCOMPARE(pgm.getValue(), 123);
65
66 KeyPressEvent keyPress(5, 60, 124);
67 QCOMPARE(keyPress.getChannel(), 5);
68 QCOMPARE(keyPress.getKey(), 60);
69 QCOMPARE(keyPress.getVelocity(), 124);
70
71 ChanPressEvent chanPress(6, 111);
72 QCOMPARE(chanPress.getChannel(), 6);
73 QCOMPARE(chanPress.getValue(), 111);
74
75 PitchBendEvent bender(7, 1234);
76 QCOMPARE(bender.getChannel(), 7);
77 QCOMPARE(bender.getValue(), 1234);
78
79 QByteArray sysexData = QByteArray::fromHex("f04110421240007f0041f7");
80 SysExEvent sysexEvent(sysexData);
81 QCOMPARE(sysexEvent.getData(), sysexData.data());
82 QCOMPARE(sysexEvent.getLength(), (unsigned) sysexData.length());
83
84 QString text = "This can be a copyright, song name, instrument, lyric...";
85 TextEvent textEvent(text, 3);
86 QCOMPARE(textEvent.getText(), text);
87 QCOMPARE(textEvent.getLength(), (unsigned) text.length());
88 }
89
90 QTEST_APPLESS_MAIN(AlsaTest1)
91
92 #include "alsatest1.moc"
93