Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed May 29, 2024
1 parent 9d81639 commit d62ec76
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions comtypes/test/test_dispifc_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ def test_inout_pointer(self):
self.assertEqual(test_record.answer, 42)
self.assertEqual(test_record.needs_clarification, True)

def test_inout_record(self):
dispifc = self._create_dispifc()
test_record = ComtypesCppTestSrvLib.StructRecordParamTest()
self.assertEqual(test_record.question, None)
self.assertEqual(test_record.answer, 0)
self.assertEqual(test_record.needs_clarification, False)
dispifc.InitRecord(test_record)
self.assertEqual(test_record.question, None)
self.assertEqual(test_record.answer, 0)
self.assertEqual(test_record.needs_clarification, False)

def test_in_record(self):
# 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
Expand Down Expand Up @@ -86,5 +97,61 @@ def test_in_record(self):
self.assertEqual(rec.needs_clarification, nc)


@unittest.skipIf(IMPORT_FAILED, "This depends on the out of process COM-server.")
class Test_Dual(unittest.TestCase):
EXPECTED_INITED_QUESTIONS = "The meaning of life, the universe and everything?"

def _create_dualifc(self) -> "ComtypesCppTestSrvLib.IDualRecordParamTest":
# Explicitely ask for the dispinterface of the component.
return CreateObject(
"Comtypes.DispIfcParamTests",
clsctx=CLSCTX_LOCAL_SERVER,
interface=ComtypesCppTestSrvLib.IDualRecordParamTest,
)

def test_inout_pointer(self):
dualifc = self._create_dualifc()
test_record = ComtypesCppTestSrvLib.StructRecordParamTest()
self.assertEqual(test_record.question, None)
self.assertEqual(test_record.answer, 0)
self.assertEqual(test_record.needs_clarification, False)
dualifc.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)

def test_inout_record(self):
dualifc = self._create_dualifc()
test_record = ComtypesCppTestSrvLib.StructRecordParamTest()
self.assertEqual(test_record.question, None)
self.assertEqual(test_record.answer, 0)
self.assertEqual(test_record.needs_clarification, False)
# Passing a record by reference to a method, such as
# `dualifc.InitRecord(byref(test_record))`, clashes Python.
dualifc.InitRecord(test_record)
self.assertEqual(test_record.question, self.EXPECTED_INITED_QUESTIONS)
self.assertEqual(test_record.answer, 42)
self.assertEqual(test_record.needs_clarification, True)

def test_in_record(self):
inited_record = ComtypesCppTestSrvLib.StructRecordParamTest()
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.StructRecordParamTest(), 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_dualifc().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()

0 comments on commit d62ec76

Please sign in to comment.