From 914f4db513477d9aff726546bac47545195a3e37 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 16 Nov 2017 13:38:56 +0200 Subject: Rename "Visual Studio" to "Visual_Studio" Rename "External Repositories" to "External_Repositories". --- Software/Visual_Studio/Tango.UnitTesting/Helper.cs | 102 ++++++++++++++++++ .../Tango.UnitTesting/Properties/AssemblyInfo.cs | 6 ++ .../Tango.UnitTesting/Protobuf_TST.cs | 115 +++++++++++++++++++++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 100 ++++++++++++++++++ .../Tango.UnitTesting/packages.config | 7 ++ 5 files changed, 330 insertions(+) create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Helper.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Protobuf_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj create mode 100644 Software/Visual_Studio/Tango.UnitTesting/packages.config (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 new file mode 100644 index 000000000..ece74d3f3 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using Tango.Logging; + +namespace Tango.UnitTesting +{ + /// + /// Contains several unit testing helper methods. + /// + public static class Helper + { + /// + /// Gets the absolute path to the specified file name in the solution 'Resources' folder. + /// + /// Name of the file. + /// + public static String GetResourcePath(String fileName) + { + return Path.GetFullPath(@"..\..\Resources\" + fileName); + } + + /// + /// Gets the PMR (Protobuf Messages Repository) path. + /// + /// + public static String GetPMRPath() + { + return Path.GetFullPath(@"..\..\..\PMR\Messages\"); + } + + /// + /// Initializes the logging manager. + /// + public static ConsoleLogger InitializeLogging(bool useConsole = false, [CallerMemberName] string testName = null) + { + LogManager.RegisterLogger(new FileLogger(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "logs", "Unit Testing", testName + ".txt"))); + if (useConsole) + { + var consoleLogger = new ConsoleLogger(testName); + LogManager.RegisterLogger(consoleLogger); + return consoleLogger; + } + + return null; + } + + /// + /// Creates a temporary folder and returns it's path. + /// + /// + public static String GetTempFolderPathAppend(String customFolder, [CallerMemberName] string testName = null) + { + String tempDirectory = Path.Combine(Path.GetTempPath(), "Twine", "Unit Testing", testName, customFolder); + Directory.CreateDirectory(tempDirectory); + return tempDirectory; + } + + /// + /// Creates a temporary folder and returns it's path. + /// + /// + public static String GetTempFolderPath([CallerMemberName] string testName = null) + { + String tempDirectory = Path.Combine(Path.GetTempPath(), "Twine", "Unit Testing", testName, Path.GetRandomFileName()); + Directory.CreateDirectory(tempDirectory); + return tempDirectory; + } + + /// + /// Tries to delete folder. + /// + /// The path. + /// + public static bool TryDeleteFolder(String path) + { + try + { + Directory.Delete(path, true); + return true; + } + catch + { + return false; + } + } + + /// + /// Shows the file in explorer. + /// + /// Name of the file/folder. + public static void ShowInExplorer(String path) + { + Process.Start("explorer.exe", string.Format("/select,\"{0}\"", path)); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.UnitTesting/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..0551f8f77 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tango - Unit Testing")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.UnitTesting/Protobuf_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Protobuf_TST.cs new file mode 100644 index 000000000..ed3bfbb7d --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Protobuf_TST.cs @@ -0,0 +1,115 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.Protobuf; +using System.Threading; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using Google.Protobuf; +using Tango.PMR.Jobs; +using Tango.PMR.Common; +using Tango.PMR; +using Tango.Logging; +using Newtonsoft.Json; +using System.Runtime.InteropServices; +using Tango.Core.Helpers; +using System.Text; +using Tango.PMR.Stubs; + +namespace Tango.UnitTesting +{ + [TestClass] + [TestCategory("Protobuf")] + public class Protobuf_TST + { + [DllImport("Tango.ProtoTest.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern int Calculate(IntPtr data, int size, ref IntPtr output); + + /// + /// Compiles all the whole PMR using all available compilers. + /// + [TestMethod] + public void Compile_All_PMR() + { + var console = Helper.InitializeLogging(true); + + String pmrFolder = Helper.GetPMRPath(); + + List tempFolders = new List(); + + foreach (var compiler in CompilerFactory.GetAvailableCompilers()) + { + CompilerFolderResult result = compiler.CompileFolder(pmrFolder); + String tmpFolder = Helper.GetTempFolderPathAppend(compiler.Language.ToString()); + result.Save(tmpFolder); + tempFolders.Add(tmpFolder); + } + + Helper.ShowInExplorer(Directory.GetParent(tempFolders.First()).FullName); + + console.WaitForConsoleExit().Wait(); + + foreach (var folder in tempFolders) + { + Helper.TryDeleteFolder(folder); + } + } + + /// + /// Writes and reads a proto message then compares. + /// + [TestMethod] + public void Read_Write_Message() + { + var console = Helper.InitializeLogging(true); + + TangoMessage container = MessageFactory.CreateTangoMessage(); + + container.Message.Name = "Test Job"; + + container.Message.Segments.Add(new Segment() + { + Color = new RGB() { R = 1, G = 2, B = 3 }, + Length = 10, + Name = "Segment 1" + }); + + container.Message.Segments.Add(new Segment() + { + Color = new RGB() { R = 10, G = 20, B = 30 }, + Length = 100, + Name = "Segment 2" + }); + + LogManager.Log("Write Message:" + Environment.NewLine + JsonConvert.SerializeObject(container.Message, Formatting.Indented)); + + var bytes = container.ToBytes(); + + var parsed = MessageFactory.ParseTangoMessage(bytes); + + LogManager.Log("Read Message:" + Environment.NewLine + JsonConvert.SerializeObject(parsed.Message, Formatting.Indented)); + + Assert.AreEqual(container.Message, parsed.Message); + + LogManager.Log("Test Passed!"); + + console.WaitForConsoleExit().Wait(); + } + + /// + /// Calls a C++ native library and get a result. + /// + [TestMethod] + public void Call_CPP_And_Get_Result() + { + CalculateRequest request = new CalculateRequest(); + request.A = 10; + request.B = 5; + + NativePMR nativePMR = new NativePMR(Calculate); + CalculateResponse response = nativePMR.Invoke(request); + + Assert.AreEqual(response.Sum, request.A + request.B); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj new file mode 100644 index 000000000..a377179b9 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -0,0 +1,100 @@ + + + + + Debug + AnyCPU + {FB82AA6B-1652-452C-8235-4FB2E524FBC0} + Library + Properties + Tango.UnitTesting + Tango.UnitTesting + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + ..\Build\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + GlobalVersionInfo.cs + + + + + + + + + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} + Tango.Logging + + + {e4927038-348d-4295-aaf4-861c58cb3943} + Tango.PMR + + + {40073806-914e-4e78-97ab-fa9639308ebe} + Tango.Protobuf + + + {ac489889-6e50-4f16-9dba-ff4c6f9ec72b} + Tango.SharedUI + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.UnitTesting/packages.config b/Software/Visual_Studio/Tango.UnitTesting/packages.config new file mode 100644 index 000000000..d3cd9d043 --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file -- cgit v1.3.1