diff options
author | Gert Driesen <drieseng@users.sourceforge.net> | 2006-04-20 12:11:31 +0400 |
---|---|---|
committer | Gert Driesen <drieseng@users.sourceforge.net> | 2006-04-20 12:11:31 +0400 |
commit | 48aa7d1ba589571884e5d8f30bbb05efb8fceffb (patch) | |
tree | 5f07264e535a71dfbe7c188a80388cc08bfc31b4 /mcs | |
parent | 6c5d4df0680c918dee04634f1e0da7812c7664e7 (diff) |
* UnixRegistryApi.cs: In KeyHandler.SetValue, immediately convert
instances of non-native registry types (meaning int, string, string[]
or byte[]) to string. This avoids returning an instance of a non-native
registry type in calls to UnixRegistryApi.GetValue. Allow instances of
non-native registry types in UnixRegistryApi.SetValue. Fixes bug #78132.
* RegistryKeyTest.cs: Added tests for bug #78132.
svn path=/trunk/mcs/; revision=59685
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/Microsoft.Win32/ChangeLog | 8 | ||||
-rw-r--r-- | mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs | 10 | ||||
-rw-r--r-- | mcs/class/corlib/Test/Microsoft.Win32/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs | 218 |
4 files changed, 236 insertions, 4 deletions
diff --git a/mcs/class/corlib/Microsoft.Win32/ChangeLog b/mcs/class/corlib/Microsoft.Win32/ChangeLog index 3af31d7b9a2..83bb9c1719e 100644 --- a/mcs/class/corlib/Microsoft.Win32/ChangeLog +++ b/mcs/class/corlib/Microsoft.Win32/ChangeLog @@ -1,3 +1,11 @@ +2006-04-20 Gert Driesen <drieseng@users.sourceforge.net> + + * UnixRegistryApi.cs: In KeyHandler.SetValue, immediately convert + instances of non-native registry types (meaning int, string, string[] + or byte[]) to string. This avoids returning an instance of a non-native + registry type in calls to UnixRegistryApi.GetValue. Allow instances of + non-native registry types in UnixRegistryApi.SetValue. Fixes bug #78132. + 2006-04-18 Gert Driesen <drieseng@users.sourceforge.net> * UnixRegistryApi.cs: Only consider the "software" subkey a well-known diff --git a/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs b/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs index 64cb09e37e9..6ad163173a6 100644 --- a/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs +++ b/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs @@ -223,7 +223,12 @@ namespace Microsoft.Win32 { public void SetValue (string name, object value) { - values [name] = value; + // immediately convert non-native registry values to string to avoid + // returning it unmodified in calls to UnixRegistryApi.GetValue + if (value is int || value is string || value is byte[] || value is string[]) + values[name] = value; + else + values[name] = value.ToString (); SetDirty (); } @@ -361,9 +366,6 @@ namespace Microsoft.Win32 { public void SetValue (RegistryKey rkey, string name, object value) { - if (!((value is int) || (value is string) || (value is string []) || (value is byte []))) - throw new ArgumentException ("The value is not int, string, string[] or byte[]", "value"); - KeyHandler self = KeyHandler.Lookup (rkey); self.SetValue (name, value); } diff --git a/mcs/class/corlib/Test/Microsoft.Win32/ChangeLog b/mcs/class/corlib/Test/Microsoft.Win32/ChangeLog index 6be798ad10a..605faa478e6 100644 --- a/mcs/class/corlib/Test/Microsoft.Win32/ChangeLog +++ b/mcs/class/corlib/Test/Microsoft.Win32/ChangeLog @@ -1,3 +1,7 @@ +2006-04-20 Gert Driesen <drieseng@users.sourceforge.net> + + * RegistryKeyTest.cs: Added tests for bug #78132. + 2006-04-18 Gert Driesen <drieseng@users.sourceforge.net> * RegistryKeyTest.cs: Added tests for OpenSubKey and CreateSubKey. diff --git a/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs b/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs index 035b38fb904..38b1e7f1997 100644 --- a/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs +++ b/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs @@ -94,5 +94,223 @@ namespace MonoTests.Microsoft.Win32 Registry.CurrentUser.DeleteSubKeyTree (subKeyName); } } + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void SetValue_Null () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // null value should result in ArgumentNullException + createdKey.SetValue ("Name", null); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_Boolean () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("Installed"), "#1"); + // create value + createdKey.SetValue ("Installed", true); + // get value + object value = createdKey.GetValue ("Installed"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be string + Assert.AreEqual (typeof (string), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual (true.ToString (), value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_Byte () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("Flags"), "#1"); + // create value + createdKey.SetValue ("Flags", (byte) 5); + // get value + object value = createdKey.GetValue ("Flags"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be string + Assert.AreEqual (typeof (string), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual ("5", value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_ByteArray () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("Flags"), "#1"); + // create value + createdKey.SetValue ("Flags", new byte[] { 1, 5 }); + // get value + object value = createdKey.GetValue ("Flags"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be string + Assert.AreEqual (typeof (byte[]), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual (new byte[] { 1, 5 }, value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_DateTime () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + object rawValue = DateTime.Now; + + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("Path"), "#1"); + // create value + createdKey.SetValue ("Path", rawValue); + // get value + object value = createdKey.GetValue ("Path"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be string + Assert.AreEqual (typeof (string), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual (rawValue.ToString (), value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_Int32 () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("RefCount"), "#1"); + // create value + createdKey.SetValue ("RefCount", 5); + // get value + object value = createdKey.GetValue ("RefCount"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be int + Assert.AreEqual (typeof (int), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual (5, value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_Int64 () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("Ticks"), "#1"); + // create value + createdKey.SetValue ("Ticks", 500L); + // get value + object value = createdKey.GetValue ("Ticks"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be string + Assert.AreEqual (typeof (string), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual ("500", value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_String () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("Path"), "#1"); + // create value + createdKey.SetValue ("Path", "/usr/lib/whatever"); + // get value + object value = createdKey.GetValue ("Path"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be string + Assert.AreEqual (typeof (string), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual ("/usr/lib/whatever", value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } + + [Test] + public void SetValue_StringArray () + { + string subKeyName = Guid.NewGuid ().ToString (); + + RegistryKey createdKey = Registry.CurrentUser.CreateSubKey (subKeyName); + try { + // we created a new subkey, so value should not exist + Assert.IsNull (createdKey.GetValue ("DependsOnGroup"), "#1"); + // create value + createdKey.SetValue ("DependsOnGroup", new string[] { "A", "B" }); + // get value + object value = createdKey.GetValue ("DependsOnGroup"); + // value should exist + Assert.IsNotNull (value, "#2"); + // type of value should be string + Assert.AreEqual (typeof (string[]), value.GetType (), "#3"); + // ensure value matches + Assert.AreEqual (new string[] { "A", "B" }, value, "#4"); + } finally { + // clean-up + Registry.CurrentUser.DeleteSubKeyTree (subKeyName); + } + } } } |