[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [atcore] /:  Add missing emit info to AtCore
From:       Chris Rizzitello <null () kde ! org>
Date:       2018-06-01 1:09:13
Message-ID: E1fOYZ7-0003iD-6v () code ! kde ! org
[Download RAW message or body]

Git commit 6e31ab35295368d9fa05c53dfad7c74fe3d93738 by Chris Rizzitello.
Committed on 01/06/2018 at 01:01.
Pushed by rizzitello into branch 'master'.

Add missing emit info to AtCore
 Add more AtCoreTests

Signed-off-by: Chris Rizzitello <rizzitello@kde.org>

M  +14   -4    src/core/atcore.cpp
M  +12   -4    src/core/atcore.h
M  +104  -0    unittests/atcoretests.cpp
M  +6    -0    unittests/atcoretests.h

https://commits.kde.org/atcore/6e31ab35295368d9fa05c53dfad7c74fe3d93738

diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp
index 9bcd99f..458b96e 100644
--- a/src/core/atcore.cpp
+++ b/src/core/atcore.cpp
@@ -178,10 +178,8 @@ void AtCore::findFirmware(const QByteArray &message)
 
     if (message.contains("EXTRUDER_COUNT:")) {
         //this code is broken if more then 9 extruders are detected. since only one \
                char is returned
-        d->extruderCount = message.at(message.indexOf("EXTRUDER_COUNT:") + 15) - \
'0'; +        setExtruderCount(message.at(message.indexOf("EXTRUDER_COUNT:") + 15) - \
'0');  }
-    qCDebug(ATCORE_CORE) << "Extruder Count:" << QString::number(extruderCount());
-
     loadFirmwarePlugin(fwName);
 }
 
@@ -285,7 +283,11 @@ void AtCore::setSerialTimerInterval(const quint16 &newTime)
         d->serialTimer = new QTimer();
         connect(d->serialTimer, &QTimer::timeout, this, &AtCore::locateSerialPort);
     }
-    //Start over with the new time.
+    //emit the newtime if it has changed.
+    if (newTime != d->serialTimer->interval()) {
+        emit serialTimerIntervalChanged(newTime);
+    }
+    //Start the timer.
     d->serialTimer->start(newTime);
 }
 
@@ -628,6 +630,14 @@ int AtCore::extruderCount() const
     return d->extruderCount;
 }
 
+void AtCore::setExtruderCount(int newCount)
+{
+    if (d->extruderCount != newCount && newCount >= 1) {
+        d->extruderCount = newCount;
+        emit extruderCountChanged(newCount);
+        qCDebug(ATCORE_CORE) << "Extruder Count:" << \
QString::number(extruderCount()); +    }
+}
 void AtCore::processQueue()
 {
     d->ready = true;
diff --git a/src/core/atcore.h b/src/core/atcore.h
index c157ad5..fafa0c2 100644
--- a/src/core/atcore.h
+++ b/src/core/atcore.h
@@ -63,7 +63,7 @@ class ATCORE_EXPORT AtCore : public QObject
     Q_OBJECT
     Q_PROPERTY(QString version READ version)
     Q_PROPERTY(QStringList availableFirmwarePlugins READ availableFirmwarePlugins)
-    Q_PROPERTY(int extruderCount READ extruderCount NOTIFY extruderCountChanged)
+    Q_PROPERTY(int extruderCount READ extruderCount WRITE setExtruderCount NOTIFY \
                extruderCountChanged)
     Q_PROPERTY(quint16 serialTimerInterval READ serialTimerInterval WRITE \
                setSerialTimerInterval NOTIFY serialTimerIntervalChanged)
     Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY portsChanged)
     Q_PROPERTY(float percentagePrinted READ percentagePrinted NOTIFY \
printProgressChanged) @@ -73,6 +73,7 @@ class ATCORE_EXPORT AtCore : public QObject
     Q_PROPERTY(bool sdMount READ isSdMounted WRITE setSdMounted NOTIFY \
                sdMountChanged)
     Q_PROPERTY(QStringList sdFileList READ sdFileList NOTIFY sdCardFileListChanged)
 
+    friend class AtCoreTests;
     //Add friends as Sd Card support is extended to more plugins.
     friend class RepetierPlugin;
     friend class MarlinPlugin;
@@ -197,6 +198,7 @@ public:
     /**
      * @brief extruderCount
      * @return The number of detected Extruders Default is 1
+     * @sa setExtruderCount(int newCount), extruderCountChanged(int newCount)
      */
     int extruderCount() const;
 
@@ -244,9 +246,9 @@ signals:
 
     /**
      * @brief New number of extruders
-     * @sa extruderCount()
+     * @sa extruderCount(), setExtruderCount(int newCount)
      */
-    void extruderCountChanged();
+    void extruderCountChanged(const int newCount);
 
     /**
      * @brief Print job's precentage changed.
@@ -265,7 +267,7 @@ signals:
     * @brief New interval between serial timer
     * @sa setSerialTimerInterval()
     */
-    void serialTimerIntervalChanged();
+    void serialTimerIntervalChanged(const quint16 newTime);
 
     /**
      * @brief The Printer's State Changed
@@ -532,6 +534,12 @@ private:
     AtCorePrivate *d;
 
 protected:
+    /**
+     * @brief Set the number of extruders on the machine.
+     * @param newCount
+     * @sa extruderCount(), extruderCountChanged(int newCount)
+     */
+    void setExtruderCount(int newCount);
     /**
      * @brief Append a file to AtCorePrivate::sdCardFileList.
      * @param fileName: new FileName
diff --git a/unittests/atcoretests.cpp b/unittests/atcoretests.cpp
index 64f64f5..185bd31 100644
--- a/unittests/atcoretests.cpp
+++ b/unittests/atcoretests.cpp
@@ -59,6 +59,110 @@ void AtCoreTests::testConnectInvalidDevice()
     QVERIFY(core->initSerial(QStringLiteral("/dev/ptyp5"), 9600));
 }
 
+void AtCoreTests::testStateChange()
+{
+    QList<QVariant> args;
+    QSignalSpy sSpy(core, SIGNAL(stateChanged(AtCore::STATES)));
+    QVERIFY(sSpy.isValid());
+
+    core->setState(AtCore::CONNECTING);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::CONNECTING);
+
+    core->setState(AtCore::IDLE);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::IDLE);
+
+    core->setState(AtCore::BUSY);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::BUSY);
+
+    core->setState(AtCore::PAUSE);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::PAUSE);
+
+    core->setState(AtCore::STOP);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::STOP);
+
+    core->setState(AtCore::ERRORSTATE);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::ERRORSTATE);
+
+    core->setState(AtCore::STARTPRINT);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::STARTPRINT);
+
+    core->setState(AtCore::FINISHEDPRINT);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::FINISHEDPRINT);
+
+    core->setState(AtCore::DISCONNECTED);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toInt() == AtCore::DISCONNECTED);
+}
+
+void AtCoreTests::testSdMountChanged()
+{
+    QList<QVariant> args;
+    QSignalSpy sSpy(core, SIGNAL(sdMountChanged(bool)));
+    QVERIFY(sSpy.isValid());
+
+    core->setSdMounted(true);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toBool() == true);
+
+    core->setSdMounted(false);
+    args = sSpy.takeFirst();
+    QVERIFY(args.at(0).toBool() == false);
+}
+
+void AtCoreTests::testSdFileList()
+{
+    QSignalSpy sSpy(core, SIGNAL(sdCardFileListChanged(QStringList)));
+    QVERIFY(sSpy.isValid());
+    core->appendSdCardFileList(QStringLiteral("FILE1"));
+    core->appendSdCardFileList(QStringLiteral("FILE2"));
+    core->appendSdCardFileList(QStringLiteral("FILE3"));
+    core->appendSdCardFileList(QStringLiteral("FILE4"));
+    core->appendSdCardFileList(QStringLiteral("FILE5"));
+
+    QList<QVariant> args = sSpy.takeLast();
+    QStringList fileList = {
+        QStringLiteral("FILE1"),
+        QStringLiteral("FILE2"),
+        QStringLiteral("FILE3"),
+        QStringLiteral("FILE4"),
+        QStringLiteral("FILE5")
+    };
+    QVERIFY(args.at(0).toStringList() == fileList);
+
+    core->clearSdCardFileList();
+    args = sSpy.takeLast();
+    QVERIFY(args.at(0).toStringList() == QStringList());
+}
+
+void AtCoreTests::testSerialTimerIntervalChanged()
+{
+    QSignalSpy sSpy(core, SIGNAL(serialTimerIntervalChanged(quint16)));
+    QVERIFY(sSpy.isValid());
+    core->setSerialTimerInterval(1000);
+    core->setSerialTimerInterval(1000);
+    core->setSerialTimerInterval(2000);
+    core->setSerialTimerInterval(0);
+    QVERIFY(sSpy.count() == 3);
+}
+
+void AtCoreTests::testExtruderCountChanged()
+{
+    QSignalSpy sSpy(core, SIGNAL(extruderCountChanged(int)));
+    QVERIFY(sSpy.isValid());
+    core->setExtruderCount(1);
+    core->setExtruderCount(2);
+    core->setExtruderCount(1);
+    QVERIFY(sSpy.count() == 2);
+}
+
 void AtCoreTests::testPluginAprinter_load()
 {
     core->loadFirmwarePlugin(QStringLiteral("aprinter"));
diff --git a/unittests/atcoretests.h b/unittests/atcoretests.h
index 8576694..975bb16 100644
--- a/unittests/atcoretests.h
+++ b/unittests/atcoretests.h
@@ -20,6 +20,7 @@
 #include <QObject>
 
 #include "../src/core/atcore.h"
+#include "../src/core/seriallayer.h"
 
 class AtCoreTests: public QObject
 {
@@ -30,6 +31,11 @@ private slots:
     void testPluginDetect();
     void testConnectInvalidDevice();
     void cleanupTestCase();
+    void testStateChange();
+    void testSdMountChanged();
+    void testSdFileList();
+    void testSerialTimerIntervalChanged();
+    void testExtruderCountChanged();
     void testPluginAprinter_load();
     void testPluginAprinter_validate();
     void testPluginGrbl_load();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic