|
@@ -12,6 +12,7 @@ using System.Windows;
|
|
|
using System.Diagnostics;
|
|
|
using TestStack.White.UIItems.WindowStripControls;
|
|
|
using TestStack.White.UIItems.MenuItems;
|
|
|
+using System.Collections.Generic;
|
|
|
|
|
|
namespace WhiteTests
|
|
|
{
|
|
@@ -140,4 +141,170 @@ namespace WhiteTests
|
|
|
mainWindow.Close();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ [TestClass]
|
|
|
+ [DeploymentItem(@"WhiteTests\test_input_files\")]
|
|
|
+ public class FileImporterTests
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private TestContext testContextInstance;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public TestContext TestContext
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return testContextInstance;
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ testContextInstance = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [DataTestMethod]
|
|
|
+ [DataRow(new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
|
|
|
+ [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
|
|
|
+ [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 })]
|
|
|
+ public void ParseISADInputSuccessfulTest(int[] xCoordinates, int[] yCoordinates)
|
|
|
+ {
|
|
|
+ FileImporter uut = new FileImporter();
|
|
|
+
|
|
|
+ List<String> file = new List<string>();
|
|
|
+ file.Add("drawing");
|
|
|
+ file.Add("300x200");
|
|
|
+ for (int i = 0; i < xCoordinates.Length - 2; i += 3)
|
|
|
+ {
|
|
|
+ file.Add("line");
|
|
|
+ file.Add(xCoordinates[i] + ";" + yCoordinates[i]);
|
|
|
+ file.Add(xCoordinates[i + 1] + ";" + yCoordinates[i + 1]);
|
|
|
+ file.Add(xCoordinates[i + 2] + ";" + yCoordinates[i + 2]);
|
|
|
+ file.Add("endline");
|
|
|
+ }
|
|
|
+ file.Add("enddrawing");
|
|
|
+
|
|
|
+ Tuple<int, int, List<InternalLine>> values = uut.ParseISADInputForTesting(file.ToArray());
|
|
|
+
|
|
|
+ Assert.AreEqual(xCoordinates.Length / 3, values.Item3.Count);
|
|
|
+ InternalLine[] lines = values.Item3.ToArray();
|
|
|
+ for (int i = 0; i < xCoordinates.Length - 2; i += 3)
|
|
|
+ {
|
|
|
+ Point[] currentLine = lines[i / 3].GetPoints().ToArray();
|
|
|
+ Assert.AreEqual(3, currentLine.Length);
|
|
|
+ for (int j = 0; j < 3; j++)
|
|
|
+ {
|
|
|
+ Assert.IsTrue(currentLine[j].X == xCoordinates[i + j] && currentLine[j].Y == yCoordinates[i + j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [DataTestMethod]
|
|
|
+ [DataRow(new String[] {})]
|
|
|
+ [DataRow(new String[] { "begindrawing", "300x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300;300", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "30.5x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "beginline", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "500;50", "100;50", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "50x50", "100;50", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "50", "100", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "line", "endline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "stopline", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "enddrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline", "endrawing" })]
|
|
|
+ [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline" })]
|
|
|
+ public void ParseISADInputExceptionTest(String[] file)
|
|
|
+ {
|
|
|
+ bool correctExceptionThrown = false;
|
|
|
+
|
|
|
+ FileImporter uut = new FileImporter();
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ Tuple<int, int, List<InternalLine>> values1 = uut.ParseISADInputForTesting(file);
|
|
|
+ }
|
|
|
+ catch (FileImporterException)
|
|
|
+ {
|
|
|
+
|
|
|
+ correctExceptionThrown = true;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Assert.IsTrue(correctExceptionThrown);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void ParseSVGInputNoErrorForWhitelistedFilesTest()
|
|
|
+ {
|
|
|
+ FileImporter uut = new FileImporter();
|
|
|
+
|
|
|
+ string[] files = Directory.GetFiles(TestContext.DeploymentDirectory + @"\test_input_files\whitelisted", "*.svg", SearchOption.AllDirectories);
|
|
|
+
|
|
|
+ Assert.IsTrue(files.Length > 0);
|
|
|
+
|
|
|
+ foreach (string s in files)
|
|
|
+ {
|
|
|
+ Console.WriteLine(s);
|
|
|
+ bool noExceptionThrown = true;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ uut.ParseSVGInputFile(s, 10000, 10000);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ noExceptionThrown = false;
|
|
|
+ }
|
|
|
+ Assert.IsTrue(noExceptionThrown);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void ParseSVGInputNoErrorForBlacklistedFilesTest()
|
|
|
+ {
|
|
|
+ FileImporter uut = new FileImporter();
|
|
|
+
|
|
|
+ string[] files = Directory.GetFiles(TestContext.DeploymentDirectory + @"\test_input_files\blacklisted", "*.svg", SearchOption.AllDirectories);
|
|
|
+ Assert.IsTrue(files.Length > 0);
|
|
|
+ foreach (string s in files)
|
|
|
+ {
|
|
|
+ bool correctExceptionThrown = false;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ uut.ParseSVGInputFile(s, 10000, 10000);
|
|
|
+ }
|
|
|
+ catch (FileImporterException e)
|
|
|
+ {
|
|
|
+ correctExceptionThrown = true;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ Assert.IsTrue(correctExceptionThrown);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|