diff --git a/unittests/atcoretests.cpp b/unittests/atcoretests.cpp index d1005a7..2e2fbb3 100644 --- a/unittests/atcoretests.cpp +++ b/unittests/atcoretests.cpp @@ -1,288 +1,290 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include +#include + #include "atcoretests.h" void AtCoreTests::initTestCase() { core = new AtCore(); } void AtCoreTests::cleanupTestCase() { } void AtCoreTests::testInitState() { QVERIFY(core->state() == AtCore::DISCONNECTED); } void AtCoreTests::testPluginDetect() { QStringList fwPluginsFound = core->availableFirmwarePlugins(); QStringList fwPluginsActual = { QStringLiteral("aprinter"), QStringLiteral("grbl"), QStringLiteral("marlin"), QStringLiteral("repetier"), QStringLiteral("smoothie"), QStringLiteral("sprinter"), QStringLiteral("teacup") }; std::sort(fwPluginsFound.begin(), fwPluginsFound.end()); std::sort(fwPluginsActual.begin(), fwPluginsActual.end()); QVERIFY(fwPluginsFound == fwPluginsActual); } void AtCoreTests::testConnectInvalidDevice() { QEXPECT_FAIL("", "Invalid Device Attempt", Continue); QVERIFY(core->initSerial(QStringLiteral("/dev/ptyp5"), 9600)); } void AtCoreTests::testStateChange() { QList 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 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 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().isEmpty()); } void AtCoreTests::testSerialTimerIntervalChanged() { QSignalSpy sSpy(core, SIGNAL(serialTimerIntervalChanged(int))); 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")); QVERIFY(core->firmwarePlugin()->name() == QStringLiteral("Aprinter")); } void AtCoreTests::testPluginAprinter_validate() { QSignalSpy sSpy(core->firmwarePlugin(), SIGNAL(readyForCommand())); QVERIFY(sSpy.isValid() == true); core->firmwarePlugin()->validateCommand(QStringLiteral("ok")); core->firmwarePlugin()->validateCommand(QStringLiteral("other text")); QVERIFY(sSpy.count() == 1); } void AtCoreTests::testPluginGrbl_load() { core->loadFirmwarePlugin(QStringLiteral("grbl")); QVERIFY(core->firmwarePlugin()->name() == QStringLiteral("Grbl")); } void AtCoreTests::testPluginGrbl_validate() { QSignalSpy sSpy(core->firmwarePlugin(), SIGNAL(readyForCommand())); QVERIFY(sSpy.isValid() == true); core->firmwarePlugin()->validateCommand(QStringLiteral("ok")); core->firmwarePlugin()->validateCommand(QStringLiteral("other text")); QVERIFY(sSpy.count() == 1); } void AtCoreTests::testPluginGrbl_translate() { QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G28")) == "G28"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("M104 S50 G28 X")) == "M104 S50\r\nG28 X"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G00 G43 H0 Z0.1")) == "G00\r\nG43 H0 Z0.1"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("M6 T0")) == "M6 T0"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G0 G49 G40 G17 G80 G50 G90")) == "G0\r\nG49\r\nG40\r\nG17\r\nG80\r\nG50\r\nG90"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G0 S49 XY G40")) == "G0 S49 XY\r\nG40"); } void AtCoreTests::testPluginMarlin_load() { core->loadFirmwarePlugin(QStringLiteral("marlin")); QVERIFY(core->firmwarePlugin()->name() == QStringLiteral("Marlin")); } void AtCoreTests::testPluginMarlin_validate() { QSignalSpy sSpy(core->firmwarePlugin(), SIGNAL(readyForCommand())); QVERIFY(sSpy.isValid() == true); core->firmwarePlugin()->validateCommand(QStringLiteral("ok")); core->firmwarePlugin()->validateCommand(QStringLiteral("other text")); QVERIFY(sSpy.count() == 1); } void AtCoreTests::testPluginRepetier_load() { core->loadFirmwarePlugin(QStringLiteral("repetier")); QVERIFY(core->firmwarePlugin()->name() == QStringLiteral("Repetier")); } void AtCoreTests::testPluginRepetier_validate() { QSignalSpy sSpy(core->firmwarePlugin(), SIGNAL(readyForCommand())); QVERIFY(sSpy.isValid() == true); core->firmwarePlugin()->validateCommand(QStringLiteral("ok")); core->firmwarePlugin()->validateCommand(QStringLiteral("other text")); QVERIFY(sSpy.count() == 1); } void AtCoreTests::testPluginSmoothie_load() { core->loadFirmwarePlugin(QStringLiteral("smoothie")); QVERIFY(core->firmwarePlugin()->name() == QStringLiteral("Smoothie")); } void AtCoreTests::testPluginSmoothie_validate() { QSignalSpy sSpy(core->firmwarePlugin(), SIGNAL(readyForCommand())); QVERIFY(sSpy.isValid() == true); core->firmwarePlugin()->validateCommand(QStringLiteral("ok")); core->firmwarePlugin()->validateCommand(QStringLiteral("other text")); QVERIFY(sSpy.count() == 1); } void AtCoreTests::testPluginSprinter_load() { core->loadFirmwarePlugin(QStringLiteral("sprinter")); QVERIFY(core->firmwarePlugin()->name() == QStringLiteral("Sprinter")); } void AtCoreTests::testPluginSprinter_validate() { QSignalSpy sSpy(core->firmwarePlugin(), SIGNAL(readyForCommand())); QVERIFY(sSpy.isValid() == true); core->firmwarePlugin()->validateCommand(QStringLiteral("ok")); core->firmwarePlugin()->validateCommand(QStringLiteral("other text")); QVERIFY(sSpy.count() == 1); } void AtCoreTests::testPluginTeacup_load() { core->loadFirmwarePlugin(QStringLiteral("teacup")); QVERIFY(core->firmwarePlugin()->name() == QStringLiteral("Teacup")); } void AtCoreTests::testPluginTeacup_validate() { QSignalSpy sSpy(core->firmwarePlugin(), SIGNAL(readyForCommand())); QVERIFY(sSpy.isValid() == true); core->firmwarePlugin()->validateCommand(QStringLiteral("ok")); core->firmwarePlugin()->validateCommand(QStringLiteral("other text")); QVERIFY(sSpy.count() == 1); } void AtCoreTests::testPluginTeacup_translate() { QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G28")) == "G28"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("M109 S50")) == "M104 S50\r\nM116"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("M190 S50")) == "M140 S50\r\nM116"); } QTEST_MAIN(AtCoreTests) diff --git a/unittests/atcoretests.h b/unittests/atcoretests.h index 975bb16..a8eabda 100644 --- a/unittests/atcoretests.h +++ b/unittests/atcoretests.h @@ -1,57 +1,56 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include #include #include "../src/core/atcore.h" #include "../src/core/seriallayer.h" class AtCoreTests: public QObject { Q_OBJECT private slots: void initTestCase(); void testInitState(); 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(); void testPluginGrbl_validate(); void testPluginGrbl_translate(); void testPluginMarlin_load(); void testPluginMarlin_validate(); void testPluginRepetier_load(); void testPluginRepetier_validate(); void testPluginSmoothie_load(); void testPluginSmoothie_validate(); void testPluginSprinter_load(); void testPluginSprinter_validate(); void testPluginTeacup_load(); void testPluginTeacup_validate(); void testPluginTeacup_translate(); private: AtCore *core = nullptr; }; diff --git a/unittests/gcodetests.cpp b/unittests/gcodetests.cpp index 3b9ca82..de1c040 100644 --- a/unittests/gcodetests.cpp +++ b/unittests/gcodetests.cpp @@ -1,231 +1,233 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include +#include + #include "gcodetests.h" bool GCodeTests::testGCodeNeedsArg(GCode::GCommands code) { return GCode::toCommand(code) == GCode::commandRequiresArgument.arg(QStringLiteral("G"), QString::number(code)); } void GCodeTests::command_G0() { QVERIFY(GCode::toCommand(GCode::G0) == QStringLiteral("G0")); QVERIFY(GCode::toCommand(GCode::G0, QStringLiteral("50")) == QStringLiteral("G0 50")); } void GCodeTests::command_G1() { QVERIFY(GCode::toCommand(GCode::G1) == QStringLiteral("G1")); QVERIFY(GCode::toCommand(GCode::G1, QStringLiteral("50")) == QStringLiteral("G1 50")); } void GCodeTests::command_G28() { QVERIFY(GCode::toCommand(GCode::G28) == QStringLiteral("G28")); QVERIFY(GCode::toCommand(GCode::G28, QStringLiteral("Y")) == QStringLiteral("G28 Y")); } void GCodeTests::command_G32() { QVERIFY(GCode::toCommand(GCode::G32) == QStringLiteral("G32 S1")); } void GCodeTests::command_G90() { QVERIFY(GCode::toCommand(GCode::G90) == QStringLiteral("G90")); } void GCodeTests::command_G91() { QVERIFY(GCode::toCommand(GCode::G91) == QStringLiteral("G91")); } void GCodeTests::command_unsupportedG() { QVERIFY(GCode::toCommand(GCode::G2) == GCode::commandNotSupported); } bool GCodeTests::testMCodeNeedsArg(GCode::MCommands code) { return GCode::toCommand(code) == GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(code)); } void GCodeTests::command_M20() { QVERIFY(GCode::toCommand(GCode::M20) == QStringLiteral("M20")); } void GCodeTests::command_M21() { QVERIFY(GCode::toCommand(GCode::M21) == QStringLiteral("M21")); QVERIFY(GCode::toCommand(GCode::M21, QStringLiteral("2")) == QStringLiteral("M21 P2")); } void GCodeTests::command_M22() { QVERIFY(GCode::toCommand(GCode::M22) == QStringLiteral("M22")); QVERIFY(GCode::toCommand(GCode::M22, QStringLiteral("5")) == QStringLiteral("M22 P5")); } void GCodeTests::command_M23() { QVERIFY(testMCodeNeedsArg(GCode::M23)); QVERIFY(GCode::toCommand(GCode::M23, QStringLiteral("FileName")) == QStringLiteral("M23 FileName")); } void GCodeTests::command_M24() { QVERIFY(GCode::toCommand(GCode::M24) == QStringLiteral("M24")); } void GCodeTests::command_M25() { QVERIFY(GCode::toCommand(GCode::M25) == QStringLiteral("M25")); } void GCodeTests::command_M26() { QVERIFY(testMCodeNeedsArg(GCode::M26)); QVERIFY(GCode::toCommand(GCode::M26, QStringLiteral("15%")) == QStringLiteral("M26 P0.15")); QVERIFY(GCode::toCommand(GCode::M26, QStringLiteral("15")) == QStringLiteral("M26 S15")); } void GCodeTests::command_M27() { QVERIFY(GCode::toCommand(GCode::M27) == QStringLiteral("M27")); } void GCodeTests::command_M28() { QVERIFY(testMCodeNeedsArg(GCode::M28)); QVERIFY(GCode::toCommand(GCode::M28, QStringLiteral("FileName")) == QStringLiteral("M28 FileName")); } void GCodeTests::command_M29() { QVERIFY(testMCodeNeedsArg(GCode::M29)); QVERIFY(GCode::toCommand(GCode::M29, QStringLiteral("FileName")) == QStringLiteral("M29 FileName")); } void GCodeTests::command_M30() { QVERIFY(testMCodeNeedsArg(GCode::M30)); QVERIFY(GCode::toCommand(GCode::M30, QStringLiteral("FileName")) == QStringLiteral("M30 FileName")); } void GCodeTests::command_M84() { QVERIFY(GCode::toCommand(GCode::M84) == QStringLiteral("M84")); QVERIFY(GCode::toCommand(GCode::M84, QStringLiteral("10")) == QStringLiteral("M84 S10")); } void GCodeTests::command_M104() { QVERIFY(testMCodeNeedsArg(GCode::M104)); QVERIFY(GCode::toCommand(GCode::M104, QStringLiteral("100")) == QStringLiteral("M104 S100")); QVERIFY(GCode::toCommand(GCode::M104, QStringLiteral("3"), QStringLiteral("100")) == QStringLiteral("M104 P3 S100")); } void GCodeTests::command_M105() { QVERIFY(GCode::toCommand(GCode::M105) == QStringLiteral("M105")); } void GCodeTests::command_M106() { QVERIFY(GCode::toCommand(GCode::M106) == QStringLiteral("M106")); QVERIFY(GCode::toCommand(GCode::M106, QStringLiteral("100")) == QStringLiteral("M106 S100")); QVERIFY(GCode::toCommand(GCode::M106, QStringLiteral("3"), QStringLiteral("100")) == QStringLiteral("M106 P3 S100")); } void GCodeTests::command_M107() { QVERIFY(GCode::toCommand(GCode::M107) == QStringLiteral("M107")); } void GCodeTests::command_M109() { QVERIFY(testMCodeNeedsArg(GCode::M109)); QVERIFY(GCode::toCommand(GCode::M109, QStringLiteral("100")) == QStringLiteral("M109 S100")); } void GCodeTests::command_M112() { QVERIFY(GCode::toCommand(GCode::M112) == QStringLiteral("M112")); } void GCodeTests::command_M114() { QVERIFY(GCode::toCommand(GCode::M114) == QStringLiteral("M114")); } void GCodeTests::command_M115() { QVERIFY(GCode::toCommand(GCode::M115) == QStringLiteral("M115")); } void GCodeTests::command_M116() { QVERIFY(GCode::toCommand(GCode::M116) == QStringLiteral("M116")); } void GCodeTests::command_M117() { QVERIFY(testMCodeNeedsArg(GCode::M117)); QVERIFY(GCode::toCommand(GCode::M117, QStringLiteral("100")) == QStringLiteral("M117 100")); } void GCodeTests::command_M119() { QVERIFY(GCode::toCommand(GCode::M119) == QStringLiteral("M119")); } void GCodeTests::command_M140() { QVERIFY(testMCodeNeedsArg(GCode::M140)); QVERIFY(GCode::toCommand(GCode::M140, QStringLiteral("100")) == QStringLiteral("M140 S100")); } void GCodeTests::command_M190() { QVERIFY(testMCodeNeedsArg(GCode::M190)); QVERIFY(GCode::toCommand(GCode::M190, QStringLiteral("100")) == QStringLiteral("M190 S100")); } void GCodeTests::command_M220() { QVERIFY(testMCodeNeedsArg(GCode::M220));; QVERIFY(GCode::toCommand(GCode::M220, QStringLiteral("100")) == QStringLiteral("M220 S100")); } void GCodeTests::command_M221() { QVERIFY(testMCodeNeedsArg(GCode::M221));; QVERIFY(GCode::toCommand(GCode::M221, QStringLiteral("100")) == QStringLiteral("M221 S100")); } void GCodeTests::command_unsupportedM() { QVERIFY(GCode::toCommand(GCode::M999) == GCode::commandNotSupported); } QTEST_MAIN(GCodeTests) diff --git a/unittests/gcodetests.h b/unittests/gcodetests.h index 5f11530..36f6f1f 100644 --- a/unittests/gcodetests.h +++ b/unittests/gcodetests.h @@ -1,66 +1,65 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include #include #include "../src/core/gcodecommands.h" class GCodeTests: public QObject { Q_OBJECT private slots: bool testGCodeNeedsArg(GCode::GCommands code); void command_G0(); void command_G1(); void command_G28(); void command_G32(); void command_G90(); void command_G91(); void command_unsupportedG(); bool testMCodeNeedsArg(GCode::MCommands code); void command_M20(); void command_M21(); void command_M22(); void command_M23(); void command_M24(); void command_M25(); void command_M26(); void command_M27(); void command_M28(); void command_M29(); void command_M30(); void command_M84(); void command_M104(); void command_M105(); void command_M106(); void command_M107(); void command_M109(); void command_M112(); void command_M114(); void command_M115(); void command_M116(); void command_M117(); void command_M119(); void command_M140(); void command_M190(); void command_M220(); void command_M221(); void command_unsupportedM(); }; diff --git a/unittests/temperaturetests.cpp b/unittests/temperaturetests.cpp index 449e79b..c462f15 100644 --- a/unittests/temperaturetests.cpp +++ b/unittests/temperaturetests.cpp @@ -1,132 +1,134 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include +#include + #include "temperaturetests.h" void TemperatureTests::initTestCase() { temperature = new Temperature(this); } void TemperatureTests::cleanup() { temperature->setBedTemperature(0); temperature->setBedTargetTemperature(0); temperature->setExtruderTemperature(0); temperature->setExtruderTargetTemperature(0); } void TemperatureTests::setExtruderTemperature() { temperature->setExtruderTemperature(20); QVERIFY(temperature->extruderTemperature() == 20); temperature->setExtruderTemperature(20.25); QVERIFY(temperature->extruderTemperature() == 20.25); } void TemperatureTests::setExtruderTargetTemperature() { temperature->setExtruderTargetTemperature(20); QVERIFY(temperature->extruderTargetTemperature() == 20); temperature->setExtruderTargetTemperature(20.25); QVERIFY(temperature->extruderTargetTemperature() == 20.25); } void TemperatureTests::setBedTemperature() { temperature->setBedTemperature(20); QVERIFY(temperature->bedTemperature() == 20); temperature->setBedTemperature(20.25); QVERIFY(temperature->bedTemperature() == 20.25); } void TemperatureTests::setBedTargetTemperature() { temperature->setBedTargetTemperature(20); QVERIFY(temperature->bedTargetTemperature() == 20); temperature->setBedTargetTemperature(20.25); QVERIFY(temperature->bedTargetTemperature() == 20.25); } void TemperatureTests::testDecodeAprinter() { temperature->decodeTemp(QByteArray("ok B:49.06 /55 T:64.78 /215")); QVERIFY(temperature->extruderTemperature() == float(64.78)); QVERIFY(temperature->extruderTargetTemperature() == 215); QVERIFY(temperature->bedTemperature() == float(49.06)); QVERIFY(temperature->bedTargetTemperature() == 55); } void TemperatureTests::testDecodeMarlin() { temperature->decodeTemp(QByteArray("ok T:49.74 /60.00 B:36.23 /50.00 @:0 B@:0")); QVERIFY(temperature->extruderTemperature() == float(49.74)); QVERIFY(temperature->extruderTargetTemperature() == 60); QVERIFY(temperature->bedTemperature() == float(36.23)); QVERIFY(temperature->bedTargetTemperature() == 50); } void TemperatureTests::testDecodeMarlinCreality() { temperature->decodeTemp(QByteArray("ok T:48.8 /215.0 B:57.5 /70.0 T0:48.8 /0.0 @:0 B@:0")); QVERIFY(temperature->extruderTemperature() == float(48.8)); QVERIFY(temperature->extruderTargetTemperature() == 215); QVERIFY(temperature->bedTemperature() == float(57.5)); QVERIFY(temperature->bedTargetTemperature() == 70); } void TemperatureTests::testDecodeRepetier() { temperature->decodeTemp(QByteArray("T:25.47 /230 B:69.42 /80 B@:255 @:0")); QVERIFY(temperature->extruderTemperature() == float(25.47)); QVERIFY(temperature->extruderTargetTemperature() == 230); QVERIFY(temperature->bedTemperature() == float(69.42)); QVERIFY(temperature->bedTargetTemperature() == 80); } void TemperatureTests::testDecodeSmoothie() { temperature->decodeTemp(QByteArray("ok T:76.36 /220.0 @0 B:24.1 /60.0 @")); QVERIFY(temperature->extruderTemperature() == float(76.36)); QVERIFY(temperature->extruderTargetTemperature() == 220); QVERIFY(temperature->bedTemperature() == float(24.1)); QVERIFY(temperature->bedTargetTemperature() == 60); } void TemperatureTests::testDecodeSprinter() { temperature->decodeTemp(QByteArray("ok T:154 @:0 B:150")); QVERIFY(temperature->extruderTemperature() == 154); QVERIFY(temperature->bedTemperature() == 150); } void TemperatureTests::testDecodeTeacup() { temperature->decodeTemp(QByteArray("T:15.50/210.0 B:46.80/82.0")); QVERIFY(temperature->extruderTemperature() == float(15.50)); QVERIFY(temperature->extruderTargetTemperature() == 210); QVERIFY(temperature->bedTemperature() == float(46.80)); QVERIFY(temperature->bedTargetTemperature() == 82); } QTEST_MAIN(TemperatureTests) diff --git a/unittests/temperaturetests.h b/unittests/temperaturetests.h index c08581e..27a55a0 100644 --- a/unittests/temperaturetests.h +++ b/unittests/temperaturetests.h @@ -1,43 +1,42 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include #include #include "../src/core/temperature.h" class TemperatureTests: public QObject { Q_OBJECT private slots: void initTestCase(); void cleanup(); void setExtruderTemperature(); void setExtruderTargetTemperature(); void setBedTemperature(); void setBedTargetTemperature(); void testDecodeAprinter(); void testDecodeMarlin(); void testDecodeMarlinCreality(); void testDecodeRepetier(); void testDecodeSmoothie(); void testDecodeSprinter(); void testDecodeTeacup(); private: Temperature *temperature; };