From 69b41f10f6824ef9e3d816a902788e488a2d72aa Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Wed, 29 May 2024 17:24:46 +0900 Subject: [PATCH] Update test_dispifc_records.py --- comtypes/test/test_dispifc_records.py | 76 +++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/comtypes/test/test_dispifc_records.py b/comtypes/test/test_dispifc_records.py index a546a978e..e5108adf2 100644 --- a/comtypes/test/test_dispifc_records.py +++ b/comtypes/test/test_dispifc_records.py @@ -96,6 +96,44 @@ def test_in_record(self): self.assertEqual(rec.answer, a) self.assertEqual(rec.needs_clarification, nc) + def test_in_pointer(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_dispifc().VerifyRecord(pointer(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) + + def test_in_byref(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_dispifc().VerifyRecord(byref(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) + @unittest.skipIf(IMPORT_FAILED, "This depends on the out of process COM-server.") class Test_Dual(unittest.TestCase): @@ -152,6 +190,44 @@ def test_in_record(self): self.assertEqual(rec.answer, a) self.assertEqual(rec.needs_clarification, nc) + def test_in_pointer(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(pointer(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) + + def test_in_byref(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(byref(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()