diff --git a/DataStorage/Datastore.cs b/DataStorage/Datastore.cs index f6ffb540c..bb9f4dde5 100644 --- a/DataStorage/Datastore.cs +++ b/DataStorage/Datastore.cs @@ -46,9 +46,7 @@ namespace MatterHackers.MatterControl.DataStorage private static readonly string applicationDataFolderName = "MatterControl"; private readonly string datastoreName = "MatterControl.db"; private string applicationPath; - //private string testDataPath = Path.Combine("..", "..", "..", "..", "Tests", "TestData"); - - + private static string applicationUserDataPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), applicationDataFolderName); public ApplicationDataStorage() //Constructor - validates that local storage folder exists, creates if necessary @@ -75,8 +73,6 @@ namespace MatterHackers.MatterControl.DataStorage } } - private static string applicationUserDataPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), applicationDataFolderName); - public string ApplicationLibraryDataPath { get @@ -93,10 +89,18 @@ namespace MatterHackers.MatterControl.DataStorage } } - internal void OverrideApplicationPath(string path) + /// + /// Overrides the AppData location. + /// + /// The new AppData path. + internal void OverrideAppDataLocation(string path) { + // Ensure the target directory exists Directory.CreateDirectory(path); + applicationUserDataPath = path; + + // Initialize a fresh datastore instance after overriding the AppData path Datastore.Instance = new Datastore(); Datastore.Instance.Initialize(); } @@ -135,8 +139,8 @@ namespace MatterHackers.MatterControl.DataStorage { return applicationUserDataPath; } - } + /// /// Returns the path to the sqlite database /// @@ -250,6 +254,8 @@ namespace MatterHackers.MatterControl.DataStorage } return globalInstance; } + + // Special case to allow tests to set custom application paths internal set { globalInstance = value; diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 368994f03..34982e01b 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -114,11 +114,10 @@ namespace MatterHackers.MatterControl } } - private MatterControlApplication(double width, double height, out bool showWindow) + private MatterControlApplication(double width, double height) : base(width, height) { Name = "MatterControl"; - showWindow = false; // set this at startup so that we can tell next time if it got set to true in close UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1; @@ -136,51 +135,11 @@ namespace MatterHackers.MatterControl string commandUpper = command.ToUpper(); switch (commandUpper) { - case "TEST": - CheckKnownAssemblyConditionalCompSymbols(); - return; - case "FORCE_SOFTWARE_RENDERING": forceSofwareRendering = true; GL.ForceSoftwareRendering(); break; - case "MHSERIAL_TO_ANDROID": - { - Dictionary vidPid_NameDictionary = new Dictionary(); - string[] MHSerialLines = File.ReadAllLines(Path.Combine("..", "..", "StaticData", "Drivers", "MHSerial", "MHSerial.inf")); - foreach (string line in MHSerialLines) - { - if (line.Contains("=DriverInstall,")) - { - string name = Regex.Match(line, "%(.*).name").Groups[1].Value; - string vid = Regex.Match(line, "VID_(.*)&PID").Groups[1].Value; - string pid = Regex.Match(line, "PID_([0-9a-fA-F]+)").Groups[1].Value; - string vidPid = "{0},{1}".FormatWith(vid, pid); - if (!vidPid_NameDictionary.ContainsKey(vidPid)) - { - vidPid_NameDictionary.Add(vidPid, name); - } - } - } - - using (StreamWriter deviceFilter = new StreamWriter("deviceFilter.txt")) - { - using (StreamWriter serialPort = new StreamWriter("serialPort.txt")) - { - foreach (KeyValuePair vidPid_Name in vidPid_NameDictionary) - { - string[] vidPid = vidPid_Name.Key.Split(','); - int vid = Int32.Parse(vidPid[0], System.Globalization.NumberStyles.HexNumber); - int pid = Int32.Parse(vidPid[1], System.Globalization.NumberStyles.HexNumber); - serialPort.WriteLine("customTable.AddProduct(0x{0:X4}, 0x{1:X4}, cdcDriverType); // {2}".FormatWith(vid, pid, vidPid_Name.Value)); - deviceFilter.WriteLine("\n".FormatWith(vid, pid, vidPid_Name.Value)); - } - } - } - } - return; - case "CLEAR_CACHE": AboutWidget.DeleteCacheData(); break; @@ -346,8 +305,6 @@ namespace MatterHackers.MatterControl DesktopPosition = new Point2D(xpos, ypos); } - - showWindow = true; } bool dropWasOnChild = true; @@ -433,20 +390,15 @@ namespace MatterHackers.MatterControl { if (instance == null) { - bool showWindow; - instance = CreateInstance(out showWindow); - - if (showWindow) - { - instance.ShowAsSystemWindow(); - } + instance = CreateInstance(); + instance.ShowAsSystemWindow(); } return instance; } } - public static MatterControlApplication CreateInstance(out bool showWindow) + public static MatterControlApplication CreateInstance() { // try and open our window matching the last size that we had for it. string windowSize = ApplicationSettings.Instance.get("WindowSize"); @@ -461,7 +413,7 @@ namespace MatterHackers.MatterControl using (new PerformanceTimer("Startup", "Total")) { - instance = new MatterControlApplication(width, height, out showWindow); + instance = new MatterControlApplication(width, height); } return instance; @@ -629,7 +581,6 @@ namespace MatterHackers.MatterControl if (firstDraw) { - //Task.Run((Action)AutomationTest); UiThread.RunOnIdle(DoAutoConnectIfRequired); firstDraw = false; @@ -645,35 +596,14 @@ namespace MatterHackers.MatterControl TerminalWindow.ShowIfLeftOpen(); - if (AfterFirstDraw != null) - { - AfterFirstDraw(); - } - - UiThread.RunOnIdle(() => - { - //StyledMessageBox.ShowMessageBox(null, "message that is long and wraps. message that is long and wraps. message that is long and wraps." , "caption", StyledMessageBox.MessageType.YES_NO); - // show a dialog to tell the user there is an update - }); + AfterFirstDraw?.Invoke(); } //msGraph.AddData("ms", totalDrawTime.ElapsedMilliseconds); //msGraph.Draw(MatterHackers.Agg.Transform.Affine.NewIdentity(), graphics2D); } - private void AutomationTest() - { - AutomationRunner test = new AutomationRunner("C:/TestImages"); - test.Wait(2); - test.ClickByName("SettingsAndControls"); - test.Wait(2); - test.ClickImage("BackButton.png"); - - - //ImageIO.SaveImageData("test.png", test.GetCurrentScreen()); - } - - public override void OnMouseMove(MouseEventArgs mouseEvent) + public override void OnMouseMove(MouseEventArgs mouseEvent) { if (GuiWidget.DebugBoundsUnderMouse) { diff --git a/StaticData/SliceSettings/Properties.json b/StaticData/SliceSettings/Properties.json index 9b6a57b56..f6cae6d20 100644 --- a/StaticData/SliceSettings/Properties.json +++ b/StaticData/SliceSettings/Properties.json @@ -796,7 +796,7 @@ }, { "SlicerConfigName": "skirt_distance", - "PresentationName": "Distance from Object", + "PresentationName": "Distance From Object", "HelpText": "The distance to start drawing the first skirt loop. Make this 0 to create an anchor for the part to the bed.", "DataEditType": "POSITIVE_DOUBLE", "ExtraSettings": "mm", diff --git a/Tests/MatterControl.AutomationTests/OptionsTabTests.cs b/Tests/MatterControl.AutomationTests/OptionsTabTests.cs index 9c4352200..aad38a139 100644 --- a/Tests/MatterControl.AutomationTests/OptionsTabTests.cs +++ b/Tests/MatterControl.AutomationTests/OptionsTabTests.cs @@ -24,7 +24,6 @@ namespace MatterHackers.MatterControl.UI { AutomationRunner testRunner = new AutomationRunner(MatterControlUtilities.DefaultTestImages); { - testRunner.ClickByName("SettingsAndControls", 5); testRunner.Wait(2); testRunner.ClickByName("Options Tab", 6); @@ -33,7 +32,8 @@ namespace MatterHackers.MatterControl.UI resultsHarness.AddTestResult(terminalWindowExists1 == false, "Terminal Window does not exist"); testRunner.ClickByName("Show Terminal Button", 6); - + testRunner.Wait(1); + SystemWindow containingWindow; GuiWidget terminalWindow = testRunner.GetWidgetByName("Gcode Terminal", out containingWindow, 3); resultsHarness.AddTestResult(terminalWindow != null, "Terminal Window exists after Show Terminal button is clicked"); @@ -44,7 +44,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests diff --git a/Tests/MatterControl.AutomationTests/PrintQueueTests.cs b/Tests/MatterControl.AutomationTests/PrintQueueTests.cs index d84ff9546..e060e0063 100644 --- a/Tests/MatterControl.AutomationTests/PrintQueueTests.cs +++ b/Tests/MatterControl.AutomationTests/PrintQueueTests.cs @@ -71,7 +71,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests @@ -157,7 +157,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests @@ -222,7 +222,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests } @@ -268,7 +268,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests } @@ -461,7 +461,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 3); // make sure we ran all our tests } @@ -524,7 +524,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 3); // make sure we ran all our tests } @@ -587,7 +587,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 3); // make sure we ran all our tests } @@ -654,7 +654,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 4); // make sure we ran all our tests } @@ -695,10 +695,15 @@ namespace MatterHackers.MatterControl.UI testRunner.Wait(2); - //Type in Absolute Path to Save string exportZipPath = MatterControlUtilities.PathToQueueItemsFolder("TestExportZip"); + // Ensure file does not exist before save + if(File.Exists(exportZipPath)) + { + File.Delete(exportZipPath); + } + testRunner.Type(exportZipPath); testRunner.Wait(2); @@ -745,7 +750,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 3); // make sure we ran all our tests } @@ -796,7 +801,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 2); // make sure we ran all our tests } @@ -867,7 +872,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 8); // make sure we ran all our tests } @@ -931,7 +936,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 5); // make sure we ran all our tests } @@ -1006,7 +1011,7 @@ namespace MatterHackers.MatterControl.UI } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, null, null, "Three_Queue_Items"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 7); // make sure we ran all our tests } diff --git a/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs b/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs index 0aacbf55c..1c4dc9d6a 100644 --- a/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs +++ b/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs @@ -40,13 +40,13 @@ namespace MatterHackers.MatterControl.UI resultsHarness.AddTestResult(testRunner.ClickByName("Save As Save Button", 1)); // ensure that it is now in the library folder (that the folder updated) - resultsHarness.AddTestResult(testRunner.WaitForName("Row Item " + "Test Part", 5), "The part we added sholud be in the library"); + resultsHarness.AddTestResult(testRunner.WaitForName("Row Item " + "Test Part", 5), "The part we added should be in the library"); - MatterControlUtilities.CloseMatterControl(testRunner); + MatterControlUtilities.CloseMatterControl(testRunner); } }; - AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, "MC_One_Queue_No_Library"); + AutomationTesterHarness testHarness = MatterControlUtilities.RunTest(testToRun, queueItemFolderToAdd: QueueTemplate.Three_Queue_Items); Assert.IsTrue(testHarness.AllTestsPassed); Assert.IsTrue(testHarness.TestCount == 8); // make sure we ran all our tests diff --git a/Tests/MatterControl.Tests/MatterControl/LibraryProviderSqliteTests.cs b/Tests/MatterControl.Tests/MatterControl/LibraryProviderSqliteTests.cs index 9706c8684..4d5eab347 100644 --- a/Tests/MatterControl.Tests/MatterControl/LibraryProviderSqliteTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/LibraryProviderSqliteTests.cs @@ -63,7 +63,7 @@ namespace MatterControl.Tests [Test, RunInApplicationDomain] public void LibraryProviderSqlite_NavigationWorking() { - MatterControlUtilities.MakeNewMatterControlAppDataFolderForTesting(); + MatterControlUtilities.OverrideAppDataLocation(); LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null, null, "Local Library"); testProvider.DataReloaded += (sender, e) => { dataReloaded = true; }; diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 9a6a0775c..1f6ec3044 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -50,6 +50,10 @@ namespace MatterHackers.MatterControl.UI { private static bool saveImagesForDebug = true; + private static int testID = 0; + + private static string runName = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss"); + private static void RemoveAllFromQueue(AutomationRunner testRunner) { Assert.IsTrue(testRunner.ClickByName("Queue... Menu", 2)); @@ -66,11 +70,8 @@ namespace MatterHackers.MatterControl.UI public static string PathToQueueItemsFolder(string queueItemToLoad) { - string temnp = Directory.GetCurrentDirectory(); string pathToQueueItemFolder = Path.Combine("..", "..", "..", "..", "Tests", "TestData", "QueueItems"); - string fullPathToQueueItem = Path.Combine(pathToQueueItemFolder, queueItemToLoad); - - return Path.GetFullPath(fullPathToQueueItem); + return Path.GetFullPath(Path.Combine(pathToQueueItemFolder, queueItemToLoad)); } public static void CloseMatterControl(AutomationRunner testRunner) @@ -107,18 +108,17 @@ namespace MatterHackers.MatterControl.UI OutputImage(test, "image-test.tga"); } - private static int testID = 0; - private static string runName = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss"); - - public static void MakeNewMatterControlAppDataFolderForTesting(string testDBFolderName = null) + /// + /// Overrides the AppData location, ensuring each test starts with a fresh MatterControl database. + /// + public static void OverrideAppDataLocation() { + string tempFolderPath = Path.Combine("..", "..", "..", "..", "Tests","temp"); - string temp = Path.Combine("..", "..", "..", "..", "Tests","temp"); - ApplicationDataStorage.Instance.OverrideApplicationPath(Path.Combine(temp, runName, $"Test{testID++}")); - + ApplicationDataStorage.Instance.OverrideAppDataLocation( + Path.Combine(tempFolderPath, runName, $"Test{testID++}")); } - public static void AddItemsToQueue(string queueItemFolderToLoad) { @@ -142,7 +142,9 @@ namespace MatterHackers.MatterControl.UI //CREATE EMPTY TESTPARTS FOLDER Directory.CreateDirectory(queueData); - foreach (string file in Directory.GetFiles(Path.Combine("..", "..", "..", "TestData", "QueueItems", queueItemFolderToLoad))) + string queueItemTestDataFolder = Path.Combine("..", "..", "..", "TestData", "QueueItems"); + + foreach (string file in Directory.GetFiles(Path.Combine(queueItemTestDataFolder, queueItemFolderToLoad))) { string newFilePath = Path.Combine(queueData, Path.GetFileName(file)); File.Copy(file, newFilePath, true); @@ -178,8 +180,13 @@ namespace MatterHackers.MatterControl.UI return goodNavigate; } - public static AutomationTesterHarness RunTest(Action testToRun, string testDbFolder = null, string staticDataPathOverride = null, string queueItemFolderToAdd = null, double maxTimeToRun = 60) + public static AutomationTesterHarness RunTest( + Action testToRun, + string staticDataPathOverride = null, + double maxTimeToRun = 60, + QueueTemplate queueItemFolderToAdd = QueueTemplate.None) { + // Walk back a step in the stack and output the callers name StackTrace st = new StackTrace(false); Console.WriteLine("\r\nRunning automation test: " + st.GetFrames().Skip(1).First().GetMethod().Name); @@ -187,22 +194,31 @@ namespace MatterHackers.MatterControl.UI { staticDataPathOverride = Path.Combine("..", "..", "..", "..", "StaticData"); } + #if !__ANDROID__ // Set the static data to point to the directory of MatterControl StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(staticDataPathOverride); #endif - bool showWindow; - /*MatterControlUtilities.DataFolderState staticDataState =*/MatterControlUtilities.MakeNewMatterControlAppDataFolderForTesting(testDbFolder); + MatterControlUtilities.OverrideAppDataLocation(); - if (queueItemFolderToAdd != null) + if (queueItemFolderToAdd != QueueTemplate.None) { - MatterControlUtilities.AddItemsToQueue(queueItemFolderToAdd); + string queueTemplateDirectory = queueItemFolderToAdd.ToString(); + MatterControlUtilities.AddItemsToQueue(queueTemplateDirectory); } - - MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(out showWindow); - AutomationTesterHarness testHarness = AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, maxTimeToRun); - return testHarness; + MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(); + return AutomationTesterHarness.ShowWindowAndExectueTests(matterControlWindow, testToRun, maxTimeToRun); } } + + /// + /// Represents a queue template folder on disk (located at Tests/TestData/QueueItems) that should be synced into the default + /// queue during test init. The enum name and folder name *must* be the same in order to function + /// + public enum QueueTemplate + { + None, + Three_Queue_Items + } } \ No newline at end of file