Improve GCodeCommands
ClosedPublic

Authored by rizzitello on Feb 11 2018, 2:46 AM.

Details

Summary

From the old Diff

  • Use Teareny opperation to make code more readable. Simplify Error Message

New in this Diff

  • Rename GCodeCommands::toString -> GCodeCommands::description.
  • Improve Error Message for when a Gcode is needed.

Diff Detail

Repository
R232 AtCore
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
rizzitello requested review of this revision.Feb 11 2018, 2:46 AM
rizzitello created this revision.
tcanabrava accepted this revision.Feb 11 2018, 12:03 PM
This revision is now accepted and ready to land.Feb 11 2018, 12:03 PM

Why we are doing tests with descriptions ?

Why we are doing tests with descriptions ?

For exactly the same reason we were checking the toString calls to have full test coverage.

Why we are doing tests with descriptions ?

For exactly the same reason we were checking the toString calls to have full test coverage.

@tcanabrava make sense to do a test of hardcoded text string ?

src/gcodecommands.cpp
94

QString code("G" + QString::number(gcode));

rizzitello updated this revision to Diff 26973.Feb 12 2018, 1:56 AM
rizzitello marked an inline comment as done.
rizzitello edited the summary of this revision. (Show Details)
  • Remove tests for GCodeCommands::description
  • Use common code for switches when possible
rizzitello updated this revision to Diff 26974.Feb 12 2018, 1:59 AM
  • rebase to master
patrickelectric requested changes to this revision.Feb 12 2018, 2:54 PM
patrickelectric added inline comments.
src/gcodecommands.cpp
96–97

Move to default.

107

Return gcode by default, check gcode range for error.

502–503

Move to default.

This revision now requires changes to proceed.Feb 12 2018, 2:54 PM
rizzitello added inline comments.Feb 12 2018, 2:58 PM
src/gcodecommands.cpp
107

We don't want to return any gcode we have not added support for . This does not prevent anyone from using the code but does stop them from getting any code via GCode functions . There is no good default either some code will work without options and some wont.

src/gcodecommands.h
141

We can change this to protect and and use it inside GCodeTest.

unittests/gcodetests.cpp
79

I see the same test around, maybe a simple function to check if argument is necessary.
QVERIFY(needArgument(GCode::M104))

rizzitello updated this revision to Diff 27060.Feb 13 2018, 2:02 PM
  • protect the error string GCodeCommands
  • use a function for the needs argument tests
src/gcodecommands.cpp
106

This can be a private class string.

106

protected*

unittests/gcodetests.cpp
71

You can inherit GCode class into GCodeTects, than you'll be able to use the protected strings for your tests.

rizzitello updated this revision to Diff 27068.EditedFeb 13 2018, 3:00 PM
  • Gcode and GCodeTest are now friends
patrickelectric requested changes to this revision.Feb 13 2018, 3:04 PM
patrickelectric added inline comments.
unittests/gcodetests.cpp
25

return condition

71

return Code::toCommand(code) == GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(code));

This revision now requires changes to proceed.Feb 13 2018, 3:04 PM
rizzitello updated this revision to Diff 27069.Feb 13 2018, 3:11 PM
  • clean up return for testGCodeNeedsArg testMCodeNeedsArg
patrickelectric accepted this revision.Feb 13 2018, 3:13 PM

Great job ! LGTM !

This revision is now accepted and ready to land.Feb 13 2018, 3:13 PM
rizzitello updated this revision to Diff 27108.Feb 13 2018, 9:28 PM
  • Update GcodeCommands
rizzitello closed this revision.Feb 13 2018, 9:28 PM
This revision was automatically updated to reflect the committed changes.