|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test/unit' |
| 4 | +require 'resolv' |
| 5 | + |
| 6 | +class TestWin32Config < Test::Unit::TestCase |
| 7 | + def setup |
| 8 | + omit 'Win32::Resolv tests only run on Windows' unless RUBY_PLATFORM =~ /mswin|mingw|cygwin/ |
| 9 | + end |
| 10 | + |
| 11 | + def test_get_item_property_string |
| 12 | + # Test reading a string registry value |
| 13 | + result = Win32::Resolv.send(:get_item_property, |
| 14 | + Win32::Resolv::TCPIP_NT, |
| 15 | + 'DataBasePath') |
| 16 | + |
| 17 | + # Should return a string (empty or with a path) |
| 18 | + assert_instance_of String, result |
| 19 | + end |
| 20 | + |
| 21 | + def test_get_item_property_with_expand |
| 22 | + # Test reading an expandable string registry value |
| 23 | + result = Win32::Resolv.send(:get_item_property, |
| 24 | + Win32::Resolv::TCPIP_NT, |
| 25 | + 'DataBasePath', |
| 26 | + expand: true) |
| 27 | + |
| 28 | + # Should return a string with environment variables expanded |
| 29 | + assert_instance_of String, result |
| 30 | + end |
| 31 | + |
| 32 | + def test_get_item_property_dword |
| 33 | + # Test reading a DWORD registry value |
| 34 | + result = Win32::Resolv.send(:get_item_property, |
| 35 | + Win32::Resolv::TCPIP_NT, |
| 36 | + 'UseDomainNameDevolution', |
| 37 | + dword: true) |
| 38 | + |
| 39 | + # Should return an integer (0 or 1 typically) |
| 40 | + assert_kind_of Integer, result |
| 41 | + end |
| 42 | + |
| 43 | + def test_get_item_property_nonexistent_key |
| 44 | + # Test reading a non-existent registry key |
| 45 | + result = Win32::Resolv.send(:get_item_property, |
| 46 | + Win32::Resolv::TCPIP_NT, |
| 47 | + 'NonExistentKeyThatShouldNotExist') |
| 48 | + |
| 49 | + # Should return empty string for non-existent string values |
| 50 | + assert_equal '', result |
| 51 | + end |
| 52 | + |
| 53 | + def test_get_item_property_nonexistent_key_dword |
| 54 | + # Test reading a non-existent registry key as DWORD |
| 55 | + result = Win32::Resolv.send(:get_item_property, |
| 56 | + Win32::Resolv::TCPIP_NT, |
| 57 | + 'NonExistentKeyThatShouldNotExist', |
| 58 | + dword: true) |
| 59 | + |
| 60 | + # Should return 0 for non-existent DWORD values |
| 61 | + assert_equal 0, result |
| 62 | + end |
| 63 | + |
| 64 | + def test_get_item_property_search_list |
| 65 | + # Test reading SearchList which may exist in the registry |
| 66 | + result = Win32::Resolv.send(:get_item_property, |
| 67 | + Win32::Resolv::TCPIP_NT, |
| 68 | + 'SearchList') |
| 69 | + |
| 70 | + # Should return a string (may be empty if not configured) |
| 71 | + assert_instance_of String, result |
| 72 | + end |
| 73 | + |
| 74 | + def test_get_item_property_nv_domain |
| 75 | + # Test reading NV Domain which may exist in the registry |
| 76 | + result = Win32::Resolv.send(:get_item_property, |
| 77 | + Win32::Resolv::TCPIP_NT, |
| 78 | + 'NV Domain') |
| 79 | + |
| 80 | + # Should return a string (may be empty if not configured) |
| 81 | + assert_instance_of String, result |
| 82 | + end |
| 83 | + |
| 84 | + def test_get_item_property_with_invalid_path |
| 85 | + # Test with an invalid registry path |
| 86 | + result = Win32::Resolv.send(:get_item_property, |
| 87 | + 'SYSTEM\NonExistent\Path', |
| 88 | + 'SomeKey') |
| 89 | + |
| 90 | + # Should return empty string for invalid path |
| 91 | + assert_equal '', result |
| 92 | + end |
| 93 | + |
| 94 | + def test_get_item_property_with_invalid_path_dword |
| 95 | + # Test with an invalid registry path as DWORD |
| 96 | + result = Win32::Resolv.send(:get_item_property, |
| 97 | + 'SYSTEM\NonExistent\Path', |
| 98 | + 'SomeKey', |
| 99 | + dword: true) |
| 100 | + |
| 101 | + # Should return 0 for invalid path |
| 102 | + assert_equal 0, result |
| 103 | + end |
| 104 | +end |
0 commit comments