Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready for Review - [Mouse Without Borders] - refactoring "Common" classes (Part 4) - #35155 #37579

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
[MouseWithoutBorders] - refactoring and fixes for logger unit test - #…
  • Loading branch information
mikeclayton committed Feb 22, 2025
commit dd7c7d2dcbe36f629c64139848cbd0c1164e5d76
42 changes: 33 additions & 9 deletions src/modules/MouseWithoutBorders/App/Core/Logger.cs
Original file line number Diff line number Diff line change
@@ -197,15 +197,9 @@ internal static void DumpObjects(int level)
myThreads.Add(t);
}

_ = Logger.PrivateDump(sb, AllLogs, "[Program logs]\r\n===============\r\n", 0, level, false);
_ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, level, false);
Logger.DumpType(sb, typeof(Logger), 0, level);
sb.AppendLine("[DragDrop]\r\n===============");
Logger.DumpType(sb, typeof(DragDrop), 0, level);
sb.AppendLine("[MachineStuff]\r\n===============");
Logger.DumpType(sb, typeof(MachineStuff), 0, level);
sb.AppendLine("[Receiver]\r\n===============");
Logger.DumpType(sb, typeof(Receiver), 0, level);
Logger.DumpProgramLogs(sb, level);
Logger.DumpOtherLogs(sb, level);
Logger.DumpStaticTypes(sb, level);

log = string.Format(
CultureInfo.CurrentCulture,
@@ -241,6 +235,36 @@ internal static void DumpObjects(int level)
}
}

internal static void DumpProgramLogs(StringBuilder sb, int level)
{
_ = Logger.PrivateDump(sb, AllLogs, "[Program logs]\r\n===============\r\n", 0, level, false);
}

internal static void DumpOtherLogs(StringBuilder sb, int level)
{
_ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, level, false);
}

internal static void DumpStaticTypes(StringBuilder sb, int level)
{
sb.AppendLine($"[{nameof(DragDrop)}]\r\n===============");
Logger.DumpType(sb, typeof(DragDrop), 0, level);
sb.AppendLine($"[{nameof(Event)}]\r\n===============");
Logger.DumpType(sb, typeof(Event), 0, level);
sb.AppendLine($"[{nameof(Helper)}]\r\n===============");
Logger.DumpType(sb, typeof(Helper), 0, level);
sb.AppendLine($"[{nameof(Launch)}]\r\n===============");
Logger.DumpType(sb, typeof(Launch), 0, level);
sb.AppendLine($"[{nameof(Logger)}]\r\n===============");
Logger.DumpType(sb, typeof(Logger), 0, level);
sb.AppendLine($"[{nameof(MachineStuff)}]\r\n===============");
Logger.DumpType(sb, typeof(MachineStuff), 0, level);
sb.AppendLine($"[{nameof(Receiver)}]\r\n===============");
Logger.DumpType(sb, typeof(Receiver), 0, level);
sb.AppendLine($"[{nameof(Service)}]\r\n===============");
Logger.DumpType(sb, typeof(Service), 0, level);
}

internal static bool PrivateDump(StringBuilder sb, object obj, string objName, int level, int maxLevel, bool stop)
{
Type t;
Original file line number Diff line number Diff line change
@@ -99,54 +99,6 @@ LegalKeyDictionary = Concurrent.ConcurrentDictionary`2[System.String,System.Byte
--_budget = ????????????
--_growLockArray = True
--_comparerIsDefaultForClasses = False
KeybdPackage = MouseWithoutBorders.DATA
--Type = 0
--Id = 0
--Src = NONE
--Des = NONE
--DateTime = 0
--Kd = MouseWithoutBorders.KEYBDDATA
--Md = MouseWithoutBorders.MOUSEDATA
--Machine1 = NONE
--Machine2 = NONE
--Machine3 = NONE
--Machine4 = NONE
--PostAction = Other
--machineNameP1 = 0
--machineNameP2 = 0
--machineNameP3 = 0
--machineNameP4 = 0
MousePackage = MouseWithoutBorders.DATA
--Type = 0
--Id = 0
--Src = NONE
--Des = NONE
--DateTime = 0
--Kd = MouseWithoutBorders.KEYBDDATA
--Md = MouseWithoutBorders.MOUSEDATA
--Machine1 = NONE
--Machine2 = NONE
--Machine3 = NONE
--Machine4 = NONE
--PostAction = Other
--machineNameP1 = 0
--machineNameP2 = 0
--machineNameP3 = 0
--machineNameP4 = 0
inputEventCount = 0
invalidPackageCount = 0
MOVE_MOUSE_RELATIVE = 100000
XY_BY_PIXEL = 300000
<RealInputEventCount>k__BackingField = 0
actualLastPos = {X=0,Y=0}
--x = 0
--y = 0
--Empty = {X=0,Y=0}
myLastX = 0
myLastY = 0
signalHelperToExit = False
signalWatchDogToExit = False
WndProcCounter = 0
initDone = False
REOPEN_WHEN_WSAECONNRESET = -10054
REOPEN_WHEN_HOTKEY = -10055
@@ -189,12 +141,6 @@ PackageReceived = MouseWithoutBorders.PackageMonitor
--ExplorerDragDrop = 0
--Nil = 0
PackageID = 0
shownErrMessage = False
lastStartServiceTime = ????????????
--_dateData = ????????????
--MinValue = 01/01/0001 00:00:00
--MaxValue = 31/12/9999 23:59:59
--UnixEpoch = 01/01/1970 00:00:00
SensitivePoints = Generic.List`1[Point]
--_items = Point[]
----System.Drawing.Point[] = Point[]: N/A
@@ -223,8 +169,6 @@ JUST_GOT_BACK_FROM_SCREEN_SAVER = 9999
NETWORK_STREAM_BUF_SIZE = 1048576
SymAlBlockSize = 16
PW_LENGTH = 16
HELPER_FORM_TEXT = Mouse without Borders Helper
HelperProcessName = PowerToys.MouseWithoutBordersHelper
PACKAGE_SIZE = 32
PACKAGE_SIZE_EX = 64
WP_PACKAGE_SIZE = 6
@@ -251,6 +195,69 @@ WM_KEYDOWN = 256
WM_KEYUP = 257
WM_SYSKEYDOWN = 260
WM_SYSKEYUP = 261
[DragDrop]
===============
isDragging = False
dragDropStep05ExCalledByIpc = 0
isDropping = False
dragMachine = NONE
<MouseDown>k__BackingField = False
[Event]
===============
KeybdPackage = MouseWithoutBorders.DATA
--Type = 0
--Id = 0
--Src = NONE
--Des = NONE
--DateTime = 0
--Kd = MouseWithoutBorders.KEYBDDATA
--Md = MouseWithoutBorders.MOUSEDATA
--Machine1 = NONE
--Machine2 = NONE
--Machine3 = NONE
--Machine4 = NONE
--PostAction = Other
--machineNameP1 = 0
--machineNameP2 = 0
--machineNameP3 = 0
--machineNameP4 = 0
MousePackage = MouseWithoutBorders.DATA
--Type = 0
--Id = 0
--Src = NONE
--Des = NONE
--DateTime = 0
--Kd = MouseWithoutBorders.KEYBDDATA
--Md = MouseWithoutBorders.MOUSEDATA
--Machine1 = NONE
--Machine2 = NONE
--Machine3 = NONE
--Machine4 = NONE
--PostAction = Other
--machineNameP1 = 0
--machineNameP2 = 0
--machineNameP3 = 0
--machineNameP4 = 0
inputEventCount = 0
invalidPackageCount = 0
MOVE_MOUSE_RELATIVE = 100000
XY_BY_PIXEL = 300000
<RealInputEventCount>k__BackingField = 0
actualLastPos = {X=0,Y=0}
--x = 0
--y = 0
--Empty = {X=0,Y=0}
myLastX = 0
myLastY = 0
[Helper]
===============
signalHelperToExit = False
signalWatchDogToExit = False
WndProcCounter = 0
HELPER_FORM_TEXT = Mouse without Borders Helper
HelperProcessName = PowerToys.MouseWithoutBordersHelper
[Launch]
===============
[Logger]
===============
AllLogsLock = Lock
@@ -319,13 +326,6 @@ MAX_LOG = 10000
MaxLogExceptionPerHour = 1000
HeaderSENT = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},Ie{12},Ni{13}
HeaderRECEIVED = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},In{12},Ni{13},Pc{14}/{15}
[DragDrop]
===============
isDragging = False
dragDropStep05ExCalledByIpc = 0
isDropping = False
dragMachine = NONE
<MouseDown>k__BackingField = False
[MachineStuff]
===============
McMatrixLock = Lock
@@ -424,3 +424,11 @@ lastXY = {X=0,Y=0}
--x = 0
--y = 0
--Empty = {X=0,Y=0}
[Service]
===============
shownErrMessage = False
lastStartServiceTime = ????????????
--_dateData = ????????????
--MinValue = 01/01/0001 00:00:00
--MaxValue = 31/12/9999 23:59:59
--UnixEpoch = 01/01/1970 00:00:00
Original file line number Diff line number Diff line change
@@ -38,11 +38,13 @@ public void PrivateDumpShouldGenerateExpectedOutput()
*/

[TestMethod]
/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended?

Copy link
Contributor Author

@mikeclayton mikeclayton Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no - we don't really want this test running in CI. I enabled it locally to test the changes, but looks like forgot to uncomment the [Ignore] attribute. I'll remove the /* */.

[Ignore(
"This test relies on internal details of the dotnet platform and is sensitive to " +
"the specific version of dotnet being used. As a result it's likely to fail if the " +
"\"expected\" result was generated with a different version to the version used to " +
"run the test, so we're going to ignore it in the CI build process.")]
*/
public void PrivateDumpShouldGenerateExpectedOutput()
{
static string NormalizeLog(string log)
@@ -114,18 +116,11 @@ static string NormalizeLog(string log)
using var streamReader = new StreamReader(stream);
var expected = streamReader.ReadToEnd();

// copied from DumpObjects in Common.Log.cs
// copied from DumpObjects in Logger.cs
var sb = new StringBuilder(1000000);
_ = Logger.PrivateDump(sb, Logger.AllLogs, "[Program logs]\r\n===============\r\n", 0, settingsDumpObjectsLevel, false);
_ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, settingsDumpObjectsLevel, false);
sb.AppendLine("[Logger]\r\n===============");
Logger.DumpType(sb, typeof(Logger), 0, settingsDumpObjectsLevel);
sb.AppendLine("[DragDrop]\r\n===============");
Logger.DumpType(sb, typeof(DragDrop), 0, settingsDumpObjectsLevel);
sb.AppendLine("[MachineStuff]\r\n===============");
Logger.DumpType(sb, typeof(MachineStuff), 0, settingsDumpObjectsLevel);
sb.AppendLine("[Receiver]\r\n===============");
Logger.DumpType(sb, typeof(Receiver), 0, settingsDumpObjectsLevel);
Logger.DumpProgramLogs(sb, settingsDumpObjectsLevel);
Logger.DumpOtherLogs(sb, settingsDumpObjectsLevel);
Logger.DumpStaticTypes(sb, settingsDumpObjectsLevel);
var actual = sb.ToString();

expected = NormalizeLog(expected);