-
-
Notifications
You must be signed in to change notification settings - Fork 104
Add tests for stdole.IPicture creation through IStream.
#892
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
+216
−4
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
Imports `comtypes.gen.stdole` in `test_stream.py` and adds a new test class `Test_Picture` with a placeholder test `test_ole_load_picture`. This is a preliminary step to implement comprehensive testing for the `stdole.IPicture` interface.
This includes setting its argument types and return type using `ctypes` to allow for loading `stdole.IPicture` objects from a `IStream`.
Introduces a new function `create_pixel_data` in `test_stream.py` to generate 32-bit BGRA BMP binary data. This utility function allows for creating synthetic image data with specified dimensions, color, and DPI.
This test validates the loading of a `stdole.IPicture` object from a stream containing bitmap data using `_OleLoadPicture`. It involves Windows API calls for device context, global memory management, and stream operations, ensuring the correct instantiation of the `IPicture` interface.
…ting. The `_create_stream` helper function in `test_stream.py` is refactored to accept `handle` and `delete_on_release` parameters. This allows for more controlled stream creation, particularly for testing scenarios involving `stdole.IPicture` where the underlying global memory management needs to be externalized.
A new `get_dc` context manager is added to `test_stream.py` to encapsulate the acquisition and release of device contexts (DC) via `_GetDC` and `_ReleaseDC`. This improves the test for `stdole.IPicture` by: - Reducing the number of variables within the main test logic, enhancing readability. - Separating setup (DC acquisition) and teardown (DC release) processes from the core test assertions, making the test cleaner and more maintainable.
…le.IPicture` testing. Two new context managers, `global_alloc` and `global_lock`, are introduced in `test_stream.py`. These encapsulate `_GlobalAlloc`/`_GlobalFree` and `_GlobalLock`/`_GlobalUnlock` Windows API calls respectively.
…e` testing. The logic for retrieving screen DPI is extracted into a new helper function, `get_screen_dpi`, in `test_stream.py`. This function utilizes the `get_dc` context manager to safely obtain and release the device context.
This is a direct validation of the `stdole.IPicture` interface's behavior.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #892 +/- ##
==========================================
+ Coverage 85.04% 85.16% +0.12%
==========================================
Files 126 126
Lines 11728 11826 +98
==========================================
+ Hits 9974 10072 +98
Misses 1754 1754 ☔ 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.
Added
test_ole_load_pictureto validate the creation of a newstdole.IPictureobject by passing a pre-filledIStream(containing bitmap data) toOleLoadPicture.This test specifically ensures that
CreateStreamOnHGlobalis invoked with a non-NULLhGlobalandfDeleteOnReleaseset toFalse.