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 <QByteArray>
21 #include <QDataStream>
22 #include <QObject>
23 #include <QString>
24 #include <QtTest>
25 #include <drumstick/pianopalette.h>
26
27 using namespace drumstick::widgets;
28
29 class WidgetsTest : public QObject
30 {
31 Q_OBJECT
32 public:
33 WidgetsTest();
34
35 private Q_SLOTS:
36 void testPaletteSingle();
37 void testPaletteDouble();
38 void testPaletteChannels();
39 void testPaletteScale();
40 void testPaletteKeys();
41 void testPaletteFont();
42
43 void testPaletteAssign();
44 void testPaletteUnchanged();
45 void testPaletteChanged();
46
47 private:
48 QList<PianoPalette> m_paletteList {
49 PianoPalette(PAL_SINGLE),
50 PianoPalette(PAL_DOUBLE),
51 PianoPalette(PAL_CHANNELS),
52 PianoPalette(PAL_SCALE),
53 PianoPalette(PAL_KEYS),
54 PianoPalette(PAL_FONT),
55 };
56 };
57
58 WidgetsTest::WidgetsTest() = default;
59 //{
60 // for( PianoPalette& pal : m_paletteList) {
61 // ... pal.paletteId();
62 // }
63 //}
64
testPaletteSingle()65 void WidgetsTest::testPaletteSingle()
66 {
67 PianoPalette p(PAL_SINGLE);
68 QCOMPARE(p, m_paletteList[PAL_SINGLE]);
69 QCOMPARE(p.paletteId(), static_cast<int>(PAL_SINGLE));
70 QCOMPARE(p.getNumColors(), 1);
71 QCOMPARE(p.isHighLight(), true);
72 QCOMPARE(p.isBackground(), false);
73 QCOMPARE(p.isForeground(), false);
74 }
75
testPaletteDouble()76 void WidgetsTest::testPaletteDouble()
77 {
78 PianoPalette p(PAL_DOUBLE);
79 QCOMPARE(p, m_paletteList[PAL_DOUBLE]);
80 QCOMPARE(p.paletteId(), static_cast<int>(PAL_DOUBLE));
81 QCOMPARE(p.getNumColors(), 2);
82 QCOMPARE(p.isHighLight(), true);
83 QCOMPARE(p.isBackground(), false);
84 QCOMPARE(p.isForeground(), false);
85 }
86
testPaletteChannels()87 void WidgetsTest::testPaletteChannels()
88 {
89 PianoPalette p(PAL_CHANNELS);
90 QCOMPARE(p, m_paletteList[PAL_CHANNELS]);
91 QCOMPARE(p.paletteId(), static_cast<int>(PAL_CHANNELS));
92 QCOMPARE(p.getNumColors(), 16);
93 QCOMPARE(p.isHighLight(), true);
94 QCOMPARE(p.isBackground(), false);
95 QCOMPARE(p.isForeground(), false);
96 }
97
testPaletteScale()98 void WidgetsTest::testPaletteScale()
99 {
100 PianoPalette p(PAL_SCALE);
101 QCOMPARE(p, m_paletteList[PAL_SCALE]);
102 QCOMPARE(p.paletteId(), static_cast<int>(PAL_SCALE));
103 QCOMPARE(p.getNumColors(), 12);
104 QCOMPARE(p.isHighLight(), false);
105 QCOMPARE(p.isBackground(), true);
106 QCOMPARE(p.isForeground(), false);
107 }
108
testPaletteKeys()109 void WidgetsTest::testPaletteKeys()
110 {
111 PianoPalette p(PAL_KEYS);
112 QCOMPARE(p, m_paletteList[PAL_KEYS]);
113 QCOMPARE(p.paletteId(), static_cast<int>(PAL_KEYS));
114 QCOMPARE(p.getNumColors(), 2);
115 QCOMPARE(p.isHighLight(), false);
116 QCOMPARE(p.isBackground(), true);
117 QCOMPARE(p.isForeground(), false);
118 }
119
testPaletteFont()120 void WidgetsTest::testPaletteFont()
121 {
122 PianoPalette p(PAL_FONT);
123 QCOMPARE(p, m_paletteList[PAL_FONT]);
124 QCOMPARE(p.paletteId(), static_cast<int>(PAL_FONT));
125 QCOMPARE(p.getNumColors(), 4);
126 QCOMPARE(p.isHighLight(), false);
127 QCOMPARE(p.isBackground(), false);
128 QCOMPARE(p.isForeground(), true);
129 }
130
testPaletteAssign()131 void WidgetsTest::testPaletteAssign()
132 {
133 PianoPalette a(PAL_SINGLE);
134 PianoPalette b(PAL_DOUBLE);
135 a = b;
136 QCOMPARE(a, b);
137 QCOMPARE(a, m_paletteList[PAL_DOUBLE]);
138 QCOMPARE(a.paletteId(), b.paletteId());
139 QCOMPARE(a.getNumColors(), b.getNumColors());
140 }
141
testPaletteUnchanged()142 void WidgetsTest::testPaletteUnchanged()
143 {
144 PianoPalette p(PAL_KEYS);
145 p.setColor(0, Qt::white);
146 p.setColor(1, Qt::black);
147 QCOMPARE(p, m_paletteList[PAL_KEYS]);
148 QCOMPARE(p.paletteId(), static_cast<int>(PAL_KEYS));
149 QCOMPARE(p.getNumColors(), 2);
150 }
151
testPaletteChanged()152 void WidgetsTest::testPaletteChanged()
153 {
154 PianoPalette p(PAL_KEYS);
155 p.setColor(0, Qt::black);
156 p.setColor(1, Qt::white);
157 QVERIFY(p != m_paletteList[PAL_KEYS]);
158 p.resetColors();
159 QCOMPARE(p, m_paletteList[PAL_KEYS]);
160 }
161
162 QTEST_MAIN(WidgetsTest)
163
164 #include "widgetstest.moc"
165