mirror of
https://github.com/soukoku/ntwain.git
synced 2025-10-25 19:19:03 +08:00
Initial move from old twain-in-dotnet.
This commit is contained in:
54
Tests/NTwain.Tests/Data/TWIdentityTest.cs
Normal file
54
Tests/NTwain.Tests/Data/TWIdentityTest.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using NTwain.Data;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using NTwain.Values;
|
||||
|
||||
namespace NTwain.Tests.Data
|
||||
{
|
||||
/// <summary>
|
||||
///This is a test class for TWIdentity and is intended
|
||||
///to contain all TWIdentityTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass]
|
||||
public class TWIdentityTest
|
||||
{
|
||||
// the maxlength expects null terminator so at maxlength it's over the limit
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "String length not enforced.")]
|
||||
public void Enforce_Manufacturer_String_Length()
|
||||
{
|
||||
TWIdentity target = new TWIdentity();
|
||||
|
||||
var overLength = TwainConst.String32;
|
||||
|
||||
string badString = new String('a', overLength);
|
||||
|
||||
target.Manufacturer = badString;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "String length not enforced.")]
|
||||
public void Enforce_ProductFamily_String_Length()
|
||||
{
|
||||
TWIdentity target = new TWIdentity();
|
||||
|
||||
var overLength = TwainConst.String32;
|
||||
|
||||
string badString = new String('a', overLength);
|
||||
target.ProductFamily = badString;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "String length not enforced.")]
|
||||
public void Enforce_ProductName_String_Length()
|
||||
{
|
||||
TWIdentity target = new TWIdentity();
|
||||
|
||||
var overLength = TwainConst.String32;
|
||||
|
||||
string badString = new String('a', overLength);
|
||||
target.ProductName = badString;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Tests/NTwain.Tests/DataTransferredEventArgsTests.cs
Normal file
26
Tests/NTwain.Tests/DataTransferredEventArgsTests.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using NTwain;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using NTwain.Values;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace NTwain.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class DataTransferredEventArgsTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Constructor_Sets_Correct_Properties()
|
||||
{
|
||||
// just some non-default values to test
|
||||
IntPtr data = new IntPtr(10);
|
||||
string file = "THIS IS A TEST.";
|
||||
|
||||
DataTransferredEventArgs target = new DataTransferredEventArgs(data, file);
|
||||
|
||||
Assert.AreEqual(data, target.Data, "Data mismatch.");
|
||||
Assert.AreEqual(file, target.FilePath, "File mismatch.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
25
Tests/NTwain.Tests/DeviceEventArgsTests.cs
Normal file
25
Tests/NTwain.Tests/DeviceEventArgsTests.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using NTwain;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using NTwain.Values;
|
||||
using System.Runtime.Serialization;
|
||||
using NTwain.Data;
|
||||
|
||||
namespace NTwain.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class DeviceEventArgsTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Constructor_Sets_Correct_Properties()
|
||||
{
|
||||
// just some non-default values to test
|
||||
TWDeviceEvent evt = new TWDeviceEvent();
|
||||
|
||||
DeviceEventArgs target = new DeviceEventArgs(evt);
|
||||
|
||||
Assert.AreEqual(evt, target.DeviceEvent, "DeviceEvent mismatch.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
94
Tests/NTwain.Tests/NTwain.Tests.csproj
Normal file
94
Tests/NTwain.Tests/NTwain.Tests.csproj
Normal file
@@ -0,0 +1,94 @@
|
||||
<?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>{6B034C50-A397-435F-8DDF-677B403FEBAA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NTwain.Tests</RootNamespace>
|
||||
<AssemblyName>NTwain.Tests</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>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>Sign.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<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>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
|
||||
<Visible>False</Visible>
|
||||
</CodeAnalysisDependentAssemblyPaths>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DataTransferredEventArgsTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Data\TWIdentityTest.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DeviceEventArgsTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TransferReadyEventArgsTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="TwainSessionTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="TwainStateExceptionTest.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\NTwain\NTwain.csproj">
|
||||
<Project>{0C5A6FB1-0282-4D61-8354-68DEB1515001}</Project>
|
||||
<Name>NTwain</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Sign.snk" />
|
||||
</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>
|
||||
35
Tests/NTwain.Tests/Properties/AssemblyInfo.cs
Normal file
35
Tests/NTwain.Tests/Properties/AssemblyInfo.cs
Normal 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("NTwain.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Yin-Chun Wang")]
|
||||
[assembly: AssemblyProduct("NTwain.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Yin-Chun Wang 2014")]
|
||||
[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("31489afd-4b8b-413a-b996-fb05bb6bc9fe")]
|
||||
|
||||
// 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")]
|
||||
BIN
Tests/NTwain.Tests/Sign.snk
Normal file
BIN
Tests/NTwain.Tests/Sign.snk
Normal file
Binary file not shown.
39
Tests/NTwain.Tests/TransferReadyEventArgsTests.cs
Normal file
39
Tests/NTwain.Tests/TransferReadyEventArgsTests.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using NTwain;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using NTwain.Values;
|
||||
using System.Runtime.Serialization;
|
||||
using NTwain.Data;
|
||||
using NTwain.Values.Cap;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NTwain.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class TransferReadyEventArgsTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Constructor_Sets_Correct_Properties()
|
||||
{
|
||||
// just some non-default values to test
|
||||
TWPendingXfers pending = new TWPendingXfers();
|
||||
List<ImageFileFormat> formats = new List<ImageFileFormat> { ImageFileFormat.Bmp, ImageFileFormat.Tiff };
|
||||
ImageFileFormat curFormat = ImageFileFormat.Tiff;
|
||||
List<Compression> compressions = new List<Compression> { Compression.None, Compression.Group4 };
|
||||
Compression curCompress = Compression.None;
|
||||
bool fileXfer = true;
|
||||
TWImageInfo info = new TWImageInfo();
|
||||
|
||||
TransferReadyEventArgs target = new TransferReadyEventArgs(pending, formats, curFormat, compressions, curCompress, fileXfer, info);
|
||||
|
||||
Assert.AreEqual(pending.Count, target.PendingCount, "PendingCount mismatch.");
|
||||
Assert.AreEqual(formats, target.SupportedFormats, "SupportedFormats mismatch.");
|
||||
Assert.AreEqual(curFormat, target.ImageFormat, "ImageFormat mismatch.");
|
||||
Assert.AreEqual(compressions, target.SupportedCompressions, "SupportedCompressions mismatch.");
|
||||
Assert.AreEqual(curCompress, target.ImageCompression, "ImageCompression mismatch.");
|
||||
Assert.AreEqual(fileXfer, target.CanDoFileXfer, "CanDoFileXfer mismatch.");
|
||||
Assert.AreEqual(info, target.ImageInfo, "ImageInfo mismatch.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
32
Tests/NTwain.Tests/TwainSessionTests.cs
Normal file
32
Tests/NTwain.Tests/TwainSessionTests.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using NTwain.Data;
|
||||
using NTwain.Values;
|
||||
|
||||
namespace NTwain.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class TwainSessionTests
|
||||
{
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(TwainStateException), "State check failed to throw.")]
|
||||
public void VerifyState_Throws_When_State_Is_Enforced()
|
||||
{
|
||||
TwainSession session = new TwainSession(TWIdentity.Create(DataGroups.Image, new Version(1, 0), "test", "test", "test", "test"));
|
||||
session.EnforceState = true;
|
||||
session.State = 4;
|
||||
|
||||
session.VerifyState(6, 6, DataGroups.Image, DataArgumentType.ImageNativeXfer, Message.Get);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyState_No_Throws_When_State_Is_Not_Enforced()
|
||||
{
|
||||
TwainSession session = new TwainSession(TWIdentity.Create(DataGroups.Image, new Version(1, 0), "test", "test", "test", "test"));
|
||||
session.EnforceState = false;
|
||||
session.State = 4;
|
||||
|
||||
session.VerifyState(6, 6, DataGroups.Image, DataArgumentType.ImageNativeXfer, Message.Get);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Tests/NTwain.Tests/TwainStateExceptionTest.cs
Normal file
43
Tests/NTwain.Tests/TwainStateExceptionTest.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using NTwain;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using NTwain.Values;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace NTwain.Tests
|
||||
{
|
||||
/// <summary>
|
||||
///This is a test class for TwainStateException and is intended
|
||||
///to contain all TwainStateExceptionTest Unit Tests
|
||||
///</summary>
|
||||
[TestClass]
|
||||
public class TwainStateExceptionTest
|
||||
{
|
||||
/// <summary>
|
||||
///A test for TwainStateException Constructor
|
||||
///</summary>
|
||||
[TestMethod]
|
||||
public void Constructor_Sets_Correct_Properties()
|
||||
{
|
||||
// just some non-default values to test
|
||||
int state = 3;
|
||||
int minState = 4;
|
||||
int maxState = 5;
|
||||
DataGroups dataGroup = DataGroups.Control;
|
||||
DataArgumentType argumentType = DataArgumentType.AudioNativeXfer;
|
||||
Message twainMessage = Message.Copy;
|
||||
string message = "THIS IS A TEST.";
|
||||
|
||||
TwainStateException target = new TwainStateException(state, minState, maxState, dataGroup, argumentType, twainMessage, message);
|
||||
|
||||
Assert.AreEqual(state, target.ActualState, "State mismatch.");
|
||||
Assert.AreEqual(minState, target.MinStateExpected, "Minimum mismatch.");
|
||||
Assert.AreEqual(maxState, target.MaxStateExpected, "Maximum mismatch.");
|
||||
Assert.AreEqual(dataGroup, target.DataGroup, "DataGroup mismatch.");
|
||||
Assert.AreEqual(argumentType, target.ArgumentType, "ArgumentType mismatch.");
|
||||
Assert.AreEqual(twainMessage, target.TwainMessage, "TwainMessage mismatch.");
|
||||
Assert.AreEqual(message, target.Message, "Message mismatch.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user