-
-
Notifications
You must be signed in to change notification settings - Fork 104
Add comprehensive testing for IGlobalInterfaceTable (GIT) marshaling.
#918
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
Merged
+177
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add `test_git` to verify `GetInterfaceFromGlobal`, `RegisterInterfaceInGlobal`, and `RevokeInterfaceFromGlobal` methods. This test reflects the logic found in the `if __name__ == "__main__":` block within `comtypes/git.py`.
…st_git`. This change introduces a context manager `register_in_global` to streamline the registration and revocation of COM objects in the Global Interface Table (GIT) within `test_git.py`. This ensures proper cleanup, improving readability.
This adds `Test_ApartmentMarshaling` to `test_git.py` to verify the correct marshaling of COM objects across different COM apartments using the Global Interface Table (GIT). It uses `Paint.Picture`, an out-of-process, STA-only COM object, to demonstrate object persistence and marshaling, including thread management and message pumping to prevent deadlocks.
Enhance `Test_ApartmentMarshaling` in `test_git.py` by adding `Queue` to retrieve the `IPersistFile.GetCurFile()` result from the marshaled object in a separate thread. This allows asserting that the object's data remains consistent after marshaling through the Global Interface Table (GIT).
…ling`. Further refines `Test_ApartmentMarshaling` in `test_git.py` by adding an immediate assertion to `IPersistFile.GetCurFile()` after loading the image file. This ensures the file path is correctly retrieved and consistent with the loaded file, even before cross-thread marshaling verification.
Further refines `Test_ApartmentMarshaling` in `test_git.py` by adding an explicit check for the COM apartment type using `CoGetApartmentType`. This assertion ensures that the test is executed within the expected main STA (Single-Threaded Apartment) thread, which is crucial for valid COM marshaling test results.
…arshaling`. Enhance `Test_ApartmentMarshaling` in `test_git.py` by adding a test case to explicitly verify that direct access to a `Paint.Picture` object (obtained from an STA object created in the main thread) from a different apartment (worker thread) fails as expected when NOT marshaled through the Global Interface Table (GIT). This highlights the necessity of GIT for cross-apartment access.
Further refines `Test_ApartmentMarshaling` in `test_git.py` to explicitly assert `RPC_E_WRONG_THREAD` when attempting to access a `Paint.Picture` object directly from a different thread without proper COM marshaling. This verifies the expected COM behavior where direct cross-apartment access to an STA object fails with this specific error, underscoring the necessity of the Global Interface Table (GIT) for such operations.
Enhance `test_git.py` by adding inline comments with direct links to the Microsoft Learn documentation for COM API functions such as `PeekMessageA`, `MsgWaitForMultipleObjects`, and `CoGetApartmentType`. This improves the readability and maintainability of the test code by providing immediate context and reference for the underlying Windows API calls.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #918 +/- ##
==========================================
+ Coverage 87.53% 87.80% +0.26%
==========================================
Files 136 137 +1
Lines 12975 13074 +99
==========================================
+ Hits 11358 11479 +121
+ Misses 1617 1595 -22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This pull request introduces comprehensive unit tests for the
IGlobalInterfaceTable(GIT) functionalities within thegitmodule.These tests are verifying the handling of COM apartment boundaries which was an untested area previously.
Demonstrated Solution for Thread Boundary Violations
The tests specifically target and reproduce "thread boundary violations" by attempting direct access to STA (Single-Threaded Apartment) COM objects from different threads without proper marshaling.
By contrasting this failed direct access with successful access through GIT, the tests clearly demonstrate that GIT provides a mechanism for sharing interfaces across apartments.
Technical Background (for documentation integration)
The tests intentionally utilize out-of-process COM objects, such as
Paint.Picture, because in-process objects can sometimes "accidentally work".