Skip to content

Commit 9efb652

Browse files
author
RandomEngy
committed
Added test for HandbrakeInterop.
1 parent 2f207da commit 9efb652

10 files changed

Lines changed: 269 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Xml;
7+
using System.Xml.Linq;
8+
using System.Xml.Serialization;
9+
using HandBrake.Interop;
10+
11+
namespace HandBrakeInterop.Test
12+
{
13+
public static class EncodeJobsPersist
14+
{
15+
private static XmlSerializer xmlSerializer = new XmlSerializer(typeof(EncodeJob));
16+
17+
public static EncodeJob GetJob(string jobName)
18+
{
19+
XDocument doc = XDocument.Load(jobName + ".xml");
20+
using (XmlReader reader = doc.CreateReader())
21+
{
22+
var job = xmlSerializer.Deserialize(reader) as EncodeJob;
23+
24+
25+
26+
return job;
27+
}
28+
}
29+
}
30+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>
7+
</ProductVersion>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{D721824C-CAFA-40B1-83C9-83E4B1215D60}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>HandBrakeInterop.Test</RootNamespace>
13+
<AssemblyName>HandBrakeInterop.Test</AssemblyName>
14+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
37+
<Reference Include="System" />
38+
<Reference Include="System.Core">
39+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
40+
</Reference>
41+
<Reference Include="System.Xml" />
42+
<Reference Include="System.Xml.Linq" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
46+
<Visible>False</Visible>
47+
</CodeAnalysisDependentAssemblyPaths>
48+
</ItemGroup>
49+
<ItemGroup>
50+
<Compile Include="EncodeJobsPersist.cs" />
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
<Compile Include="TestEncodes.cs" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<ProjectReference Include="..\HandBrakeInterop\HandBrakeInterop.csproj">
56+
<Project>{F0A61F62-2C3B-4A87-AFF4-0C4256253DA1}</Project>
57+
<Name>HandBrakeInterop</Name>
58+
</ProjectReference>
59+
</ItemGroup>
60+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
61+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
62+
Other similar extension points exist, see Microsoft.Common.targets.
63+
<Target Name="BeforeBuild">
64+
</Target>
65+
<Target Name="AfterBuild">
66+
</Target>
67+
-->
68+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("HandBrakeInterop.Test")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("HandBrakeInterop.Test")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("2731c894-c1fc-4690-9557-aa56591b17ab")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading;
7+
using HandBrake.Interop;
8+
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
10+
namespace HandBrakeInterop.Test
11+
{
12+
[TestClass]
13+
public class TestEncodes
14+
{
15+
public const string OutputVideoDirectoryName = "OutputVideos";
16+
private static readonly string OutputVideoDirectory = Path.Combine(Environment.CurrentDirectory, OutputVideoDirectoryName);
17+
18+
private ManualResetEvent resetEvent = new ManualResetEvent(false);
19+
20+
[ClassInitialize]
21+
public static void Init(TestContext context)
22+
{
23+
EnsureOutputVideoDirectoryExists();
24+
}
25+
26+
[TestMethod]
27+
public void Normal()
28+
{
29+
this.RunJob("Normal");
30+
}
31+
32+
private void RunJob(string jobName)
33+
{
34+
this.resetEvent.Reset();
35+
36+
EncodeJob job = EncodeJobsPersist.GetJob("Normal");
37+
38+
if (job.SourceType == SourceType.VideoFolder)
39+
{
40+
job.SourcePath = Path.Combine(Environment.CurrentDirectory, Path.GetFileName(job.SourcePath));
41+
}
42+
43+
if (job.SourceType == SourceType.File)
44+
{
45+
job.SourcePath = Path.Combine(Environment.CurrentDirectory, Path.GetFileName(job.SourcePath));
46+
}
47+
48+
string extension;
49+
if (job.EncodingProfile.OutputFormat == OutputFormat.Mkv)
50+
{
51+
extension = ".mkv";
52+
}
53+
else
54+
{
55+
extension = ".mp4";
56+
}
57+
58+
job.OutputPath = Path.Combine(OutputVideoDirectory, jobName + extension);
59+
60+
var instance = new HandBrakeInstance();
61+
instance.Initialize(0);
62+
instance.ScanCompleted += (sender, e) =>
63+
{
64+
this.resetEvent.Set();
65+
};
66+
67+
instance.StartScan(job.SourcePath, 10);
68+
this.resetEvent.WaitOne();
69+
70+
this.resetEvent.Reset();
71+
instance.EncodeCompleted += (sender, e) =>
72+
{
73+
Assert.IsFalse(e.Error);
74+
this.resetEvent.Set();
75+
};
76+
77+
instance.StartEncode(job);
78+
this.resetEvent.WaitOne();
79+
80+
Assert.IsTrue(File.Exists(job.OutputPath));
81+
82+
var fileInfo = new FileInfo(job.OutputPath);
83+
Assert.IsTrue(fileInfo.Length > 1024);
84+
}
85+
86+
private static void EnsureOutputVideoDirectoryExists()
87+
{
88+
if (!Directory.Exists(OutputVideoDirectory))
89+
{
90+
Directory.CreateDirectory(OutputVideoDirectory);
91+
}
92+
}
93+
}
94+
}
5.13 KB
Binary file not shown.

HandBrakeInterop/HandBrakeInterop.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 11.00
33
# Visual Studio 2010
44
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HandBrakeInterop", "HandBrakeInterop\HandBrakeInterop.csproj", "{F0A61F62-2C3B-4A87-AFF4-0C4256253DA1}"
55
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HandBrakeInterop.Test", "HandBrakeInterop.Test\HandBrakeInterop.Test.csproj", "{D721824C-CAFA-40B1-83C9-83E4B1215D60}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F9A6B796-8476-4F7D-BD4E-A1B73A42E2F7}"
9+
ProjectSection(SolutionItems) = preProject
10+
HandBrakeInterop.vsmdi = HandBrakeInterop.vsmdi
11+
Local.testsettings = Local.testsettings
12+
EndProjectSection
13+
EndProject
614
Global
15+
GlobalSection(TestCaseManagementSettings) = postSolution
16+
CategoryFile = HandBrakeInterop.vsmdi
17+
EndGlobalSection
718
GlobalSection(SolutionConfigurationPlatforms) = preSolution
819
Debug|x64 = Debug|x64
920
Debug|x86 = Debug|x86
@@ -19,6 +30,11 @@ Global
1930
{F0A61F62-2C3B-4A87-AFF4-0C4256253DA1}.Release|x64.Build.0 = Release|x64
2031
{F0A61F62-2C3B-4A87-AFF4-0C4256253DA1}.Release|x86.ActiveCfg = Release|x86
2132
{F0A61F62-2C3B-4A87-AFF4-0C4256253DA1}.Release|x86.Build.0 = Release|x86
33+
{D721824C-CAFA-40B1-83C9-83E4B1215D60}.Debug|x64.ActiveCfg = Debug|Any CPU
34+
{D721824C-CAFA-40B1-83C9-83E4B1215D60}.Debug|x64.Build.0 = Debug|Any CPU
35+
{D721824C-CAFA-40B1-83C9-83E4B1215D60}.Debug|x86.ActiveCfg = Debug|Any CPU
36+
{D721824C-CAFA-40B1-83C9-83E4B1215D60}.Release|x64.ActiveCfg = Release|Any CPU
37+
{D721824C-CAFA-40B1-83C9-83E4B1215D60}.Release|x86.ActiveCfg = Release|Any CPU
2238
EndGlobalSection
2339
GlobalSection(SolutionProperties) = preSolution
2440
HideSolutionNode = FALSE
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
3+
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
4+
<RunConfiguration id="5e2e1c3b-c045-4781-88b7-8fd6b6c6596b" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
5+
</TestList>
6+
</TestLists>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<TestSettings name="Local" id="5e2e1c3b-c045-4781-88b7-8fd6b6c6596b" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
3+
<Description>These are default test settings for a local test run.</Description>
4+
<Deployment>
5+
<DeploymentItem filename="..\Lib\x64\hb.dll" />
6+
<DeploymentItem filename="HandBrakeInterop.Test\TestFiles\Videos\" />
7+
<DeploymentItem filename="HandBrakeInterop.Test\TestFiles\Jobs\" />
8+
</Deployment>
9+
<Execution hostProcessPlatform="MSIL">
10+
<TestTypeSpecific>
11+
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
12+
<AssemblyResolution>
13+
<TestDirectory useLoadContext="true" />
14+
</AssemblyResolution>
15+
</UnitTestRunConfig>
16+
</TestTypeSpecific>
17+
<AgentRule name="LocalMachineDefaultRole">
18+
</AgentRule>
19+
</Execution>
20+
</TestSettings>

Lib/x64/System.Data.SQLite.dll

1.05 MB
Binary file not shown.

Lib/x86/System.Data.SQLite.dll

884 KB
Binary file not shown.

0 commit comments

Comments
 (0)