Skip to content

Commit 712e949

Browse files
committed
Next round of fakes added
1 parent 2d344f7 commit 712e949

File tree

14 files changed

+736
-4
lines changed

14 files changed

+736
-4
lines changed

Rubberduck.Core/Runtime/BeepInterceptor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ private void VbaBeepCallback()
7474

7575
if (!e.Handled)
7676
{
77-
//_vbeApi.Beep();
7877
nativeCall();
7978
}
8079
}

Rubberduck.Main/ComClientLibrary/Abstract/UnitTesting/IFakesProvider.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace Rubberduck.UnitTesting
1313
public interface IFakesProvider
1414
{
1515
[DispId(1)]
16-
[Description("Configures VBA.Interactions.MsgBox calls.")]
16+
[Description("Configures VBA.Interaction.MsgBox calls.")]
1717
IFake MsgBox { get; }
1818

1919
[DispId(2)]
20-
[Description("Configures VBA.Interactions.InputBox calls.")]
20+
[Description("Configures VBA.Interaction.InputBox calls.")]
2121
IFake InputBox { get; }
2222

2323
[DispId(3)]
@@ -99,5 +99,41 @@ public interface IFakesProvider
9999
[DispId(22)]
100100
[Description("Configures VBA.Math.Randomize calls.")]
101101
IStub Randomize { get; }
102+
103+
[DispId(23)]
104+
[Description("Configures VBA.Iteraction.GetAllSettings calls.")]
105+
IFake GetAllSettings { get; }
106+
107+
[DispId(24)]
108+
[Description("Configures VBA.FileSystem.SetAttr calls.")]
109+
IStub SetAttr { get; }
110+
111+
[DispId(25)]
112+
[Description("Configures VBA.FileSystem.GetAttr calls.")]
113+
IFake GetAttr { get; }
114+
115+
[DispId(26)]
116+
[Description("Configures VBA.FileSystem.FileLen calls.")]
117+
IFake FileLen { get; }
118+
119+
[DispId(27)]
120+
[Description("Configures VBA.FileSystem.FileDateTime calls.")]
121+
IFake FileDateTime { get; }
122+
123+
[DispId(28)]
124+
[Description("Configures VBA.FileSystem.FreeFile calls.")]
125+
IFake FreeFile { get; }
126+
127+
[DispId(29)]
128+
[Description("Configures VBA.Information.IMEStatus calls.")]
129+
IFake IMEStatus { get; }
130+
131+
[DispId(30)]
132+
[Description("Configures VBA.FileSystem.Dir calls.")]
133+
IFake Dir { get; }
134+
135+
[DispId(31)]
136+
[Description("Configures VBA.FileSystem.FileCopy calls.")]
137+
IStub FileCopy { get; }
102138
}
103139
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Rubberduck.Parsing.Grammar;
4+
5+
namespace Rubberduck.UnitTesting.Fakes
6+
{
7+
internal class Dir : FakeBase
8+
{
9+
public Dir()
10+
{
11+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeNativeApi.DllName, "rtcDir");
12+
13+
InjectDelegate(new DirDelegate(DirCallback), processAddress);
14+
}
15+
16+
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
17+
[return: MarshalAs(UnmanagedType.BStr)]
18+
private delegate string DirDelegate(IntPtr pathname, short attributes);
19+
20+
public string DirCallback(IntPtr pathname, short attributes)
21+
{
22+
OnCallBack();
23+
24+
TrackUsage("pathname", pathname);
25+
TrackUsage("attributes", attributes, Tokens.Integer);
26+
if (PassThrough)
27+
{
28+
var nativeCall = Marshal.GetDelegateForFunctionPointer<DirDelegate>(NativeFunctionAddress);
29+
return nativeCall(pathname, attributes);
30+
}
31+
32+
return ReturnValue?.ToString() ?? string.Empty;
33+
}
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Rubberduck.Parsing.Grammar;
4+
5+
namespace Rubberduck.UnitTesting.Fakes
6+
{
7+
internal class FileDateTime : FakeBase
8+
{
9+
public FileDateTime()
10+
{
11+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeNativeApi.DllName, "rtcFileDateTime");
12+
13+
InjectDelegate(new FileDateTimeDelegate(FileDateTimeCallback), processAddress);
14+
}
15+
16+
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
17+
private delegate void FileDateTimeDelegate(IntPtr retVal, IntPtr pathname);
18+
19+
public void FileDateTimeCallback(IntPtr retVal, IntPtr pathname)
20+
{
21+
OnCallBack();
22+
23+
var pathNameArg = Marshal.PtrToStringBSTR(pathname);
24+
TrackUsage("pathname", pathNameArg, Tokens.String);
25+
if (PassThrough)
26+
{
27+
var nativeCall = Marshal.GetDelegateForFunctionPointer<FileDateTimeDelegate>(NativeFunctionAddress);
28+
nativeCall(retVal, pathname);
29+
}
30+
31+
Marshal.GetNativeVariantForObject(ReturnValue ?? 0, retVal);
32+
}
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Rubberduck.Parsing.Grammar;
4+
5+
namespace Rubberduck.UnitTesting.Fakes
6+
{
7+
internal class FileLen : FakeBase
8+
{
9+
public FileLen()
10+
{
11+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeNativeApi.DllName, "rtcFileLen");
12+
13+
InjectDelegate(new FileLenDelegate(FileLenCallback), processAddress);
14+
}
15+
16+
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
17+
[return: MarshalAs(UnmanagedType.I4)]
18+
private delegate int FileLenDelegate(IntPtr pathname);
19+
20+
public int FileLenCallback(IntPtr pathname)
21+
{
22+
OnCallBack();
23+
24+
var pathNameArg = Marshal.PtrToStringBSTR(pathname);
25+
TrackUsage("pathname", pathNameArg, Tokens.String);
26+
if (PassThrough)
27+
{
28+
var nativeCall = Marshal.GetDelegateForFunctionPointer<FileLenDelegate>(NativeFunctionAddress);
29+
return nativeCall(pathname);
30+
}
31+
32+
return Convert.ToInt32(ReturnValue ?? 0);
33+
}
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Rubberduck.UnitTesting.Fakes
5+
{
6+
internal class FreeFile : FakeBase
7+
{
8+
public FreeFile()
9+
{
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeNativeApi.DllName, "rtcFreeFile");
11+
12+
InjectDelegate(new FreeFileDelegate(FreeFileCallback), processAddress);
13+
}
14+
15+
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
16+
[return: MarshalAs(UnmanagedType.I2)]
17+
private delegate short FreeFileDelegate(IntPtr rangenumber);
18+
19+
public short FreeFileCallback(IntPtr rangenumber)
20+
{
21+
OnCallBack();
22+
23+
TrackUsage("rangenumber", rangenumber);
24+
if (PassThrough)
25+
{
26+
var nativeCall = Marshal.GetDelegateForFunctionPointer<FreeFileDelegate>(NativeFunctionAddress);
27+
return nativeCall(rangenumber);
28+
}
29+
30+
return Convert.ToInt16(ReturnValue ?? 0);
31+
}
32+
}
33+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Rubberduck.Parsing.Grammar;
4+
5+
namespace Rubberduck.UnitTesting.Fakes
6+
{
7+
internal class GetAllSettings : FakeBase
8+
{
9+
public GetAllSettings()
10+
{
11+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeNativeApi.DllName, "rtcGetAllSettings");
12+
13+
InjectDelegate(new GetAllSettingsDelegate(GetAllSettingsCallback), processAddress);
14+
}
15+
16+
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
17+
//[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_BSTR)]
18+
private delegate void GetAllSettingsDelegate(IntPtr retVal, IntPtr appName, IntPtr section);
19+
20+
public void GetAllSettingsCallback(IntPtr retVal, IntPtr appName, IntPtr section)
21+
{
22+
OnCallBack();
23+
24+
var appNameArg = Marshal.PtrToStringBSTR(appName);
25+
var sectionArg = Marshal.PtrToStringBSTR(section);
26+
TrackUsage("appname", appNameArg, Tokens.String);
27+
TrackUsage("section", sectionArg, Tokens.String);
28+
if (PassThrough)
29+
{
30+
var nativeCall = Marshal.GetDelegateForFunctionPointer<GetAllSettingsDelegate>(NativeFunctionAddress);
31+
nativeCall(retVal, appName, section);
32+
return;
33+
}
34+
Marshal.GetNativeVariantForObject(ReturnValue ?? 0, retVal); // ReturnValue ?? IntPtr.Zero;
35+
}
36+
}
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Rubberduck.Parsing.Grammar;
4+
5+
namespace Rubberduck.UnitTesting.Fakes
6+
{
7+
internal class GetAttr : FakeBase
8+
{
9+
public GetAttr()
10+
{
11+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeNativeApi.DllName, "rtcGetFileAttr");
12+
13+
InjectDelegate(new GetAttrDelegate(GetAttrCallback), processAddress);
14+
}
15+
16+
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
17+
[return: MarshalAs(UnmanagedType.I2)]
18+
private delegate short GetAttrDelegate(IntPtr pathname);
19+
20+
public short GetAttrCallback(IntPtr pathname)
21+
{
22+
OnCallBack();
23+
24+
var pathNameArg = Marshal.PtrToStringBSTR(pathname);
25+
TrackUsage("pathname", pathNameArg, Tokens.String);
26+
if (PassThrough)
27+
{
28+
var nativeCall = Marshal.GetDelegateForFunctionPointer<GetAttrDelegate>(NativeFunctionAddress);
29+
return nativeCall(pathname);
30+
}
31+
32+
return Convert.ToInt16(ReturnValue ?? 0);
33+
}
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Rubberduck.UnitTesting.Fakes
5+
{
6+
internal class IMEStatus : FakeBase
7+
{
8+
public IMEStatus()
9+
{
10+
var processAddress = EasyHook.LocalHook.GetProcAddress(VbeProvider.VbeNativeApi.DllName, "rtcIMEStatus");
11+
12+
InjectDelegate(new IMEStatusDelegate(IMEStatusCallback), processAddress);
13+
}
14+
15+
[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
16+
[return: MarshalAs(UnmanagedType.I2)]
17+
private delegate short IMEStatusDelegate();
18+
19+
public short IMEStatusCallback()
20+
{
21+
OnCallBack(true);
22+
if (!TrySetReturnValue()) // specific invocation
23+
{
24+
TrySetReturnValue(true); // any invocation
25+
}
26+
27+
if (PassThrough)
28+
{
29+
var nativeCall = Marshal.GetDelegateForFunctionPointer<IMEStatusDelegate>(NativeFunctionAddress);
30+
return nativeCall();
31+
}
32+
return Convert.ToInt16(ReturnValue ?? 0);
33+
}
34+
}
35+
}

Rubberduck.Main/ComClientLibrary/UnitTesting/FakesProvider.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ private T RetrieveOrCreateFunction<T>(Func<T> factory)
9191
public IStub SaveSetting => RetrieveOrCreateFunction<SaveSetting>();
9292
public IFake GetSetting => RetrieveOrCreateFunction<GetSetting>();
9393
public IStub Randomize => RetrieveOrCreateFunction<Randomize>();
94+
public IFake GetAllSettings => RetrieveOrCreateFunction<GetAllSettings>();
95+
public IStub SetAttr => RetrieveOrCreateFunction<SetAttr>();
96+
public IFake GetAttr => RetrieveOrCreateFunction<GetAttr>();
97+
public IFake FileLen => RetrieveOrCreateFunction<FileLen>();
98+
public IFake FileDateTime => RetrieveOrCreateFunction<FileDateTime>();
99+
public IFake FreeFile => RetrieveOrCreateFunction<FreeFile>();
100+
public IFake IMEStatus => RetrieveOrCreateFunction<IMEStatus>();
101+
public IFake Dir => RetrieveOrCreateFunction<Dir>();
102+
public IStub FileCopy => RetrieveOrCreateFunction<FileCopy>();
94103
#endregion
95104
}
96105
}

0 commit comments

Comments
 (0)