static Chaser* createChaser(Doc* doc) { Fixture* fxi = new Fixture(doc); fxi->setChannels(1); doc->addFixture(fxi); Scene* s1 = new Scene(doc); s1->setName("First"); s1->setValue(fxi->id(), 0, 255); doc->addFunction(s1); Scene* s2 = new Scene(doc); s2->setName("Second"); s2->setValue(fxi->id(), 0, 127); doc->addFunction(s2); Scene* s3 = new Scene(doc); s3->setName("Third"); s3->setValue(fxi->id(), 0, 64); doc->addFunction(s3); Scene* s4 = new Scene(doc); s4->setName("Fourth"); s4->setValue(fxi->id(), 0, 32); doc->addFunction(s4); Chaser* c = new Chaser(doc); c->addStep(ChaserStep(s1->id())); c->addStep(ChaserStep(s2->id())); c->addStep(ChaserStep(s3->id())); c->addStep(ChaserStep(s4->id())); doc->addFunction(c); return c; }
void Chaser::slotFunctionRemoved(quint32 fid) { m_stepListMutex.lock(); int count = m_steps.removeAll(ChaserStep(fid)); m_stepListMutex.unlock(); if (count > 0) emit changed(this->id()); }
void Chaser_Test::clear() { Chaser c(m_doc); c.setID(50); QCOMPARE(c.steps().size(), 0); c.addStep(ChaserStep(0)); c.addStep(ChaserStep(1)); c.addStep(ChaserStep(2)); c.addStep(ChaserStep(470)); QCOMPARE(c.steps().size(), 4); QSignalSpy spy(&c, SIGNAL(changed(quint32))); c.clear(); QCOMPARE(c.steps().size(), 0); QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).size(), 1); QCOMPARE(spy.at(0).at(0).toUInt(), quint32(50)); }
void Chaser::slotFunctionRemoved(quint32 fid) { int count; { QMutexLocker stepListLocker(&m_stepListMutex); count = m_steps.removeAll(ChaserStep(fid)); } if (count > 0) emit changed(this->id()); }
void ChaserRunner_Test::init() { QLCFixtureDef* def = m_doc->fixtureDefCache()->fixtureDef("Futurelight", "DJScan250"); QVERIFY(def != NULL); QLCFixtureMode* mode = def->mode("Mode 1"); QVERIFY(mode != NULL); Fixture* fxi = new Fixture(m_doc); QVERIFY(fxi != NULL); fxi->setFixtureDefinition(def, mode); fxi->setName("Test Fixture"); fxi->setAddress(0); fxi->setUniverse(0); m_doc->addFixture(fxi); m_scene1 = new Scene(m_doc); m_scene1->setName("S1"); QVERIFY(m_scene1 != NULL); for (quint32 i = 0; i < fxi->channels(); i++) m_scene1->setValue(fxi->id(), i, 255 - i); m_doc->addFunction(m_scene1); m_scene2 = new Scene(m_doc); m_scene2->setName("S2"); QVERIFY(m_scene2 != NULL); for (quint32 i = 0; i < fxi->channels(); i++) m_scene2->setValue(fxi->id(), i, 127 - i); m_doc->addFunction(m_scene2); m_scene3 = new Scene(m_doc); m_scene3->setName("S3"); QVERIFY(m_scene3 != NULL); for (quint32 i = 0; i < fxi->channels(); i++) m_scene3->setValue(fxi->id(), i, 0 + i); m_doc->addFunction(m_scene3); m_chaser = new Chaser(m_doc); m_chaser->addStep(ChaserStep(m_scene1->id())); m_chaser->addStep(ChaserStep(m_scene2->id())); m_chaser->addStep(ChaserStep(m_scene3->id())); }
void Chaser_Test::createCopy() { Doc doc(this); Chaser* c1 = new Chaser(m_doc); c1->setName("First"); c1->setFadeInSpeed(42); c1->setFadeOutSpeed(69); c1->setDuration(1337); c1->setDirection(Chaser::Backward); c1->setRunOrder(Chaser::SingleShot); c1->addStep(ChaserStep(20)); c1->addStep(ChaserStep(30)); c1->addStep(ChaserStep(40)); doc.addFunction(c1); QVERIFY(c1->id() != Function::invalidId()); Function* f = c1->createCopy(&doc); QVERIFY(f != NULL); QVERIFY(f != c1); QVERIFY(f->id() != c1->id()); Chaser* copy = qobject_cast<Chaser*> (f); QVERIFY(copy != NULL); QVERIFY(copy->fadeInSpeed() == 42); QVERIFY(copy->fadeOutSpeed() == 69); QVERIFY(copy->duration() == 1337); QVERIFY(copy->direction() == Chaser::Backward); QVERIFY(copy->runOrder() == Chaser::SingleShot); QVERIFY(copy->steps().size() == 3); QVERIFY(copy->steps().at(0) == ChaserStep(20)); QVERIFY(copy->steps().at(1) == ChaserStep(30)); QVERIFY(copy->steps().at(2) == ChaserStep(40)); }
void Chaser_Test::stepAt() { Chaser c(m_doc); c.setID(42); QVERIFY(c.addStep(ChaserStep(0, 1000, 5000, 0)) == true); QVERIFY(c.stepsCount() == 1); QVERIFY(c.stepAt(10) == NULL); ChaserStep *cs = c.stepAt(0); QVERIFY(cs != NULL); QVERIFY(cs->fadeIn == 1000); QVERIFY(cs->hold == 5000); cs->fadeIn = 500; cs->hold = 8000; QVERIFY(cs->fadeIn == 500); QVERIFY(cs->hold == 8000); }
void Chaser_Test::loadSuccess() { QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); xmlWriter.writeStartElement("Function"); xmlWriter.writeAttribute("Type", "Chaser"); xmlWriter.writeStartElement("Speed"); xmlWriter.writeAttribute("FadeIn", "42"); xmlWriter.writeAttribute("FadeOut", "69"); xmlWriter.writeAttribute("Duration", "1337"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Direction", "Backward"); xmlWriter.writeTextElement("RunOrder", "SingleShot"); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "1"); xmlWriter.writeAttribute("FadeIn", "600"); xmlWriter.writeAttribute("FadeOut", "700"); xmlWriter.writeAttribute("Duration", "800"); xmlWriter.writeCharacters("50"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "2"); xmlWriter.writeAttribute("FadeIn", "1600"); xmlWriter.writeAttribute("FadeOut", "1700"); xmlWriter.writeAttribute("Duration", "1800"); xmlWriter.writeCharacters("12"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "0"); // Let's leave these out from this step just for test's sake //s3.setAttribute("FadeIn", 2600); //s3.setAttribute("FadeOut", 2700); //s3.setAttribute("Duration", 2800); xmlWriter.writeCharacters("87"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("SpeedModes"); xmlWriter.writeAttribute("FadeIn", "Common"); xmlWriter.writeAttribute("FadeOut", "Default"); xmlWriter.writeAttribute("Duration", "PerStep"); xmlWriter.writeEndElement(); // Unknown tag xmlWriter.writeStartElement("Foo"); xmlWriter.writeAttribute("Number", "3"); xmlWriter.writeCharacters("1"); xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); Chaser c(m_doc); QVERIFY(c.loadXML(xmlReader) == true); QVERIFY(c.fadeInSpeed() == 42); QVERIFY(c.fadeOutSpeed() == 69); QVERIFY(c.duration() == 1337); QCOMPARE(c.fadeInMode(), Chaser::Common); QCOMPARE(c.fadeOutMode(), Chaser::Default); QCOMPARE(c.durationMode(), Chaser::PerStep); QVERIFY(c.direction() == Chaser::Backward); QVERIFY(c.runOrder() == Chaser::SingleShot); QVERIFY(c.steps().size() == 3); QVERIFY(c.steps().at(0) == ChaserStep(87)); QCOMPARE(c.steps().at(0).fadeIn, uint(0)); QCOMPARE(c.steps().at(0).fadeOut, uint(0)); QCOMPARE(c.steps().at(0).duration, uint(0)); QVERIFY(c.steps().at(1) == ChaserStep(50)); QCOMPARE(c.steps().at(1).fadeIn, uint(600)); QCOMPARE(c.steps().at(1).fadeOut, uint(700)); QCOMPARE(c.steps().at(1).duration, uint(800)); QVERIFY(c.steps().at(2) == ChaserStep(12)); QCOMPARE(c.steps().at(2).fadeIn, uint(1600)); QCOMPARE(c.steps().at(2).fadeOut, uint(1700)); QCOMPARE(c.steps().at(2).duration, uint(1800)); }
void Chaser_Test::copyFrom() { Chaser c1(m_doc); c1.setName("First"); c1.setDirection(Chaser::Backward); c1.setRunOrder(Chaser::PingPong); c1.setFadeInSpeed(42); c1.setFadeOutSpeed(69); c1.setDuration(1337); c1.addStep(ChaserStep(2)); c1.addStep(ChaserStep(0)); c1.addStep(ChaserStep(1)); c1.addStep(ChaserStep(25)); /* Verify that chaser contents are copied */ Chaser c2(m_doc); QSignalSpy spy(&c2, SIGNAL(changed(quint32))); QVERIFY(c2.copyFrom(&c1) == true); QCOMPARE(spy.size(), 1); QVERIFY(c2.name() == c1.name()); QVERIFY(c2.fadeInSpeed() == 42); QVERIFY(c2.fadeOutSpeed() == 69); QVERIFY(c2.duration() == 1337); QVERIFY(c2.direction() == Chaser::Backward); QVERIFY(c2.runOrder() == Chaser::PingPong); QVERIFY(c2.steps().size() == 4); QVERIFY(c2.steps().at(0) == ChaserStep(2)); QVERIFY(c2.steps().at(1) == ChaserStep(0)); QVERIFY(c2.steps().at(2) == ChaserStep(1)); QVERIFY(c2.steps().at(3) == ChaserStep(25)); /* Verify that a Chaser gets a copy only from another Chaser */ Scene s(m_doc); QVERIFY(c2.copyFrom(&s) == false); /* Make a third Chaser */ Chaser c3(m_doc); c3.setName("Third"); c3.setFadeInSpeed(142); c3.setFadeOutSpeed(169); c3.setDuration(11337); c3.setDirection(Chaser::Forward); c3.setRunOrder(Chaser::Loop); c3.addStep(ChaserStep(15)); c3.addStep(ChaserStep(94)); c3.addStep(ChaserStep(3)); /* Verify that copying TO the same Chaser a second time succeeds and that steps are not appended but replaced completely. */ QVERIFY(c2.copyFrom(&c3) == true); QVERIFY(c2.name() == c3.name()); QVERIFY(c2.fadeInSpeed() == 142); QVERIFY(c2.fadeOutSpeed() == 169); QVERIFY(c2.duration() == 11337); QVERIFY(c2.direction() == Chaser::Forward); QVERIFY(c2.runOrder() == Chaser::Loop); QVERIFY(c2.steps().size() == 3); QVERIFY(c2.steps().at(0) == ChaserStep(15)); QVERIFY(c2.steps().at(1) == ChaserStep(94)); QVERIFY(c2.steps().at(2) == ChaserStep(3)); }
void Chaser_Test::functionRemoval() { Chaser c(m_doc); c.setID(42); QVERIFY(c.steps().size() == 0); QVERIFY(c.addStep(ChaserStep(0)) == true); QVERIFY(c.addStep(ChaserStep(1)) == true); QVERIFY(c.addStep(ChaserStep(2)) == true); QVERIFY(c.addStep(ChaserStep(3)) == true); QVERIFY(c.steps().size() == 4); /* Simulate function removal signal with an uninteresting function id */ c.slotFunctionRemoved(6); QVERIFY(c.steps().size() == 4); /* Simulate function removal signal with a function in the chaser */ c.slotFunctionRemoved(1); QVERIFY(c.steps().size() == 3); QVERIFY(c.steps().at(0) == ChaserStep(0)); QVERIFY(c.steps().at(1) == ChaserStep(2)); QVERIFY(c.steps().at(2) == ChaserStep(3)); /* Simulate function removal signal with an invalid function id */ c.slotFunctionRemoved(Function::invalidId()); QVERIFY(c.steps().size() == 3); QVERIFY(c.steps().at(0) == ChaserStep(0)); QVERIFY(c.steps().at(1) == ChaserStep(2)); QVERIFY(c.steps().at(2) == ChaserStep(3)); /* Simulate function removal signal with a function in the chaser */ c.slotFunctionRemoved(0); QVERIFY(c.steps().size() == 2); QVERIFY(c.steps().at(0) == ChaserStep(2)); QVERIFY(c.steps().at(1) == ChaserStep(3)); }
void ChaserRunner_Test::currentDuration() { m_chaser->setDirection(Function::Forward); m_chaser->setRunOrder(Function::Loop); m_chaser->setDuration(300); m_chaser->replaceStep(ChaserStep(m_scene1->id(), 1000, 2000, 3000), 0); m_chaser->replaceStep(ChaserStep(m_scene2->id(), 1100, 2100, 3100), 1); m_chaser->replaceStep(ChaserStep(m_scene3->id(), 1200, 2200, 3200), 2); ChaserRunner cr(m_doc, m_chaser); // Default mode for duration is interpreted as Common m_chaser->setDurationMode(Chaser::Default); cr.m_currentStep = 0; QCOMPARE(cr.currentDuration(), uint(300)); cr.m_currentStep = 1; QCOMPARE(cr.currentDuration(), uint(300)); cr.m_currentStep = 2; QCOMPARE(cr.currentDuration(), uint(300)); m_chaser->setDurationMode(Chaser::Common); cr.m_currentStep = 0; QCOMPARE(cr.currentDuration(), uint(300)); cr.m_currentStep = 1; QCOMPARE(cr.currentDuration(), uint(300)); cr.m_currentStep = 2; QCOMPARE(cr.currentDuration(), uint(300)); m_chaser->setDurationMode(Chaser::PerStep); cr.m_currentStep = 0; QCOMPARE(cr.currentDuration(), uint(3000)); cr.m_currentStep = 1; QCOMPARE(cr.currentDuration(), uint(3200)); cr.m_currentStep = 2; QCOMPARE(cr.currentDuration(), uint(3400)); cr.m_currentStep = 3; // Nonexistent step QCOMPARE(cr.currentDuration(), uint(300)); // Fall back to common speed // Check that override speed really overrides any setting m_chaser->setOverrideDuration(1234); m_chaser->setDurationMode(Chaser::Default); cr.m_currentStep = 0; QCOMPARE(cr.currentDuration(), uint(1234)); cr.m_currentStep = 1; QCOMPARE(cr.currentDuration(), uint(1234)); cr.m_currentStep = 2; QCOMPARE(cr.currentDuration(), uint(1234)); m_chaser->setDurationMode(Chaser::Common); cr.m_currentStep = 0; QCOMPARE(cr.currentDuration(), uint(1234)); cr.m_currentStep = 1; QCOMPARE(cr.currentDuration(), uint(1234)); cr.m_currentStep = 2; QCOMPARE(cr.currentDuration(), uint(1234)); m_chaser->setDurationMode(Chaser::PerStep); cr.m_currentStep = 0; QCOMPARE(cr.currentDuration(), uint(1234)); cr.m_currentStep = 1; QCOMPARE(cr.currentDuration(), uint(1234)); cr.m_currentStep = 2; QCOMPARE(cr.currentDuration(), uint(1234)); cr.m_currentStep = 3; // Nonexistent step QCOMPARE(cr.currentDuration(), uint(1234)); }
void Chaser_Test::steps() { Chaser c(m_doc); c.setID(50); QVERIFY(c.steps().size() == 0); /* A chaser should not be allowed to be its own member */ QVERIFY(c.addStep(ChaserStep(50)) == false); QVERIFY(c.steps().size() == 0); /* Add a function with id "12" to the chaser */ QVERIFY(c.addStep(12)); QVERIFY(c.steps().size() == 1); QVERIFY(c.steps().at(0) == ChaserStep(12)); /* Add another function in the middle */ QVERIFY(c.addStep(ChaserStep(34))); QVERIFY(c.steps().size() == 2); QVERIFY(c.steps().at(0) == ChaserStep(12)); QVERIFY(c.steps().at(1) == ChaserStep(34)); /* Must be able to add the same function multiple times */ QVERIFY(c.addStep(ChaserStep(12))); QVERIFY(c.steps().size() == 3); QVERIFY(c.steps().at(0) == ChaserStep(12)); QVERIFY(c.steps().at(1) == ChaserStep(34)); QVERIFY(c.steps().at(2) == ChaserStep(12)); /* Must be able to replace a step to another */ QVERIFY(c.replaceStep(ChaserStep(42), 1)); QVERIFY(c.steps().at(0) == ChaserStep(12)); QVERIFY(c.steps().at(1) == ChaserStep(42)); QVERIFY(c.steps().at(2) == ChaserStep(12)); /* Cannot replace a nonexistent step */ QVERIFY(c.replaceStep(ChaserStep(69), 5) == false); /* Removing a non-existent index should make no modifications */ QVERIFY(c.removeStep(3) == false); QVERIFY(c.steps().size() == 3); QVERIFY(c.steps().at(0) == ChaserStep(12)); QVERIFY(c.steps().at(1) == ChaserStep(42)); QVERIFY(c.steps().at(2) == ChaserStep(12)); /* Removing the last step should succeed */ QVERIFY(c.removeStep(2) == true); QVERIFY(c.steps().size() == 2); QVERIFY(c.steps().at(0) == ChaserStep(12)); QVERIFY(c.steps().at(1) == ChaserStep(42)); /* Removing the first step should succeed */ QVERIFY(c.removeStep(0) == true); QVERIFY(c.steps().size() == 1); QVERIFY(c.steps().at(0) == ChaserStep(42)); /* Removing the only step should succeed */ QVERIFY(c.removeStep(0) == true); QVERIFY(c.steps().size() == 0); /* Step insertion */ QVERIFY(c.addStep(ChaserStep(1), 0)); QVERIFY(c.addStep(ChaserStep(2), 0)); QVERIFY(c.steps().size() == 2); QVERIFY(c.steps().at(0) == ChaserStep(2)); QVERIFY(c.steps().at(1) == ChaserStep(1)); }
ChaserStep Chaser::stepAt(int idx) { if (idx >= 0 && idx < m_steps.count()) return m_steps.at(idx); return ChaserStep(); }
void ChaserRunner_Test::currentFadeOut() { m_chaser->setDirection(Function::Forward); m_chaser->setRunOrder(Function::Loop); m_chaser->setFadeOutSpeed(200); m_chaser->replaceStep(ChaserStep(m_scene1->id(), 1000, 2000, 3000), 0); m_chaser->replaceStep(ChaserStep(m_scene2->id(), 1100, 2100, 3100), 1); m_chaser->replaceStep(ChaserStep(m_scene3->id(), 1200, 2200, 3200), 2); ChaserRunner cr(m_doc, m_chaser); m_chaser->setFadeOutMode(Chaser::Default); cr.m_currentStep = 0; QCOMPARE(cr.currentFadeOut(), Function::defaultSpeed()); cr.m_currentStep = 1; QCOMPARE(cr.currentFadeOut(), Function::defaultSpeed()); cr.m_currentStep = 2; QCOMPARE(cr.currentFadeOut(), Function::defaultSpeed()); m_chaser->setFadeOutMode(Chaser::Common); cr.m_currentStep = 0; QCOMPARE(cr.currentFadeOut(), uint(200)); cr.m_currentStep = 1; QCOMPARE(cr.currentFadeOut(), uint(200)); cr.m_currentStep = 2; QCOMPARE(cr.currentFadeOut(), uint(200)); m_chaser->setFadeOutMode(Chaser::PerStep); cr.m_currentStep = 0; QCOMPARE(cr.currentFadeOut(), uint(3000)); cr.m_currentStep = 1; QCOMPARE(cr.currentFadeOut(), uint(3100)); cr.m_currentStep = 2; QCOMPARE(cr.currentFadeOut(), uint(3200)); cr.m_currentStep = 3; // Nonexistent step QCOMPARE(cr.currentFadeOut(), Function::defaultSpeed()); // Check that override speed really overrides any setting m_chaser->setOverrideFadeOutSpeed(1234); m_chaser->setFadeOutMode(Chaser::Default); cr.m_currentStep = 0; QCOMPARE(cr.currentFadeOut(), uint(1234)); cr.m_currentStep = 1; QCOMPARE(cr.currentFadeOut(), uint(1234)); cr.m_currentStep = 2; QCOMPARE(cr.currentFadeOut(), uint(1234)); m_chaser->setFadeOutMode(Chaser::Common); cr.m_currentStep = 0; QCOMPARE(cr.currentFadeOut(), uint(1234)); cr.m_currentStep = 1; QCOMPARE(cr.currentFadeOut(), uint(1234)); cr.m_currentStep = 2; QCOMPARE(cr.currentFadeOut(), uint(1234)); m_chaser->setFadeOutMode(Chaser::PerStep); cr.m_currentStep = 0; QCOMPARE(cr.currentFadeOut(), uint(1234)); cr.m_currentStep = 1; QCOMPARE(cr.currentFadeOut(), uint(1234)); cr.m_currentStep = 2; QCOMPARE(cr.currentFadeOut(), uint(1234)); cr.m_currentStep = 3; // Nonexistent step QCOMPARE(cr.currentFadeOut(), uint(1234)); }
void Chaser_Test::postLoad() { Scene* sc1 = new Scene(m_doc); m_doc->addFunction(sc1); Scene* sc2 = new Scene(m_doc); m_doc->addFunction(sc2); Chaser* ch1 = new Chaser(m_doc); m_doc->addFunction(ch1); Chaser* ch2 = new Chaser(m_doc); m_doc->addFunction(ch2); Collection* co1 = new Collection(m_doc); m_doc->addFunction(co1); Collection* co2 = new Collection(m_doc); m_doc->addFunction(co2); EFX* ef1 = new EFX(m_doc); m_doc->addFunction(ef1); EFX* ef2 = new EFX(m_doc); m_doc->addFunction(ef2); QDomDocument doc; QDomElement root = doc.createElement("Function"); root.setAttribute("Type", "Chaser"); QDomElement bus = doc.createElement("Bus"); bus.setAttribute("Role", "Hold"); QDomText busText = doc.createTextNode("16"); bus.appendChild(busText); root.appendChild(bus); QDomElement dir = doc.createElement("Direction"); QDomText dirText = doc.createTextNode("Backward"); dir.appendChild(dirText); root.appendChild(dir); QDomElement run = doc.createElement("RunOrder"); QDomText runText = doc.createTextNode("SingleShot"); run.appendChild(runText); root.appendChild(run); QDomElement step0 = doc.createElement("Step"); step0.setAttribute("Number", 0); QDomText step0Text = doc.createTextNode(QString::number(sc1->id())); step0.appendChild(step0Text); root.appendChild(step0); QDomElement step1 = doc.createElement("Step"); step1.setAttribute("Number", 1); QDomText step1Text = doc.createTextNode(QString::number(sc2->id())); step1.appendChild(step1Text); root.appendChild(step1); QDomElement step2 = doc.createElement("Step"); step2.setAttribute("Number", 2); QDomText step2Text = doc.createTextNode(QString::number(ch1->id())); step2.appendChild(step2Text); root.appendChild(step2); QDomElement step3 = doc.createElement("Step"); step3.setAttribute("Number", 3); QDomText step3Text = doc.createTextNode(QString::number(ch2->id())); step3.appendChild(step3Text); root.appendChild(step3); QDomElement step4 = doc.createElement("Step"); step4.setAttribute("Number", 4); QDomText step4Text = doc.createTextNode(QString::number(co1->id())); step4.appendChild(step4Text); root.appendChild(step4); QDomElement step5 = doc.createElement("Step"); step5.setAttribute("Number", 5); QDomText step5Text = doc.createTextNode(QString::number(co2->id())); step5.appendChild(step5Text); root.appendChild(step5); QDomElement step6 = doc.createElement("Step"); step6.setAttribute("Number", 6); QDomText step6Text = doc.createTextNode(QString::number(ef1->id())); step6.appendChild(step6Text); root.appendChild(step6); QDomElement step7 = doc.createElement("Step"); step7.setAttribute("Number", 7); QDomText step7Text = doc.createTextNode(QString::number(ef2->id())); step7.appendChild(step7Text); root.appendChild(step7); // Nonexistent function QDomElement step8 = doc.createElement("Step"); step8.setAttribute("Number", 8); QDomText step8Text = doc.createTextNode(QString::number(INT_MAX - 1)); step8.appendChild(step8Text); root.appendChild(step8); // Unknown tag QDomElement foo = doc.createElement("Foo"); foo.setAttribute("Number", 3); QDomText fooText = doc.createTextNode("1"); foo.appendChild(fooText); root.appendChild(foo); Chaser c(m_doc); QCOMPARE(c.loadXML(root), true); QCOMPARE(c.direction(), Chaser::Backward); QCOMPARE(c.runOrder(), Chaser::SingleShot); QCOMPARE(c.steps().size(), 9); c.postLoad(); QCOMPARE(c.steps().size(), 8); QCOMPARE(c.steps().at(0), ChaserStep(sc1->id())); QCOMPARE(c.steps().at(1), ChaserStep(sc2->id())); QCOMPARE(c.steps().at(2), ChaserStep(ch1->id())); QCOMPARE(c.steps().at(3), ChaserStep(ch2->id())); QCOMPARE(c.steps().at(4), ChaserStep(co1->id())); QCOMPARE(c.steps().at(5), ChaserStep(co2->id())); QCOMPARE(c.steps().at(6), ChaserStep(ef1->id())); QCOMPARE(c.steps().at(7), ChaserStep(ef2->id())); }
void Chaser_Test::loadSuccessLegacy() { QDomDocument doc; QDomElement root = doc.createElement("Function"); root.setAttribute("Type", "Chaser"); QDomElement bus = doc.createElement("Bus"); bus.setAttribute("Role", "Hold"); QDomText busText = doc.createTextNode("16"); bus.appendChild(busText); root.appendChild(bus); QDomElement dir = doc.createElement("Direction"); QDomText dirText = doc.createTextNode("Backward"); dir.appendChild(dirText); root.appendChild(dir); QDomElement run = doc.createElement("RunOrder"); QDomText runText = doc.createTextNode("SingleShot"); run.appendChild(runText); root.appendChild(run); QDomElement s1 = doc.createElement("Step"); s1.setAttribute("Number", 1); QDomText s1Text = doc.createTextNode("50"); s1.appendChild(s1Text); root.appendChild(s1); QDomElement s2 = doc.createElement("Step"); s2.setAttribute("Number", 2); QDomText s2Text = doc.createTextNode("12"); s2.appendChild(s2Text); root.appendChild(s2); QDomElement s3 = doc.createElement("Step"); s3.setAttribute("Number", 0); QDomText s3Text = doc.createTextNode("87"); s3.appendChild(s3Text); root.appendChild(s3); // Unknown tag QDomElement foo = doc.createElement("Foo"); foo.setAttribute("Number", 3); QDomText fooText = doc.createTextNode("1"); foo.appendChild(fooText); root.appendChild(foo); Bus::instance()->setValue(16, MasterTimer::frequency()); Chaser c(m_doc); QVERIFY(c.loadXML(root) == true); QVERIFY(c.direction() == Chaser::Backward); QVERIFY(c.runOrder() == Chaser::SingleShot); QCOMPARE(c.steps().size(), 3); QVERIFY(c.steps().at(0) == ChaserStep(87)); QVERIFY(c.steps().at(1) == ChaserStep(50)); QVERIFY(c.steps().at(2) == ChaserStep(12)); // postLoad() removes nonexistent functions so let's check this here c.postLoad(); QCOMPARE(c.duration(), MasterTimer::frequency() * MasterTimer::tick()); }
void Chaser_Test::loadSuccessLegacy() { QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); xmlWriter.writeStartElement("Function"); xmlWriter.writeAttribute("Type", "Chaser"); xmlWriter.writeStartElement("Bus"); xmlWriter.writeAttribute("Role", "Hold"); xmlWriter.writeCharacters("16"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Direction", "Backward"); xmlWriter.writeTextElement("RunOrder", "SingleShot"); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "1"); xmlWriter.writeCharacters("50"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "2"); xmlWriter.writeCharacters("12"); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "0"); xmlWriter.writeCharacters("87"); xmlWriter.writeEndElement(); // Unknown tag xmlWriter.writeStartElement("Foo"); xmlWriter.writeAttribute("Number", "3"); xmlWriter.writeCharacters("1"); xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); Bus::instance()->setValue(16, MasterTimer::frequency()); Chaser c(m_doc); QVERIFY(c.loadXML(xmlReader) == true); QVERIFY(c.direction() == Chaser::Backward); QVERIFY(c.runOrder() == Chaser::SingleShot); QCOMPARE(c.steps().size(), 3); QVERIFY(c.steps().at(0) == ChaserStep(87)); QVERIFY(c.steps().at(1) == ChaserStep(50)); QVERIFY(c.steps().at(2) == ChaserStep(12)); // postLoad() removes nonexistent functions so let's check this here c.postLoad(); QCOMPARE(c.duration(), MasterTimer::frequency() * MasterTimer::tick()); }
void Chaser_Test::loadSuccess() { QDomDocument doc; QDomElement root = doc.createElement("Function"); root.setAttribute("Type", "Chaser"); QDomElement speed = doc.createElement("Speed"); speed.setAttribute("FadeIn", "42"); speed.setAttribute("FadeOut", "69"); speed.setAttribute("Duration", "1337"); root.appendChild(speed); QDomElement dir = doc.createElement("Direction"); QDomText dirText = doc.createTextNode("Backward"); dir.appendChild(dirText); root.appendChild(dir); QDomElement run = doc.createElement("RunOrder"); QDomText runText = doc.createTextNode("SingleShot"); run.appendChild(runText); root.appendChild(run); QDomElement s1 = doc.createElement("Step"); s1.setAttribute("Number", 1); s1.setAttribute("FadeIn", 600); s1.setAttribute("FadeOut", 700); s1.setAttribute("Duration", 800); QDomText s1Text = doc.createTextNode("50"); s1.appendChild(s1Text); root.appendChild(s1); QDomElement s2 = doc.createElement("Step"); s2.setAttribute("Number", 2); s2.setAttribute("FadeIn", 1600); s2.setAttribute("FadeOut", 1700); s2.setAttribute("Duration", 1800); QDomText s2Text = doc.createTextNode("12"); s2.appendChild(s2Text); root.appendChild(s2); QDomElement s3 = doc.createElement("Step"); s3.setAttribute("Number", 0); // Let's leave these out from this step just for test's sake //s3.setAttribute("FadeIn", 2600); //s3.setAttribute("FadeOut", 2700); //s3.setAttribute("Duration", 2800); QDomText s3Text = doc.createTextNode("87"); s3.appendChild(s3Text); root.appendChild(s3); QDomElement spd = doc.createElement("SpeedModes"); spd.setAttribute("FadeIn", "Common"); spd.setAttribute("FadeOut", "Default"); spd.setAttribute("Duration", "PerStep"); root.appendChild(spd); // Unknown tag QDomElement foo = doc.createElement("Foo"); foo.setAttribute("Number", 3); QDomText fooText = doc.createTextNode("1"); foo.appendChild(fooText); root.appendChild(foo); Chaser c(m_doc); QVERIFY(c.loadXML(root) == true); QVERIFY(c.fadeInSpeed() == 42); QVERIFY(c.fadeOutSpeed() == 69); QVERIFY(c.duration() == 1337); QCOMPARE(c.fadeInMode(), Chaser::Common); QCOMPARE(c.fadeOutMode(), Chaser::Default); QCOMPARE(c.durationMode(), Chaser::PerStep); QVERIFY(c.direction() == Chaser::Backward); QVERIFY(c.runOrder() == Chaser::SingleShot); QVERIFY(c.steps().size() == 3); QVERIFY(c.steps().at(0) == ChaserStep(87)); QCOMPARE(c.steps().at(0).fadeIn, uint(0)); QCOMPARE(c.steps().at(0).fadeOut, uint(0)); QCOMPARE(c.steps().at(0).duration, uint(0)); QVERIFY(c.steps().at(1) == ChaserStep(50)); QCOMPARE(c.steps().at(1).fadeIn, uint(600)); QCOMPARE(c.steps().at(1).fadeOut, uint(700)); QCOMPARE(c.steps().at(1).duration, uint(800)); QVERIFY(c.steps().at(2) == ChaserStep(12)); QCOMPARE(c.steps().at(2).fadeIn, uint(1600)); QCOMPARE(c.steps().at(2).fadeOut, uint(1700)); QCOMPARE(c.steps().at(2).duration, uint(1800)); }
void Chaser_Test::postLoad() { Scene* sc1 = new Scene(m_doc); m_doc->addFunction(sc1); Scene* sc2 = new Scene(m_doc); m_doc->addFunction(sc2); Chaser* ch1 = new Chaser(m_doc); m_doc->addFunction(ch1); Chaser* ch2 = new Chaser(m_doc); m_doc->addFunction(ch2); Collection* co1 = new Collection(m_doc); m_doc->addFunction(co1); Collection* co2 = new Collection(m_doc); m_doc->addFunction(co2); EFX* ef1 = new EFX(m_doc); m_doc->addFunction(ef1); EFX* ef2 = new EFX(m_doc); m_doc->addFunction(ef2); QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); xmlWriter.writeStartElement("Function"); xmlWriter.writeAttribute("Type", "Chaser"); xmlWriter.writeStartElement("Bus"); xmlWriter.writeAttribute("Role", "Hold"); xmlWriter.writeCharacters("16"); xmlWriter.writeEndElement(); xmlWriter.writeTextElement("Direction", "Backward"); xmlWriter.writeTextElement("RunOrder", "SingleShot"); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "0"); xmlWriter.writeCharacters(QString::number(sc1->id())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "1"); xmlWriter.writeCharacters(QString::number(sc2->id())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "2"); xmlWriter.writeCharacters(QString::number(ch1->id())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "3"); xmlWriter.writeCharacters(QString::number(ch2->id())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "4"); xmlWriter.writeCharacters(QString::number(co1->id())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "5"); xmlWriter.writeCharacters(QString::number(co2->id())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "6"); xmlWriter.writeCharacters(QString::number(ef1->id())); xmlWriter.writeEndElement(); xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "7"); xmlWriter.writeCharacters(QString::number(ef2->id())); xmlWriter.writeEndElement(); // Nonexistent function xmlWriter.writeStartElement("Step"); xmlWriter.writeAttribute("Number", "8"); xmlWriter.writeCharacters(QString::number(INT_MAX - 1)); xmlWriter.writeEndElement(); // Unknown tag xmlWriter.writeStartElement("Foo"); xmlWriter.writeAttribute("Number", "3"); xmlWriter.writeCharacters("1"); xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); Chaser c(m_doc); QCOMPARE(c.loadXML(xmlReader), true); QCOMPARE(c.direction(), Chaser::Backward); QCOMPARE(c.runOrder(), Chaser::SingleShot); QCOMPARE(c.steps().size(), 9); c.postLoad(); QCOMPARE(c.steps().size(), 8); QCOMPARE(c.steps().at(0), ChaserStep(sc1->id())); QCOMPARE(c.steps().at(1), ChaserStep(sc2->id())); QCOMPARE(c.steps().at(2), ChaserStep(ch1->id())); QCOMPARE(c.steps().at(3), ChaserStep(ch2->id())); QCOMPARE(c.steps().at(4), ChaserStep(co1->id())); QCOMPARE(c.steps().at(5), ChaserStep(co2->id())); QCOMPARE(c.steps().at(6), ChaserStep(ef1->id())); QCOMPARE(c.steps().at(7), ChaserStep(ef2->id())); }
void Chaser_Test::save() { Chaser c(m_doc); c.setDirection(Chaser::Backward); c.setRunOrder(Chaser::SingleShot); c.setFadeInSpeed(42); c.setFadeOutSpeed(69); c.setDuration(1337); c.addStep(ChaserStep(3)); c.addStep(ChaserStep(1)); c.addStep(ChaserStep(0)); c.addStep(ChaserStep(2)); c.setFadeInMode(Chaser::Default); c.setFadeOutMode(Chaser::PerStep); c.setDurationMode(Chaser::Common); QDomDocument doc; QDomElement root = doc.createElement("TestRoot"); QVERIFY(c.saveXML(&doc, &root) == true); QVERIFY(root.firstChild().toElement().tagName() == "Function"); QVERIFY(root.firstChild().toElement().attribute("Type") == "Chaser"); int run = 0, dir = 0, speed = 0, fids = 0, speedmodes = 0; QDomNode node = root.firstChild().firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == "Bus") { QFAIL("Chaser must not write a Bus tag anymore!"); } else if (tag.tagName() == "Direction") { QVERIFY(tag.text() == "Backward"); dir++; } else if (tag.tagName() == "RunOrder") { QVERIFY(tag.text() == "SingleShot"); run++; } else if (tag.tagName() == "Step") { quint32 fid = tag.text().toUInt(); QVERIFY(fid == 0 || fid == 1 || fid == 2 || fid == 3); fids++; } else if (tag.tagName() == "Speed") { speed++; } else if (tag.tagName() == "SpeedModes") { QCOMPARE(tag.attribute("FadeIn"), QString("Default")); QCOMPARE(tag.attribute("FadeOut"), QString("PerStep")); QCOMPARE(tag.attribute("Duration"), QString("Common")); speedmodes++; } else { QFAIL("Unhandled XML tag."); } node = node.nextSibling(); } QCOMPARE(speed, 1); QCOMPARE(speedmodes, 1); QCOMPARE(dir, 1); QCOMPARE(run, 1); QCOMPARE(fids, 4); }
void Chaser_Test::save() { Chaser c(m_doc); c.setDirection(Chaser::Backward); c.setRunOrder(Chaser::SingleShot); c.setFadeInSpeed(42); c.setFadeOutSpeed(69); c.setDuration(1337); c.addStep(ChaserStep(3)); c.addStep(ChaserStep(1)); c.addStep(ChaserStep(0)); c.addStep(ChaserStep(2)); c.setFadeInMode(Chaser::Default); c.setFadeOutMode(Chaser::PerStep); c.setDurationMode(Chaser::Common); QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); QVERIFY(c.saveXML(&xmlWriter) == true); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); QVERIFY(xmlReader.name().toString() == "Function"); QVERIFY(xmlReader.attributes().value("Type").toString() == "Chaser"); int run = 0, dir = 0, speed = 0, fids = 0, speedmodes = 0; while (xmlReader.readNextStartElement()) { if (xmlReader.name() == "Bus") { QFAIL("Chaser must not write a Bus tag anymore!"); } else if (xmlReader.name() == "Direction") { QVERIFY(xmlReader.readElementText() == "Backward"); dir++; } else if (xmlReader.name() == "RunOrder") { QVERIFY(xmlReader.readElementText() == "SingleShot"); run++; } else if (xmlReader.name() == "Step") { quint32 fid = xmlReader.readElementText().toUInt(); QVERIFY(fid == 0 || fid == 1 || fid == 2 || fid == 3); fids++; } else if (xmlReader.name() == "Speed") { speed++; xmlReader.skipCurrentElement(); } else if (xmlReader.name() == "SpeedModes") { QCOMPARE(xmlReader.attributes().value("FadeIn").toString(), QString("Default")); QCOMPARE(xmlReader.attributes().value("FadeOut").toString(), QString("PerStep")); QCOMPARE(xmlReader.attributes().value("Duration").toString(), QString("Common")); speedmodes++; xmlReader.skipCurrentElement(); } else { QFAIL("Unhandled XML tag."); xmlReader.skipCurrentElement(); } } QCOMPARE(speed, 1); QCOMPARE(speedmodes, 1); QCOMPARE(dir, 1); QCOMPARE(run, 1); QCOMPARE(fids, 4); }