Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2926 from comintern/next
Minor Fake\Stub refactors, implement a handful of system impacting functions.
- Loading branch information
Showing
29 changed files
with
847 additions
and
55 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
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,56 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Rubberduck.UI; | ||
|
||
namespace Rubberduck.UnitTesting | ||
{ | ||
// TODO: This is currently broken. The runtime throws a "bad dll calling convention error when it returns", which leads me to | ||
// believe that it is trying to cast the return value and it isn't marshalling correctly. | ||
internal class CurDir : FakeBase | ||
{ | ||
private static readonly IntPtr ProcessAddressString = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcCurrentDir"); | ||
private static readonly IntPtr ProcessAddressVariant = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcCurrentDirBstr"); | ||
|
||
public CurDir() | ||
{ | ||
InjectDelegate(new CurDirStringDelegate(CurDirStringCallback), ProcessAddressString); | ||
InjectDelegate(new CurDirVariantDelegate(CurDirStringCallback), ProcessAddressVariant); | ||
} | ||
|
||
public override bool PassThrough | ||
{ | ||
get { return false; } | ||
// ReSharper disable once ValueParameterNotUsed | ||
set | ||
{ | ||
Verifier.SuppressAsserts(); | ||
AssertHandler.OnAssertInconclusive(string.Format(RubberduckUI.Assert_InvalidFakePassThrough, "CurDir")); | ||
} | ||
} | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] | ||
private delegate string CurDirStringDelegate(IntPtr drive); | ||
|
||
public string CurDirStringCallback(IntPtr drive) | ||
{ | ||
TrackInvocation(drive); | ||
return ReturnValue?.ToString() ?? string.Empty; | ||
} | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] | ||
private delegate string CurDirVariantDelegate(IntPtr drive); | ||
|
||
public object CurDirVariantCallback(IntPtr drive) | ||
{ | ||
TrackInvocation(drive); | ||
return ReturnValue?.ToString() ?? string.Empty; | ||
} | ||
|
||
private void TrackInvocation(IntPtr drive) | ||
{ | ||
OnCallBack(); | ||
|
||
TrackUsage("drive", drive); | ||
} | ||
} | ||
} |
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,43 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Rubberduck.UnitTesting | ||
{ | ||
internal class DoEvents : FakeBase | ||
{ | ||
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcDoEvents"); | ||
|
||
public DoEvents() | ||
{ | ||
InjectDelegate(new DoEventsDelegate(DoEventsCallback), ProcessAddress); | ||
} | ||
|
||
private readonly ValueTypeConverter<int> _converter = new ValueTypeConverter<int>(); | ||
public override void Returns(object value, int invocation = FakesProvider.AllInvocations) | ||
{ | ||
_converter.Value = value; | ||
base.Returns((int)_converter.Value, invocation); | ||
} | ||
|
||
[DllImport(TargetLibrary, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.I4)] | ||
private static extern int rtcDoEvents(); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.I4)] | ||
private delegate int DoEventsDelegate(); | ||
|
||
public int DoEventsCallback() | ||
{ | ||
OnCallBack(true); | ||
|
||
if (PassThrough) | ||
{ | ||
return rtcDoEvents(); | ||
} | ||
return (int)(ReturnValue ?? 0); | ||
} | ||
} | ||
|
||
|
||
} |
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,56 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Rubberduck.UI; | ||
|
||
namespace Rubberduck.UnitTesting | ||
{ | ||
internal class Environ : FakeBase | ||
{ | ||
private static readonly IntPtr ProcessAddressString = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcEnvironBstr"); | ||
private static readonly IntPtr ProcessAddressVariant = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcEnvironVar"); | ||
|
||
public Environ() | ||
{ | ||
InjectDelegate(new EnvironStringDelegate(EnvironStringCallback), ProcessAddressString); | ||
InjectDelegate(new EnvironVariantDelegate(EnvironStringCallback), ProcessAddressVariant); | ||
} | ||
|
||
public override bool PassThrough | ||
{ | ||
get { return false; } | ||
// ReSharper disable once ValueParameterNotUsed | ||
set | ||
{ | ||
Verifier.SuppressAsserts(); | ||
AssertHandler.OnAssertInconclusive(string.Format(RubberduckUI.Assert_InvalidFakePassThrough, "Environ")); | ||
} | ||
} | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.BStr)] | ||
private delegate string EnvironStringDelegate(IntPtr envstring, IntPtr number); | ||
|
||
public string EnvironStringCallback(IntPtr envstring, IntPtr number) | ||
{ | ||
TrackInvocation(envstring, number); | ||
return ReturnValue?.ToString() ?? string.Empty; | ||
} | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] | ||
private delegate string EnvironVariantDelegate(IntPtr envstring, IntPtr number); | ||
|
||
public object EnvironVariantCallback(IntPtr envstring, IntPtr number) | ||
{ | ||
TrackInvocation(envstring, number); | ||
return ReturnValue?.ToString() ?? string.Empty; | ||
} | ||
|
||
private void TrackInvocation(IntPtr envstring, IntPtr number) | ||
{ | ||
OnCallBack(); | ||
|
||
TrackUsage("envstring", envstring); | ||
TrackUsage("number", number); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,47 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Rubberduck.Parsing.ComReflection; | ||
using Rubberduck.Parsing.Grammar; | ||
|
||
namespace Rubberduck.UnitTesting | ||
{ | ||
internal class Shell : FakeBase | ||
{ | ||
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcShell"); | ||
|
||
public Shell() | ||
{ | ||
InjectDelegate(new ShellDelegate(ShellCallback), ProcessAddress); | ||
} | ||
|
||
private readonly ValueTypeConverter<double> _converter = new ValueTypeConverter<double>(); | ||
public override void Returns(object value, int invocation = FakesProvider.AllInvocations) | ||
{ | ||
_converter.Value = value; | ||
base.Returns((double)_converter.Value, invocation); | ||
} | ||
|
||
[DllImport(TargetLibrary, SetLastError = true)] | ||
private static extern double rtcShell(IntPtr pathname, short windowstyle); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.R8)] | ||
private delegate double ShellDelegate(IntPtr pathname, short windowstyle); | ||
|
||
public double ShellCallback(IntPtr pathname, short windowstyle) | ||
{ | ||
OnCallBack(true); | ||
|
||
var path = Marshal.PtrToStringBSTR(pathname); | ||
|
||
TrackUsage("pathname", pathname); | ||
TrackUsage("windowstyle", windowstyle, Tokens.Integer); | ||
|
||
if (PassThrough) | ||
{ | ||
return Convert.ToDouble(rtcShell(pathname, windowstyle)); | ||
} | ||
return Convert.ToDouble(ReturnValue ?? 0); | ||
} | ||
} | ||
} |
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,41 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Rubberduck.UnitTesting | ||
{ | ||
internal class Timer : FakeBase | ||
{ | ||
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcGetTimer"); | ||
|
||
public Timer() | ||
{ | ||
InjectDelegate(new TimerDelegate(TimerCallback), ProcessAddress); | ||
} | ||
|
||
private readonly ValueTypeConverter<float> _converter = new ValueTypeConverter<float>(); | ||
public override void Returns(object value, int invocation = FakesProvider.AllInvocations) | ||
{ | ||
_converter.Value = value; | ||
base.Returns((float)_converter.Value, invocation); | ||
} | ||
|
||
[DllImport(TargetLibrary, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.R4)] | ||
private static extern float rtcGetTimer(); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.R4)] | ||
private delegate float TimerDelegate(); | ||
|
||
public float TimerCallback() | ||
{ | ||
OnCallBack(true); | ||
|
||
if (PassThrough) | ||
{ | ||
return rtcGetTimer(); | ||
} | ||
return Convert.ToSingle(ReturnValue ?? 0); | ||
} | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.