-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+kernel32 +user32 via new ConariX [DLR version]:
~ ``` dynamic user32 = new User32(); user32.ShowWindow(0x000A0A28, 3); user32.MessageBoxA(0, "Conari in action", "Hello!", 0); ``` ``` dynamic kernel32 = new Kernel32(); kernel32.GetModuleHandleA<IntPtr>("libcurl-x64"); kernel32.GetModuleHandleW<IntPtr>((WCharPtr)ustr); ``` +Added tests
- Loading branch information
Showing
6 changed files
with
358 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2019 Denis Kuzmin < [email protected] > GitHub/3F | ||
* Copyright (c) Conari contributors: https://github.com/3F/Conari/graphs/contributors | ||
* | ||
* 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; | ||
using net.r_eg.Conari.Core; | ||
|
||
namespace net.r_eg.Conari.Accessors.WinAPI | ||
{ | ||
/// <summary> | ||
/// kernel32 via Conari engine [DLR version]: | ||
/// https://github.com/3F/Conari | ||
/// https://docs.microsoft.com/en-us/windows/win32/api/ | ||
/// </summary> | ||
public sealed class Kernel32: ConariX | ||
{ | ||
private const CallingConvention __v_conv = CallingConvention.Winapi; | ||
private const string __v_module = "kernel32"; | ||
|
||
public override CallingConvention Convention | ||
{ | ||
get => __v_conv; | ||
set => throw new NotSupportedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Initialize kernel32 via Conari engine. | ||
/// </summary> | ||
/// <param name="cfg">Custom configuration. Module cannot be overridden.</param> | ||
public Kernel32(IConfig cfg) | ||
: base(DefConf(cfg), __v_conv, null) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Initialize kernel32 via Conari engine. | ||
/// </summary> | ||
public Kernel32() | ||
: this(DefConf()) | ||
{ | ||
|
||
} | ||
|
||
private static IConfig DefConf(IConfig cfg = null) | ||
{ | ||
if(cfg == null) { | ||
cfg = new Config(); | ||
} | ||
|
||
cfg.Module = __v_module; | ||
return cfg; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2019 Denis Kuzmin < [email protected] > GitHub/3F | ||
* Copyright (c) Conari contributors: https://github.com/3F/Conari/graphs/contributors | ||
* | ||
* 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; | ||
using net.r_eg.Conari.Core; | ||
|
||
namespace net.r_eg.Conari.Accessors.WinAPI | ||
{ | ||
/// <summary> | ||
/// user32 via Conari engine [DLR version]: | ||
/// https://github.com/3F/Conari | ||
/// https://docs.microsoft.com/en-us/windows/win32/api/winuser/ | ||
/// </summary> | ||
public sealed class User32: ConariX | ||
{ | ||
private const CallingConvention __v_conv = CallingConvention.Winapi; | ||
private const string __v_module = "user32"; | ||
|
||
public override CallingConvention Convention | ||
{ | ||
get => __v_conv; | ||
set => throw new NotSupportedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Initialize user32 via Conari engine. | ||
/// </summary> | ||
/// <param name="cfg">Custom configuration. Module cannot be overridden.</param> | ||
public User32(IConfig cfg) | ||
: base(DefConf(cfg), __v_conv, null) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Initialize user32 via Conari engine. | ||
/// </summary> | ||
public User32() | ||
: this(DefConf()) | ||
{ | ||
|
||
} | ||
|
||
private static IConfig DefConf(IConfig cfg = null) | ||
{ | ||
if(cfg == null) { | ||
cfg = new Config(); | ||
} | ||
|
||
cfg.Module = __v_module; | ||
return cfg; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using net.r_eg.Conari.Accessors.WinAPI; | ||
using net.r_eg.Conari.Core; | ||
using Xunit; | ||
|
||
namespace ConariTest.Accessors.WinAPI | ||
{ | ||
public class Kernel32Test | ||
{ | ||
[Fact] | ||
public void ctorTest1() | ||
{ | ||
using(dynamic kernel32 = new Kernel32()) | ||
{ | ||
Assert.True(kernel32.Library.IsActive); | ||
Assert.NotEqual(IntPtr.Zero, kernel32.Library.handle); | ||
Assert.False(kernel32.Library.isolated); | ||
|
||
Assert.NotNull(kernel32.Library.resolved); | ||
Assert.True(kernel32.Library.resolved.value); | ||
|
||
string module = (string)kernel32.Library.module; | ||
Assert.NotNull(module); | ||
Assert.True(module.Contains("kernel32", StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ctorTest2() | ||
{ | ||
using(dynamic kernel32 = new Kernel32(new Config() | ||
{ | ||
Module = "CustomModule.dll" | ||
})) | ||
{ | ||
Assert.Equal(CallingConvention.Winapi, kernel32.Convention); | ||
|
||
Assert.True(kernel32.Library.IsActive); | ||
Assert.NotEqual(IntPtr.Zero, kernel32.Library.handle); | ||
Assert.False(kernel32.Library.isolated); | ||
|
||
Assert.NotNull(kernel32.Library.resolved); | ||
Assert.True(kernel32.Library.resolved.value); | ||
|
||
string module = (string)kernel32.Library.module; | ||
Assert.NotNull(module); | ||
Assert.True(module.Contains("kernel32", StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ctorTest3() | ||
{ | ||
using(dynamic kernel32 = new Kernel32((IConfig)null)) | ||
{ | ||
Assert.True(kernel32.Library.IsActive); | ||
Assert.NotEqual(IntPtr.Zero, kernel32.Library.handle); | ||
Assert.False(kernel32.Library.isolated); | ||
|
||
Assert.NotNull(kernel32.Library.resolved); | ||
Assert.True(kernel32.Library.resolved.value); | ||
|
||
string module = (string)kernel32.Library.module; | ||
Assert.NotNull(module); | ||
Assert.True(module.Contains("kernel32", StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void convTest1() | ||
{ | ||
Assert.Throws<NotSupportedException>(() => | ||
{ | ||
using(dynamic kernel32 = new Kernel32()) | ||
{ | ||
kernel32.Convention = CallingConvention.Cdecl; | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using net.r_eg.Conari.Accessors.WinAPI; | ||
using net.r_eg.Conari.Core; | ||
using Xunit; | ||
|
||
namespace ConariTest.Accessors.WinAPI | ||
{ | ||
public class User32Test | ||
{ | ||
[Fact] | ||
public void ctorTest1() | ||
{ | ||
using(dynamic user32 = new User32()) | ||
{ | ||
Assert.True(user32.Library.IsActive); | ||
Assert.NotEqual(IntPtr.Zero, user32.Library.handle); | ||
Assert.False(user32.Library.isolated); | ||
|
||
Assert.NotNull(user32.Library.resolved); | ||
Assert.True(user32.Library.resolved.value); | ||
|
||
string module = (string)user32.Library.module; | ||
Assert.NotNull(module); | ||
Assert.True(module.Contains("user32", StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ctorTest2() | ||
{ | ||
using(dynamic user32 = new User32(new Config() | ||
{ | ||
Module = "CustomModule.dll" | ||
})) | ||
{ | ||
Assert.Equal(CallingConvention.Winapi, user32.Convention); | ||
|
||
Assert.True(user32.Library.IsActive); | ||
Assert.NotEqual(IntPtr.Zero, user32.Library.handle); | ||
Assert.False(user32.Library.isolated); | ||
|
||
Assert.NotNull(user32.Library.resolved); | ||
Assert.True(user32.Library.resolved.value); | ||
|
||
string module = (string)user32.Library.module; | ||
Assert.NotNull(module); | ||
Assert.True(module.Contains("user32", StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ctorTest3() | ||
{ | ||
using(dynamic user32 = new User32((IConfig)null)) | ||
{ | ||
Assert.True(user32.Library.IsActive); | ||
Assert.NotEqual(IntPtr.Zero, user32.Library.handle); | ||
Assert.False(user32.Library.isolated); | ||
|
||
Assert.NotNull(user32.Library.resolved); | ||
Assert.True(user32.Library.resolved.value); | ||
|
||
string module = (string)user32.Library.module; | ||
Assert.NotNull(module); | ||
Assert.True(module.Contains("user32", StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void convTest1() | ||
{ | ||
Assert.Throws<NotSupportedException>(() => | ||
{ | ||
using(dynamic user32 = new User32()) | ||
{ | ||
user32.Convention = CallingConvention.Cdecl; | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters