aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2019-03-28 10:55:56 +0200
committerShlomo Hecht <shlomo@twine-s.com>2019-03-28 10:55:56 +0200
commit36f19301ac0cc27d74b73eb4b31fdecfd86f5060 (patch)
treee4f4a636f4a2dc03376e6eff2077ced4079429ed /Software/Visual_Studio/Tango.UnitTesting
parent1ea2a13900697e203658ff8c9489b70866792a49 (diff)
parentb62c4b8b67b3103c691564df80f65423a9c315a0 (diff)
downloadTango-36f19301ac0cc27d74b73eb4b31fdecfd86f5060.tar.gz
Tango-36f19301ac0cc27d74b73eb4b31fdecfd86f5060.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmpbin0 -> 140174 bytes
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmpbin0 -> 1351734 bytes
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs95
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj20
4 files changed, 115 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp
new file mode 100644
index 000000000..1d48c010b
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap.bmp
Binary files differ
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmp b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmp
new file mode 100644
index 000000000..0135298a5
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC Resources/bitmap_ok.bmp
Binary files differ
diff --git a/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
new file mode 100644
index 000000000..475bc68fd
--- /dev/null
+++ b/Software/Visual_Studio/Tango.UnitTesting/TCC/TCC_TST.cs
@@ -0,0 +1,95 @@
+using Google.Protobuf;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.IO;
+using Tango.CSV;
+using Tango.PMR.TCC;
+using Tango.TCC.BL;
+
+namespace Tango.UnitTesting.TCC
+{
+ [TestClass]
+ [TestCategory("TCC")]
+ public class TCC_TST
+ {
+ [TestMethod]
+ public void Detect()
+ {
+ var original_bitmap = Directory.GetCurrentDirectory() + "\\TCC\\TCC Resources\\bitmap_ok.bmp";
+
+ using (ColorDetector detector = new ColorDetector())
+ {
+ DetectionInput input = new DetectionInput()
+ {
+ Number = 5,
+ Columns = 10,
+ Rows = 11,
+ TargetIndex = 99,
+ Bitmap = ByteString.CopyFrom(File.ReadAllBytes(original_bitmap)),
+ DebugMode = true,
+ };
+
+ var output = detector.Detect(input);
+
+ using (MemoryStream ms = new MemoryStream(output.DebugBitmap.ToArray()))
+ {
+ var outputBitmap = TemporaryManager.Default.CreateFile(".bmp");
+ outputBitmap.Persist = true;
+ ms.Position = 0;
+ Bitmap bmp = new Bitmap(ms);
+ bmp.Save(outputBitmap);
+ Process.Start(outputBitmap);
+ }
+
+ using (Bitmap colorMatrixBmp = ColorDetector.DetectionOutputToImage(input, output, 300, 320))
+ {
+ var outputBitmap = TemporaryManager.Default.CreateFile(".bmp");
+ outputBitmap.Persist = true;
+ colorMatrixBmp.Save(outputBitmap);
+ Process.Start(outputBitmap);
+ }
+
+ var benchmarksCsvFile = TemporaryManager.Default.CreateFile(".csv");
+ benchmarksCsvFile.Persist = true;
+
+ using (CsvFile<DetectionColor> benchmarksRGB = new CsvFile<DetectionColor>(new CsvDestination(benchmarksCsvFile)))
+ {
+ foreach (var color in output.ColorMatrix)
+ {
+ benchmarksRGB.Append(color);
+ }
+ }
+
+ Helper.ShowInExplorer(benchmarksCsvFile);
+
+ Assert.IsTrue(output.Number == 15);
+ }
+ }
+
+ private byte[] GetBitmapData(byte[] bitmap)
+ {
+ using (MemoryStream ms = new MemoryStream(bitmap))
+ {
+ ms.Position = 0;
+ Bitmap image = new Bitmap(ms);
+ Rectangle area = new Rectangle(0, 0, image.Width, image.Height);
+ BitmapData bitmapData = image.LockBits(area, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
+ int stride = bitmapData.Stride;
+ IntPtr ptr = bitmapData.Scan0;
+ int numBytes = bitmapData.Stride * image.Height;
+ byte[] rgbValues = new byte[numBytes];
+ Marshal.Copy(ptr, rgbValues, 0, numBytes);
+ return rgbValues;
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj
index d1bba995e..3e5434c98 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj
+++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj
@@ -102,6 +102,7 @@
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.108.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
+ <Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
@@ -126,6 +127,7 @@
<Compile Include="RemoteRunner_TST.cs" />
<Compile Include="SQLExaminer\SQLExaminer_TST.cs" />
<Compile Include="Core\TemporaryManager_TST.cs" />
+ <Compile Include="TCC\TCC_TST.cs" />
<Compile Include="TFS\TFS_TST.cs" />
<Compile Include="Outlook_TST.cs" />
<Compile Include="Embroidery\Embroidery_TST.cs" />
@@ -138,6 +140,12 @@
<Content Include="AdvancedInstaller\DemoProject\DemoProject.aip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <Content Include="TCC\TCC Resources\bitmap.bmp">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="TCC\TCC Resources\bitmap_ok.bmp">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
@@ -174,6 +182,10 @@
<Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
<Name>Tango.Core</Name>
</ProjectReference>
+ <ProjectReference Include="..\Tango.CSV\Tango.CSV.csproj">
+ <Project>{58e8825f-0c96-449c-b320-1e82b0aa876b}</Project>
+ <Name>Tango.CSV</Name>
+ </ProjectReference>
<ProjectReference Include="..\Tango.DAL.Local\Tango.DAL.Local.csproj">
<Project>{0e0eef3e-8f4e-4f23-9d19-479fd8d76c12}</Project>
<Name>Tango.DAL.Local</Name>
@@ -230,6 +242,14 @@
<Project>{5001990f-977b-48ff-b217-0236a5022ad8}</Project>
<Name>Tango.Web</Name>
</ProjectReference>
+ <ProjectReference Include="..\TCC\Tango.TCC.BL\Tango.TCC.BL.csproj">
+ <Project>{f209fae8-73f9-441b-97f4-0844a0279390}</Project>
+ <Name>Tango.TCC.BL</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\TCC\Tango.TCC.OpenCV.DLL\Tango.TCC.OpenCV.DLL.csproj">
+ <Project>{5d0d4053-cab3-4a4a-929e-37a76483bc22}</Project>
+ <Name>Tango.TCC.OpenCV.DLL</Name>
+ </ProjectReference>
<ProjectReference Include="..\Utilities\Tango.DBObservablesGenerator.CLI\Tango.DBObservablesGenerator.CLI.csproj">
<Project>{ebb7cb9f-6af2-456b-a5dd-1b136b605d90}</Project>
<Name>Tango.DBObservablesGenerator.CLI</Name>