Initial commit

This commit is contained in:
Ebrahim Byagowi
2012-03-03 13:20:54 +03:30
commit 849cb8865a
26 changed files with 1825 additions and 0 deletions

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{928609B4-70AB-4D93-A43E-4BE75C279066}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PInvokeSerialPort.Test</RootNamespace>
<AssemblyName>PInvokeSerialPort.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</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="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PInvokeSerialPortTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PInvokeSerialPort\PInvokeSerialPort.csproj">
<Project>{AEC711A5-AA9B-4127-A82C-C4D8FDA9741A}</Project>
<Name>PInvokeSerialPort</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\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>

View File

@ -0,0 +1,84 @@
using System;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
namespace PInvokeSerialPort.Test
{
/// <summary>
/// Test class.
/// Attention: Run it just in test debug.
/// </summary>
[TestClass]
public class PInvokeSerialPortTest
{
dynamic _sender;
dynamic _reciever;
StringBuilder _stringBuilder;
public void OpenWriteDoWaitClose(Action action)
{
const string testSting = "test";
_stringBuilder = new StringBuilder();
_sender.Open();
_reciever.Open();
action();
_sender.Write(testSting);
Thread.Sleep(100);
Assert.AreEqual(testSting, _stringBuilder.ToString());
_sender.Close();
_reciever.Close();
}
[TestMethod]
public void OverallTest1()
{
_sender = new SerialPort("com1");
_reciever = new SerialPort("com2");
OpenWriteDoWaitClose(() =>
{
((SerialPort)_reciever).DataReceived += x => _stringBuilder.Append((char)x);
});
}
[TestMethod]
public void OverallTest2()
{
_sender = new System.IO.Ports.SerialPort("com1");
_reciever = new SerialPort("com2");
OpenWriteDoWaitClose(() =>
{
((SerialPort)(object)_reciever).DataReceived += x => _stringBuilder.Append((char)x);
});
}
[TestMethod]
public void OverallTest3()
{
_sender = new SerialPort("com1");
_reciever = new System.IO.Ports.SerialPort("com2");
OpenWriteDoWaitClose(() =>
{
((System.IO.Ports.SerialPort)_reciever).DataReceived += (x, y) => _stringBuilder.Append(_reciever.ReadExisting());
});
}
[TestMethod]
public void OverallTest4() // this is not really a PInvokeSerialTest :D
{
_sender = new System.IO.Ports.SerialPort("com1");
_reciever = new System.IO.Ports.SerialPort("com2");
OpenWriteDoWaitClose(() =>
{
((System.IO.Ports.SerialPort)_reciever).DataReceived += (x, y) => _stringBuilder.Append(_reciever.ReadExisting());
});
}
}
}

View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PInvokeSerialPort.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PInvokeSerialPort.Test")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7e55b1ff-e888-4433-ab65-c9b32bb8125f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]