Browse Source

Added debug mode, added Test

Martin Edlund 5 years ago
parent
commit
8ca8a00438

File diff suppressed because it is too large
+ 11 - 0
SketchAssistant/SketchAssistantWPF/DebugData.cs


+ 4 - 1
SketchAssistant/SketchAssistantWPF/MainWindow.xaml

@@ -32,7 +32,10 @@
                     <MenuItem x:Name="CanvasMenuButton" Header="New Canvas" Click="CanvasButton_Click"/>
                     <MenuItem x:Name="UndoMenuButton" Header="Undo" Click="UndoButton_Click"/>
                     <MenuItem x:Name="RedoMenuButton" Header="Redo" Click="RedoButton_Click"/>
-                    <MenuItem x:Name="DebugMode" Header="Start Test Input" Click="DebugButton"/>
+                    <MenuItem x:Name="DebugMode" Header="Debug Input">
+                        <MenuItem x:Name="DebugOne" Header="Debug 1" Click="DebugOne_Click"/>
+                        <MenuItem x:Name="DebugTwo" Header="Debug 2" Click="DebugTwo_Click"/>
+                    </MenuItem>
                 </MenuItem>
             </Menu>
         </ToolBar>

+ 76 - 10
SketchAssistant/SketchAssistantWPF/MainWindow.xaml.cs

@@ -28,7 +28,20 @@ namespace SketchAssistantWPF
     {
         public MainWindow()
         {
+            bool InDebugMode = false;
+            String[] commArgs = Environment.GetCommandLineArgs();
             InitializeComponent();
+            if (commArgs.Length > 1)
+            {
+                if (commArgs[1].Equals("-debug"))
+                {
+                    InDebugMode = true;
+                }
+            }
+            if(!InDebugMode)
+            {
+                DebugMode.Visibility = Visibility.Collapsed;
+            }
             ProgramPresenter = new MVP_Presenter(this);
             //  DispatcherTimer setup
             dispatcherTimer = new DispatcherTimer(DispatcherPriority.Render);
@@ -66,6 +79,14 @@ namespace SketchAssistantWPF
         /// The line currently being drawn
         /// </summary>
         Polyline currentLine;
+        /// <summary>
+        /// If the debug function is running.
+        /// </summary>
+        bool debugRunning = false;
+        /// <summary>
+        /// Point collections for debugging.
+        /// </summary>
+        DebugData debugDat = new DebugData();
 
         /********************************************/
         /*** WINDOW SPECIFIC FUNCTIONS START HERE ***/
@@ -118,6 +139,7 @@ namespace SketchAssistantWPF
         private void RightCanvas_MouseDown(object sender, MouseButtonEventArgs e)
         {
             ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down);
+            //System.Diagnostics.Debug.WriteLine("ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down);");
         }
 
         /// <summary>
@@ -126,6 +148,7 @@ namespace SketchAssistantWPF
         private void RightCanvas_MouseUp(object sender, MouseButtonEventArgs e)
         {
             ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up);
+            //System.Diagnostics.Debug.WriteLine("ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up);");
         }
 
         /// <summary>
@@ -150,6 +173,7 @@ namespace SketchAssistantWPF
         private void RightCanvas_MouseMove(object sender, MouseEventArgs e)
         {
             ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, e.GetPosition(RightCanvas));
+            //System.Diagnostics.Debug.WriteLine("new Point(" + ((int)e.GetPosition(RightCanvas).X).ToString() + "," + ((int)e.GetPosition(RightCanvas).Y).ToString() + "), ");
         }
 
         /// <summary>
@@ -164,17 +188,20 @@ namespace SketchAssistantWPF
 
         /// <summary>
         /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
+        /// Takes 7000ms
         /// </summary>
-        private void DebugButton(object sender, RoutedEventArgs e)
+        private void DebugOne_Click(object sender, RoutedEventArgs e)
         {
-            dispatcherTimer.Stop();
-            ProgramPresenter.NewCanvas(); Thread.Sleep(50); ProgramPresenter.Tick(); Thread.Sleep(200);
-            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, new Point(20,20)); Thread.Sleep(50); ProgramPresenter.Tick(); Thread.Sleep(50);
-            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down); Thread.Sleep(50); ProgramPresenter.Tick(); Thread.Sleep(50);
-            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, new Point(200, 200)); Thread.Sleep(50); ProgramPresenter.Tick(); Thread.Sleep(50);
-            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, new Point(30, 80)); Thread.Sleep(50); ProgramPresenter.Tick(); Thread.Sleep(50);
-            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up); Thread.Sleep(50); ProgramPresenter.Tick(); Thread.Sleep(50);
-            dispatcherTimer.Start();
+            Debug(1);
+        }
+
+        /// <summary>
+        /// Sends inputs to the presenter simulating drawing, used for testing and debugging.
+        /// Takes 24000ms
+        /// </summary>
+        private void DebugTwo_Click(object sender, RoutedEventArgs e)
+        {
+            Debug(2);
         }
 
         /// <summary>
@@ -183,6 +210,7 @@ namespace SketchAssistantWPF
         private void dispatcherTimer_Tick(object sender, EventArgs e)
         {
             ProgramPresenter.Tick();
+            //System.Diagnostics.Debug.WriteLine("ProgramPresenter.Tick();");
         }
 
         /// <summary>
@@ -212,7 +240,9 @@ namespace SketchAssistantWPF
         /// <returns>Whether or not the mouse is pressed.</returns>
         public bool IsMousePressed()
         {
-            return (Mouse.LeftButton.Equals(MouseButtonState.Pressed) || Mouse.RightButton.Equals(MouseButtonState.Pressed));
+            if (!debugRunning) {
+                return (Mouse.LeftButton.Equals(MouseButtonState.Pressed) || Mouse.RightButton.Equals(MouseButtonState.Pressed)); }
+            else return true;
         }
 
         /// <summary>
@@ -461,5 +491,41 @@ namespace SketchAssistantWPF
                 canvas.Background = Brushes.SlateGray;
             }
         }
+
+        /************************/
+        /*** HELPING FUNCTION ***/
+        /************************/
+
+        /// <summary>
+        /// A function which simulates canvas input for debugging.
+        /// </summary>
+        /// <param name="option"></param>
+        private async void Debug(int option)
+        {
+            Point[] points;
+            if (option == 1)
+                points = debugDat.debugPoints1;
+            else if (option == 2)
+                points = debugDat.debugPoints2;
+            else { return; }
+            dispatcherTimer.Stop();
+            debugRunning = true;
+            ProgramPresenter.Tick(); await Task.Delay(10);
+            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, new Point(50, 50));
+            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Down); await Task.Delay(10);
+            for (int x = 0; x < points.Length; x++)
+            {
+                ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Move, points[x]);
+                await Task.Delay(1);
+                if (x % 5 == 0)
+                {
+                    ProgramPresenter.Tick();
+                    await Task.Delay(1);
+                }
+            }
+            ProgramPresenter.MouseEvent(MVP_Presenter.MouseAction.Up); await Task.Delay(1);
+            debugRunning = false;
+            dispatcherTimer.Start();
+        }
     }
 }

+ 1 - 0
SketchAssistant/SketchAssistantWPF/SketchAssistantWPF.csproj

@@ -75,6 +75,7 @@
     </ApplicationDefinition>
     <Compile Include="ActionHistory.cs" />
     <Compile Include="CustomCanvas.cs" />
+    <Compile Include="DebugData.cs" />
     <Compile Include="FileImporter.cs" />
     <Compile Include="FileImporterException.cs" />
     <Compile Include="GeometryCalculator.cs" />

+ 27 - 3
SketchAssistant/WhiteTests/UITest.cs

@@ -9,6 +9,9 @@ using TestStack.White.UIItems.Finders;
 using System.Threading;
 using SketchAssistantWPF;
 using System.Windows;
+using System.Diagnostics;
+using TestStack.White.UIItems.WindowStripControls;
+using TestStack.White.UIItems.MenuItems;
 
 namespace WhiteTests
 {
@@ -22,7 +25,8 @@ namespace WhiteTests
             string outputDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
             string editedDir = outputDir.Replace("WhiteTests", "SketchAssistantWPF");
             string app_path = editedDir + @"\SketchAssistantWPF.exe";
-            application = Application.Launch(app_path);
+            ProcessStartInfo processStart = new ProcessStartInfo(app_path, "-debug");
+            application = Application.Launch(processStart);
             Window mainWindow = application.GetWindow("Sketch Assistant");
         }
 
@@ -31,12 +35,32 @@ namespace WhiteTests
         {
             setupapp();
             Window mainWindow = application.GetWindow("Sketch Assistant");
-            Thread.Sleep(100);
+            Thread.Sleep(20);
             Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
             mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
-            Thread.Sleep(100);
+            Thread.Sleep(20);
             Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
             mainWindow.Close();
         }
+
+        [TestMethod]
+        public void DrawLineTest()
+        {
+            setupapp();
+            Window mainWindow = application.GetWindow("Sketch Assistant");
+            Thread.Sleep(20);
+            Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
+            mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
+            Thread.Sleep(20);
+            Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
+            mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
+            Thread.Sleep(20);
+            mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
+            Thread.Sleep(20);
+            mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
+            Thread.Sleep(7000);
+            Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
+            mainWindow.Close();
+        }
     }
 }

Some files were not shown because too many files changed in this diff