diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-04-17 14:48:09 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-04-17 14:48:09 +0300 |
| commit | c4cc44a16a7da32d8bcf23928aa396b035bc1ad2 (patch) | |
| tree | 05e50121a61537625b76ba479a4e273b8a72786f /Software/Visual_Studio/Tango.UnitTesting | |
| parent | 225ffd633d781537de51f1c59ef2f1eb77d1ee67 (diff) | |
| parent | 07550eee00f4b6de20e01679cf8811e9a6597df2 (diff) | |
| download | Tango-c4cc44a16a7da32d8bcf23928aa396b035bc1ad2.tar.gz Tango-c4cc44a16a7da32d8bcf23928aa396b035bc1ad2.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
3 files changed, 99 insertions, 1 deletions
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 |
