Skip to content

Commit c1bd830

Browse files
committed
Update the stubs & fakes to use VBERuntime instead of directly implementing the VBE functions & use the correct DLL name.
1 parent c396b40 commit c1bd830

File tree

18 files changed

+70
-111
lines changed

18 files changed

+70
-111
lines changed

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/CurDir.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace Rubberduck.UnitTesting.Fakes
66
{
77
internal class CurDir : FakeBase
88
{
9-
private static readonly IntPtr ProcessAddressVariant = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcCurrentDir");
10-
private static readonly IntPtr ProcessAddressString = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcCurrentDirBstr");
11-
129
public CurDir()
1310
{
14-
InjectDelegate(new CurDirStringDelegate(CurDirStringCallback), ProcessAddressString);
15-
InjectDelegate(new CurDirVariantDelegate(CurDirVariantCallback), ProcessAddressVariant);
11+
var processAddressVariant = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcCurrentDir");
12+
var processAddressString = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcCurrentDirBstr");
13+
14+
InjectDelegate(new CurDirStringDelegate(CurDirStringCallback), processAddressString);
15+
InjectDelegate(new CurDirVariantDelegate(CurDirVariantCallback), processAddressVariant);
1616
}
1717

1818
public override bool PassThrough

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Date.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ namespace Rubberduck.UnitTesting.Fakes
55
{
66
internal class Date : FakeBase
77
{
8-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcGetDateVar");
9-
108
public Date()
119
{
12-
InjectDelegate(new DateDelegate(DateCallback), ProcessAddress);
13-
}
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcGetDateVar");
1411

15-
[DllImport(TargetLibrary, SetLastError = true)]
16-
private static extern void rtcGetDateVar(out object retVal);
12+
InjectDelegate(new DateDelegate(DateCallback), processAddress);
13+
}
1714

1815
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
1916
private delegate void DateDelegate(IntPtr retVal);
@@ -28,7 +25,7 @@ public void DateCallback(IntPtr retVal)
2825
if (PassThrough)
2926
{
3027
object result;
31-
rtcGetDateVar(out result);
28+
VbeProvider.VbeRuntime.GetDateVar(out result);
3229
Marshal.GetNativeVariantForObject(result, retVal);
3330
return;
3431
}

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/DoEvents.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using Rubberduck.UnitTesting.ComClientHelpers;
2-
using System;
32
using System.Runtime.InteropServices;
43

54
namespace Rubberduck.UnitTesting.Fakes
65
{
76
internal class DoEvents : FakeBase
87
{
9-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcDoEvents");
10-
118
public DoEvents()
129
{
13-
InjectDelegate(new DoEventsDelegate(DoEventsCallback), ProcessAddress);
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcDoEvents");
11+
12+
InjectDelegate(new DoEventsDelegate(DoEventsCallback), processAddress);
1413
}
1514

1615
private readonly ValueTypeConverter<int> _converter = new ValueTypeConverter<int>();
@@ -20,10 +19,6 @@ public override void Returns(object value, int invocation = FakesProvider.AllInv
2019
base.Returns((int)_converter.Value, invocation);
2120
}
2221

23-
[DllImport(TargetLibrary, SetLastError = true)]
24-
[return: MarshalAs(UnmanagedType.I4)]
25-
private static extern int rtcDoEvents();
26-
2722
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
2823
[return: MarshalAs(UnmanagedType.I4)]
2924
private delegate int DoEventsDelegate();
@@ -34,7 +29,7 @@ public int DoEventsCallback()
3429

3530
if (PassThrough)
3631
{
37-
return rtcDoEvents();
32+
return VbeProvider.VbeRuntime.DoEvents();
3833
}
3934
return (int)(ReturnValue ?? 0);
4035
}

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Environ.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace Rubberduck.UnitTesting.Fakes
66
{
77
internal class Environ : FakeBase
88
{
9-
private static readonly IntPtr ProcessAddressString = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcEnvironBstr");
10-
private static readonly IntPtr ProcessAddressVariant = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcEnvironVar");
11-
129
public Environ()
1310
{
14-
InjectDelegate(new EnvironStringDelegate(EnvironStringCallback), ProcessAddressString);
15-
InjectDelegate(new EnvironVariantDelegate(EnvironVariantCallback), ProcessAddressVariant);
11+
var processAddressString = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcEnvironBstr");
12+
var processAddressVariant = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcEnvironVar");
13+
14+
InjectDelegate(new EnvironStringDelegate(EnvironStringCallback), processAddressString);
15+
InjectDelegate(new EnvironVariantDelegate(EnvironVariantCallback), processAddressVariant);
1616
}
1717

1818
public override bool PassThrough

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/InputBox.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ namespace Rubberduck.UnitTesting.Fakes
66
{
77
internal class InputBox : FakeBase
88
{
9-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcInputBox");
10-
119
public InputBox()
1210
{
13-
InjectDelegate(new InputBoxDelegate(InputBoxCallback), ProcessAddress);
11+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcInputBox");
12+
13+
InjectDelegate(new InputBoxDelegate(InputBoxCallback), processAddress);
1414
}
1515

1616
public override bool PassThrough

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/MsgBox.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace Rubberduck.UnitTesting.Fakes
88
{
99
internal class MsgBox : FakeBase
1010
{
11-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcMsgBox");
12-
1311
public MsgBox()
1412
{
15-
InjectDelegate(new MessageBoxDelegate(MsgBoxCallback), ProcessAddress);
13+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcMsgBox");
14+
15+
InjectDelegate(new MessageBoxDelegate(MsgBoxCallback), processAddress);
1616
}
1717

1818
public override bool PassThrough

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Now.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ namespace Rubberduck.UnitTesting.Fakes
55
{
66
internal class Now : FakeBase
77
{
8-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcGetPresentDate");
9-
108
public Now()
119
{
12-
InjectDelegate(new NowDelegate(NowCallback), ProcessAddress);
13-
}
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcGetPresentDate");
1411

15-
[DllImport(TargetLibrary, SetLastError = true)]
16-
private static extern void rtcGetPresentDate(out object retVal);
12+
InjectDelegate(new NowDelegate(NowCallback), processAddress);
13+
}
1714

1815
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
1916
private delegate void NowDelegate(IntPtr retVal);
@@ -28,7 +25,7 @@ public void NowCallback(IntPtr retVal)
2825
if (PassThrough)
2926
{
3027
object result;
31-
rtcGetPresentDate(out result);
28+
VbeProvider.VbeRuntime.GetPresentDate(out result);
3229
Marshal.GetNativeVariantForObject(result, retVal);
3330
return;
3431
}

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Shell.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace Rubberduck.UnitTesting.Fakes
77
{
88
internal class Shell : FakeBase
99
{
10-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcShell");
11-
1210
public Shell()
1311
{
14-
InjectDelegate(new ShellDelegate(ShellCallback), ProcessAddress);
12+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcShell");
13+
14+
InjectDelegate(new ShellDelegate(ShellCallback), processAddress);
1515
}
1616

1717
private readonly ValueTypeConverter<double> _converter = new ValueTypeConverter<double>();
@@ -21,9 +21,6 @@ public override void Returns(object value, int invocation = FakesProvider.AllInv
2121
base.Returns((double)_converter.Value, invocation);
2222
}
2323

24-
[DllImport(TargetLibrary, SetLastError = true)]
25-
private static extern double rtcShell(IntPtr pathname, short windowstyle);
26-
2724
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
2825
[return: MarshalAs(UnmanagedType.R8)]
2926
private delegate double ShellDelegate(IntPtr pathname, short windowstyle);
@@ -39,7 +36,7 @@ public double ShellCallback(IntPtr pathname, short windowstyle)
3936

4037
if (PassThrough)
4138
{
42-
return Convert.ToDouble(rtcShell(pathname, windowstyle));
39+
return Convert.ToDouble(VbeProvider.VbeRuntime.Shell(pathname, windowstyle));
4340
}
4441
return Convert.ToDouble(ReturnValue ?? 0);
4542
}

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Time.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ namespace Rubberduck.UnitTesting.Fakes
55
{
66
internal class Time : FakeBase
77
{
8-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcGetTimeVar");
9-
108
public Time()
119
{
12-
InjectDelegate(new TimeDelegate(TimeCallback), ProcessAddress);
13-
}
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcGetTimeVar");
1411

15-
[DllImport(TargetLibrary, SetLastError = true)]
16-
private static extern void rtcGetTimeVar(out object retVal);
12+
InjectDelegate(new TimeDelegate(TimeCallback), processAddress);
13+
}
1714

1815
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
1916
private delegate void TimeDelegate(IntPtr retVal);
@@ -28,7 +25,7 @@ public void TimeCallback(IntPtr retVal)
2825
if (PassThrough)
2926
{
3027
object result;
31-
rtcGetTimeVar(out result);
28+
VbeProvider.VbeRuntime.GetTimeVar(out result);
3229
Marshal.GetNativeVariantForObject(result, retVal);
3330
return;
3431
}

Rubberduck.Main/ComClientLibrary/UnitTesting/Fakes/Timer.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ namespace Rubberduck.UnitTesting.Fakes
66
{
77
internal class Timer : FakeBase
88
{
9-
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcGetTimer");
10-
119
public Timer()
1210
{
13-
InjectDelegate(new TimerDelegate(TimerCallback), ProcessAddress);
11+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeRuntime.DllName, "rtcGetTimer");
12+
13+
InjectDelegate(new TimerDelegate(TimerCallback), processAddress);
1414
}
1515

1616
private readonly ValueTypeConverter<float> _converter = new ValueTypeConverter<float>();
@@ -20,10 +20,6 @@ public override void Returns(object value, int invocation = FakesProvider.AllInv
2020
base.Returns((float)_converter.Value, invocation);
2121
}
2222

23-
[DllImport(TargetLibrary, SetLastError = true)]
24-
[return: MarshalAs(UnmanagedType.R4)]
25-
private static extern float rtcGetTimer();
26-
2723
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
2824
[return: MarshalAs(UnmanagedType.R4)]
2925
private delegate float TimerDelegate();
@@ -34,7 +30,7 @@ public float TimerCallback()
3430

3531
if (PassThrough)
3632
{
37-
return rtcGetTimer();
33+
return VbeProvider.VbeRuntime.GetTimer();
3834
}
3935
return Convert.ToSingle(ReturnValue ?? 0);
4036
}

0 commit comments

Comments
 (0)