From 34d86579a1f4e3842566b3dd187f9fa5f3838d07 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 14 Apr 2019 17:40:23 +0300 Subject: Implemented some test methods for pulse. --- Software/Visual_Studio/Tango.UnitTesting/Helper.cs | 9 +++ .../Tango.UnitTesting/Pulse/Pulse_TST.cs | 84 ++++++++++++++++++++++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 7 +- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs index 6a4f860b9..0498935ae 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs @@ -27,6 +27,15 @@ namespace Tango.UnitTesting return Path.GetFullPath(@"..\..\..\Resources\" + fileName); } + /// + /// Gets the absolute path to the 'Resources' folder. + /// + /// + public static String GetResourcePath() + { + return Path.GetFullPath(@"..\..\..\Resources\"); + } + /// /// Gets the PMR (Protobuf Messages Repository) path. /// diff --git a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs new file mode 100644 index 000000000..b25a3140b --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs @@ -0,0 +1,84 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.IO; +using Tango.Pulse; + +namespace Tango.UnitTesting.Pulse +{ + [TestClass] + [TestCategory("Pulse")] + public class Pulse_TST + { + [TestMethod] + public void Validate_Reading_Writing() + { + String abcFile = Path.Combine(Helper.GetResourcePath(), "Pulse", "ABC.dst"); + + TwnFile twnFile = new TwnFile(); + twnFile.Name = "My design"; + twnFile.NumberOfCopies = 1; + twnFile.MediaID = 0; + twnFile.SpoolingMethod = SpoolingMethods.SpoolPerSegment; + + Bitmap thumbnail = new Bitmap(1280, 720); + using (Graphics g = Graphics.FromImage(thumbnail)) + { + g.Clear(Color.Transparent); + g.DrawString("My design", new Font(new FontFamily("Arial"), 70), Brushes.Red, 1280 / 2, 720 / 2); + } + twnFile.Thumbnail = thumbnail; + + twnFile.EmbroideryFileFormat = "dst"; + twnFile.EmbroideryFile = File.ReadAllBytes(abcFile); + + //Add gradient segment. + TwnSegment gradientSegment = new TwnSegment(); + gradientSegment.Length = 10; //10 centimeters. + gradientSegment.BrushStops.Add(new TwnStop(255, 0, 0, 0)); //0% + gradientSegment.BrushStops.Add(new TwnStop(0, 0, 255, 1)); //100% + twnFile.Segments.Add(gradientSegment); + + //Add solid segment. + TwnSegment solidSegment = new TwnSegment(); + solidSegment.Length = 20; + solidSegment.BrushStops.Add(new TwnStop(0, 255, 0, 0)); + twnFile.Segments.Add(solidSegment); + + //Validate reading/writing. + using (MemoryStream ms = new MemoryStream()) + { + twnFile.ToStream(ms); + + ms.Position = 0; + + TwnFile twnFile2 = TwnFile.FromStream(ms); + + String serialized = JsonConvert.SerializeObject(twnFile, Formatting.Indented); + + String deserialized = JsonConvert.SerializeObject(twnFile2, Formatting.Indented); + + Assert.AreEqual(serialized, deserialized); + } + } + + [TestMethod] + public void Read_Pulse_Sample_File() + { + String sampleFile = Path.Combine(Helper.GetResourcePath(), "Pulse", "test.twn"); + TwnFile twnFile = TwnFile.FromFile(sampleFile); + var imgFile = TemporaryManager.Default.CreateFile(".png"); + + twnFile.Thumbnail.Save(imgFile, ImageFormat.Png); + + Helper.ShowInExplorer(imgFile); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 3e5434c98..6fd23451d 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -124,6 +124,7 @@ + @@ -214,6 +215,10 @@ {40073806-914e-4e78-97ab-fa9639308ebe} Tango.Protobuf + + {8435223D-DB6B-45E3-A08B-45B7416F8481} + Tango.Pulse + {401989e7-ae1e-4002-b0ee-9a9f63740b97} Tango.Scripting @@ -284,7 +289,7 @@ - + \ No newline at end of file -- cgit v1.3.1