From 0482b558c5aaa36f63afccae3d5704d4d21a4808 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 18 Dec 2020 18:07:37 -0800 Subject: [PATCH] finishing up new g92 test --- .../Library/Widgets/CloneSettingsPage.cs | 3 +- Submodules/agg-sharp | 2 +- .../ExportItemWindowTests.cs | 145 ++++++++++++++++-- .../MatterControl/GCodeStreamTests.cs | 3 +- .../MatterControl/MatterControlUtilities.cs | 14 +- 5 files changed, 144 insertions(+), 23 deletions(-) diff --git a/MatterControlLib/Library/Widgets/CloneSettingsPage.cs b/MatterControlLib/Library/Widgets/CloneSettingsPage.cs index ff8a84dfa..3ef5cec41 100644 --- a/MatterControlLib/Library/Widgets/CloneSettingsPage.cs +++ b/MatterControlLib/Library/Widgets/CloneSettingsPage.cs @@ -62,7 +62,8 @@ namespace MatterHackers.MatterControl.PrintLibrary var textEditWidget = new MHTextEditWidget("", theme) { HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Center + VAnchor = VAnchor.Center, + Name = "Profile Path Widget" }; textEditWidget.ActualTextEditWidget.EditComplete += (s, e) => { diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 512b55877..78eb57f49 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 512b55877333267e62c6ab3a6035702e38c67de8 +Subproject commit 78eb57f49593f4dec1c8df517ab94bcba54c8cd2 diff --git a/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs b/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs index c724ae472..67b2a34f4 100644 --- a/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs +++ b/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs @@ -1,8 +1,13 @@ using System.IO; using System.Threading; using System.Threading.Tasks; +using MatterHackers.MatterControl.Library.Export; using MatterHackers.MatterControl.SlicerConfiguration; +using MatterControl.Tests.MatterControl; using NUnit.Framework; +using MatterHackers.MatterControl.PrinterCommunication.Io; +using MatterHackers.VectorMath; +using System.Collections.Generic; namespace MatterHackers.MatterControl.Tests.Automation { @@ -24,21 +29,20 @@ namespace MatterHackers.MatterControl.Tests.Automation //Get parts to add string rowItemPath = MatterControlUtilities.GetTestItemPath("Batman.stl"); - testRunner.Delay(1) + testRunner.Delay() .Type(MatterControlUtilities.GetTestItemPath("Batman.stl")) - .Delay(1) + .Delay() .Type("{Enter}"); //Get test results testRunner.ClickByName("Row Item Batman.stl") .ClickByName("Print Library Overflow Menu") .ClickByName("Export Menu Item") - .Delay(2) .WaitForName("Export Item Window"); testRunner.ClickByName("Machine File (G-Code) Button") .ClickByName("Export Button") - .Delay(2); + .Delay(); string gcodeOutputPath = MatterControlUtilities.PathToExportGcodeFolder; @@ -65,7 +69,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { testRunner.WaitForFirstDraw(); - testRunner.CloneAndSelectPrinter("No Retraction after Purge.printer"); + testRunner.CloneAndSelectPrinter("No Retraction after Purge"); var printer = testRunner.FirstPrinter(); printer.Settings.SetValue(SettingsKey.start_gcode, startGCode); @@ -76,21 +80,19 @@ namespace MatterHackers.MatterControl.Tests.Automation //Get parts to add string rowItemPath = MatterControlUtilities.GetTestItemPath("Batman.stl"); - testRunner.Delay(1) + testRunner.Delay() .Type(MatterControlUtilities.GetTestItemPath("Batman.stl")) - .Delay(1) + .Delay() .Type("{Enter}"); //Get test results testRunner.ClickByName("Row Item Batman.stl") .ClickByName("Print Library Overflow Menu") .ClickByName("Export Menu Item") - .Delay(2) .WaitForName("Export Item Window"); testRunner.ClickByName("Machine File (G-Code) Button") - .ClickByName("Export Button") - .Delay(2); + .ClickByName("Export Button"); string gcodeOutputPath = MatterControlUtilities.PathToExportGcodeFolder; @@ -104,12 +106,131 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.WaitFor(() => File.Exists(filename), 10) .Delay(2); - var gcode = File.ReadAllLines(filename); + var inputLines = new string[] + { + "G28 ; home all axes", + "M109 S[temperature]", + "", + "G1 Y5 X5 Z0.8 F1800; Purge line", + "G92 E0; Purge line", + "G1 X100 Z0.3 E25 F900; Purge line", + "G92 E0; Purge line", + "G1 E-2 F2400; Purge line", + "M75; start print timer" + }; + + var expectedLines = new string[] + { + "G28 ; home all axes", + "M280 P0 S160", + "G4 P400", + "M280 P0 S90", + "M109 S205", + "G1 X5 Y5 Z3.13 F1800", + "G92 E0; Purge line", + "G1 X100 Y5 Z2.28 E25 F900", + "G92 E0; Purge line", + "G1 E-2", + "M75 ; start print timer" + }; + + // validate that the gcode export stack has the right output + var testStream = GCodeExport.GetExportStream(printer, new TestGCodeStream(printer, inputLines), true); + ValidateStreamResponse(expectedLines, testStream); + + // validate that the actual printer output has the right lines + var actualLines = File.ReadAllLines(filename); + ValidateLinesStartingWithFirstExpected(expectedLines, actualLines); // make sure the file has the expected header return Task.FromResult(0); - }); + }, maxTimeToRun: 200); + } + + private void ValidateLinesStartingWithFirstExpected(string[] expectedLines, string[] actualLines) + { + throw new System.NotImplementedException(); + } + + public static void ValidateStreamResponse(string[] expected, GCodeStream testStream, List streamList = null) + { + int lineIndex = 0; + + // Advance + string actualLine = testStream.ReadLine(); + string expectedLine = expected[lineIndex++]; + + while (actualLine != null) + { + if (actualLine.StartsWith("G92 E0")) + { + testStream.SetPrinterPosition(new PrinterMove(default(Vector3), 0, 300)); + } + + if (actualLine.StartsWith("G92 Z0")) + { + testStream.SetPrinterPosition(new PrinterMove(new Vector3(), 0, 0)); + } + + if (actualLine == "; do_resume") + { + PauseHandlingStream pauseStream = null; + foreach (var stream in streamList) + { + if (stream as PauseHandlingStream != null) + { + pauseStream = (PauseHandlingStream)stream; + pauseStream.Resume(); + } + } + } + + if (expectedLine != actualLine) + { + int a = 0; + } + + Debug.WriteLine(actualLine); + Assert.AreEqual(expectedLine, actualLine, "Unexpected response from testStream"); + + // Advance + actualLine = testStream.ReadLine(); + if (lineIndex < expected.Length) + { + expectedLine = expected[lineIndex++]; + } + } } } + + public class TestGCodeStream : GCodeStream + { + private int index = 0; + private string[] lines; + + public TestGCodeStream(PrinterConfig printer, string[] lines) + : base(printer) + { + this.lines = lines; + } + + public override void Dispose() + { + } + + public override string ReadLine() + { + return index < lines.Length ? lines[index++] : null; + } + + public override void SetPrinterPosition(PrinterMove position) + { + } + + public override GCodeStream InternalStream => null; + + public override string DebugInfo => ""; + } + } diff --git a/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs b/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs index 9e3d0670c..f3cab9ae1 100644 --- a/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/GCodeStreamTests.cs @@ -31,7 +31,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using MatterControl.Printing; -using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.MatterControl; using MatterHackers.MatterControl.Library.Export; @@ -741,7 +740,7 @@ namespace MatterControl.Tests.MatterControl ValidateStreamResponse(expected, pauseHandlingStream, streamList); } - private static void ValidateStreamResponse(string[] expected, GCodeStream testStream, List streamList = null) + public static void ValidateStreamResponse(string[] expected, GCodeStream testStream, List streamList = null) { int lineIndex = 0; diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 4425c9f5c..66540365c 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -446,17 +446,17 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName("Hardware Tab") .ClickByName("Import Printer Button"); - string profilePath = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestProfiles", profileName); + string profilePath = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestProfiles", profileName + ".printer"); // Apply filter - testRunner.ClickByName("Open File Button") + testRunner.ClickByName("Profile Path Widget") // Continue to next page .Type(Path.GetFullPath(profilePath)) // open the right file + .Type("{Tab}") .ClickByName("Import Button") // Continue to next page - .Delay() - .Type("{Enter}") - .ClickByName("Next Button") // Continue to next page - .Delay(); - + .ClickByName("Cancel Wizard Button") + .DoubleClickByName(profileName + " Node") + .WaitForName("PrintPopupMenu"); + return testRunner; }