mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-10 10:11:31 +00:00
Add the helper class
This commit is contained in:
parent
06afbf4c18
commit
8ea60202a3
7 changed files with 215 additions and 0 deletions
9
Tests/Cosmos.Common.Tests/.editorconfig
Normal file
9
Tests/Cosmos.Common.Tests/.editorconfig
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
; 4-column space indentation
|
||||
root=true
|
||||
tab_width=4
|
||||
indent_size=4
|
||||
|
||||
[*.cs]
|
||||
tab_width=4
|
||||
indent_size=4
|
||||
indent_style=space
|
||||
92
Tests/Cosmos.Common.Tests/Cosmos.Common.Tests.csproj
Normal file
92
Tests/Cosmos.Common.Tests/Cosmos.Common.Tests.csproj
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Cosmos.Common.Tests</RootNamespace>
|
||||
<AssemblyName>Cosmos.Common.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="ToHexStringTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\source\Cosmos.Common\Cosmos.Common.csproj">
|
||||
<Project>{1fac100c-d732-4ea4-b518-5af4baf64f2e}</Project>
|
||||
<Name>Cosmos.Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".editorconfig" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
19
Tests/Cosmos.Common.Tests/Properties/AssemblyInfo.cs
Normal file
19
Tests/Cosmos.Common.Tests/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("Cosmos.Common.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Cosmos")]
|
||||
[assembly: AssemblyProduct("Cosmos.Common.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Cosmos 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Если данный проект доступен для модели COM, следующий GUID используется в качестве идентификатора библиотеки типов
|
||||
[assembly: Guid("0d2dce1c-2a34-4cff-9a33-e9d9b8518d50")]
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
47
Tests/Cosmos.Common.Tests/ToHexStringTest.cs
Normal file
47
Tests/Cosmos.Common.Tests/ToHexStringTest.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
namespace Cosmos.Common.Tests
|
||||
{
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Cosmos.Common.Extensions;
|
||||
|
||||
[TestClass]
|
||||
public class ToHexStringTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Test to hex conversion method.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestToHexUnit32()
|
||||
{
|
||||
uint testValue = 32;
|
||||
Assert.AreEqual("00000020", testValue.ToHex());
|
||||
Assert.AreEqual("00000020", testValue.ToHex(8));
|
||||
Assert.AreEqual("0000020", testValue.ToHex(7));
|
||||
Assert.AreEqual("0020", testValue.ToHex(4));
|
||||
Assert.AreEqual("20", testValue.ToHex(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test to hex conversion method.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestToHexUnit16()
|
||||
{
|
||||
ushort testValue = 34;
|
||||
Assert.AreEqual("0022", testValue.ToHex());
|
||||
Assert.AreEqual("0022", testValue.ToHex(4));
|
||||
Assert.AreEqual("22", testValue.ToHex(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test to hex conversion method.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestToHexUnit8()
|
||||
{
|
||||
byte testValue = 34;
|
||||
Assert.AreEqual("22", testValue.ToHex());
|
||||
Assert.AreEqual("0022", testValue.ToHex(4));
|
||||
Assert.AreEqual("22", testValue.ToHex(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,6 +80,7 @@
|
|||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="Extensions\ByteConverter.cs" />
|
||||
<Compile Include="Extensions\ToHexString.cs" />
|
||||
<Compile Include="NumberHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RingAttribute.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
28
source/Cosmos.Common/NumberHelper.cs
Normal file
28
source/Cosmos.Common/NumberHelper.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
namespace Cosmos.Common
|
||||
{
|
||||
using System;
|
||||
using Cosmos.Common.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for working with numbers.
|
||||
/// </summary>
|
||||
public static class NumberHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Write number to console.
|
||||
/// </summary>
|
||||
/// <param name="aValue">A value to print.</param>
|
||||
/// <param name="aZeroFill">A value indicating whether strarting zeros should be present.</param>
|
||||
public static void WriteNumber(uint aValue, bool aZeroFill)
|
||||
{
|
||||
if (aZeroFill)
|
||||
{
|
||||
Console.WriteLine("0x" + aValue.ToHex());
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("0x" + aValue.ToHex().TrimStart('0'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -215,6 +215,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElfMap2DebugDb", "ElfMap2De
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emile.TestApp", "..\Users\Emile\Emile.TestApp\Emile.TestApp.csproj", "{99A78D26-0277-4882-97BE-F5A0FA90CBCF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Common.Tests", "..\Tests\Cosmos.Common.Tests\Cosmos.Common.Tests.csproj", "{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -1060,6 +1062,22 @@ Global
|
|||
{99A78D26-0277-4882-97BE-F5A0FA90CBCF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{99A78D26-0277-4882-97BE-F5A0FA90CBCF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{99A78D26-0277-4882-97BE-F5A0FA90CBCF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|Itanium.ActiveCfg = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|Itanium.Build.0 = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|Itanium.ActiveCfg = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|Itanium.Build.0 = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -1141,5 +1159,6 @@ Global
|
|||
{ABE135D1-ACF8-4C25-A5DF-A96F013242C5} = {45E223F1-F219-4D48-96EC-85E0E0065BE7}
|
||||
{BD054B3B-D183-4C19-BBD3-E853B736818A} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
|
||||
{99A78D26-0277-4882-97BE-F5A0FA90CBCF} = {EE39BC20-06D5-49F7-943A-58C1C1B179D3}
|
||||
{0D2DCE1C-2A34-4CFF-9A33-E9D9B8518D50} = {CAF5EB57-6CAD-446D-8FC7-4C03D4B996A6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
Loading…
Reference in a new issue