Skip to content

Add 38 C++ MSTest tests for FileLocksmith#46936

Open
crutkas wants to merge 5 commits intomicrosoft:mainfrom
crutkas:split/filelocksmith-tests
Open

Add 38 C++ MSTest tests for FileLocksmith#46936
crutkas wants to merge 5 commits intomicrosoft:mainfrom
crutkas:split/filelocksmith-tests

Conversation

@crutkas
Copy link
Copy Markdown
Member

@crutkas crutkas commented Apr 12, 2026

Summary

38 new TEST_METHODs covering FileLocksmith:

  • Path normalization: forward->backslash, UNC paths, spaces
  • Case-insensitive path comparison including UNC paths
  • ProcessResult operations, output formatting
  • Registry constants

Split from #46905 (7/7) — see that PR for full context.

Files Changed (6)

  • src/modules/FileLocksmith/UnitTests/FileLocksmithTests.cpp (new)
  • src/modules/FileLocksmith/UnitTests/UnitTests-FileLocksmith.vcxproj (new)
  • src/modules/FileLocksmith/UnitTests/UnitTests-FileLocksmith.vcxproj.filters (new)
  • src/modules/FileLocksmith/UnitTests/pch.cpp (new)
  • src/modules/FileLocksmith/UnitTests/pch.h (new)
  • PowerToys.slnx (modified — +1 project ref in /modules/FileLocksmith/Tests/)

Path normalization (forward->backslash, UNC paths, spaces), case-insensitive
path comparison including UNC paths, ProcessResult operations, output formatting,
and registry constants.

Split from PR microsoft#46905 (7/7)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@crutkas crutkas added the Area-Tests issues that relate to tests label Apr 12, 2026
@crutkas
Copy link
Copy Markdown
Member Author

crutkas commented Apr 12, 2026

/azp run

@crutkas crutkas added the Needs-Review This Pull Request awaits the review of a maintainer. label Apr 12, 2026
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@DHowett
Copy link
Copy Markdown
Member

DHowett commented Apr 12, 2026

An engineer--not a computer--needs to verify each of these test cases to ensure that they are worthwhile and on-target.

Copy link
Copy Markdown
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

I read thirteen of these tests and they are, at best, useless. They are testing the test harness, they are testing C++ string equality, and they are testing no product code of value.

Comment thread src/modules/FileLocksmith/UnitTests/FileLocksmithTests.cpp Outdated
…g CLI tests

- Deleted src/modules/FileLocksmith/UnitTests/ (27/38 tests were hollow)
- Added 8 Constants validation tests to existing CLI test project
- Added 3 ProcessResult struct tests
- Added 3 new CLI scenario tests using existing mock infrastructure
- Every test has deep comments explaining what it tests and why

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

crutkas and others added 3 commits April 12, 2026 20:49
DWORD pid -> DWORD pid{} to zero-initialize and satisfy
code analysis warning C26495 (uninitialized member variable).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Headers should include their own dependencies explicitly, not rely on
a project-specific pch.h. Constants.h only needs WCHAR from Windows.h.
When included from the test project, the quoted pch.h search found
the wrong pch (or no pch), causing build failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@crutkas crutkas requested a review from DHowett April 15, 2026 04:43
Copy link
Copy Markdown
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

I would throw all of the new ProcessResultsTests in the trash.

// Product code: ProcessResult.h — ProcessResult struct
// What: Validates all four fields (name, pid, user, files) round-trip correctly
// Why: find_processes_recursive() populates these; get_json()/get_text() reads them
// Risk: Field misalignment silently corrupts IPC data between CLI and UI
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test is unable to actually verify field alignment over the IPC channel, because it does not use an IPC channel. It is only capable of testing that two .cpp files compiled into the same .dll see the same structure definition.

However, it is not even capable of that, because only the structure definition visible to this cpp file matters inside this test.

This test boils down to...

int foo = 1;
Assert::AreEqual(1, foo);

which is... i mean. not going to prevent a regression

Comment on lines +133 to +135
pr.name = L"proc.exe";
pr.pid = 0;
pr.user = L"";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is extraneous and not related to the test condition

Comment on lines +147 to +149
pr.files = { L"A", L"B", L"C", L"D" };
Assert::AreEqual((size_t)4, pr.files.size());
Assert::AreEqual(std::wstring(L"C"), pr.files[2]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is a test to make sure std::vector works properly. I assume the C++ STL has 10,000 of those already, and this will not prevent a new regression in PowerToys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Tests issues that relate to tests Needs-Review This Pull Request awaits the review of a maintainer.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants