summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.Interop/HandBrakeInterop.Test
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-06-12 16:54:23 +0000
committersr55 <[email protected]>2011-06-12 16:54:23 +0000
commit399ab292d7feddf5e83be866caafbaef634eca87 (patch)
tree519a29f631a5d07c25e4b01ef195005d166ddad6 /win/CS/HandBrake.Interop/HandBrakeInterop.Test
parent191aad2ed1e77d8292f72ab7caf8996d117edd63 (diff)
WinGui: Bring in the HandBrake Interop library written by RandomEngy.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4045 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.Interop/HandBrakeInterop.Test')
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop.Test/EncodeJobsPersist.cs30
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop.Test/HandBrakeInterop.Test.csproj68
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop.Test/Properties/AssemblyInfo.cs35
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestEncodes.cs100
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestFiles/Jobs/Normal.xmlbin0 -> 5250 bytes
5 files changed, 233 insertions, 0 deletions
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop.Test/EncodeJobsPersist.cs b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/EncodeJobsPersist.cs
new file mode 100644
index 000000000..5ede69963
--- /dev/null
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/EncodeJobsPersist.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Xml;
+using System.Xml.Linq;
+using System.Xml.Serialization;
+using HandBrake.Interop;
+
+namespace HandBrakeInterop.Test
+{
+ public static class EncodeJobsPersist
+ {
+ private static XmlSerializer xmlSerializer = new XmlSerializer(typeof(EncodeJob));
+
+ public static EncodeJob GetJob(string jobName)
+ {
+ XDocument doc = XDocument.Load(jobName + ".xml");
+ using (XmlReader reader = doc.CreateReader())
+ {
+ var job = xmlSerializer.Deserialize(reader) as EncodeJob;
+
+
+
+ return job;
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop.Test/HandBrakeInterop.Test.csproj b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/HandBrakeInterop.Test.csproj
new file mode 100644
index 000000000..5b7a8b72c
--- /dev/null
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/HandBrakeInterop.Test.csproj
@@ -0,0 +1,68 @@
+<?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>{D721824C-CAFA-40B1-83C9-83E4B1215D60}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>HandBrakeInterop.Test</RootNamespace>
+ <AssemblyName>HandBrakeInterop.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.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.Xml" />
+ <Reference Include="System.Xml.Linq" />
+ </ItemGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="EncodeJobsPersist.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TestEncodes.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\HandBrakeInterop\HandBrakeInterop.csproj">
+ <Project>{F0A61F62-2C3B-4A87-AFF4-0C4256253DA1}</Project>
+ <Name>HandBrakeInterop</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> \ No newline at end of file
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop.Test/Properties/AssemblyInfo.cs b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..2352dc269
--- /dev/null
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/Properties/AssemblyInfo.cs
@@ -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("HandBrakeInterop.Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("HandBrakeInterop.Test")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[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("2731c894-c1fc-4690-9557-aa56591b17ab")]
+
+// 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")]
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestEncodes.cs b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestEncodes.cs
new file mode 100644
index 000000000..cb5a848eb
--- /dev/null
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestEncodes.cs
@@ -0,0 +1,100 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using HandBrake.Interop;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HandBrakeInterop.Test
+{
+ [TestClass]
+ public class TestEncodes
+ {
+ public const string OutputVideoDirectoryName = "OutputVideos";
+ private static readonly string OutputVideoDirectory = Path.Combine(Environment.CurrentDirectory, OutputVideoDirectoryName);
+
+ private ManualResetEvent resetEvent = new ManualResetEvent(false);
+
+ [ClassInitialize]
+ public static void Init(TestContext context)
+ {
+ EnsureOutputVideoDirectoryExists();
+
+ FileInfo[] files = new DirectoryInfo(OutputVideoDirectory).GetFiles();
+ foreach (FileInfo file in files)
+ {
+ file.Delete();
+ }
+ }
+
+ [TestMethod]
+ public void Normal()
+ {
+ this.RunJob("Normal");
+ }
+
+ private void RunJob(string jobName)
+ {
+ this.resetEvent.Reset();
+
+ EncodeJob job = EncodeJobsPersist.GetJob("Normal");
+
+ if (job.SourceType == SourceType.VideoFolder)
+ {
+ job.SourcePath = Path.Combine(Environment.CurrentDirectory, Path.GetFileName(job.SourcePath));
+ }
+
+ if (job.SourceType == SourceType.File)
+ {
+ job.SourcePath = Path.Combine(Environment.CurrentDirectory, Path.GetFileName(job.SourcePath));
+ }
+
+ string extension;
+ if (job.EncodingProfile.OutputFormat == OutputFormat.Mkv)
+ {
+ extension = ".mkv";
+ }
+ else
+ {
+ extension = ".mp4";
+ }
+
+ job.OutputPath = Path.Combine(OutputVideoDirectory, jobName + extension);
+
+ var instance = new HandBrakeInstance();
+ instance.Initialize(0);
+ instance.ScanCompleted += (sender, e) =>
+ {
+ this.resetEvent.Set();
+ };
+
+ instance.StartScan(job.SourcePath, 10);
+ this.resetEvent.WaitOne();
+
+ this.resetEvent.Reset();
+ instance.EncodeCompleted += (sender, e) =>
+ {
+ Assert.IsFalse(e.Error);
+ this.resetEvent.Set();
+ };
+
+ instance.StartEncode(job);
+ this.resetEvent.WaitOne();
+
+ Assert.IsTrue(File.Exists(job.OutputPath));
+
+ var fileInfo = new FileInfo(job.OutputPath);
+ Assert.IsTrue(fileInfo.Length > 1024);
+ }
+
+ private static void EnsureOutputVideoDirectoryExists()
+ {
+ if (!Directory.Exists(OutputVideoDirectory))
+ {
+ Directory.CreateDirectory(OutputVideoDirectory);
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestFiles/Jobs/Normal.xml b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestFiles/Jobs/Normal.xml
new file mode 100644
index 000000000..b717a7c36
--- /dev/null
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop.Test/TestFiles/Jobs/Normal.xml
Binary files differ