-
-
Notifications
You must be signed in to change notification settings - Fork 104
Implement record pointers as method parameters of a Dispatch Interface #535
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
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e1378f8
Implement record pointers as method parameters of a Dispatch Interface
geppi f7f461f
Merge branch 'enthought:main' into main
geppi 22daf9a
Adding the source files for a simple out of process COM-server under
geppi c000104
Modified the testing workflow to compile the out of process
geppi 8b2fe44
Added test for passing a record as a pure [in] parameter.
geppi d914023
Apply suggestions from code review
geppi c86326f
Apply suggestions from code review
junkmd 7720cac
Apply suggestions from code review
geppi c882cfb
Commit for renaming.
geppi f373411
Renamed the structure used for record parameter testing.
geppi 4eee732
Fixed typo that rendered a subtest useless.
geppi 9d81639
Apply suggestions from code review
junkmd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # coding: utf-8 | ||
|
|
||
| import unittest | ||
|
|
||
| from comtypes import CLSCTX_LOCAL_SERVER | ||
| from comtypes.client import CreateObject, GetModule | ||
| from ctypes import byref, pointer | ||
|
|
||
| ComtypesCppTestSrvLib_GUID = "{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}" | ||
|
|
||
| try: | ||
| GetModule((ComtypesCppTestSrvLib_GUID, 1, 0, 0)) | ||
| import comtypes.gen.ComtypesCppTestSrvLib as ComtypesCppTestSrvLib | ||
|
|
||
| IMPORT_FAILED = False | ||
| except (ImportError, OSError): | ||
| IMPORT_FAILED = True | ||
|
|
||
|
|
||
| @unittest.skipIf(IMPORT_FAILED, "This depends on the out of process COM-server.") | ||
| class Test(unittest.TestCase): | ||
| """Test dispmethods with record and record pointer parameters.""" | ||
|
|
||
| EXPECTED_INITED_QUESTIONS = "The meaning of life, the universe and everything?" | ||
|
|
||
| def _create_dispifc(self) -> "ComtypesCppTestSrvLib.IDispRecordParamTest": | ||
| # Explicitely ask for the dispinterface of the component. | ||
| return CreateObject( | ||
| "Comtypes.DispIfcParamTests", | ||
| clsctx=CLSCTX_LOCAL_SERVER, | ||
| interface=ComtypesCppTestSrvLib.IDispRecordParamTest, | ||
| ) | ||
|
|
||
geppi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_byref(self): | ||
junkmd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| dispifc = self._create_dispifc() | ||
| # Passing a record by reference to a method that has declared the parameter | ||
| # as [in, out] we expect modifications of the record on the server side to | ||
| # also change the record on the client side. | ||
| test_record = ComtypesCppTestSrvLib.T_TEST_RECORD() | ||
| self.assertEqual(test_record.question, None) | ||
| self.assertEqual(test_record.answer, 0) | ||
| self.assertEqual(test_record.needs_clarification, False) | ||
| dispifc.InitRecord(byref(test_record)) | ||
| self.assertEqual(test_record.question, self.EXPECTED_INITED_QUESTIONS) | ||
| self.assertEqual(test_record.answer, 42) | ||
| self.assertEqual(test_record.needs_clarification, True) | ||
|
|
||
geppi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_pointer(self): | ||
junkmd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| dispifc = self._create_dispifc() | ||
| # Passing a record pointer to a method that has declared the parameter | ||
| # as [in, out] we expect modifications of the record on the server side to | ||
| # also change the record on the client side. | ||
| test_record = ComtypesCppTestSrvLib.T_TEST_RECORD() | ||
| self.assertEqual(test_record.question, None) | ||
| self.assertEqual(test_record.answer, 0) | ||
| self.assertEqual(test_record.needs_clarification, False) | ||
| dispifc.InitRecord(pointer(test_record)) | ||
| self.assertEqual(test_record.question, self.EXPECTED_INITED_QUESTIONS) | ||
| self.assertEqual(test_record.answer, 42) | ||
| self.assertEqual(test_record.needs_clarification, True) | ||
|
|
||
geppi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_record(self): | ||
junkmd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Passing a record to a method that has declared the parameter just as [in] | ||
| # we expect modifications of the record on the server side NOT to change | ||
| # the record on the client side. | ||
| # We also need to test if the record gets properly passed to the method on | ||
| # the server side. For this, the 'VerifyRecord' method returns 'True' if | ||
| # all record fields have values equivalent to the initialization values | ||
| # provided by 'InitRecord'. | ||
| inited_record = ComtypesCppTestSrvLib.T_TEST_RECORD() | ||
| inited_record.question = self.EXPECTED_INITED_QUESTIONS | ||
| inited_record.answer = 42 | ||
| inited_record.needs_clarification = True | ||
| for rec, expected, (q, a, nc) in [ | ||
| (inited_record, True, (self.EXPECTED_INITED_QUESTIONS, 42, True)), | ||
| # Also perform the inverted test. For this, create a blank record. | ||
| (ComtypesCppTestSrvLib.T_TEST_RECORD(), False, (None, 0, False)), | ||
| ]: | ||
| with self.subTest(expected=expected, q=q, a=a, nc=nc): | ||
| # Perform the check on initialization values. | ||
| self.assertEqual(self._create_dispifc().VerifyRecord(rec), expected) | ||
| self.assertEqual(rec.question, q) | ||
| # Check if the 'answer' field is unchanged although the method | ||
| # modifies this field on the server side. | ||
| self.assertEqual(rec.answer, a) | ||
| self.assertEqual(rec.needs_clarification, nc) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.