Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12)

Side by Side Diff: Lib/test/test_winreg.py

Issue 25778: winreg.EnumValue does not truncate strings correctly
Patch Set: Created 4 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | PC/winreg.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Test the windows specific win32reg module. 1 # Test the windows specific win32reg module.
2 # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey 2 # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
3 3
4 import os, sys, errno 4 import os, sys, errno
5 import unittest 5 import unittest
6 from test import support 6 from test import support
7 threading = support.import_module("threading") 7 threading = support.import_module("threading")
8 from platform import machine 8 from platform import machine
9 9
10 # Do this first so test will be skipped if module doesn't exist 10 # Do this first so test will be skipped if module doesn't exist
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 class BaseWinregTests(unittest.TestCase): 50 class BaseWinregTests(unittest.TestCase):
51 51
52 def setUp(self): 52 def setUp(self):
53 # Make sure that the test key is absent when the test 53 # Make sure that the test key is absent when the test
54 # starts. 54 # starts.
55 self.delete_tree(HKEY_CURRENT_USER, test_key_name) 55 self.delete_tree(HKEY_CURRENT_USER, test_key_name)
56 56
57 def delete_tree(self, root, subkey): 57 def delete_tree(self, root, subkey):
58 try: 58 try:
59 hkey = OpenKey(root, subkey, KEY_ALL_ACCESS) 59 hkey = OpenKey(root, subkey, 0, KEY_ALL_ACCESS)
60 except OSError: 60 except OSError:
61 # subkey does not exist 61 # subkey does not exist
62 return 62 return
63 while True: 63 while True:
64 try: 64 try:
65 subsubkey = EnumKey(hkey, 0) 65 subsubkey = EnumKey(hkey, 0)
66 except OSError: 66 except OSError:
67 # no more subkeys 67 # no more subkeys
68 break 68 break
69 self.delete_tree(hkey, subsubkey) 69 self.delete_tree(hkey, subsubkey)
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 def test_setvalueex_crash_with_none_arg(self): 357 def test_setvalueex_crash_with_none_arg(self):
358 # Test for Issue #21151, segfault when None is passed to SetValueEx 358 # Test for Issue #21151, segfault when None is passed to SetValueEx
359 try: 359 try:
360 with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: 360 with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
361 self.assertNotEqual(ck.handle, 0) 361 self.assertNotEqual(ck.handle, 0)
362 test_val = None 362 test_val = None
363 SetValueEx(ck, "test_name", 0, REG_BINARY, test_val) 363 SetValueEx(ck, "test_name", 0, REG_BINARY, test_val)
364 ret_val, ret_type = QueryValueEx(ck, "test_name") 364 ret_val, ret_type = QueryValueEx(ck, "test_name")
365 self.assertEqual(ret_type, REG_BINARY) 365 self.assertEqual(ret_type, REG_BINARY)
366 self.assertEqual(ret_val, test_val) 366 self.assertEqual(ret_val, test_val)
367 finally:
368 DeleteKey(HKEY_CURRENT_USER, test_key_name)
369
370 def test_read_string_containing_null(self):
371 # Test for issue 25778: REG_SZ should not contain null characters
372 try:
373 with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
374 self.assertNotEqual(ck.handle, 0)
375 test_val = "A string\x00 with a null"
376 SetValueEx(ck, "test_name", 0, REG_SZ, test_val)
377 ret_val, ret_type = QueryValueEx(ck, "test_name")
378 self.assertEqual(ret_type, REG_SZ)
379 self.assertEqual(ret_val, "A string")
367 finally: 380 finally:
368 DeleteKey(HKEY_CURRENT_USER, test_key_name) 381 DeleteKey(HKEY_CURRENT_USER, test_key_name)
369 382
370 383
371
372 @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") 384 @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")
373 class RemoteWinregTests(BaseWinregTests): 385 class RemoteWinregTests(BaseWinregTests):
374 386
375 def test_remote_registry_works(self): 387 def test_remote_registry_works(self):
376 remote_key = ConnectRegistry(REMOTE_NAME, HKEY_CURRENT_USER) 388 remote_key = ConnectRegistry(REMOTE_NAME, HKEY_CURRENT_USER)
377 self._test_all(remote_key) 389 self._test_all(remote_key)
378 390
379 391
380 @unittest.skipUnless(WIN64_MACHINE, "x64 specific registry tests") 392 @unittest.skipUnless(WIN64_MACHINE, "x64 specific registry tests")
381 class Win64WinregTests(BaseWinregTests): 393 class Win64WinregTests(BaseWinregTests):
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 488
477 def test_main(): 489 def test_main():
478 support.run_unittest(LocalWinregTests, RemoteWinregTests, 490 support.run_unittest(LocalWinregTests, RemoteWinregTests,
479 Win64WinregTests) 491 Win64WinregTests)
480 492
481 if __name__ == "__main__": 493 if __name__ == "__main__":
482 if not REMOTE_NAME: 494 if not REMOTE_NAME:
483 print("Remote registry calls can be tested using", 495 print("Remote registry calls can be tested using",
484 "'test_winreg.py --remote \\\\machine_name'") 496 "'test_winreg.py --remote \\\\machine_name'")
485 test_main() 497 test_main()
OLDNEW
« no previous file with comments | « no previous file | PC/winreg.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+