void QLCChannel_Test::loadWrongRoot()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("Chanel");
    xmlWriter.writeAttribute("Name", "Channel1");

    xmlWriter.writeStartElement("Group");
    xmlWriter.writeAttribute("Byte", "1");
    xmlWriter.writeCharacters("Tilt");
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("Capability");
    xmlWriter.writeAttribute("Min", "0");
    xmlWriter.writeAttribute("Max", "10");
    xmlWriter.writeCharacters("Cap1");
    xmlWriter.writeEndElement();

    /* Overlaps with cap1, shouldn't appear in the channel */
    xmlWriter.writeStartElement("Capability");
    xmlWriter.writeAttribute("Min", "5");
    xmlWriter.writeAttribute("Max", "15");
    xmlWriter.writeCharacters("Cap2");
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("Capability");
    xmlWriter.writeAttribute("Min", "11");
    xmlWriter.writeAttribute("Max", "20");
    xmlWriter.writeCharacters("Cap3");
    xmlWriter.writeEndElement();

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    QLCChannel ch;
    QVERIFY(ch.loadXML(xmlReader) == false);
    QVERIFY(ch.name().isEmpty());
    QVERIFY(ch.group() == QLCChannel::Intensity);
    QVERIFY(ch.controlByte() == QLCChannel::MSB);
    QVERIFY(ch.capabilities().size() == 0);
}
Exemple #2
0
void QLCChannel_Test::loadWrongRoot()
{
    QDomDocument doc;

    QDomElement root = doc.createElement("Chanel");
    root.setAttribute("Name", "Channel1");
    doc.appendChild(root);

    QDomElement group = doc.createElement("Group");
    root.appendChild(group);
    group.setAttribute("Byte", 1);
    QDomText groupName = doc.createTextNode("Tilt");
    group.appendChild(groupName);

    QDomElement cap1 = doc.createElement("Capability");
    root.appendChild(cap1);
    cap1.setAttribute("Min", 0);
    cap1.setAttribute("Max", 10);
    QDomText cap1name = doc.createTextNode("Cap1");
    cap1.appendChild(cap1name);

    /* Overlaps with cap1, shouldn't appear in the channel */
    QDomElement cap2 = doc.createElement("Capability");
    root.appendChild(cap2);
    cap2.setAttribute("Min", 5);
    cap2.setAttribute("Max", 15);
    QDomText cap2name = doc.createTextNode("Cap2");
    cap2.appendChild(cap2name);

    QDomElement cap3 = doc.createElement("Capability");
    root.appendChild(cap3);
    cap3.setAttribute("Min", 11);
    cap3.setAttribute("Max", 20);
    QDomText cap3name = doc.createTextNode("Cap3");
    cap3.appendChild(cap3name);

    QLCChannel ch;
    QVERIFY(ch.loadXML(&root) == false);
    QVERIFY(ch.name().isEmpty());
    QVERIFY(ch.group() == QLCChannel::Intensity);
    QVERIFY(ch.controlByte() == QLCChannel::MSB);
    QVERIFY(ch.capabilities().size() == 0);
}
Exemple #3
0
void QLCChannel_Test::load()
{
    QDomDocument doc;

    QDomElement root = doc.createElement("Channel");
    root.setAttribute("Name", "Channel1");
    doc.appendChild(root);

    QDomElement group = doc.createElement("Group");
    root.appendChild(group);
    group.setAttribute("Byte", 1);
    QDomText groupName = doc.createTextNode("Tilt");
    group.appendChild(groupName);

    QDomElement colour = doc.createElement("Colour");
    QDomText colourText = doc.createTextNode(QLCChannel::colourToString(QLCChannel::Cyan));
    colour.appendChild(colourText);
    root.appendChild(colour);

    QDomElement cap1 = doc.createElement("Capability");
    root.appendChild(cap1);
    cap1.setAttribute("Min", 0);
    cap1.setAttribute("Max", 10);
    QDomText cap1name = doc.createTextNode("Cap1");
    cap1.appendChild(cap1name);

    /* Overlaps with cap1, shouldn't appear in the channel */
    QDomElement cap2 = doc.createElement("Capability");
    root.appendChild(cap2);
    cap2.setAttribute("Min", 5);
    cap2.setAttribute("Max", 15);
    QDomText cap2name = doc.createTextNode("Cap2");
    cap2.appendChild(cap2name);

    QDomElement cap3 = doc.createElement("Capability");
    root.appendChild(cap3);
    cap3.setAttribute("Min", 11);
    cap3.setAttribute("Max", 20);
    QDomText cap3name = doc.createTextNode("Cap3");
    cap3.appendChild(cap3name);

    /* Invalid capability tag, shouldn't appear in the channel, since it
       is not recognized by the channel. */
    QDomElement cap4 = doc.createElement("apability");
    root.appendChild(cap4);
    cap4.setAttribute("Min", 21);
    cap4.setAttribute("Max", 30);
    QDomText cap4name = doc.createTextNode("Cap4");
    cap4.appendChild(cap4name);

    /* Missing minimum value, shouldn't appear in the channel, because
       loadXML() fails. */
    QDomElement cap5 = doc.createElement("Capability");
    root.appendChild(cap5);
    cap5.setAttribute("Max", 30);
    QDomText cap5name = doc.createTextNode("Cap5");
    cap5.appendChild(cap5name);

    QLCChannel ch;
    QVERIFY(ch.loadXML(&root) == true);
    qDebug() << int(ch.colour());
    QVERIFY(ch.name() == "Channel1");
    QVERIFY(ch.group() == QLCChannel::Tilt);
    QVERIFY(ch.controlByte() == QLCChannel::LSB);
    QVERIFY(ch.colour() == QLCChannel::Cyan);
    QVERIFY(ch.capabilities().size() == 2);
    QVERIFY(ch.capabilities()[0]->name() == "Cap1");
    QVERIFY(ch.capabilities()[1]->name() == "Cap3");
}
Exemple #4
0
bool QLCFixtureDef::loadXML(QXmlStreamReader& doc)
{
    bool retval = false;

    if (doc.readNextStartElement() == false)
        return false;

    if (doc.name() == KXMLQLCFixtureDef)
    {
        while (doc.readNextStartElement())
        {
            if (doc.name() == KXMLQLCCreator)
            {
                loadCreator(doc);
            }
            else if (doc.name() == KXMLQLCFixtureDefManufacturer)
            {
                setManufacturer(doc.readElementText());
            }
            else if (doc.name() == KXMLQLCFixtureDefModel)
            {
                setModel(doc.readElementText());
            }
            else if (doc.name() == KXMLQLCFixtureDefType)
            {
                setType(doc.readElementText());
            }
            else if (doc.name() == KXMLQLCChannel)
            {
                QLCChannel* ch = new QLCChannel();
                if (ch->loadXML(doc) == true)
                {
                    /* Loading succeeded */
                    if (addChannel(ch) == false)
                    {
                        /* Channel already exists */
                        delete ch;
                    }
                }
                else
                {
                    /* Loading failed */
                    delete ch;
                }
            }
            else if (doc.name() == KXMLQLCFixtureMode)
            {
                QLCFixtureMode* mode = new QLCFixtureMode(this);
                if (mode->loadXML(doc) == true)
                {
                    /* Loading succeeded */
                    if (addMode(mode) == false)
                    {
                        /* Mode already exists */
                        delete mode;
                    }
                }
                else
                {
                    /* Loading failed */
                    delete mode;
                }
            }
            else
            {
                qWarning() << Q_FUNC_INFO << "Unknown Fixture tag: " << doc.name();
                doc.skipCurrentElement();
            }
        }

        retval = true;
    }
    else
    {
        qWarning() << Q_FUNC_INFO << "Fixture node not found";
        retval = false;
    }

    if (retval == true)
        m_isLoaded = true;
    return retval;
}
void QLCChannel_Test::load()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("Channel");
    xmlWriter.writeAttribute("Name", "Channel1");

    xmlWriter.writeStartElement("Group");
    xmlWriter.writeAttribute("Byte", "1");
    xmlWriter.writeCharacters("Tilt");
    xmlWriter.writeEndElement();

    xmlWriter.writeTextElement("Colour", QLCChannel::colourToString(QLCChannel::Cyan));

    xmlWriter.writeStartElement("Capability");
    xmlWriter.writeAttribute("Min", "0");
    xmlWriter.writeAttribute("Max", "10");
    xmlWriter.writeCharacters("Cap1");
    xmlWriter.writeEndElement();

    /* Overlaps with cap1, shouldn't appear in the channel */
    xmlWriter.writeStartElement("Capability");
    xmlWriter.writeAttribute("Min", "5");
    xmlWriter.writeAttribute("Max", "15");
    xmlWriter.writeCharacters("Cap2");
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("Capability");
    xmlWriter.writeAttribute("Min", "11");
    xmlWriter.writeAttribute("Max", "20");
    xmlWriter.writeCharacters("Cap3");
    xmlWriter.writeEndElement();

    /* Invalid capability tag, shouldn't appear in the channel, since it
       is not recognized by the channel. */
    xmlWriter.writeStartElement("apability");
    xmlWriter.writeAttribute("Min", "21");
    xmlWriter.writeAttribute("Max", "30");
    xmlWriter.writeCharacters("Cap4");
    xmlWriter.writeEndElement();

    /* Missing minimum value, shouldn't appear in the channel, because
       loadXML() fails. */
    xmlWriter.writeStartElement("Capability");
    xmlWriter.writeAttribute("Max", "30");
    xmlWriter.writeCharacters("Cap5");
    xmlWriter.writeEndElement();

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    QLCChannel ch;
    QVERIFY(ch.loadXML(xmlReader) == true);
    qDebug() << int(ch.colour());
    QVERIFY(ch.name() == "Channel1");
    QVERIFY(ch.group() == QLCChannel::Tilt);
    QVERIFY(ch.controlByte() == QLCChannel::LSB);
    QVERIFY(ch.colour() == QLCChannel::Cyan);
    QVERIFY(ch.capabilities().size() == 2);
    QVERIFY(ch.capabilities()[0]->name() == "Cap1");
    QVERIFY(ch.capabilities()[1]->name() == "Cap3");
}
Exemple #6
0
bool QLCFixtureDef::loadXML(const QDomDocument& doc)
{
    bool retval = false;

    QDomElement root = doc.documentElement();
    if (root.tagName() == KXMLQLCFixtureDef)
    {
        QDomNode node = root.firstChild();
        while (node.isNull() == false)
        {
            QDomElement tag = node.toElement();
            if (tag.tagName() == KXMLQLCCreator)
            {
                loadCreator(tag);
            }
            else if (tag.tagName() == KXMLQLCFixtureDefManufacturer)
            {
                setManufacturer(tag.text());
            }
            else if (tag.tagName() == KXMLQLCFixtureDefModel)
            {
                setModel(tag.text());
            }
            else if (tag.tagName() == KXMLQLCFixtureDefType)
            {
                setType(tag.text());
            }
            else if (tag.tagName() == KXMLQLCChannel)
            {
                QLCChannel* ch = new QLCChannel();
                if (ch->loadXML(tag) == true)
                {
                    /* Loading succeeded */
                    if (addChannel(ch) == false)
                    {
                        /* Channel already exists */
                        delete ch;
                    }
                }
                else
                {
                    /* Loading failed */
                    delete ch;
                }
            }
            else if (tag.tagName() == KXMLQLCFixtureMode)
            {
                QLCFixtureMode* mode = new QLCFixtureMode(this);
                if (mode->loadXML(tag) == true)
                {
                    /* Loading succeeded */
                    if (addMode(mode) == false)
                    {
                        /* Mode already exists */
                        delete mode;
                    }
                }
                else
                {
                    /* Loading failed */
                    delete mode;
                }
            }
            else
            {
                qWarning() << Q_FUNC_INFO << "Unknown Fixture tag: " << tag.tagName();
            }

            node = node.nextSibling();
        }

        retval = true;
    }
    else
    {
        qWarning() << Q_FUNC_INFO << "Fixture node not found";
        retval = false;
    }

    return retval;
}