Skip to content

Commit

Permalink
added test and example project
Browse files Browse the repository at this point in the history
  • Loading branch information
tebjan committed May 3, 2012
1 parent e33df91 commit 490e599
Show file tree
Hide file tree
Showing 16 changed files with 15,038 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ samples/csharp/bin/*
csharp/obj/*
csharp/bin/*
libs/libpd.*
libs/libpdnative.*
libs/libpdnative.*
csharptests/bin
csharptests/obj
csharptests/PartCover/coverage.xml
79 changes: 79 additions & 0 deletions csharptests/LibPDBindingTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>LibPDBindingTest</RootNamespace>
<AssemblyName>LibPDBindingTest</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<SignAssembly>False</SignAssembly>
<DelaySign>False</DelaySign>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<RunCodeAnalysis>False</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<ItemGroup>
<Reference Include="NUnit.Framework">
<HintPath>$(SharpDevelopBinPath)\Tools\NUnit\NUnit.Framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="LibPDTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\csharp\LibPDBinding.csproj">
<Project>0D2EF933-6094-4DE1-9D63-9B43786C06AE</Project>
<Name>LibPDBinding</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="test_csharp.pd">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
97 changes: 97 additions & 0 deletions csharptests/LibPDTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*
*
* Created by SharpDevelop.
* User: Tebjan Halm
* Date: 03.05.2012
* Time: 16:54
*
*
*/

using System;
using NUnit.Framework;

using LibPDBinding;

namespace LibPDBindingTest
{
[TestFixture]
public class LibPDTests
{
private static int patch;

[SetUp]
public static void loadPatch()
{
LibPD.OpenAudio(2, 3, 44100);
//LibPD.Subscribe("eggs");
patch = LibPD.OpenPatch(@"..\..\test_csharp.pd");
LibPD.ComputeAudio(true);
LibPD.Print += new LibPDPrint(LibPD_Print);
}

private static string Msg;
static void LibPD_Print(string text)
{
Msg = text;
}

[TearDown]
public static void closePatch()
{
LibPD.Release();
}

[Test]
public virtual void testAudio()
{
float[] @in = new float[256];
float[] @out = new float[768];
for (int i = 0; i < 256; i++)
{
@in[i] = i;
}
int err = LibPD.Process(2, @in, @out);
Assert.AreEqual(0, err);
for (int i = 0; i < 128; i++)
{
Assert.AreEqual(2 * i, @out[3 * i], 0.0001);
Assert.AreEqual(-6 * i, @out[3 * i + 1], 0.0001);
Assert.AreEqual(Math.Cos(2 * Math.PI * 440 / 44100 * i), @out[3 * i + 2], 0.0001);
}
for (int i = 384; i < 768; i++)
{
Assert.AreEqual(0, @out[i], 0);
}
}

[Test]
public virtual void testBlockSize()
{
Assert.AreEqual(64, LibPD.BlockSize);
}

[Test]
public virtual void testDollarZero()
{
Assert.AreEqual(1004, patch);
}

[Test]
public virtual void testPrint()
{
var msg = "";
LibPD.Print += delegate(string text) { msg = text; };
LibPD.SendFloat("foo", 0);
Assert.AreEqual("0", msg);
LibPD.SendFloat("foo", 42);
Assert.AreEqual("42", msg);
LibPD.SendSymbol("foo", "don't panic");
Assert.AreEqual("don't panic", msg);
}

}
}
55 changes: 55 additions & 0 deletions csharptests/test_csharp.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#N canvas 128 522 535 471 10;
#X obj 18 16 r spam;
#X obj 18 37 s eggs;
#X obj 19 72 notein;
#X obj 16 96 noteout;
#X obj 73 75 ctlin;
#X obj 71 95 ctlout;
#X obj 122 75 pgmin;
#X obj 119 96 pgmout;
#X obj 167 34 bendin;
#X obj 167 96 bendout;
#X obj 222 76 touchin;
#X obj 218 96 touchout;
#X obj 278 75 polytouchin;
#X obj 275 95 polytouchout;
#X obj 91 18 r foo;
#X obj 91 39 print;
#X obj 160 57 - 8192;
#N canvas 0 22 450 300 (subpatch) 0;
#X array array1 128 float 2;
#X coords 0 1 127 -1 200 140 1;
#X restore 16 153 graph;
#X obj 245 172 adc~;
#X obj 260 201 *~ -3;
#X obj 247 231 dac~ 1 2 3;
#X obj 304 170 osc~ 440;
#X obj 301 328 s foo;
#X msg 402 216 hello;
#X obj 451 161 metro 1000;
#X obj 464 102 loadbang;
#X connect 0 0 1 0;
#X connect 2 0 3 0;
#X connect 2 1 3 1;
#X connect 2 2 3 2;
#X connect 4 0 5 0;
#X connect 4 1 5 1;
#X connect 4 2 5 2;
#X connect 6 0 7 0;
#X connect 6 1 7 1;
#X connect 8 0 16 0;
#X connect 8 1 9 1;
#X connect 10 0 11 0;
#X connect 10 1 11 1;
#X connect 12 0 13 0;
#X connect 12 1 13 1;
#X connect 12 2 13 2;
#X connect 14 0 15 0;
#X connect 16 0 9 0;
#X connect 18 0 19 0;
#X connect 18 0 20 0;
#X connect 19 0 20 1;
#X connect 21 0 20 2;
#X connect 23 0 22 0;
#X connect 24 0 23 0;
#X connect 25 0 24 0;
36 changes: 28 additions & 8 deletions libpd_win.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# SharpDevelop 4.2.0.8649-Beta 2
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibPDBinding", "csharp\LibPDBinding.csproj", "0D2EF933-6094-4DE1-9D63-9B43786C06AE"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibPDBindingTest", "csharptests\LibPDBindingTest.csproj", "{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibPDExample", "samples\csharp\LibPDExample.csproj", "{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Expand All @@ -12,13 +16,29 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|x86.Build.0 = Debug|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|x86.ActiveCfg = Debug|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|Any CPU.Build.0 = Debug|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|Any CPU.ActiveCfg = Debug|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|x86.Build.0 = Release|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|x86.ActiveCfg = Release|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|Any CPU.Build.0 = Release|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|Any CPU.ActiveCfg = Release|x86
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|x86.Build.0 = Debug|Any CPU
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|x86.ActiveCfg = Debug|Any CPU
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|Any CPU.Build.0 = Debug|Any CPU
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Debug|Any CPU.ActiveCfg = Debug|Any CPU
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|x86.Build.0 = Release|Any CPU
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|x86.ActiveCfg = Release|Any CPU
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|Any CPU.Build.0 = Release|Any CPU
0D2EF933-6094-4DE1-9D63-9B43786C06AE.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Debug|x86.Build.0 = Debug|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Debug|x86.ActiveCfg = Debug|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Release|x86.Build.0 = Release|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Release|x86.ActiveCfg = Release|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Release|Any CPU.Build.0 = Release|Any CPU
{DC510CBA-CD9F-4C7A-BD04-C37AE01FC90B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Debug|x86.Build.0 = Debug|x86
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Debug|x86.ActiveCfg = Debug|x86
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Debug|Any CPU.Build.0 = Debug|x86
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Debug|Any CPU.ActiveCfg = Debug|x86
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Release|x86.Build.0 = Release|x86
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Release|x86.ActiveCfg = Release|x86
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Release|Any CPU.Build.0 = Release|x86
{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}.Release|Any CPU.ActiveCfg = Release|x86
EndGlobalSection
EndGlobal
70 changes: 70 additions & 0 deletions samples/csharp/LibPDExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{60EA10B2-F0F4-4948-B6BB-9DCC803D6F68}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>LibPDBinding</RootNamespace>
<AssemblyName>LibPDExample</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="NAudio">
<HintPath>dependencies\NAudio.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="LibPDWaveProvider.cs" />
<Compile Include="MainForm.cs" />
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\csharp\LibPDBinding.csproj">
<Project>0D2EF933-6094-4DE1-9D63-9B43786C06AE</Project>
<Name>LibPDBinding</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
Loading

0 comments on commit 490e599

Please sign in to comment.