diff options
author | garyb <garyb@system1.(none)> | 2012-07-17 21:01:04 +0400 |
---|---|---|
committer | garyb <garyb@system1.(none)> | 2012-10-11 02:20:04 +0400 |
commit | b08f93651d879059f42aad8c8ac8543660cf3f46 (patch) | |
tree | 74a3ecc6c1c36cf71706db175e2f9776fabdd962 | |
parent | 899099ab7c2112568736ab635b309b9273240915 (diff) |
More tests, more tidying, all present currently pass
22 files changed, 697 insertions, 799 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/ByteArrayFromResXHandler.cs b/mcs/class/Managed.Windows.Forms/System.Resources/ByteArrayFromResXHandler.cs index 6798b7223c2..49406e5f455 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/ByteArrayFromResXHandler.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/ByteArrayFromResXHandler.cs @@ -50,14 +50,12 @@ namespace System.Resources { public override string GetValueTypeName (ITypeResolutionService typeResolver) { - //FIXME: what if only fullname for byte[] present? Type type = ResolveType (typeof (byte[]).AssemblyQualifiedName, typeResolver); return type.AssemblyQualifiedName; } public override string GetValueTypeName (AssemblyName[] assemblyNames) { - //FIXME: what if only fullname for byte[] present? return typeof (byte[]).AssemblyQualifiedName; } #endregion diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/FileRefHandler.cs b/mcs/class/Managed.Windows.Forms/System.Resources/FileRefHandler.cs index 0f24d14e7ed..3f7712d7d03 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/FileRefHandler.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/FileRefHandler.cs @@ -51,7 +51,6 @@ namespace System.Resources { public override string GetValueTypeName (ITypeResolutionService typeResolver) { // although params ignored by GetValue. .NET resolves the type for GetValueTypeName - // FIXME: create test to check the resXFileRef.TypeName is returned if type not resolved Type type = ResolveType (resXFileRef.TypeName, typeResolver); if (type == null) @@ -62,8 +61,6 @@ namespace System.Resources { public override string GetValueTypeName (AssemblyName[] assemblyNames) { - // although params ignored by GetValue. .NET resolves the type for GetValueTypeName - // FIXME: create test to check the resXFileRef.TypeName is returned if type not resolved Type type = ResolveType (resXFileRef.TypeName, assemblyNames); if (type == null) @@ -76,10 +73,14 @@ namespace System.Resources { private object GetValue () { TypeConverter c = TypeDescriptor.GetConverter (typeof (ResXFileRef)); + try { return c.ConvertFromInvariantString (resXFileRef.ToString ()); - } catch (Exception ex) { - throw new TypeLoadException ("Could not load object",ex); //FIXME: error message? + } catch (ArgumentNullException ex) { + if (ex.ParamName == "type") + throw new TypeLoadException ("Could not find type", ex); //FIXME: error message? + else + throw ex; } } diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNode.cs b/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNode.cs index 82d3b376892..9952a8f54bb 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNode.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNode.cs @@ -49,7 +49,7 @@ namespace System.Resources private string comment; private Point pos; - private ResXDataNodeHandler handler; + internal ResXDataNodeHandler handler; public string Comment { diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNodeHandler.cs b/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNodeHandler.cs index 293f1e15357..896ec892374 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNodeHandler.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/ResXDataNodeHandler.cs @@ -77,7 +77,6 @@ namespace System.Resources { protected Type ResolveType (string typeString, ITypeResolutionService typeResolver) { - // mono implementation previously didnt fallback to type check Type result = null; if (typeResolver != null) diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceReader.cs b/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceReader.cs index 6bd10e52dbb..c4dd5b6f4bb 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceReader.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceReader.cs @@ -40,6 +40,7 @@ using System.Runtime.Serialization.Formatters.Binary; using System.Xml; using System.Reflection; using System.Drawing; +using System.Runtime.Serialization; namespace System.Resources { @@ -184,6 +185,10 @@ namespace System.Resources } } catch (XmlException ex) { throw new ArgumentException ("Invalid ResX input.", ex); + } catch (SerializationException ex) { + throw ex; + } catch (TargetInvocationException ex) { + throw ex; } catch (Exception ex) { XmlException xex = new XmlException (ex.Message, ex, xmlReader.LineNumber, xmlReader.LinePosition); @@ -296,33 +301,29 @@ namespace System.Resources node.GetValue ((AssemblyName []) null).ToString())); // useResXDataNodes is false, add to dictionary of values - if (assemblyNames != null) - hashtable [name] = node.GetValue (assemblyNames); - else - hashtable [name] = node.GetValue (typeresolver); // saves another else - - } - - private Type ResolveType (string type) - { - if (typeresolver != null) { - return typeresolver.GetType (type); - } - if (assemblyNames != null) { - Type result; - foreach (AssemblyName assem in assemblyNames) { - Assembly myAssembly = Assembly.Load (assem); - result = myAssembly.GetType (type, false); - if (result != null) - return result; - //else loop + if (assemblyNames != null) { + try { + hashtable [name] = node.GetValue (assemblyNames); + } catch (TypeLoadException ex) { + // different error messages depending on type of resource, hacky solution + if (node.handler is TypeConverterFromResXHandler) + hashtable [name] = null; + else + throw ex; + } + } else { // there is a typeresolver or its null + try { + hashtable [name] = node.GetValue (typeresolver); + } catch (TypeLoadException ex) { + if (node.handler is TypeConverterFromResXHandler) + hashtable [name] = null; + else + throw ex; } - //if type not found on assembly list we return null or we get from current assembly? - //=> unit test needed } - return Type.GetType (type); } + #endregion // Private Methods #region Public Methods diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs b/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs index 400dd01841c..7a5b84c7bb6 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs @@ -257,7 +257,6 @@ namespace System.Resources if (value == null) { // nulls written as ResXNullRef - //throw new ArgumentNullException ("value"); WriteString (name, "", typeof (ResXNullRef), comment); //FIXME: ive included comment here return; } diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/SerializedFromResXHandler.cs b/mcs/class/Managed.Windows.Forms/System.Resources/SerializedFromResXHandler.cs index bdbf02c968e..a5684d3ed79 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/SerializedFromResXHandler.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/SerializedFromResXHandler.cs @@ -48,24 +48,30 @@ namespace System.Resources { #region implemented abstract members of System.Resources.ResXDataNodeHandler public override object GetValue (ITypeResolutionService typeResolver) { - if (retrievedObject == null) - retrievedObject = DeserializeObject (typeResolver); + if (retrievedObject == null) + retrievedObject = DeserializeObject (typeResolver); - return retrievedObject; + return retrievedObject; + } public override object GetValue (AssemblyName[] assemblyNames) { - if (retrievedObject == null) - retrievedObject = DeserializeObject ((ITypeResolutionService) null); + if (retrievedObject == null) + retrievedObject = DeserializeObject ((ITypeResolutionService) null); - return retrievedObject; + return retrievedObject; } public override string GetValueTypeName (ITypeResolutionService typeResolver) { - if (retrievedObject == null) - retrievedObject = DeserializeObject (typeResolver); + if (retrievedObject == null) { + try { + retrievedObject = DeserializeObject (typeResolver); + } catch { + return typeof (object).AssemblyQualifiedName; + } + } if (retrievedObject == null) return null; @@ -75,8 +81,13 @@ namespace System.Resources { public override string GetValueTypeName (AssemblyName[] assemblyNames) { - if (retrievedObject == null) - retrievedObject = DeserializeObject ((ITypeResolutionService) null); + if (retrievedObject == null) { + try { + retrievedObject = DeserializeObject ((ITypeResolutionService) null); + } catch { + return typeof (object).AssemblyQualifiedName; + } + } if (retrievedObject == null) return null; @@ -95,25 +106,32 @@ namespace System.Resources { object DeserializeObject (ITypeResolutionService typeResolver) { - if (mime_type == ResXResourceWriter.SoapSerializedObjectMimeType) { - //FIXME: theres a test in the suite to check that a type converter converts from invariant string - //do i need to take the string culture into consideration here? - SoapFormatter soapF = new SoapFormatter (); - soapF.Binder = new CustomBinder (typeResolver); - byte [] data = Convert.FromBase64String (dataString); - using (MemoryStream s = new MemoryStream (data)) { - return soapF.Deserialize (s); - } - } else if (mime_type == ResXResourceWriter.BinSerializedObjectMimeType) { - BinaryFormatter binF = new BinaryFormatter(); - binF.Binder = new CustomBinder (typeResolver); - - byte [] data = Convert.FromBase64String (dataString); - using (MemoryStream s = new MemoryStream (data)) { - return binF.Deserialize (s); - } - } else // invalid mime_type - return null; + try { + if (mime_type == ResXResourceWriter.SoapSerializedObjectMimeType) { + //FIXME: theres a test in the suite to check that a type converter converts from invariant string + //do i need to take the string culture into consideration here? + SoapFormatter soapF = new SoapFormatter (); + soapF.Binder = new CustomBinder (typeResolver); + byte [] data = Convert.FromBase64String (dataString); + using (MemoryStream s = new MemoryStream (data)) { + return soapF.Deserialize (s); + } + } else if (mime_type == ResXResourceWriter.BinSerializedObjectMimeType) { + BinaryFormatter binF = new BinaryFormatter(); + binF.Binder = new CustomBinder (typeResolver); + + byte [] data = Convert.FromBase64String (dataString); + using (MemoryStream s = new MemoryStream (data)) { + return binF.Deserialize (s); + } + } else // invalid mime_type + return null; + } catch (SerializationException ex) { + if (ex.Message.StartsWith ("Couldn't find assembly")) + throw new ArgumentException (ex.Message); + else + throw ex; + } } sealed class CustomBinder : SerializationBinder diff --git a/mcs/class/Managed.Windows.Forms/System.Resources/TypeConverterFromResXHandler.cs b/mcs/class/Managed.Windows.Forms/System.Resources/TypeConverterFromResXHandler.cs index 6799453b425..0d793d61191 100644 --- a/mcs/class/Managed.Windows.Forms/System.Resources/TypeConverterFromResXHandler.cs +++ b/mcs/class/Managed.Windows.Forms/System.Resources/TypeConverterFromResXHandler.cs @@ -44,9 +44,6 @@ namespace System.Resources { #region implemented abstract members of System.Resources.ResXDataNodeHandler public override object GetValue (ITypeResolutionService typeResolver) { - /*if (typeString == String.Empty || typeString == null) - return null;*/ - if (!String.IsNullOrEmpty(mime_type) && mime_type != ResXResourceWriter.ByteArraySerializedObjectMimeType) return null; @@ -64,9 +61,6 @@ namespace System.Resources { public override object GetValue (AssemblyName[] assemblyNames) { - /*if (typeString == String.Empty || typeString == null) - return null;*/ - if (!String.IsNullOrEmpty(mime_type) && mime_type != ResXResourceWriter.ByteArraySerializedObjectMimeType) return null; @@ -84,9 +78,6 @@ namespace System.Resources { public override string GetValueTypeName (ITypeResolutionService typeResolver) { - /*if (typeString == String.Empty || typeString == null) - return String.Empty;*/ - Type type = ResolveType (typeString, typeResolver); if (type == null) @@ -97,9 +88,6 @@ namespace System.Resources { public override string GetValueTypeName (AssemblyName[] assemblyNames) { - /*if (typeString == String.Empty || typeString == null) - return String.Empty;*/ - Type type = ResolveType (typeString, assemblyNames); if (type == null) @@ -119,7 +107,6 @@ namespace System.Resources { object ConvertData (TypeConverter c) { - //FIXME: throw errors when converter not found? if (mime_type == ResXResourceWriter.ByteArraySerializedObjectMimeType) { if (c.CanConvertFrom (typeof (byte []))) return c.ConvertFrom (Convert.FromBase64String (dataString)); diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources b/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources index 1c8c148f357..a18ec387a89 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources @@ -186,9 +186,7 @@ System.Resources/HelperClasses_ITRS.cs System.Resources/HelperClasses_Resources.cs System.Resources/ResourcesTestHelper.cs System.Resources/ResXDataNodeAliasTests.cs -System.Resources/ResXDataNodeAssemblyNameTests.cs System.Resources/ResXDataNodeByteArrayTests.cs -System.Resources/ResXDataNodeFileRefBitmapTests.cs System.Resources/ResXDataNodeFileRefGetValueTests.cs System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs deleted file mode 100644 index aa0598f7db7..00000000000 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs +++ /dev/null @@ -1,349 +0,0 @@ -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -// Copyright (c) 2012 Gary Barnett -// -// Authors: -// Gary Barnett - -#if NET_2_0 -using System; -using System.IO; -using System.Reflection; -using System.Resources; -using System.Runtime.Serialization; -using System.Collections; -using NUnit.Framework; -using System.ComponentModel; -using System.Globalization; - -namespace MonoTests.System.Resources { - [TestFixture] - public class ResXDataNodeAssemblyNameTests : ResourcesTestHelper { - /* - [Test] - public void CanPassAssemblyNameToGetValueToReturnSpecificVersionOfObjectClassInstance () - { - // tries to force use of 2.0 assembly but DOESNT WORK - - ResXDataNode originalNode, returnedNode; - originalNode = GetNodeEmdeddedIcon (); - string fileName = GetResXFileWithNode (originalNode, "test.resx"); - - using (ResXResourceReader reader = new ResXResourceReader (fileName)) { - reader.UseResXDataNodes = true; - - IDictionaryEnumerator enumerator = reader.GetEnumerator (); - enumerator.MoveNext (); - returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value; - - Assert.IsNotNull (returnedNode, "#A1"); - - string aName = "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - object val = returnedNode.GetValue (assemblyNames); - - //typeof(Icon).AssemblyQualifiedName - - Assert.AreEqual ("System.Drawing.Icon, " + aName, val.GetType ().AssemblyQualifiedName, "#A2"); - - //Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A2"); - } - } - - [Test] - public void CanPassAssemblyNameToGetValueTypeNameToReturnSpecificVersionOfObject () - { - // tries to force use of 2.0 assembly DOESNT WORK - returns 4.0.0.0 - - ResXDataNode originalNode, returnedNode; - originalNode = GetNodeEmdeddedIcon (); - string fileName = GetResXFileWithNode (originalNode, "test.resx"); - - using (ResXResourceReader reader = new ResXResourceReader (fileName)) { - reader.UseResXDataNodes = true; - - IDictionaryEnumerator enumerator = reader.GetEnumerator (); - enumerator.MoveNext (); - returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value; - - Assert.IsNotNull (returnedNode, "#A1"); - - string aName = "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - string returnedName = returnedNode.GetValueTypeName (assemblyNames); - - //typeof(Icon).AssemblyQualifiedName - - Assert.AreEqual ("System.Drawing.Icon, " + aName, returnedName, "#A2"); - - //Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A2"); - } - } - - [Test] - public void GetValueParamIsUsedWhenFileRefCreatedNewTRYOUT () - { - // doesnt work - - ResXDataNode node; - - node = GetNodeFileRefToSerializableWithoutQualifiedTypeName ("ser.bbb"); - - string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; - - // string aName = typeof (serializable).AssemblyQualifiedName; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - object val = node.GetValue ((AssemblyName[]) null); - - //object val = node.GetValue ((AssemblyName[]) null); - } - - */ - - [Test] - public void GetValueAssemblyNameUsedWhereOnlyFullNameInResX_TypeConverter () - { - // DummyAssembly must be in the same directory as current assembly to work correctly - string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); - - Assert.IsNotNull (node, "#A1"); - object obj = node.GetValue (assemblyNames); - Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName); - } - - [Test, ExpectedException (typeof (TypeLoadException))] - public void GetValueAssemblyNameRequiredEachTimeWhereOnlyFullNameInResX_TypeConverter () - { - // DummyAssembly must be in the same directory as current assembly to work correctly - string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); - - Assert.IsNotNull (node, "#A1"); - object obj = node.GetValue (assemblyNames); - Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2"); - object obj2 = node.GetValue ((AssemblyName []) null); //should cause exception here - - } - //FIXME: does the way this test is run by NUnit affect the validity of the results showing that you need assembly name to pull type from current assembly? - [Test, ExpectedException (typeof (TypeLoadException))] - public void CantLoadTypeFromThisAssemblyWithOnlyFullName_TypeConverter () - { - ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName); - Assert.IsNotNull (node, "#A1"); - object obj = node.GetValue ((AssemblyName []) null); - } - - [Test] - public void CanLoadTypeFromThisAssemblyWithOnlyFullNamePassingAssemblyNames_TypeConverter () - { - string aName = "System.Windows.Forms_test_net_2_0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName); - - Assert.IsNotNull (node, "#A1"); - // would cause exception if couldnt find type - object obj = node.GetValue (assemblyNames); - Assert.IsInstanceOfType (typeof (ThisAssemblyConvertable), obj, "#A2"); - } - - [Test] - public void GetValueTypeNameReturnsFullNameWereOnlyFullNameInResX_TypeConverter () - { - // just a check, if this passes other tests will give false results - ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); - - Assert.IsNotNull (node, "#A1"); - string returnedType = node.GetValueTypeName ((AssemblyName []) null); - Assert.AreEqual ("DummyAssembly.Convertable", returnedType, "#A2"); - } - - [Test] - public void GetValueTypeNameAssemblyNameUsedWhereOnlyFullNameInResX_TypeConverter () - { - // DummyAssembly must be in the same directory as current assembly to work correctly - string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); - - Assert.IsNotNull (node, "#A1"); - string returnedType = node.GetValueTypeName (assemblyNames); - Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedType, "#A2"); - } - - [Test] - public void GetValueTypeNameAssemblyNameUsedEachTimeWhereOnlyFullNameInResX_TypeConverter () - { - // DummyAssembly must be in the same directory as current assembly to work correctly - string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; - AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; - - ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); - - Assert.IsNotNull (node, "#A1"); - string returnedName = node.GetValueTypeName (assemblyNames); - Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedName, "#A2"); - string nameWithNullParam = node.GetValueTypeName ((AssemblyName []) null); - Assert.AreEqual ("DummyAssembly.Convertable", nameWithNullParam, "#A3"); - } - - [Test] - public void AssemblyAutomaticallyLoaded_Serialized_GetValue () - { - ResXDataNode node = GetNodeFromResXReader (anotherSerializableFromDummyAssembly); - Assert.IsNotNull (node, "#A1"); - object value = node.GetValue ((AssemblyName[]) null); - Assert.AreEqual ("DummyAssembly.AnotherSerializable, DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", value.GetType ().AssemblyQualifiedName, "#A2"); - } - - [Test] - public void AssemblyAutomaticallyLoaded_Serialized_GetValueTypeName () - { - ResXDataNode node = GetNodeFromResXReader (anotherSerializableFromDummyAssembly); - Assert.IsNotNull (node, "#A1"); - string type = node.GetValueTypeName ((AssemblyName []) null); - Assert.AreEqual ("DummyAssembly.AnotherSerializable, DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", type, "#A2"); - } - - [Test, ExpectedException (typeof (ArgumentException))] - public void ErrorWhenAssemblyMissing_Serialized_GetValue () - { - ResXDataNode node = GetNodeFromResXReader (missingSerializableFromMissingAssembly); - Assert.IsNotNull (node, "#A1"); - object val = node.GetValue ((AssemblyName[]) null); - } - - [Test] - public void ReturnsObjectAssemblyMissing_Serialized_GetValueTypeName () - { - ResXDataNode node = GetNodeFromResXReader (missingSerializableFromMissingAssembly); - Assert.IsNotNull (node, "#A1"); - string type = node.GetValueTypeName ((AssemblyName []) null); - Assert.AreEqual (typeof (object).AssemblyQualifiedName, type, "#A2"); - } - - static string missingSerializableFromMissingAssembly = -@"<?xml version=""1.0"" encoding=""utf-8""?> -<root> - <resheader name=""resmimetype""> - <value>text/microsoft-resx</value> - </resheader> - <resheader name=""version""> - <value>2.0</value> - </resheader> - <resheader name=""reader""> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name=""writer""> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> - <value> - AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs - dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n - U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs - dWUL -</value> - </data> -</root>"; - - static string anotherSerializableFromDummyAssembly = -@"<?xml version=""1.0"" encoding=""utf-8""?> -<root> - - <resheader name=""resmimetype""> - <value>text/microsoft-resx</value> - </resheader> - <resheader name=""version""> - <value>2.0</value> - </resheader> - <resheader name=""reader""> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name=""writer""> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> - <value> - AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1 - cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl - cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl - Cw== -</value> - </data> -</root>"; - - static string convertableResXWithoutAssemblyName = -@"<?xml version=""1.0"" encoding=""utf-8""?> -<root> - - <resheader name=""resmimetype""> - <value>text/microsoft-resx</value> - </resheader> - <resheader name=""version""> - <value>2.0</value> - </resheader> - <resheader name=""reader""> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name=""writer""> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - - <data name=""test"" type=""DummyAssembly.Convertable""> - <value>im a name im a value</value> - </data> -</root>"; - - static string thisAssemblyConvertableResXWithoutAssemblyName = - @"<?xml version=""1.0"" encoding=""utf-8""?> -<root> - - <resheader name=""resmimetype""> - <value>text/microsoft-resx</value> - </resheader> - <resheader name=""version""> - <value>2.0</value> - </resheader> - <resheader name=""reader""> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name=""writer""> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - - <data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable""> - <value>im a name im a value</value> - </data> -</root>"; - - } - -} -#endif
\ No newline at end of file diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeByteArrayTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeByteArrayTests.cs index 770a3f9b38e..32cae72d5a8 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeByteArrayTests.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeByteArrayTests.cs @@ -45,24 +45,10 @@ namespace MonoTests.System.Resources { object val = returnedNode.GetValue (new AlwaysReturnIntTypeResolutionService ()); Assert.IsInstanceOfType (typeof (byte[]), val, "#A2"); } - /* - [Test, ExpectedException (typeof (NotImplementedException))] - public void GetValueITRSIsTouchedWhenNodeReturnedFromReader () - { - ResXDataNode originalNode, returnedNode; - originalNode = GetNodeEmdeddedBytes1To10 (); - returnedNode = GetNodeFromResXReader (originalNode); - Assert.IsNotNull (returnedNode, "#A1"); - //would raise error if touched - object val = returnedNode.GetValue (new ExceptionalTypeResolutionService ()); - } - */ [Test] public void GetValueITRSNotTouchedWhenNodeCreatedNew () { - // check supplied params to GetValue are not touched - // for an instance created manually ResXDataNode node; node = GetNodeEmdeddedBytes1To10 (); @@ -99,8 +85,6 @@ namespace MonoTests.System.Resources { [Test] public void GetValueTypeNameITRSNotUsedWhenNodeCreatedNew () { - // check supplying params to GetValueType of the ResXDataNode does not change the output - // of the method for an instance created manually ResXDataNode node; node = GetNodeEmdeddedBytes1To10 (); diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefBitmapTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefBitmapTests.cs deleted file mode 100644 index 66ce9e92ef4..00000000000 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefBitmapTests.cs +++ /dev/null @@ -1,255 +0,0 @@ -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -// Copyright (c) 2012 Gary Barnett -// -// Authors: -// Gary Barnett - -/* -#if NET_2_0 -using System; -using System.IO; -using System.Reflection; -using System.Drawing; -using System.Resources; -using System.Runtime.Serialization; -using System.Collections.Generic; -using System.Collections; - -using NUnit.Framework; -using System.ComponentModel.Design; - -namespace MonoTests.System.Resources -{ - [TestFixture] - public class ResXDataNodeFileRefBitmapTests : MonoTests.System.Windows.Forms.TestHelper - { - string _tempDirectory; - string _otherTempDirectory; - - [Test, ExpectedException (typeof (NotImplementedException))] - public void GetValueParamIsTouchedWhenFileRefReturnedFromResXResourceReader () - { - // after running the enumerator of ResXResourceReader with UseResXDataNodes set - // to true, check params supplied to GetValue method - // of ResXDataNode are used to deserialise - - // for now just throwing exception in param object to ensure its accessed - - ResXDataNode originalNode, returnedNode; - - originalNode = GetNodeFileRefToBitmap (); - - string fileName = GetResXFileWithNode (originalNode); - - using (ResXResourceReader reader = new ResXResourceReader (fileName)) { - reader.UseResXDataNodes = true; - - IDictionaryEnumerator enumerator = reader.GetEnumerator (); - enumerator.MoveNext (); - returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value; - - Assert.IsNotNull (returnedNode, "#A1"); - - Bitmap ico = (Bitmap)returnedNode.GetValue (new ExceptionalTypeResolutionService ()); - - } - } - - [Test] // FIXME: i would like an valid alternative TypeResolutionService that could be used to test - public void GetValueParamIsNotUsedWhenFileRefReturnedFromResXResourceReader () - { - // after running the enumerator of ResXResourceReader with UseResXDataNodes set - // to true, check params supplied to GetValue method - // of ResXDataNode are used to deserialise - - ResXDataNode originalNode, returnedNode; - - originalNode = GetNodeFileRefToBitmap (); - - string fileName = GetResXFileWithNode (originalNode); - - using (ResXResourceReader reader = new ResXResourceReader (fileName)) { - reader.UseResXDataNodes = true; - - IDictionaryEnumerator enumerator = reader.GetEnumerator (); - enumerator.MoveNext (); - returnedNode = (ResXDataNode)((DictionaryEntry)enumerator.Current).Value; - - Assert.IsNotNull (returnedNode, "#A1"); - - object val = returnedNode.GetValue (new AlwaysReturnIntTypeResolutionService ()); - - Assert.IsInstanceOfType (typeof (Bitmap),val, "#A2"); - } - } - - [Test] - public void GetValueTypeParamIsUsedWhenFileRefReturnedFromResXResourceReader () - { - // after running the enumerator of ResXResourceReader with UseResXDataNodes set - // to true, check supplying params GetValueType of the - // ResXDataNode changes the output of the method - - ResXDataNode originalNode, returnedNode; - - originalNode = GetNodeFileRefToBitmap (); - - string fileName = GetResXFileWithNode (originalNode); - - using (ResXResourceReader reader = new ResXResourceReader (fileName)) { - reader.UseResXDataNodes = true; - - IDictionaryEnumerator enumerator = reader.GetEnumerator (); - enumerator.MoveNext (); - returnedNode = (ResXDataNode)((DictionaryEntry)enumerator.Current).Value; - - Assert.IsNotNull (returnedNode, "#A1"); - - string returnedType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ()); - - Assert.AreEqual ((typeof (Int32)).AssemblyQualifiedName, returnedType, "#A2"); - } - } - - [Test] - public void GetValueTypeParamIsUsedWhenFileRefCreatedNew () - { - // check supplying params GetValueType of the - // UseResXDataNode does not change the output of the method for an instance - // initialised by me - - ResXDataNode node; - - node = GetNodeFileRefToBitmap (); - - string returnedType = node.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ()); - - Assert.AreEqual ((typeof (Int32)).AssemblyQualifiedName, returnedType, "#A1"); - } - - [Test, ExpectedException (typeof (NotImplementedException))] - public void GetValueParamIsTouchedWhenFileRefCreatedNew () - { - // check supplying params GetValue of the - // UseResXDataNode is ignored for an instance - // initialised by me - - ResXDataNode node; - - node = GetNodeFileRefToBitmap (); - - //raise exception if param used - Bitmap ico = (Bitmap)node.GetValue (new ExceptionalTypeResolutionService ()); - - } - - [Test] // FIXME: i would like an valid alternative TypeResolutionService that could be used to test - public void GetValueParamIsNotUsedWhenFileRefCreatedNew () - { - // after running the enumerator of ResXResourceReader with UseResXDataNodes set - // to true, check params supplied to GetValue method - // of ResXDataNode are used to deserialise - - ResXDataNode node; - - node = GetNodeFileRefToBitmap (); - - object val = node.GetValue (new AlwaysReturnIntTypeResolutionService ()); - - Assert.IsInstanceOfType (typeof (Bitmap), val, "#A2"); - - } - - [TearDown] - protected override void TearDown () - { - //teardown - if (Directory.Exists (_tempDirectory)) - Directory.Delete (_tempDirectory, true); - - base.TearDown (); - } - - string GetResXFileWithNode (ResXDataNode node) - { - string fileName; - - _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest"); - _otherTempDirectory = Path.Combine (_tempDirectory, "in"); - if (!Directory.Exists (_otherTempDirectory)) { - Directory.CreateDirectory (_otherTempDirectory); - } - - fileName = Path.Combine (_tempDirectory, "myresx.resx"); - - using (ResXResourceWriter writer = new ResXResourceWriter (fileName)) { - writer.AddResource (node); - } - - return fileName; - } - - ResXDataNode GetNodeFileRefToBitmap () - { - _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest"); - _otherTempDirectory = Path.Combine (_tempDirectory, "in"); - if (!Directory.Exists (_otherTempDirectory)) { - Directory.CreateDirectory (_otherTempDirectory); - } - - string refFile = Path.Combine (_tempDirectory, "a.cur"); - WriteEmbeddedResource ("a.cur", refFile); - - ResXFileRef fileRef = new ResXFileRef (refFile, typeof (Bitmap).AssemblyQualifiedName); - ResXDataNode node = new ResXDataNode ("test", fileRef); - - return node; - } - - private static void WriteEmbeddedResource (string name, string filename) - { - const int size = 512; - byte[] buffer = new byte[size]; - int count = 0; - - Stream input = typeof (ResXDataNodeTest).Assembly. - GetManifestResourceStream (name); - Stream output = File.Open (filename, FileMode.Create); - - try - { - while ((count = input.Read (buffer, 0, size)) > 0) - { - output.Write (buffer, 0, count); - } - } - finally - { - output.Close (); - } - } - - } - -} -#endif - -*/
\ No newline at end of file diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs index 268c959a596..394f89d9ff6 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs @@ -36,26 +36,9 @@ using System.Runtime.Serialization.Formatters.Binary; namespace MonoTests.System.Resources { [TestFixture] public class ResXDataNodeFileRefGetValueTests : ResourcesTestHelper { - /* - [Test, ExpectedException (typeof (NotImplementedException))] - public void ITRSTouchedWhenNodeFromReader () - { - // for a node returned from ResXResourceReader with FileRef, - // check params supplied to GetValue method of ResXDataNode are touched - ResXDataNode originalNode, returnedNode; - originalNode = GetNodeFileRefToSerializable ("ser.bbb",true); - returnedNode = GetNodeFromResXReader (originalNode); - - Assert.IsNotNull (returnedNode, "#A1"); - // raises error if touched - Icon ico = (Icon) returnedNode.GetValue (new ExceptionalTypeResolutionService ()); - } - */ [Test] public void ITRSNotUsedWhenNodeFromReader () { - // for a node returned from reader with a FileRef, - // check ITRS supplied to GetValue method not actually used ResXDataNode originalNode, returnedNode; originalNode = GetNodeFileRefToSerializable ("ser.bbb",true); returnedNode = GetNodeFromResXReader (originalNode); @@ -91,24 +74,10 @@ namespace MonoTests.System.Resources { Assert.IsNotNull (returnedNode, "#A1"); object obj = returnedNode.GetValue (assemblyNames); } - /* - [Test, ExpectedException (typeof (NotImplementedException))] - public void ITRSTouchedWhenNodeCreatedNew () - { - // check supplyied params to GetValue of the ResXDataNode are touched for - // an instance initialised by me - ResXDataNode node; - node = GetNodeFileRefToSerializable ("ser.bbb",true); - //raises exception if param touched - Object obj = node.GetValue (new ExceptionalTypeResolutionService ()); - } - */ [Test] public void ITRSNotUsedWhenNodeCreatedNew () { - // check supplyied params to GetValue of the ResXDataNode are not used for - // an instance initialised by me ResXDataNode node; node = GetNodeFileRefToSerializable ("ser.bbb",true); @@ -117,7 +86,18 @@ namespace MonoTests.System.Resources { Assert.IsInstanceOfType (typeof (serializable), val, "#A2"); } - #region Initial Exploratory Tests + [Test, ExpectedException (typeof (TargetInvocationException))] + public void LoadingFileFails () + { + string corruptFile = Path.GetTempFileName (); + ResXFileRef fileRef = new ResXFileRef (corruptFile, typeof (serializable).AssemblyQualifiedName); + + File.AppendAllText (corruptFile, "corrupt"); + ResXDataNode node = new ResXDataNode ("aname", fileRef); + node.GetValue ((AssemblyName []) null); + } + + #region initial [Test] public void ResXFileRefNullAssemblyNamesOK () diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs index ad154a07183..9c1f44cabeb 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs @@ -67,8 +67,6 @@ namespace MonoTests.System.Resources { [Test] public void ITRSUsedWhenNodeFromReader () { - // for a node returned from ResXResourceReader, check supplying params to - // GetValueTypeName changes the output of the method ResXDataNode originalNode, returnedNode; originalNode = GetNodeFileRefToSerializable ("ser.bbb",true); returnedNode = GetNodeFromResXReader (originalNode); @@ -81,9 +79,6 @@ namespace MonoTests.System.Resources { [Test] public void ITRSUsedWhenNodeCreatedNew () { - // check supplying params GetValueTypeName of the - // UseResXDataNode does the output of the method for an instance - // initialised manually ResXDataNode node; node = GetNodeFileRefToSerializable ("ser.bbb",true); diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs index 7473c761111..0bf22aba742 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs @@ -69,8 +69,6 @@ namespace MonoTests.System.Resources { [Test] public void ITRSNotUsedWhenNodeCreatedNew () { - // check supplying params to GetValueType of the UseResXDataNode does not change the output - // of the method for an instance created manually ResXDataNode node; node = GetNodeEmdeddedSerializable (); @@ -79,19 +77,6 @@ namespace MonoTests.System.Resources { } [Test] - public void ITRSNotTouchedWhenNodeCreatedNew () - { - // check supplied params to GetValueType of the UseResXDataNode are not touched - // for an instance created manually - ResXDataNode node; - node = GetNodeEmdeddedSerializable (); - - // would raise exception if accessed - string returnedType = node.GetValueTypeName (new ExceptionalTypeResolutionService ()); - //Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, returnedType, "#A1"); - } - - [Test] public void ITRSIsIgnoredIfGetValueAlreadyCalledWithAnotherITRS () { // check that first call to GetValue sets the type for GetValueTypeName @@ -140,6 +125,25 @@ namespace MonoTests.System.Resources { Assert.IsNull (type, "#A2"); } + [Test] + public void AssemblyAutomaticallyLoaded () + { + // DummyAssembly must be in the same directory as current assembly to work correctly + ResXDataNode node = GetNodeFromResXReader (anotherSerializableFromDummyAssembly); + Assert.IsNotNull (node, "#A1"); + string type = node.GetValueTypeName ((AssemblyName []) null); + Assert.AreEqual ("DummyAssembly.AnotherSerializable, DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", type, "#A2"); + } + + [Test] + public void ReturnsObjectAssemblyMissing () + { + ResXDataNode node = GetNodeFromResXReader (missingSerializableFromMissingAssembly); + Assert.IsNotNull (node, "#A1"); + string type = node.GetValueTypeName ((AssemblyName []) null); + Assert.AreEqual (typeof (object).AssemblyQualifiedName, type, "#A2"); + } + static string serializedResXInvalidMimeType = @"<?xml version=""1.0"" encoding=""utf-8""?> <root> @@ -223,6 +227,102 @@ namespace MonoTests.System.Resources { </value> </data> </root>"; + + static string missingSerializableFromMissingAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs + dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n + U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs + dWUL +</value> + </data> +</root>"; + + static string anotherSerializableFromDummyAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1 + cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl + cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl + Cw== +</value> + </data> +</root>"; + + static string convertableResXWithoutAssemblyName = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""DummyAssembly.Convertable""> + <value>im a name im a value</value> + </data> +</root>"; + + static string thisAssemblyConvertableResXWithoutAssemblyName = + @"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable""> + <value>im a name im a value</value> + </data> +</root>"; + } } diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerializedGetValueTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerializedGetValueTests.cs index 5afd7163088..442d6f4024b 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerializedGetValueTests.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerializedGetValueTests.cs @@ -73,7 +73,6 @@ namespace MonoTests.System.Resources { { // check although calls subsequent to an ITRS being supplied to GetValue return that resolved type // when the node is written back using ResXResourceWriter it uses the original type - ResXDataNode originalNode, returnedNode, finalNode; originalNode = GetNodeEmdeddedSerializable (); @@ -142,6 +141,37 @@ namespace MonoTests.System.Resources { Assert.IsNull (val, "#A2"); } + [Test] + public void SoapFormattedObject () + { + ResXDataNode node = GetNodeFromResXReader (serializedResXSOAP); + + Assert.IsNotNull (node, "#A1"); + object val = node.GetValue ((AssemblyName []) null); + Assert.IsInstanceOfType (typeof (serializable), val, "#A2"); + serializable ser = (serializable) val; + Assert.AreEqual ("aname", ser.name, "#A3"); + Assert.AreEqual ("avalue", ser.value, "#A4"); + } + + [Test] + public void AssemblyAutomaticallyLoaded () + { + // DummyAssembly must be in the same directory as current assembly to work correctly + ResXDataNode node = GetNodeFromResXReader (anotherSerializableFromDummyAssembly); + Assert.IsNotNull (node, "#A1"); + object value = node.GetValue ((AssemblyName[]) null); + Assert.AreEqual ("DummyAssembly.AnotherSerializable, DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", value.GetType ().AssemblyQualifiedName, "#A2"); + } + + [Test, ExpectedException (typeof (ArgumentException))] + public void ErrorWhenAssemblyMissing () + { + ResXDataNode node = GetNodeFromResXReader (missingSerializableFromMissingAssembly); + Assert.IsNotNull (node, "#A1"); + object val = node.GetValue ((AssemblyName[]) null); + } + static string serializedResXInvalidMimeType = @"<?xml version=""1.0"" encoding=""utf-8""?> <root> @@ -235,19 +265,101 @@ namespace MonoTests.System.Resources { </value> </data> </root>"; + + static string missingSerializableFromMissingAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs + dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n + U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs + dWUL +</value> + </data> +</root>"; - [Test] - public void SoapFormattedObject () - { - ResXDataNode node = GetNodeFromResXReader (serializedResXSOAP); + static string anotherSerializableFromDummyAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1 + cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl + cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl + Cw== +</value> + </data> +</root>"; - Assert.IsNotNull (node, "#A1"); - object val = node.GetValue ((AssemblyName []) null); - Assert.IsInstanceOfType (typeof (serializable), val, "#A2"); - serializable ser = (serializable) val; - Assert.AreEqual ("aname", ser.name, "#A3"); - Assert.AreEqual ("avalue", ser.value, "#A4"); - } + static string convertableResXWithoutAssemblyName = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""DummyAssembly.Convertable""> + <value>im a name im a value</value> + </data> +</root>"; + + static string thisAssemblyConvertableResXWithoutAssemblyName = + @"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable""> + <value>im a name im a value</value> + </data> +</root>"; } } diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTest.cs index d54542295d9..d0c3fa3f55a 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTest.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTest.cs @@ -301,7 +301,6 @@ namespace MonoTests.System.Resources { [Test] public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter () { - ResXDataNode dn = new ResXDataNode ("test", 34L); string resXFile = GetResXFileWithNode (dn,"resx.resx"); @@ -326,7 +325,6 @@ namespace MonoTests.System.Resources { [Test] public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_Serializable () { - serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); @@ -351,7 +349,6 @@ namespace MonoTests.System.Resources { [Test] public void ITRSPassedToResourceReaderAffectsDictionary_Serializable () { - serializable ser = new serializable ("aaaaa", "bbbbb"); ResXDataNode dn = new ResXDataNode ("test", ser); @@ -374,7 +371,6 @@ namespace MonoTests.System.Resources { [Test] public void ITRSPassedToResourceReaderAffectsDictionary_TypeConverter () { - ResXDataNode dn = new ResXDataNode ("test", 34L); string resXFile = GetResXFileWithNode (dn,"resx.resx"); diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTests.cs index 9a322b030cb..11cfd7d9df0 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTests.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTests.cs @@ -39,8 +39,6 @@ namespace MonoTests.System.Resources [Test] public void ITRSNotUsedWhenCreatedNew () { - // check supplying params to GetValue of the UseResXDataNode does not change the output - // of the method for an instance created manually ResXDataNode node; node = new ResXDataNode ("along", 34L); @@ -51,8 +49,6 @@ namespace MonoTests.System.Resources [Test] public void ITRSUsedEachTimeWithNodeFromReader () { - // check GetValue uses ITRS param each time its called for a node from a ResXResourceReader - // for an object stored by means of a typeconverter, ResXDataNode returnedNode, originalNode; originalNode = new ResXDataNode ("aNumber", 23L); returnedNode = GetNodeFromResXReader (originalNode); @@ -66,23 +62,6 @@ namespace MonoTests.System.Resources Assert.AreEqual (typeof (long).AssemblyQualifiedName, origVal.GetType ().AssemblyQualifiedName, "#A3"); } - [Test, ExpectedException (typeof (NotImplementedException))] - public void GetValueParamIsTouchedWhenEmbeddedReturnedFromResXResourceReader () - { - // after running the enumerator of ResXResourceReader with UseResXDataNodes set - // to true, check params supplied to GetValue method - // of ResXDataNode are used to deserialise - // for now just throwing exception in param object to ensure its accessed - ResXDataNode originalNode, returnedNode; - - originalNode = GetNodeEmdeddedIcon (); - returnedNode = GetNodeFromResXReader (originalNode); - - Assert.IsNotNull (returnedNode, "#A1"); - // should raise error - Icon ico = (Icon)returnedNode.GetValue (new ExceptionalTypeResolutionService ()); - } - [Test] public void InvalidMimeTypeAndTypeReturnedFromReader_ObjectIsNull () { @@ -100,6 +79,58 @@ namespace MonoTests.System.Resources object obj = node.GetValue ((AssemblyName []) null); } + [Test] + public void AssemblyNameUsedWhereOnlyFullNameInResX () + { + // DummyAssembly must be in the same directory as current assembly to work correctly + string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; + AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; + + ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); + + Assert.IsNotNull (node, "#A1"); + object obj = node.GetValue (assemblyNames); + Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName); + } + + [Test, ExpectedException (typeof (TypeLoadException))] + public void AssemblyNameRequiredEachTimeWhereOnlyFullNameInResX () + { + // DummyAssembly must be in the same directory as current assembly to work correctly + string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; + AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; + + ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); + + Assert.IsNotNull (node, "#A1"); + object obj = node.GetValue (assemblyNames); + Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2"); + object obj2 = node.GetValue ((AssemblyName []) null); //should cause exception here + + } + //FIXME: does the way this test is run by NUnit affect the validity of the results showing that you need assembly name to pull type from current assembly? + [Test, ExpectedException (typeof (TypeLoadException))] + public void CantLoadTypeFromThisAssemblyWithOnlyFullName () + { + ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName); + Assert.IsNotNull (node, "#A1"); + object obj = node.GetValue ((AssemblyName []) null); + } + + [Test] + public void CanLoadTypeFromThisAssemblyWithOnlyFullNamePassingAssemblyNames () + { + string aName = "System.Windows.Forms_test_net_2_0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; + + ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName); + + Assert.IsNotNull (node, "#A1"); + // would cause exception if couldnt find type + object obj = node.GetValue (assemblyNames); + Assert.IsInstanceOfType (typeof (ThisAssemblyConvertable), obj, "#A2"); + } + static string typeconResXInvalidType = @"<?xml version=""1.0"" encoding=""utf-8""?> <root> @@ -142,6 +173,101 @@ namespace MonoTests.System.Resources </data> </root>"; + static string missingSerializableFromMissingAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs + dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n + U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs + dWUL +</value> + </data> +</root>"; + + static string anotherSerializableFromDummyAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1 + cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl + cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl + Cw== +</value> + </data> +</root>"; + + static string convertableResXWithoutAssemblyName = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""DummyAssembly.Convertable""> + <value>im a name im a value</value> + </data> +</root>"; + + static string thisAssemblyConvertableResXWithoutAssemblyName = + @"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable""> + <value>im a name im a value</value> + </data> +</root>"; + #region initial [Test] diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTypeNameTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTypeNameTests.cs index 8e888cce905..599aa6da925 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTypeNameTests.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTypeNameTests.cs @@ -39,8 +39,6 @@ namespace MonoTests.System.Resources [Test] public void ITRSUsedWithNodeFromReader () { - // for node returned from ResXResourceReader for an object stored by means of a typeconverter, - // check supplying ITRS changes output of method ResXDataNode returnedNode, originalNode; originalNode = new ResXDataNode ("aNumber", 23L); returnedNode = GetNodeFromResXReader (originalNode); @@ -53,8 +51,6 @@ namespace MonoTests.System.Resources [Test] public void ITRSUsedEachTimeWhenNodeFromReader () { - // for node returned from ResXResourceReader for an object stored by means of a typeconverter, - // check supplied ITRS changes output each time ResXDataNode returnedNode, originalNode; originalNode = new ResXDataNode ("aNumber", 23L); returnedNode = GetNodeFromResXReader (originalNode); @@ -64,14 +60,11 @@ namespace MonoTests.System.Resources Assert.AreEqual (typeof (int).AssemblyQualifiedName, newType, "#A2"); string origType = returnedNode.GetValueTypeName ((ITypeResolutionService) null); Assert.AreEqual (typeof (long).AssemblyQualifiedName, origType, "#A3"); - } [Test] public void ITRSNotUsedWhenNodeCreatedNew () { - // check supplying params to GetValueTypeName of the UseResXDataNode does not change the output - // of the method for an instance created manually ResXDataNode node; node = new ResXDataNode ("along", 34L); @@ -97,6 +90,46 @@ namespace MonoTests.System.Resources Assert.AreEqual (typeof (string).AssemblyQualifiedName, type, "#A2"); } + [Test] + public void ReturnsFullNameWereOnlyFullNameInResX () + { + ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); + + Assert.IsNotNull (node, "#A1"); + string returnedType = node.GetValueTypeName ((AssemblyName []) null); + Assert.AreEqual ("DummyAssembly.Convertable", returnedType, "#A2"); + } + + [Test] + public void AssemblyNameUsedWhereOnlyFullNameInResX () + { + // DummyAssembly must be in the same directory as current assembly to work correctly + string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; + AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; + + ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); + + Assert.IsNotNull (node, "#A1"); + string returnedType = node.GetValueTypeName (assemblyNames); + Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedType, "#A2"); + } + + [Test] + public void AssemblyNameUsedEachTimeWhereOnlyFullNameInResX () + { + // DummyAssembly must be in the same directory as current assembly to work correctly + string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; + AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) }; + + ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName); + + Assert.IsNotNull (node, "#A1"); + string returnedName = node.GetValueTypeName (assemblyNames); + Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedName, "#A2"); + string nameWithNullParam = node.GetValueTypeName ((AssemblyName []) null); + Assert.AreEqual ("DummyAssembly.Convertable", nameWithNullParam, "#A3"); + } + static string typeconResXInvalidMimeTypeAndType = @"<?xml version=""1.0"" encoding=""utf-8""?> <root> @@ -139,6 +172,102 @@ namespace MonoTests.System.Resources </data> </root>"; + + static string missingSerializableFromMissingAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs + dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n + U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs + dWUL +</value> + </data> +</root>"; + + static string anotherSerializableFromDummyAssembly = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1 + cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl + cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl + Cw== +</value> + </data> +</root>"; + + static string convertableResXWithoutAssemblyName = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""DummyAssembly.Convertable""> + <value>im a name im a value</value> + </data> +</root>"; + + static string thisAssemblyConvertableResXWithoutAssemblyName = + @"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + + <data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable""> + <value>im a name im a value</value> + </data> +</root>"; + #region initial [Test] diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs index 4e40b6ee031..258c0e3d9cb 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs @@ -60,7 +60,7 @@ namespace MonoTests.System.Resources { [Test, ExpectedException (typeof (ArgumentException))] public void FileRefIsLoaded () { - // .NET does instantiate the encoding until the write, as exception not thrown until write + // .NET doesnt instantiate the encoding until the write ResXDataNode node = GetNodeFromResXReader (fileRefResXCorrupted); Assert.IsNotNull (node, "#A1"); // would cause error if object loaded diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXResourceReaderTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXResourceReaderTest.cs index 13eab8670b5..959ffef4659 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXResourceReaderTest.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXResourceReaderTest.cs @@ -15,6 +15,7 @@ using System.Resources; using System.Text; using System.Windows.Forms; using System.Xml; +using System.Runtime.Serialization; using NUnit.Framework; using System.Reflection; @@ -1721,13 +1722,13 @@ namespace MonoTests.System.Resources { " <data name=\"Data\" mimetype=\"application/x-microsoft.net.object.bytearray.base64\">" + " <value>Random Thoughts</value>" + " </data>" + - " <data name=\"Foo\" type=\"System.Windows.Forms.Application, {1}\">" + + /*s*/" <data name=\"Foo\" type=\"System.Windows.Forms.Application, {1}\">" + " <value>A B C</value>" + " </data>" + " <data name=\"Image\" type=\"{2}\">" + " <value>Summer.jpg</value>" + " </data>" + - " <data name=\"Text\">" + + /*e*/" <data name=\"Text\">" + " <value>OK</value>" + " </data>" + " <data name=\"Unknown\" mimetype=\"application/xxx\">" + @@ -1736,10 +1737,10 @@ namespace MonoTests.System.Resources { " <data name=\"Wrong\" typeof=\"{2}\" mimetype=\"application/xxx\">" + " <value>SuperUnknown</value>" + " </data>" + - " <data name=\"Xtra\" type=\"System.Windows.Forms.AnchorStyles, {1}\" mimetype=\"application/x-microsoft.net.object.bytearray.base64\">" + + /*s*/" <data name=\"Xtra\" type=\"System.Windows.Forms.AnchorStyles, {1}\" mimetype=\"application/x-microsoft.net.object.bytearray.base64\">" + " <value>LeftRight</value>" + " </data>" + - "</root>", + /*e*/"</root>", ResXResourceWriter.ResMimeType, Consts.AssemblySystem_Windows_Forms, typeof (Bitmap).AssemblyQualifiedName, typeof (byte []).AssemblyQualifiedName); @@ -1824,6 +1825,85 @@ namespace MonoTests.System.Resources { } } + [Test, ExpectedException (typeof (SerializationException))] + public void DeSerializationErrorBubbles () + { + using (StringReader sr = new StringReader (serializedResXCorruped)) { + using (ResXResourceReader r = new ResXResourceReader (sr)) { + IDictionaryEnumerator enumerator = r.GetEnumerator (); + // should throw exception + } + } + } + + [Test, ExpectedException (typeof (TargetInvocationException))] + public void FileRef_DeserializationFails () + { + string corruptFile = Path.GetTempFileName (); + ResXFileRef fileRef = new ResXFileRef (corruptFile, typeof (serializable).AssemblyQualifiedName); + + File.AppendAllText (corruptFile,"corrupt"); + + StringBuilder sb = new StringBuilder(); + using (StringWriter sw = new StringWriter (sb)) { + using (ResXResourceWriter writer = new ResXResourceWriter (sw)) { + writer.AddResource ("test", fileRef); + } + } + + using (StringReader sr = new StringReader (sb.ToString ())) { + using (ResXResourceReader reader = new ResXResourceReader (sr)) { + reader.GetEnumerator (); + } + } + } + + [Test, ExpectedException (typeof (ArgumentException))] + public void FileRef_TypeCantBeResolved () + { + string aFile = Path.GetTempFileName (); + ResXFileRef fileRef = new ResXFileRef (aFile, "a.type.doesnt.exist"); + + StringBuilder sb = new StringBuilder (); + using (StringWriter sw = new StringWriter (sb)) { + using (ResXResourceWriter writer = new ResXResourceWriter (sw)) { + writer.AddResource ("test", fileRef); + } + } + + using (StringReader sr = new StringReader (sb.ToString ())) { + using (ResXResourceReader reader = new ResXResourceReader (sr)) { + reader.GetEnumerator (); + } + } + } + + static string serializedResXCorruped = +@"<?xml version=""1.0"" encoding=""utf-8""?> +<root> + + <resheader name=""resmimetype""> + <value>text/microsoft-resx</value> + </resheader> + <resheader name=""version""> + <value>2.0</value> + </resheader> + <resheader name=""reader""> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name=""writer""> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <data name=""test"" mimetype=""application/x-microsoft.net.object.binary.base64""> + <value> + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +</value> + </data> +</root>"; + private static void WriteEmbeddedResource (string name, string filename) { const int size = 512; diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs index 338445114cb..a8746ea4242 100644 --- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs +++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs @@ -160,7 +160,6 @@ namespace MonoTests.System.Resources { stream.Close (); } - [TearDown] protected virtual void TearDown () { |