* Claunia.IO/Claunia.IO.csproj:

* Claunia.IO/Tests/Interop.Apple.cs:
	* Claunia.IO/Interop/Apple/Interop.Apple.uname.cs:
	  Added code for uname() in OS X

	* Claunia.IO/Tests/Interop.DetectOS.cs:
	  Only compile tests in DEBUG
This commit is contained in:
2015-02-12 06:28:54 +00:00
parent 1cff36aec7
commit 4466982328
5 changed files with 100 additions and 4 deletions

View File

@@ -1,3 +1,13 @@
2015-02-12 Natalia Portillo <claunia@claunia.com>
* Claunia.IO.csproj:
* Tests/Interop.Apple.cs:
* Interop/Apple/Interop.Apple.uname.cs:
Added code for uname() in OS X
* Tests/Interop.DetectOS.cs:
Only compile tests in DEBUG
2015-02-12 Natalia Portillo <claunia@claunia.com>
* Claunia.IO.csproj:

View File

@@ -48,6 +48,7 @@
<Compile Include="Interop\Interop.DetectOS.cs" />
<Compile Include="Interop\Interop.PlatformID.cs" />
<Compile Include="Tests\Interop.DetectOS.cs" />
<Compile Include="Interop\Apple\Interop.Apple.uname.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View File

@@ -0,0 +1,70 @@
//
// Interop.Apple.uname.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// Copyright (c) 2015 © Claunia.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
internal static partial class Interop
{
internal static partial class Apple
{
/// <summary>
/// OS X uname structure
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal struct utsname
{
/// <summary>
/// System name
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string sysname;
/// <summary>
/// Node name
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string nodename;
/// <summary>
/// Release level
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string release;
/// <summary>
/// Version level
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string version;
/// <summary>
/// Hardware level
/// </summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string machine;
}
[DllImport("libc", SetLastError = true)]
internal static extern int uname(out utsname name);
}
}

View File

@@ -36,7 +36,6 @@ namespace Tests
[Test]
public void TestStat()
{
// Take care, Mono returns UNIX for Mac OS X
if (Interop.DetectOS.GetRealPlatformID() == Interop.PlatformID.MacOSX || Interop.DetectOS.GetRealPlatformID() == Interop.PlatformID.iOS)
{
string testFile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/.localized";
@@ -79,7 +78,6 @@ namespace Tests
[Test]
public void TestStat64()
{
// Take care, Mono returns UNIX for Mac OS X
if (Interop.DetectOS.GetRealPlatformID() == Interop.PlatformID.MacOSX || Interop.DetectOS.GetRealPlatformID() == Interop.PlatformID.iOS)
{
string testFile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/.localized";
@@ -120,6 +118,23 @@ namespace Tests
#pragma warning restore 618
}
}
[Test]
public void TestUname()
{
if (Interop.DetectOS.GetRealPlatformID() == Interop.PlatformID.MacOSX || Interop.DetectOS.GetRealPlatformID() == Interop.PlatformID.iOS)
{
Interop.Apple.utsname utsName;
int errno = Interop.Apple.uname(out utsName);
Assert.AreEqual(0, errno, "uname returned error {0}", (Interop.Apple.Errors)Marshal.GetLastWin32Error());
Assert.AreEqual("Darwin", utsName.sysname);
Assert.AreEqual("zeus.claunia.com", utsName.nodename);
Assert.AreEqual("14.0.0", utsName.release);
Assert.AreEqual("Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64", utsName.version);
Assert.AreEqual("x86_64", utsName.machine);
}
}
}
}
#endif

View File

@@ -23,7 +23,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
#if DEBUG
using NUnit.Framework;
namespace Tests
@@ -40,4 +40,4 @@ namespace Tests
}
}
}
#endif