Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive unit tests for the FltCommunicationPort class using mock objects to avoid dependencies on actual Windows kernel APIs. The implementation introduces a dependency injection pattern through IWinApi interface abstraction to enable testability.
- Introduces IWinApi interface and WinApi wrapper class for Windows API abstraction
- Creates WinApiMock for testing FltCommunicationPort functionality
- Adds comprehensive test coverage for FltCommunicationPort creation, error handling, and cleanup scenarios
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/pch.h | Adds fltKernel.h include for filter manager types |
| test/WinApiMock.h | Implements mock Windows API for unit testing |
| test/FltCommunicationPortTest.cpp | Comprehensive test suite for FltCommunicationPort |
| test/CMakeLists.txt | Adds new test files to build configuration |
| include/kf/WinApi.h | Production wrapper implementing IWinApi interface |
| include/kf/IWinApi.h | Interface definition for Windows API abstraction |
| include/kf/FltCommunicationPort.h | Updates to use IWinApi dependency injection |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| static bool freeCalled = false; | ||
| apiMock.m_funcs.FltFreeSecurityDescriptor = [](PSECURITY_DESCRIPTOR) { freeCalled = true; }; |
There was a problem hiding this comment.
Static variable 'freeCalled' could cause race conditions or state pollution between test runs. Consider using a non-static variable or resetting it before each test.
| static bool freeCalled = false; | |
| apiMock.m_funcs.FltFreeSecurityDescriptor = [](PSECURITY_DESCRIPTOR) { freeCalled = true; }; | |
| bool freeCalled = false; | |
| apiMock.m_funcs.FltFreeSecurityDescriptor = [&freeCalled](PSECURITY_DESCRIPTOR) { freeCalled = true; }; |
| static bool freeCalled = false; | ||
| apiMock.m_funcs.FltCloseCommunicationPort = [](PFLT_PORT) { freeCalled = true; }; |
There was a problem hiding this comment.
Another static variable 'freeCalled' that could cause race conditions or state pollution between test runs. Consider using a non-static variable or resetting it before each test.
| static bool freeCalled = false; | |
| apiMock.m_funcs.FltCloseCommunicationPort = [](PFLT_PORT) { freeCalled = true; }; | |
| bool freeCalled = false; | |
| apiMock.m_funcs.FltCloseCommunicationPort = [&freeCalled](PFLT_PORT) { freeCalled = true; }; |
24265eb to
0c2d2f3
Compare
Task: https://jira.dev.local/jira/browse/KF-34