diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-14 17:40:23 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-04-14 17:40:23 +0300 |
| commit | 34d86579a1f4e3842566b3dd187f9fa5f3838d07 (patch) | |
| tree | c0467e2408a63d9bffcb4ece4f28ffa642a63f31 | |
| parent | 5ed60ca1b49fd67ccca9e80be02924050c2ae87a (diff) | |
| download | Tango-34d86579a1f4e3842566b3dd187f9fa5f3838d07.tar.gz Tango-34d86579a1f4e3842566b3dd187f9fa5f3838d07.zip | |
Implemented some test methods for pulse.
| -rw-r--r-- | Software/Visual_Studio/Resources/Pulse/ABC.dst | bin | 0 -> 4266 bytes | |||
| -rw-r--r-- | Software/Visual_Studio/Resources/Pulse/test.twn | bin | 0 -> 4938881 bytes | |||
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/Helper.cs | 9 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs | 84 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj | 7 |
5 files changed, 99 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Resources/Pulse/ABC.dst b/Software/Visual_Studio/Resources/Pulse/ABC.dst Binary files differnew file mode 100644 index 000000000..71839e39f --- /dev/null +++ b/Software/Visual_Studio/Resources/Pulse/ABC.dst diff --git a/Software/Visual_Studio/Resources/Pulse/test.twn b/Software/Visual_Studio/Resources/Pulse/test.twn Binary files differnew file mode 100644 index 000000000..3a564f625 --- /dev/null +++ b/Software/Visual_Studio/Resources/Pulse/test.twn 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 @@ -28,6 +28,15 @@ namespace Tango.UnitTesting } /// <summary> + /// Gets the absolute path to the 'Resources' folder. + /// </summary> + /// <returns></returns> + public static String GetResourcePath() + { + return Path.GetFullPath(@"..\..\..\Resources\"); + } + + /// <summary> /// Gets the PMR (Protobuf Messages Repository) path. /// </summary> /// <returns></returns> 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 @@ <Compile Include="Logging\Parsing_TST.cs" /> <Compile Include="MachineService\PPC_Controller_TST.cs" /> <Compile Include="MachineStudio\MachineStudio_TST.cs" /> + <Compile Include="Pulse\Pulse_TST.cs" /> <Compile Include="RemoteRunner_TST.cs" /> <Compile Include="SQLExaminer\SQLExaminer_TST.cs" /> <Compile Include="Core\TemporaryManager_TST.cs" /> @@ -214,6 +215,10 @@ <Project>{40073806-914e-4e78-97ab-fa9639308ebe}</Project> <Name>Tango.Protobuf</Name> </ProjectReference> + <ProjectReference Include="..\Tango.Pulse\Tango.Pulse.csproj"> + <Project>{8435223D-DB6B-45E3-A08B-45B7416F8481}</Project> + <Name>Tango.Pulse</Name> + </ProjectReference> <ProjectReference Include="..\Tango.Scripting\Tango.Scripting.csproj"> <Project>{401989e7-ae1e-4002-b0ee-9a9f63740b97}</Project> <Name>Tango.Scripting</Name> @@ -284,7 +289,7 @@ <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file |
