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 From 14f0ccfdac1b5bcecab3854204be1e071faa80f5 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 22 Apr 2019 13:03:09 +0300 Subject: Applied proper permissions to color capture module. --- .../ColorCaptureModule.cs | 63 ++++++++++++++++++++++ .../ColorLabModule.cs | 63 ---------------------- .../Tango.MachineStudio.ColorCapture.csproj | 2 +- .../Tango.UnitTesting/Pulse/Pulse_TST.cs | 2 + 4 files changed, 66 insertions(+), 64 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorCaptureModule.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorLabModule.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorCaptureModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorCaptureModule.cs new file mode 100644 index 000000000..8724f675c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorCaptureModule.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; +using Tango.BL.Enumerations; +using Tango.MachineStudio.ColorCapture.Views; +using Tango.MachineStudio.Common; +using Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.ColorCapture +{ + [StudioModule(15)] + public class ColorCaptureModule : StudioModuleBase + { + public override string Name + { + get + { + return "Color Capture"; + } + } + + public override string Description + { + get + { + return "Exposes Twine's color calibration technology through a real-time video capturing engine."; + } + } + + public override BitmapSource Image + { + get + { + return ResourceHelper.GetImageFromResources("Images/colorcapture_module.png"); + } + } + + public override Type MainViewType + { + get + { + return typeof(MainView); + } + } + + public override Permissions Permission + { + get + { + return Permissions.RunColorCaptureModule; + } + } + + public override void Dispose() + { + + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorLabModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorLabModule.cs deleted file mode 100644 index ef616daca..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ColorLabModule.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media.Imaging; -using Tango.BL.Enumerations; -using Tango.MachineStudio.ColorCapture.Views; -using Tango.MachineStudio.Common; -using Tango.SharedUI.Helpers; - -namespace Tango.MachineStudio.ColorCapture -{ - [StudioModule(15)] - public class ColorLabModule : StudioModuleBase - { - public override string Name - { - get - { - return "Color Capture"; - } - } - - public override string Description - { - get - { - return "Exposes Twine's color calibration technology through a real-time video capturing engine."; - } - } - - public override BitmapSource Image - { - get - { - return ResourceHelper.GetImageFromResources("Images/colorcapture_module.png"); - } - } - - public override Type MainViewType - { - get - { - return typeof(MainView); - } - } - - public override Permissions Permission - { - get - { - return Permissions.RunColorLabModule; - } - } - - public override void Dispose() - { - - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj index b399d9971..9f21cadf2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj @@ -97,7 +97,7 @@ GlobalVersionInfo.cs - + diff --git a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs index b25a3140b..073841997 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs @@ -76,6 +76,8 @@ namespace Tango.UnitTesting.Pulse TwnFile twnFile = TwnFile.FromFile(sampleFile); var imgFile = TemporaryManager.Default.CreateFile(".png"); + String json = twnFile.ToJsonString(); + twnFile.Thumbnail.Save(imgFile, ImageFormat.Png); Helper.ShowInExplorer(imgFile); -- cgit v1.3.1