File indexing completed on 2025-02-02 08:04:52
0001 /* AtCore Unit Tests 0002 * SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 * SPDX-FileCopyrightText: 2017-2019 Chris Rizzitello <rizzitello@kde.org> 0004 * SPDX-FileCopyrightText: 2018 Patrick José Pereira <patrickjp@kde.org> 0005 */ 0006 0007 #include <algorithm> 0008 0009 #include <QtTest> 0010 0011 #include "gcodetests.h" 0012 0013 bool GCodeTests::testGCodeNeedsArg(GCode::GCommands code) 0014 { 0015 return GCode::toCommand(code) == GCode::commandRequiresArgument.arg(QStringLiteral("G"), QString::number(code)); 0016 } 0017 0018 void GCodeTests::command_G0() 0019 { 0020 QVERIFY(GCode::toCommand(GCode::G0) == QStringLiteral("G0")); 0021 QVERIFY(GCode::toCommand(GCode::G0, QStringLiteral("50")) == QStringLiteral("G0 50")); 0022 } 0023 0024 void GCodeTests::command_G1() 0025 { 0026 QVERIFY(GCode::toCommand(GCode::G1) == QStringLiteral("G1")); 0027 QVERIFY(GCode::toCommand(GCode::G1, QStringLiteral("50")) == QStringLiteral("G1 50")); 0028 } 0029 0030 void GCodeTests::command_G28() 0031 { 0032 QVERIFY(GCode::toCommand(GCode::G28) == QStringLiteral("G28")); 0033 QVERIFY(GCode::toCommand(GCode::G28, QStringLiteral("Y")) == QStringLiteral("G28 Y")); 0034 } 0035 0036 void GCodeTests::command_G32() 0037 { 0038 QVERIFY(GCode::toCommand(GCode::G32) == QStringLiteral("G32 S1")); 0039 } 0040 0041 void GCodeTests::command_G90() 0042 { 0043 QVERIFY(GCode::toCommand(GCode::G90) == QStringLiteral("G90")); 0044 } 0045 0046 void GCodeTests::command_G91() 0047 { 0048 QVERIFY(GCode::toCommand(GCode::G91) == QStringLiteral("G91")); 0049 } 0050 0051 void GCodeTests::command_unsupportedG() 0052 { 0053 QVERIFY(GCode::toCommand(GCode::G2) == GCode::commandNotSupported); 0054 } 0055 0056 bool GCodeTests::testMCodeNeedsArg(GCode::MCommands code) 0057 { 0058 return GCode::toCommand(code) == GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(code)); 0059 } 0060 0061 void GCodeTests::command_M20() 0062 { 0063 QVERIFY(GCode::toCommand(GCode::M20) == QStringLiteral("M20")); 0064 } 0065 0066 void GCodeTests::command_M21() 0067 { 0068 QVERIFY(GCode::toCommand(GCode::M21) == QStringLiteral("M21")); 0069 QVERIFY(GCode::toCommand(GCode::M21, QStringLiteral("2")) == QStringLiteral("M21 P2")); 0070 } 0071 0072 void GCodeTests::command_M22() 0073 { 0074 QVERIFY(GCode::toCommand(GCode::M22) == QStringLiteral("M22")); 0075 QVERIFY(GCode::toCommand(GCode::M22, QStringLiteral("5")) == QStringLiteral("M22 P5")); 0076 } 0077 0078 void GCodeTests::command_M23() 0079 { 0080 QVERIFY(testMCodeNeedsArg(GCode::M23)); 0081 QVERIFY(GCode::toCommand(GCode::M23, QStringLiteral("FileName")) == QStringLiteral("M23 FileName")); 0082 } 0083 0084 void GCodeTests::command_M24() 0085 { 0086 QVERIFY(GCode::toCommand(GCode::M24) == QStringLiteral("M24")); 0087 } 0088 0089 void GCodeTests::command_M25() 0090 { 0091 QVERIFY(GCode::toCommand(GCode::M25) == QStringLiteral("M25")); 0092 } 0093 0094 void GCodeTests::command_M26() 0095 { 0096 QVERIFY(testMCodeNeedsArg(GCode::M26)); 0097 QVERIFY(GCode::toCommand(GCode::M26, QStringLiteral("15%")) == QStringLiteral("M26 P0.15")); 0098 QVERIFY(GCode::toCommand(GCode::M26, QStringLiteral("15")) == QStringLiteral("M26 S15")); 0099 } 0100 0101 void GCodeTests::command_M27() 0102 { 0103 QVERIFY(GCode::toCommand(GCode::M27) == QStringLiteral("M27")); 0104 } 0105 0106 void GCodeTests::command_M28() 0107 { 0108 QVERIFY(testMCodeNeedsArg(GCode::M28)); 0109 QVERIFY(GCode::toCommand(GCode::M28, QStringLiteral("FileName")) == QStringLiteral("M28 FileName")); 0110 } 0111 0112 void GCodeTests::command_M29() 0113 { 0114 QVERIFY(testMCodeNeedsArg(GCode::M29)); 0115 QVERIFY(GCode::toCommand(GCode::M29, QStringLiteral("FileName")) == QStringLiteral("M29 FileName")); 0116 } 0117 0118 void GCodeTests::command_M30() 0119 { 0120 QVERIFY(testMCodeNeedsArg(GCode::M30)); 0121 QVERIFY(GCode::toCommand(GCode::M30, QStringLiteral("FileName")) == QStringLiteral("M30 FileName")); 0122 } 0123 0124 void GCodeTests::command_M84() 0125 { 0126 QVERIFY(GCode::toCommand(GCode::M84) == QStringLiteral("M84")); 0127 QVERIFY(GCode::toCommand(GCode::M84, QStringLiteral("10")) == QStringLiteral("M84 S10")); 0128 } 0129 0130 void GCodeTests::command_M104() 0131 { 0132 QVERIFY(testMCodeNeedsArg(GCode::M104)); 0133 QVERIFY(GCode::toCommand(GCode::M104, QStringLiteral("100")) == QStringLiteral("M104 S100")); 0134 QVERIFY(GCode::toCommand(GCode::M104, QStringLiteral("3"), QStringLiteral("100")) == QStringLiteral("M104 P3 S100")); 0135 } 0136 0137 void GCodeTests::command_M105() 0138 { 0139 QVERIFY(GCode::toCommand(GCode::M105) == QStringLiteral("M105")); 0140 } 0141 0142 void GCodeTests::command_M106() 0143 { 0144 QVERIFY(GCode::toCommand(GCode::M106) == QStringLiteral("M106")); 0145 QVERIFY(GCode::toCommand(GCode::M106, QStringLiteral("100")) == QStringLiteral("M106 S100")); 0146 QVERIFY(GCode::toCommand(GCode::M106, QStringLiteral("3"), QStringLiteral("100")) == QStringLiteral("M106 P3 S100")); 0147 } 0148 0149 void GCodeTests::command_M107() 0150 { 0151 QVERIFY(GCode::toCommand(GCode::M107) == QStringLiteral("M107")); 0152 } 0153 0154 void GCodeTests::command_M109() 0155 { 0156 QVERIFY(testMCodeNeedsArg(GCode::M109)); 0157 QVERIFY(GCode::toCommand(GCode::M109, QStringLiteral("100")) == QStringLiteral("M109 S100")); 0158 } 0159 0160 void GCodeTests::command_M112() 0161 { 0162 QVERIFY(GCode::toCommand(GCode::M112) == QStringLiteral("M112")); 0163 } 0164 0165 void GCodeTests::command_M114() 0166 { 0167 QVERIFY(GCode::toCommand(GCode::M114) == QStringLiteral("M114")); 0168 } 0169 0170 void GCodeTests::command_M115() 0171 { 0172 QVERIFY(GCode::toCommand(GCode::M115) == QStringLiteral("M115")); 0173 } 0174 0175 void GCodeTests::command_M116() 0176 { 0177 QVERIFY(GCode::toCommand(GCode::M116) == QStringLiteral("M116")); 0178 } 0179 0180 void GCodeTests::command_M117() 0181 { 0182 QVERIFY(testMCodeNeedsArg(GCode::M117)); 0183 QVERIFY(GCode::toCommand(GCode::M117, QStringLiteral("100")) == QStringLiteral("M117 100")); 0184 } 0185 0186 void GCodeTests::command_M119() 0187 { 0188 QVERIFY(GCode::toCommand(GCode::M119) == QStringLiteral("M119")); 0189 } 0190 0191 void GCodeTests::command_M140() 0192 { 0193 QVERIFY(testMCodeNeedsArg(GCode::M140)); 0194 QVERIFY(GCode::toCommand(GCode::M140, QStringLiteral("100")) == QStringLiteral("M140 S100")); 0195 } 0196 0197 void GCodeTests::command_M155() 0198 { 0199 QVERIFY(testMCodeNeedsArg(GCode::M155)); 0200 QVERIFY(GCode::toCommand(GCode::M155, QStringLiteral("1")) == QStringLiteral("M155 S1")); 0201 } 0202 0203 void GCodeTests::command_M190() 0204 { 0205 QVERIFY(testMCodeNeedsArg(GCode::M190)); 0206 QVERIFY(GCode::toCommand(GCode::M190, QStringLiteral("100")) == QStringLiteral("M190 S100")); 0207 } 0208 0209 void GCodeTests::command_M220() 0210 { 0211 QVERIFY(testMCodeNeedsArg(GCode::M220)); 0212 ; 0213 QVERIFY(GCode::toCommand(GCode::M220, QStringLiteral("100")) == QStringLiteral("M220 S100")); 0214 } 0215 0216 void GCodeTests::command_M221() 0217 { 0218 QVERIFY(testMCodeNeedsArg(GCode::M221)); 0219 ; 0220 QVERIFY(GCode::toCommand(GCode::M221, QStringLiteral("100")) == QStringLiteral("M221 S100")); 0221 } 0222 0223 void GCodeTests::command_unsupportedM() 0224 { 0225 QVERIFY(GCode::toCommand(GCode::M999) == GCode::commandNotSupported); 0226 } 0227 0228 QTEST_MAIN(GCodeTests)