diff --git a/.gitignore b/.gitignore index d776c3a..bb97bb7 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,9 @@ /LibMpcApp/LibMpcApp.xproj.user /LibMpcApp/project.lock.json -/LibMpc.sln.DotSettings.user +/LibMpcTest/bin +/LibMpcTest/obj +/LibMpcTest/LibMpcTest.xproj.user +/LibMpcTest/project.lock.json + +/LibMpc.sln.DotSettings.user \ No newline at end of file diff --git a/LibMpc.sln b/LibMpc.sln index 6d8fd00..6379c04 100644 --- a/LibMpc.sln +++ b/LibMpc.sln @@ -7,6 +7,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpc", "LibMpc\LibMpc.xpr EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpcApp", "LibMpcApp\LibMpcApp.xproj", "{FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpcTest", "LibMpcTest\LibMpcTest.xproj", "{69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Release|Any CPU.Build.0 = Release|Any CPU + {69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LibMpcTest/LibMpcTest.cs b/LibMpcTest/LibMpcTest.cs new file mode 100644 index 0000000..cbf1d5d --- /dev/null +++ b/LibMpcTest/LibMpcTest.cs @@ -0,0 +1,40 @@ +using LibMpc; +using System; +using System.IO; +using System.Net; +using System.Reflection; +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +namespace LibMpcTest +{ + public class LibMpcTest : IClassFixture, IDisposable + { + private readonly ITestOutputHelper _output; + private readonly Mpc _mpc; + + public LibMpcTest(ITestOutputHelper output) + { + _output = output; + _mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600)); + + var connected = _mpc.ConnectAsync().GetAwaiter().GetResult(); + if (connected) + { + _output.WriteLine("Connected to MPD."); + } + else + { + _output.WriteLine("Could not connect to MPD."); + } + + _mpc.SendAsync(new Commands.Database.Update()).GetAwaiter().GetResult(); + } + + public void Dispose() + { + _mpc?.DisconnectAsync().GetAwaiter().GetResult(); + } + } +} diff --git a/LibMpcTest/LibMpcTest.xproj b/LibMpcTest/LibMpcTest.xproj new file mode 100644 index 0000000..14fbe0b --- /dev/null +++ b/LibMpcTest/LibMpcTest.xproj @@ -0,0 +1,22 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 69f1d68f-9cd5-4ea6-9b47-2a7a9bf8ced9 + LibMpcTest + .\obj + .\bin\ + v4.5.2 + + + 2.0 + + + + + + \ No newline at end of file diff --git a/LibMpcTest/MpdConf.cs b/LibMpcTest/MpdConf.cs new file mode 100644 index 0000000..b6269c9 --- /dev/null +++ b/LibMpcTest/MpdConf.cs @@ -0,0 +1,40 @@ +using System.IO; +using System.Text; + +namespace LibMpcTest +{ + public class MpdConf + { + private const string MPD_CONF_FILE = "mpd.conf"; + private const string MPD_LOG_FILE = "mpd_log.txt"; + private const string MPD_DB_FILE = "mpd.db"; + + public static void Create(string rootDirectory) + { + File.Create(Path.Combine(rootDirectory, MPD_LOG_FILE)).Dispose(); + + CreateConfFile(rootDirectory); + } + + private static void CreateConfFile(string rootDirectory) + { + var builder = new StringBuilder(); + + builder.AppendLine($"log_file \"{Path.Combine(rootDirectory, MPD_LOG_FILE).Replace("\\", "\\\\")}\""); + builder.AppendLine($"db_file \"{Path.Combine(rootDirectory, MPD_DB_FILE).Replace("\\", "\\\\")}\""); + builder.AppendLine($"bind_to_address \"any\""); + builder.AppendLine($"music_directory \"{Path.Combine(rootDirectory, "Music").Replace("\\", "\\\\")}\""); + builder.AppendLine($"playlist_directory \"{Path.Combine(rootDirectory, "Playlists").Replace("\\", "\\\\")}\""); + builder.AppendLine($"port \"6600\""); + builder.AppendLine($"mixer_type \"software\""); + + var mpdConfContent = builder.ToString(); + + using (var file = File.CreateText(Path.Combine(rootDirectory, MPD_CONF_FILE))) + { + file.Write(mpdConfContent); + file.Flush(); + } + } + } +} \ No newline at end of file diff --git a/LibMpcTest/MpdServerTest.cs b/LibMpcTest/MpdServerTest.cs new file mode 100644 index 0000000..fb54412 --- /dev/null +++ b/LibMpcTest/MpdServerTest.cs @@ -0,0 +1,46 @@ +using System; +using System.Diagnostics; +using System.IO; + +namespace LibMpcTest +{ + internal class MpdServerTest : IDisposable + { + private Process _process; + + public MpdServerTest() + { + var serverPath = Path.Combine(AppContext.BaseDirectory, "Server"); + + MpdConf.Create(serverPath); + + var mpdExePath = Path.Combine(serverPath, "mpd.exe"); + var mpdConfPath = Path.Combine(serverPath, "mpd.conf"); + + _process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = mpdExePath, + WorkingDirectory = serverPath, + Arguments = string.Join(" ", mpdConfPath, "-v"), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true, + } + }; + + _process.Start(); + var logOutput = _process.StandardOutput.ReadToEnd(); + var logError = _process.StandardError.ReadToEnd(); + } + + public void Dispose() + { + _process?.Kill(); + _process?.Dispose(); + _process = null; + } + } +} \ No newline at end of file diff --git a/LibMpcTest/Properties/AssemblyInfo.cs b/LibMpcTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0accc6b --- /dev/null +++ b/LibMpcTest/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +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: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("LibMpcTest")] +[assembly: AssemblyTrademark("")] + +// 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("69f1d68f-9cd5-4ea6-9b47-2a7a9bf8ced9")] diff --git a/LibMpcTest/Server/Music/A long name directory with some spaces/Ghost-Sounds.mp3 b/LibMpcTest/Server/Music/A long name directory with some spaces/Ghost-Sounds.mp3 new file mode 100644 index 0000000..ae0a048 Binary files /dev/null and b/LibMpcTest/Server/Music/A long name directory with some spaces/Ghost-Sounds.mp3 differ diff --git a/LibMpcTest/Server/Music/A long name directory with some spaces/pouring-water-into-mug-of-coffee.mp3 b/LibMpcTest/Server/Music/A long name directory with some spaces/pouring-water-into-mug-of-coffee.mp3 new file mode 100644 index 0000000..501b965 Binary files /dev/null and b/LibMpcTest/Server/Music/A long name directory with some spaces/pouring-water-into-mug-of-coffee.mp3 differ diff --git a/LibMpcTest/Server/Music/A long name directory with some spaces/short-trouser-pants-zip-closing.mp3 b/LibMpcTest/Server/Music/A long name directory with some spaces/short-trouser-pants-zip-closing.mp3 new file mode 100644 index 0000000..22c4290 Binary files /dev/null and b/LibMpcTest/Server/Music/A long name directory with some spaces/short-trouser-pants-zip-closing.mp3 differ diff --git a/LibMpcTest/Server/Music/A long name directory with some spaces/starting-engine-Ford-Mondeo-Mk-3-diesel.mp3 b/LibMpcTest/Server/Music/A long name directory with some spaces/starting-engine-Ford-Mondeo-Mk-3-diesel.mp3 new file mode 100644 index 0000000..d287fb0 Binary files /dev/null and b/LibMpcTest/Server/Music/A long name directory with some spaces/starting-engine-Ford-Mondeo-Mk-3-diesel.mp3 differ diff --git a/LibMpcTest/Server/Music/Directory With Spaces/central-locking-Ford-Mondeo-Mk-3.mp3 b/LibMpcTest/Server/Music/Directory With Spaces/central-locking-Ford-Mondeo-Mk-3.mp3 new file mode 100644 index 0000000..3150a26 Binary files /dev/null and b/LibMpcTest/Server/Music/Directory With Spaces/central-locking-Ford-Mondeo-Mk-3.mp3 differ diff --git a/LibMpcTest/Server/Music/Directory With Spaces/coin-spin-light.mp3 b/LibMpcTest/Server/Music/Directory With Spaces/coin-spin-light.mp3 new file mode 100644 index 0000000..24e4620 Binary files /dev/null and b/LibMpcTest/Server/Music/Directory With Spaces/coin-spin-light.mp3 differ diff --git a/LibMpcTest/Server/Music/Directory With Spaces/finger-snap-click.mp3 b/LibMpcTest/Server/Music/Directory With Spaces/finger-snap-click.mp3 new file mode 100644 index 0000000..849b21f Binary files /dev/null and b/LibMpcTest/Server/Music/Directory With Spaces/finger-snap-click.mp3 differ diff --git a/LibMpcTest/Server/Music/Directory/2-Kids-Laughing.mp3 b/LibMpcTest/Server/Music/Directory/2-Kids-Laughing.mp3 new file mode 100644 index 0000000..bec3f83 Binary files /dev/null and b/LibMpcTest/Server/Music/Directory/2-Kids-Laughing.mp3 differ diff --git a/LibMpcTest/Server/Music/Directory/ambient-noise-server-room.mp3 b/LibMpcTest/Server/Music/Directory/ambient-noise-server-room.mp3 new file mode 100644 index 0000000..5d74a10 Binary files /dev/null and b/LibMpcTest/Server/Music/Directory/ambient-noise-server-room.mp3 differ diff --git a/LibMpcTest/Server/Music/_My Directory/gas-fire-lighting.mp3 b/LibMpcTest/Server/Music/_My Directory/gas-fire-lighting.mp3 new file mode 100644 index 0000000..d37ac0b Binary files /dev/null and b/LibMpcTest/Server/Music/_My Directory/gas-fire-lighting.mp3 differ diff --git a/LibMpcTest/Server/Music/teaspoon-stirring-mug-of-coffee.mp3 b/LibMpcTest/Server/Music/teaspoon-stirring-mug-of-coffee.mp3 new file mode 100644 index 0000000..9c3abb0 Binary files /dev/null and b/LibMpcTest/Server/Music/teaspoon-stirring-mug-of-coffee.mp3 differ diff --git a/LibMpcTest/Server/Music/whistle-kettle-boiling.mp3 b/LibMpcTest/Server/Music/whistle-kettle-boiling.mp3 new file mode 100644 index 0000000..339eb99 Binary files /dev/null and b/LibMpcTest/Server/Music/whistle-kettle-boiling.mp3 differ diff --git a/LibMpcTest/Server/Music/wine-glass-double-chink-clink-cheers.mp3 b/LibMpcTest/Server/Music/wine-glass-double-chink-clink-cheers.mp3 new file mode 100644 index 0000000..dc0ed1c Binary files /dev/null and b/LibMpcTest/Server/Music/wine-glass-double-chink-clink-cheers.mp3 differ diff --git a/LibMpcTest/Server/OpenAL32.dll b/LibMpcTest/Server/OpenAL32.dll new file mode 100644 index 0000000..b6b3f86 Binary files /dev/null and b/LibMpcTest/Server/OpenAL32.dll differ diff --git a/LibMpcTest/Server/Playlists/dummy b/LibMpcTest/Server/Playlists/dummy new file mode 100644 index 0000000..e69de29 diff --git a/LibMpcTest/Server/mpd.db b/LibMpcTest/Server/mpd.db new file mode 100644 index 0000000..386bd2d --- /dev/null +++ b/LibMpcTest/Server/mpd.db @@ -0,0 +1,68 @@ +info_begin +format: 1 +mpd_version: 0.17.4 +fs_charset: cp1252 +tag: Artist +tag: ArtistSort +tag: Album +tag: AlbumArtist +tag: AlbumArtistSort +tag: Title +tag: Track +tag: Name +tag: Genre +tag: Date +tag: Composer +tag: Performer +tag: Disc +tag: MUSICBRAINZ_ARTISTID +tag: MUSICBRAINZ_ALBUMID +tag: MUSICBRAINZ_ALBUMARTISTID +tag: MUSICBRAINZ_TRACKID +info_end +directory: Dir1 +mtime: 1481580300 +begin: Dir1 +song_begin: piano2-Audacity1.2.5.mp3 +Time: 6 +Artist: piano2 +Genre: Blues +mtime: 1481120569 +song_end +end: Dir1 +directory: Dir2 +mtime: 1481580300 +begin: Dir2 +song_begin: c304-2.wav +Time: 49 +mtime: 1481109933 +song_end +song_begin: 32.mp3 +Time: 32 +Artist: organ +Album: Test 2 +Date: 1995 +Genre: Rock +mtime: 1481123918 +song_end +end: Dir2 +directory: Dir3 +mtime: 1481580300 +begin: Dir3 +song_begin: piano2-Audacity1.2.5 (1).mp3 +Time: 6 +Artist: piano2 +Genre: Blues +mtime: 1481120554 +song_end +end: Dir3 +song_begin: organfinale.mp3 +Time: 13 +Artist: organ +mtime: 1481120544 +song_end +song_begin: piano2-CoolEdit.mp3 +Time: 6 +Artist: piano2 +mtime: 1481120536 +song_end diff --git a/LibMpcTest/Server/mpd.exe b/LibMpcTest/Server/mpd.exe new file mode 100644 index 0000000..ef013f9 Binary files /dev/null and b/LibMpcTest/Server/mpd.exe differ diff --git a/LibMpcTest/Server/openal-info.exe b/LibMpcTest/Server/openal-info.exe new file mode 100644 index 0000000..0a7b9d8 Binary files /dev/null and b/LibMpcTest/Server/openal-info.exe differ diff --git a/LibMpcTest/Server/winmm-info.exe b/LibMpcTest/Server/winmm-info.exe new file mode 100644 index 0000000..6bdd762 Binary files /dev/null and b/LibMpcTest/Server/winmm-info.exe differ diff --git a/LibMpcTest/project.json b/LibMpcTest/project.json new file mode 100644 index 0000000..bae6daf --- /dev/null +++ b/LibMpcTest/project.json @@ -0,0 +1,32 @@ +{ + "buildOptions": + { + "copyToOutput": "Server\\" + }, + + "version": "1.0.0-*", + + "testRunner": "xunit", + + "dependencies": + { + "xunit": "2.2.0-beta2-build3300", + "LibMpc": "1.0.0-*", + "dotnet-test-xunit": "2.2.0-preview2-build1029" + }, + + "frameworks": + { + "netcoreapp1.0": + { + "dependencies": + { + "Microsoft.NETCore.App": + { + "type": "platform", + "version": "1.0.0" + } + } + } + } +}