1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
/*
Q Light Controller Plus - Unit test
keypadparser_test.cpp
Copyright (c) Massimo Callegari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <QtTest>
#include "keypadparser_test.h"
#include "keypadparser.h"
#include "qlcfile.h"
#include "fixture.h"
#include "doc.h"
#undef private
#undef protected
#include "../common/resource_paths.h"
void KeyPadParser_Test::initTestCase()
{
m_doc = new Doc(this);
QDir dir(INTERNAL_FIXTUREDIR);
dir.setFilter(QDir::Files);
dir.setNameFilters(QStringList() << QString("*%1").arg(KExtFixture));
QVERIFY(m_doc->fixtureDefCache()->loadMap(dir));
}
void KeyPadParser_Test::parsing()
{
KeyPadParser parser;
QList<SceneValue> scvList;
QByteArray universeValues;
quint32 chnum;
universeValues.fill(0, 512);
/* set channel 13 to value 148 */
scvList = parser.parseCommand(m_doc, "13 AT 148", universeValues);
QCOMPARE(scvList.count(), 1);
QCOMPARE(scvList.first().fxi, Fixture::invalidId());
QCOMPARE(scvList.first().channel, quint32(12));
QCOMPARE(scvList.first().value, uchar(148));
/* set channels 3 to 15 to value 133 */
scvList = parser.parseCommand(m_doc, "3 THRU 15 AT 133", universeValues);
QCOMPARE(scvList.count(), 13);
chnum = 2;
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum++);
QCOMPARE(scv.value, uchar(133));
}
/* Set channel 18 to value 255 */
scvList = parser.parseCommand(m_doc, "18 FULL", universeValues);
QCOMPARE(scvList.count(), 1);
QCOMPARE(scvList.first().fxi, Fixture::invalidId());
QCOMPARE(scvList.first().channel, quint32(17));
QCOMPARE(scvList.first().value, uchar(255));
/* Set channels 1 to 10 to value 255 */
scvList = parser.parseCommand(m_doc, "1 THRU 10 FULL", universeValues);
chnum = 0;
QCOMPARE(scvList.count(), 10);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum++);
QCOMPARE(scv.value, uchar(255));
}
/* Set channel 4 to value 0 */
scvList = parser.parseCommand(m_doc, "4 ZERO", universeValues);
QCOMPARE(scvList.count(), 1);
QCOMPARE(scvList.first().fxi, Fixture::invalidId());
QCOMPARE(scvList.first().channel, quint32(3));
QCOMPARE(scvList.first().value, uchar(0));
scvList = parser.parseCommand(m_doc, "18 THRU 25 AT 0 THRU 255", universeValues);
chnum = 17;
float val = 0;
float delta = 255.0 / 7;
QCOMPARE(scvList.count(), 8);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum++);
QCOMPARE(scv.value, uchar(val));
universeValues[chnum] = val;
val += delta;
}
scvList = parser.parseCommand(m_doc, "AT ZERO", universeValues);
chnum = 17;
QCOMPARE(scvList.count(), 8);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum++);
QCOMPARE(scv.value, uchar(0));
universeValues[chnum] = val;
}
scvList = parser.parseCommand(m_doc, "AT 123", universeValues);
chnum = 17;
QCOMPARE(scvList.count(), 8);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum++);
QCOMPARE(scv.value, uchar(123));
universeValues[chnum] = val;
}
scvList = parser.parseCommand(m_doc, "AT FULL", universeValues);
chnum = 17;
QCOMPARE(scvList.count(), 8);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum++);
QCOMPARE(scv.value, uchar(255));
universeValues[chnum] = val;
}
/* Set channels 6, 8, 10, 12, 14 and 16 to value 100 */
scvList = parser.parseCommand(m_doc, "6 THRU 16 BY 2 AT 100", universeValues);
chnum = 5;
QCOMPARE(scvList.count(), 6);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum);
QCOMPARE(scv.value, uchar(100));
universeValues[chnum] = 100;
chnum += 2;
}
/* Increase the value of the channels set by last command by 20% */
scvList = parser.parseCommand(m_doc, "6 THRU 16 BY 2 +% 20", universeValues);
chnum = 5;
QCOMPARE(scvList.count(), 6);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum);
QCOMPARE(scv.value, uchar(120));
universeValues[chnum] = 120;
chnum += 2;
}
/* Decrease the value of the channels set by last command by 40% */
scvList = parser.parseCommand(m_doc, "6 THRU 16 BY 2 -% 40", universeValues);
chnum = 5;
QCOMPARE(scvList.count(), 6);
foreach (SceneValue scv, scvList)
{
QCOMPARE(scv.fxi, Fixture::invalidId());
QCOMPARE(scv.channel, chnum);
QCOMPARE(scv.value, uchar(72));
universeValues[chnum] = 72;
chnum += 2;
}
}
void KeyPadParser_Test::cleanupTestCase()
{
delete m_doc;
}
QTEST_APPLESS_MAIN(KeyPadParser_Test)
|