finishing up new g92 test

This commit is contained in:
Lars Brubaker 2020-12-18 18:07:37 -08:00
parent b37b6b4e8a
commit 0482b558c5
5 changed files with 144 additions and 23 deletions

View file

@ -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) =>
{

@ -1 +1 @@
Subproject commit 512b55877333267e62c6ab3a6035702e38c67de8
Subproject commit 78eb57f49593f4dec1c8df517ab94bcba54c8cd2

View file

@ -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<GCodeStream> 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 => "";
}
}

View file

@ -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<GCodeStream> streamList = null)
public static void ValidateStreamResponse(string[] expected, GCodeStream testStream, List<GCodeStream> streamList = null)
{
int lineIndex = 0;

View file

@ -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;
}