Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgaryb <garyb@system1.(none)>2012-07-12 20:56:39 +0400
committergaryb <garyb@system1.(none)>2012-10-11 02:20:03 +0400
commit03655fa4a892a07056f5369b4d552edcc71cd514 (patch)
tree4b29929e096281fc44e0e80e04d716537ec547f8 /mcs/class/Managed.Windows.Forms/Test
parent6d447963ad7f08ff167007352bf9c9a3c27cdce2 (diff)
ResXDataNode test refactoring, few more member tests.
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/Test')
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_ITRS.cs155
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_Resources.cs165
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAliasTests.cs193
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs273
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeByteArrayTests.cs210
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs168
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs139
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs269
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerializedGetValueTests.cs243
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTest.cs878
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTests.cs185
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTypeNameTests.cs133
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs453
-rw-r--r--mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs156
14 files changed, 1900 insertions, 1720 deletions
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_ITRS.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_ITRS.cs
new file mode 100644
index 00000000000..c22a527844e
--- /dev/null
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_ITRS.cs
@@ -0,0 +1,155 @@
+using System;
+using System.ComponentModel.Design;
+using System.Reflection;
+
+namespace MonoTests.System.Resources {
+ public class DummyTypeResolutionService : ITypeResolutionService {
+ public Assembly GetAssembly (AssemblyName name, bool throwOnError)
+ {
+ return null;
+ }
+
+ public Assembly GetAssembly (AssemblyName name)
+ {
+ return null;
+ }
+
+ public string GetPathOfAssembly (AssemblyName name)
+ {
+ return null;
+ }
+
+ public Type GetType (string name, bool throwOnError, bool ignoreCase)
+ {
+ return null;
+ }
+
+ public Type GetType (string name, bool throwOnError)
+ {
+ return null;
+ }
+
+ public Type GetType (string name)
+ {
+ return null;
+ }
+
+ public void ReferenceAssembly (AssemblyName name)
+ {
+
+ }
+ }
+
+ public class AlwaysReturnSerializableSubClassTypeResolutionService : ITypeResolutionService {
+ public Assembly GetAssembly (AssemblyName name, bool throwOnError)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Assembly GetAssembly (AssemblyName name)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public string GetPathOfAssembly (AssemblyName name)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Type GetType (string name, bool throwOnError, bool ignoreCase)
+ {
+ return typeof (serializableSubClass);
+ }
+
+ public Type GetType (string name, bool throwOnError)
+ {
+ return typeof (serializableSubClass);
+ }
+
+ public Type GetType (string name)
+ {
+ return typeof (serializableSubClass);
+ }
+
+ public void ReferenceAssembly (AssemblyName name)
+ {
+
+ }
+
+ }
+
+ public class AlwaysReturnIntTypeResolutionService : ITypeResolutionService {
+ public Assembly GetAssembly (AssemblyName name, bool throwOnError)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Assembly GetAssembly (AssemblyName name)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public string GetPathOfAssembly (AssemblyName name)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Type GetType (string name, bool throwOnError, bool ignoreCase)
+ {
+ return typeof (Int32);
+ }
+
+ public Type GetType (string name, bool throwOnError)
+ {
+ return typeof (Int32);
+ }
+
+ public Type GetType (string name)
+ {
+ return typeof (Int32);
+ }
+
+ public void ReferenceAssembly (AssemblyName name)
+ {
+
+ }
+ }
+
+ public class ExceptionalTypeResolutionService : ITypeResolutionService {
+ public Assembly GetAssembly (AssemblyName name, bool throwOnError)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Assembly GetAssembly (AssemblyName name)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public string GetPathOfAssembly (AssemblyName name)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Type GetType (string name, bool throwOnError, bool ignoreCase)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Type GetType (string name, bool throwOnError)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public Type GetType (string name)
+ {
+ throw new NotImplementedException ("I was accessed");
+ }
+
+ public void ReferenceAssembly (AssemblyName name)
+ {
+
+ }
+ }
+
+}
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_Resources.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_Resources.cs
new file mode 100644
index 00000000000..ed596289b1b
--- /dev/null
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/HelperClasses_Resources.cs
@@ -0,0 +1,165 @@
+using System;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.ComponentModel;
+using System.Globalization;
+using System.IO;
+
+namespace MonoTests.System.Resources {
+ class notserializable {
+ public object test;
+ public notserializable ()
+ {
+
+ }
+ }
+
+ [SerializableAttribute]
+ public class serializable : ISerializable {
+ public string name;
+ public string value;
+
+ public serializable ()
+ {
+ }
+
+ public serializable (string name, string value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ public serializable (SerializationInfo info, StreamingContext ctxt)
+ {
+ name = (string) info.GetValue ("sername", typeof (string));
+ value = (String) info.GetValue ("servalue", typeof (string));
+ }
+
+ public serializable (Stream stream)
+ {
+ BinaryFormatter bFormatter = new BinaryFormatter ();
+ serializable deser = (serializable) bFormatter.Deserialize (stream);
+ stream.Close ();
+
+ name = deser.name;
+ value = deser.value;
+ }
+
+ public void GetObjectData (SerializationInfo info, StreamingContext ctxt)
+ {
+ info.AddValue ("sername", name);
+ info.AddValue ("servalue", value);
+ }
+
+ public override string ToString ()
+ {
+ return String.Format ("name={0};value={1}", this.name, this.value);
+ }
+
+ public override bool Equals (object obj)
+ {
+ serializable o = obj as serializable;
+ if (o == null)
+ return false;
+ return this.name.Equals (o.name) && this.value.Equals (o.value);
+ }
+ }
+
+ [SerializableAttribute]
+ public class serializableSubClass : serializable {
+ public serializableSubClass ()
+ {
+ }
+
+ public serializableSubClass (SerializationInfo info, StreamingContext ctxt)
+ : base (info, ctxt)
+ {
+ }
+
+ public serializableSubClass (Stream stream)
+ {
+ BinaryFormatter bFormatter = new BinaryFormatter ();
+ serializableSubClass deser = (serializableSubClass) bFormatter.Deserialize (stream);
+ stream.Close ();
+
+ name = deser.name;
+ value = deser.value;
+ }
+ }
+
+ [SerializableAttribute]
+ [TypeConverter (typeof (ThisAssemblyConvertableConverter))]
+ public class ThisAssemblyConvertable {
+ protected string name;
+ protected string value;
+
+ public ThisAssemblyConvertable ()
+ {
+ }
+
+ public ThisAssemblyConvertable (string name, string value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ public void GetObjectData (SerializationInfo info, StreamingContext ctxt)
+ {
+ info.AddValue ("sername", name);
+ info.AddValue ("servalue", value);
+ }
+
+ public override string ToString ()
+ {
+ return String.Format ("{0}\t{1}", name, value);
+ }
+
+ public override bool Equals (object obj)
+ {
+ ThisAssemblyConvertable o = obj as ThisAssemblyConvertable;
+ if (o == null)
+ return false;
+ return this.name.Equals (o.name) && this.value.Equals (o.value);
+ }
+ }
+
+ class ThisAssemblyConvertableConverter : TypeConverter {
+ public ThisAssemblyConvertableConverter ()
+ {
+ }
+
+ public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
+ {
+ return sourceType == typeof (string);
+ }
+
+ public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
+ {
+ return destinationType == typeof (string);
+ }
+
+ public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ if (value.GetType () != typeof (string))
+ throw new Exception ("value not string");
+
+ string serialised = (string) value;
+
+ string [] parts = serialised.Split ('\t');
+
+ if (parts.Length != 2)
+ throw new Exception ("string in incorrect format");
+
+ ThisAssemblyConvertable convertable = new ThisAssemblyConvertable (parts [0], parts [1]);
+ return convertable;
+ }
+
+ public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
+ if (destinationType != typeof (String)) {
+ return base.ConvertTo (context, culture, value, destinationType);
+ }
+
+ return ((ThisAssemblyConvertable) value).ToString ();
+ }
+ }
+}
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAliasTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAliasTests.cs
index 93a4fb4ba32..b29c9bb5b76 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAliasTests.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAliasTests.cs
@@ -26,181 +26,53 @@
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;
-using System.Runtime.Serialization.Formatters.Binary;
-namespace MonoTests.System.Resources
-{
+namespace MonoTests.System.Resources {
[TestFixture]
- public class ResXDataNodeAliasTests : MonoTests.System.Windows.Forms.TestHelper {
- string _tempDirectory;
- string _otherTempDirectory;
+ public class ResXDataNodeAliasTests : ResourcesTestHelper {
[Test, ExpectedException (typeof (TypeLoadException))]
public void CantAccessValueWereOnlyFullNameInResXForEmbedded () // same as validity check in assemblynames tests
{
-
- string filePath = GetFileFromString ("convertableResX.resx", convertableResX);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue ((AssemblyName[]) null);
- }
+ ResXDataNode node = GetNodeFromResXReader (convertableResX);
+ Assert.IsNotNull (node, "#A1");
+ object obj = node.GetValue ((AssemblyName[]) null);
}
[Test, ExpectedException (typeof (TypeLoadException))]
public void CantAccessValueWereOnlyFullNameAndAliasInResXForEmbedded ()
{
-
- string filePath = GetFileFromString ("convertableResXAlias.resx", convertableResXAlias);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue ((AssemblyName []) null);
- }
+ ResXDataNode node = GetNodeFromResXReader (convertableResXAlias);
+ Assert.IsNotNull (node, "#A1");
+ object obj = node.GetValue ((AssemblyName []) null);
}
[Test]
public void CanAccessValueWereOnlyFullNameAndAssemblyInResXForEmbedded ()
{
+ ResXDataNode node = GetNodeFromResXReader (convertableResXAssembly);
- string filePath = GetFileFromString ("convertableResXAssembly.resx", convertableResXAssembly);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue ((AssemblyName []) null);
- // this is the qualified name of the assembly found in dir
- string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
-
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A1");
- }
- }
-
- [Test]
- public void CanAccessValueWereOnlyFullNameAndQualifiedAssemblyInResXForEmbedded ()
- {
-
- string filePath = GetFileFromString ("convertableResXQAN.resx", convertableResXQualifiedAssemblyName);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue ((AssemblyName []) null);
-
- string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
-
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A1");
- }
- }
-
- /*
- [Test]
- public void GetValueAssemblyNameUsedWhereOnlyFullNameInResXForEmbedded ()
- {
- // DummyAssembly must be in the same directory as current assembly to work correctly
-
+ Assert.IsNotNull (node, "#A1");
+ object obj = node.GetValue ((AssemblyName []) null);
+ // this is the qualified name of the assembly found in dir
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
- AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
-
- string filePath = GetFileFromString ("convertableResX.resx", convertableResX);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue (assemblyNames);
-
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName);
- }
+ Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2");
}
[Test]
- public void GetValueTypeNameReturnsFullNameWereOnlyFullNameInResXForEmbedded ()
- {
- // just a check, if this passes other tests will give false results
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResX);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- string returnedType = node.GetValueTypeName ((AssemblyName []) null);
-
- Assert.AreEqual ("DummyAssembly.Convertable", returnedType);
- }
- }
-
- [Test]
- public void GetValueTypeNameAssemblyNameUsedWhereOnlyFullNameInResXForEmbedded ()
+ public void CanAccessValueWereOnlyFullNameAndQualifiedAssemblyInResXForEmbedded ()
{
- // DummyAssembly must be in the same directory as current assembly to work correctly
+ ResXDataNode node = GetNodeFromResXReader (convertableResXQualifiedAssemblyName);
+ Assert.IsNotNull (node, "#A1");
+ object obj = node.GetValue ((AssemblyName []) null);
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
- AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
-
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResX);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- string returnedType = node.GetValueTypeName (assemblyNames);
-
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedType);
- }
+ Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2");
}
- */
-
-
static string convertableResX =
@"<?xml version=""1.0"" encoding=""utf-8""?>
@@ -708,35 +580,6 @@ namespace MonoTests.System.Resources
</data>
</root>";
-
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
-
- base.TearDown ();
- }
-
- private string GetFileFromString (string filename, string filecontents)
- {
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
-
- string filepath = Path.Combine (_tempDirectory, filename);
-
- StreamWriter writer = new StreamWriter(filepath,false);
-
- writer.Write (filecontents);
- writer.Close ();
-
- return filepath;
- }
-
}
}
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs
index f92158955e0..6a7adbb39c0 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeAssemblyNameTests.cs
@@ -26,24 +26,16 @@
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;
-using System.Runtime.Serialization.Formatters.Binary;
using System.ComponentModel;
using System.Globalization;
namespace MonoTests.System.Resources {
[TestFixture]
- public class ResXDataNodeAssemblyNameTests : MonoTests.System.Windows.Forms.TestHelper {
- string _tempDirectory;
- string _otherTempDirectory;
-
+ public class ResXDataNodeAssemblyNameTests : ResourcesTestHelper {
/*
[Test]
public void CanPassAssemblyNameToGetValueToReturnSpecificVersionOfObjectClassInstance ()
@@ -132,190 +124,105 @@ namespace MonoTests.System.Resources {
public void GetValueAssemblyNameUsedWereOnlyFullNameInResXForEmbedded_TestValidityCheck ()
{
// just a check, if this passes other tests will give false results
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResXWithoutAssemblyName);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
+ ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
- object obj = node.GetValue ((AssemblyName []) null);
- }
+ Assert.IsNotNull (node, "#A1");
+ object obj = node.GetValue ((AssemblyName []) null);
}
[Test]
public void GetValueAssemblyNameUsedWhereOnlyFullNameInResXForEmbedded ()
{
// 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) };
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResXWithoutAssemblyName);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue (assemblyNames);
+ ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName);
- }
+ Assert.IsNotNull (node, "#A1");
+ object obj = node.GetValue (assemblyNames);
+ Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName);
}
[Test, ExpectedException (typeof (TypeLoadException))]
public void GetValueAssemblyNameRequiredEachTimeWhereOnlyFullNameInResXForEmbedded ()
{
// 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) };
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResXWithoutAssemblyName);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue (assemblyNames);
+ ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A1");
-
- object obj2 = node.GetValue ((AssemblyName []) null); //should cause exception here
- }
+ 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 ()
{
- string filePath = GetFileFromString ("thisAssemblyconvertableWithOutAssembly.resx", thisAssemblyConvertableResXWithoutAssemblyName);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- object obj = node.GetValue ((AssemblyName []) null);
- }
+ ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName);
+ Assert.IsNotNull (node, "#A1");
+ object obj = node.GetValue ((AssemblyName []) null);
}
[Test]
public void CanLoadTypeFromThisAssemblyWithOnlyFullNamePassingAssemblyNames ()
{
- string filePath = GetFileFromString ("thisAssemblyConvertableWithOutAssembly.resx", thisAssemblyConvertableResXWithoutAssemblyName);
-
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) };
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
- // would cause exception if couldnt find type
- object obj = node.GetValue (assemblyNames);
+ ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName);
- Assert.IsInstanceOfType (typeof (ThisAssemblyConvertable), obj, "#A1");
- }
+ 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 GetValueTypeNameReturnsFullNameWereOnlyFullNameInResXForEmbedded ()
{
// just a check, if this passes other tests will give false results
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResXWithoutAssemblyName);
+ ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- string returnedType = node.GetValueTypeName ((AssemblyName []) null);
-
- Assert.AreEqual ("DummyAssembly.Convertable", returnedType);
- }
+ Assert.IsNotNull (node, "#A1");
+ string returnedType = node.GetValueTypeName ((AssemblyName []) null);
+ Assert.AreEqual ("DummyAssembly.Convertable", returnedType, "#A2");
}
[Test]
public void GetValueTypeNameAssemblyNameUsedWhereOnlyFullNameInResXForEmbedded ()
{
// 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) };
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResXWithoutAssemblyName);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
-
- reader.UseResXDataNodes = true;
+ ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- string returnedType = node.GetValueTypeName (assemblyNames);
-
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedType);
- }
+ Assert.IsNotNull (node, "#A1");
+ string returnedType = node.GetValueTypeName (assemblyNames);
+ Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedType, "#A2");
}
[Test]
public void GetValueTypeNameAssemblyNameUsedEachTimeWhereOnlyFullNameInResXForEmbedded ()
{
// 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) };
- string filePath = GetFileFromString ("convertableWithOutAssembly.resx", convertableResXWithoutAssemblyName);
-
- using (ResXResourceReader reader = new ResXResourceReader (filePath)) {
+ ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
- reader.UseResXDataNodes = true;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- DictionaryEntry current = (DictionaryEntry) enumerator.Current;
- ResXDataNode node = (ResXDataNode) current.Value;
-
- string returnedName = node.GetValueTypeName (assemblyNames);
-
- Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedName, "#A1");
-
- string nameWithNullParam = node.GetValueTypeName ((AssemblyName []) null);
-
- Assert.AreEqual ("DummyAssembly.Convertable", nameWithNullParam, "#A2");
- }
+ 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 convertableResXWithoutAssemblyName =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
@@ -567,113 +474,7 @@ namespace MonoTests.System.Resources {
<value>im a name im a value</value>
</data>
</root>";
-
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
-
- base.TearDown ();
- }
-
- private string GetFileFromString (string filename, string filecontents)
- {
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
-
- string filepath = Path.Combine (_tempDirectory, filename);
-
- StreamWriter writer = new StreamWriter (filepath, false);
-
- writer.Write (filecontents);
- writer.Close ();
-
- return filepath;
- }
-
- }
-
-
- [SerializableAttribute]
- [TypeConverter (typeof (ThisAssemblyConvertableConverter))]
- public class ThisAssemblyConvertable {
- protected string name;
- protected string value;
-
- public ThisAssemblyConvertable ()
- {
- }
-
- public ThisAssemblyConvertable (string name, string value)
- {
- this.name = name;
- this.value = value;
- }
-
- public void GetObjectData (SerializationInfo info, StreamingContext ctxt)
- {
- info.AddValue ("sername", name);
- info.AddValue ("servalue", value);
- }
-
- public override string ToString ()
- {
- return String.Format ("{0}\t{1}", name, value);
- }
-
- public override bool Equals (object obj)
- {
- ThisAssemblyConvertable o = obj as ThisAssemblyConvertable;
- if (o == null)
- return false;
- return this.name.Equals (o.name) && this.value.Equals (o.value);
- }
- }
-
- class ThisAssemblyConvertableConverter : TypeConverter {
- public ThisAssemblyConvertableConverter ()
- {
- }
-
- public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof (string);
- }
-
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
- {
- return destinationType == typeof (string);
- }
-
- public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- if (value.GetType () != typeof (string))
- throw new Exception ("value not string");
-
- string serialised = (string) value;
-
- string [] parts = serialised.Split ('\t');
-
- if (parts.Length != 2)
- throw new Exception ("string in incorrect format");
-
- ThisAssemblyConvertable convertable = new ThisAssemblyConvertable (parts [0], parts [1]);
- return convertable;
- }
-
- public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType != typeof (String)) {
- return base.ConvertTo (context, culture, value, destinationType);
- }
-
- return ((ThisAssemblyConvertable) value).ToString ();
- }
+
}
}
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 a213d5c675f..f17dfddb2d8 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeByteArrayTests.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeByteArrayTests.cs
@@ -25,70 +25,37 @@
#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;
-using System.Runtime.Serialization.Formatters.Binary;
-namespace MonoTests.System.Resources
-{
+namespace MonoTests.System.Resources {
[TestFixture]
- public class ResXDataNodeByteArrayTests : MonoTests.System.Windows.Forms.TestHelper {
- string _tempDirectory;
- string _otherTempDirectory;
+ public class ResXDataNodeByteArrayTests : ResourcesTestHelper {
[Test]
public void GetValueITRSNotUsedWhenNodeReturnedFromReader ()
{
-
ResXDataNode originalNode, returnedNode;
+ originalNode = GetNodeEmdeddedBytes1To10 ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- originalNode = GetNodeEmdeddedBytes ();
-
- 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");
-
- object val = returnedNode.GetValue (new AlwaysReturnIntTypeResolutionService ());
- Assert.IsInstanceOfType (typeof (byte[]), val, "#A2");
- }
+ Assert.IsNotNull (returnedNode, "#A1");
+ 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);
- originalNode = GetNodeEmdeddedBytes ();
-
- 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");
- //would raise error if touched
- object val = returnedNode.GetValue (new ExceptionalTypeResolutionService ());
-
- }
+ Assert.IsNotNull (returnedNode, "#A1");
+ //would raise error if touched
+ object val = returnedNode.GetValue (new ExceptionalTypeResolutionService ());
}
[Test]
@@ -96,10 +63,8 @@ namespace MonoTests.System.Resources
{
// check supplied params to GetValue are not touched
// for an instance created manually
-
ResXDataNode node;
-
- node = GetNodeEmdeddedBytes ();
+ node = GetNodeEmdeddedBytes1To10 ();
//would raise exception if param used
Object obj = node.GetValue (new ExceptionalTypeResolutionService ());
@@ -109,53 +74,26 @@ namespace MonoTests.System.Resources
[Test]
public void GetValueTypeNameITRSIsUsedWithNodeFromReader ()
{
-
ResXDataNode originalNode, returnedNode;
+ originalNode = GetNodeEmdeddedBytes1To10 ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- originalNode = GetNodeEmdeddedBytes ();
-
- 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 returnedType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
-
- Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
- }
+ Assert.IsNotNull (returnedNode, "#A1");
+ string returnedType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
+ Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
}
[Test]
public void GetValueTypeNameITRSIsUsedAfterGetValueCalledWithNodeFromReader ()
{
-
ResXDataNode originalNode, returnedNode;
+ originalNode = GetNodeEmdeddedBytes1To10 ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- originalNode = GetNodeEmdeddedBytes ();
-
- 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");
-
- object obj = returnedNode.GetValue ((ITypeResolutionService) null);
-
- string returnedType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
-
- Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
- }
+ Assert.IsNotNull (returnedNode, "#A1");
+ object obj = returnedNode.GetValue ((ITypeResolutionService) null);
+ string returnedType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
+ Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
}
[Test]
@@ -163,9 +101,9 @@ namespace MonoTests.System.Resources
{
// check supplying params to GetValueType of the ResXDataNode does not change the output
// of the method for an instance created manually
-
ResXDataNode node;
- node = GetNodeEmdeddedBytes ();
+ node = GetNodeEmdeddedBytes1To10 ();
+
string returnedType = node.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
Assert.AreEqual ((typeof (byte[])).AssemblyQualifiedName, returnedType, "#A1");
}
@@ -173,90 +111,28 @@ namespace MonoTests.System.Resources
[Test]
public void ChangesToReturnedByteArrayNotLaterWrittenBack ()
{
+ ResXDataNode originalNode, returnedNode, finalNode;
+ originalNode = GetNodeEmdeddedBytes1To10 ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- ResXDataNode originalNode = GetNodeEmdeddedBytes ();
-
- string fileName = GetResXFileWithNode (originalNode, "test.resx");
-
- string newFileName;
-
- using (ResXResourceReader reader = new ResXResourceReader (fileName)) {
- reader.UseResXDataNodes = true;
-
- ResXDataNode returnedNode;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
-
- Assert.IsNotNull (returnedNode, "#A1");
-
- object val = returnedNode.GetValue ((ITypeResolutionService) null);
- Assert.IsInstanceOfType (typeof (byte []), val, "#A2");
-
- byte[] newBytes = (byte[]) val;
-
- Assert.AreEqual (1, newBytes [0], "A3");
-
- newBytes [0] = 99;
-
- newFileName = GetResXFileWithNode (returnedNode,"another.resx");
- }
-
- using (ResXResourceReader reader = new ResXResourceReader (newFileName)) {
- reader.UseResXDataNodes = true;
-
- ResXDataNode returnedNode;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
-
- Assert.IsNotNull (returnedNode, "#A4");
-
- object val = returnedNode.GetValue ((ITypeResolutionService) null);
- Assert.IsInstanceOfType (typeof (byte []), val, "#A5");
-
- byte [] newBytes = (byte []) val;
- // would be 99 if written back
- Assert.AreEqual (1,newBytes [0],"A6");
- }
- }
-
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
-
- base.TearDown ();
- }
-
- string GetResXFileWithNode (ResXDataNode node, string filename)
- {
- string fullfileName;
+ Assert.IsNotNull (returnedNode, "#A1");
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
+ object val = returnedNode.GetValue ((ITypeResolutionService) null);
+ Assert.IsInstanceOfType (typeof (byte []), val, "#A2");
- fullfileName = Path.Combine (_tempDirectory, filename);
+ byte[] newBytes = (byte[]) val;
+ Assert.AreEqual (1, newBytes [0], "A3");
+ newBytes [0] = 99;
- using (ResXResourceWriter writer = new ResXResourceWriter (fullfileName)) {
- writer.AddResource (node);
- }
+ finalNode = GetNodeFromResXReader (returnedNode);
+
+ Assert.IsNotNull (finalNode, "#A4");
- return fullfileName;
- }
-
- ResXDataNode GetNodeEmdeddedBytes ()
- {
- byte[] someBytes = new byte[] {1,2,3,4,5,6,7,8,9,10};
- ResXDataNode node = new ResXDataNode ("test", someBytes);
- return node;
+ object finalVal = finalNode.GetValue ((ITypeResolutionService) null);
+ Assert.IsInstanceOfType (typeof (byte []), finalVal, "#A5");
+ byte [] finalBytes = (byte []) finalVal;
+ // would be 99 if written back
+ Assert.AreEqual (1,finalBytes [0],"A6");
}
}
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs
new file mode 100644
index 00000000000..c2c82258fb1
--- /dev/null
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTests.cs
@@ -0,0 +1,168 @@
+// 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.Collections;
+using NUnit.Framework;
+using System.ComponentModel.Design;
+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);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+ object val = returnedNode.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A2");
+ Assert.IsInstanceOfType (typeof (serializable), val, "#A3");
+ }
+
+ [Test, ExpectedException(typeof (TypeLoadException))]
+ public void CantGetValueWithOnlyFullNameAsType ()
+ {
+ ResXDataNode originalNode, returnedNode;
+ originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
+ returnedNode = GetNodeFromResXReader (originalNode);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+ object obj = returnedNode.GetValue ((AssemblyName[]) null);
+ }
+
+ [Test, ExpectedException (typeof (TypeLoadException))]
+ public void CantGetValueWithOnlyFullNameAsTypeByProvidingAssemblyName ()
+ {
+ ResXDataNode originalNode, returnedNode;
+
+ 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) };
+
+ originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
+ returnedNode = GetNodeFromResXReader (originalNode);
+
+ 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);
+
+ object val = node.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A1");
+ Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
+ }
+
+ #region Initial Exploratory Tests
+
+ [Test]
+ public void ResXFileRefNullAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+
+ Object ico = node.GetValue ((AssemblyName []) null);
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
+
+ [Test]
+ public void ResXFileRefNullITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+
+ Object ico = node.GetValue ((ITypeResolutionService) null);
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
+
+ [Test]
+ public void ResXFileRefWrongITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+
+ Object ico = node.GetValue (new DummyTypeResolutionService ());
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
+
+ [Test]
+ public void ResXFileRefWrongAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+ AssemblyName [] ass = new AssemblyName [1];
+ ass [0] = new AssemblyName ("System.Design");
+
+ Object ico = node.GetValue (ass);
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
+
+ #endregion
+
+ }
+
+}
+#endif \ No newline at end of file
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs
new file mode 100644
index 00000000000..15622bdf735
--- /dev/null
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeFileRefGetValueTypeNameTests.cs
@@ -0,0 +1,139 @@
+// 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.Collections;
+using NUnit.Framework;
+using System.ComponentModel.Design;
+using System.Runtime.Serialization.Formatters.Binary;
+
+namespace MonoTests.System.Resources {
+ [TestFixture]
+ public class ResXDataNodeFileRefGetValueTypeNameTests : ResourcesTestHelper {
+ [Test]
+ public void CanGetStrongNameFromGetValueTypeNameWithOnlyFullNameAsTypeByProvidingAssemblyName ()
+ {
+ ResXDataNode originalNode, returnedNode;
+
+ 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) };
+
+ originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
+ returnedNode = GetNodeFromResXReader (originalNode);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+ string typeName = returnedNode.GetValueTypeName (assemblyNames);
+ Assert.AreEqual ("MonoTests.System.Resources.serializable, " + aName, typeName, "#A2");
+ }
+
+ public void CanGetValueTypeNameWithOnlyFullNameAsType ()
+ {
+ ResXDataNode originalNode, returnedNode;
+
+ originalNode = GetNodeFileRefToSerializable ("ser.bbb", false);
+ returnedNode = GetNodeFromResXReader (originalNode);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+ string typeName = returnedNode.GetValueTypeName ((AssemblyName []) null);
+ Assert.AreEqual ((typeof (serializable)).FullName, typeName, "#A2");
+ }
+
+ [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);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+ string returnedType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, returnedType, "#A2");
+ }
+
+ [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);
+
+ string returnedType = node.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, returnedType, "#A1");
+ }
+
+ #region Initial Exploratory Tests
+
+ [Test]
+ public void ResXFileRefNullAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+
+ string name = node.GetValueTypeName ((AssemblyName []) null);
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
+
+ [Test]
+ public void ResXFileRefNullITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+
+ string name = node.GetValueTypeName ((ITypeResolutionService) null);
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
+
+ [Test]
+ public void ResXFileRefWrongITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+
+ string name = node.GetValueTypeName (new DummyTypeResolutionService ());
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
+
+ [Test]
+ public void ResXFileRefWrongAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeFileRefToIcon ();
+ AssemblyName [] ass = new AssemblyName [1];
+ ass [0] = new AssemblyName ("System.Design");
+
+ string name = node.GetValueTypeName (ass);
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
+
+ #endregion
+
+ }
+
+}
+#endif \ No newline at end of file
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 47780a51975..31828e35216 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerialisedGetValueTypeNameTests.cs
@@ -26,46 +26,26 @@
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;
using System.Runtime.Serialization.Formatters.Binary;
-namespace MonoTests.System.Resources
-{
+namespace MonoTests.System.Resources {
[TestFixture]
- public class ResXDataNodeSerializedGetValueTypeNameTests : MonoTests.System.Windows.Forms.TestHelper {
- string _tempDirectory;
- string _otherTempDirectory;
-
+ public class ResXDataNodeSerializedGetValueTypeNameTests : ResourcesTestHelper {
[Test]
public void ITRSUsedWithNodeFromReader ()
{
-
ResXDataNode originalNode, returnedNode;
-
originalNode = GetNodeEmdeddedSerializable ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- 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 returnedType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
-
- Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, returnedType, "#A2");
- }
+ Assert.IsNotNull (returnedNode, "#A1");
+ string returnedType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, returnedType, "#A2");
}
[Test]
@@ -73,29 +53,17 @@ namespace MonoTests.System.Resources
{
// check ITRS supplied to GetValueTypeName method for a node returned from reader are used when
// retrieving the value first time and returns this same value ignoring any new ITRS passed thereafter
-
ResXDataNode originalNode, returnedNode;
-
originalNode = GetNodeEmdeddedSerializable ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- 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 defaultType = returnedNode.GetValueTypeName ((ITypeResolutionService) null);
+ Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, defaultType, "#A2");
- Assert.IsNotNull (returnedNode, "#A1");
-
- string defaultType = returnedNode.GetValueTypeName ((ITypeResolutionService) null);
- Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, defaultType, "#A2");
-
- string newType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
- Assert.AreNotEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A3");
- Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A4");
- }
+ string newType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.AreNotEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A3");
+ Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A4");
}
[Test]
@@ -103,9 +71,9 @@ namespace MonoTests.System.Resources
{
// 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 ();
+
string returnedType = node.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, returnedType, "#A1");
}
@@ -115,9 +83,7 @@ namespace MonoTests.System.Resources
{
// 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
@@ -129,210 +95,23 @@ namespace MonoTests.System.Resources
public void ITRSIsIgnoredIfGetValueAlreadyCalledWithAnotherITRS ()
{
// check that first call to GetValue sets the type for GetValueTypeName
-
ResXDataNode originalNode, returnedNode;
-
originalNode = GetNodeEmdeddedSerializable ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- 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");
-
- // get value passing no params
- object val = returnedNode.GetValue ((ITypeResolutionService) null);
- Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
- Assert.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A3");
-
- //get value type passing different params
- string newType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
- Assert.AreNotEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A4");
- Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A5");
- }
- }
-
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
-
- base.TearDown ();
- }
-
- string GetResXFileWithNode (ResXDataNode node, string filename)
- {
- string fullfileName;
-
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
-
- fullfileName = Path.Combine (_tempDirectory, filename);
-
- using (ResXResourceWriter writer = new ResXResourceWriter (fullfileName)) {
- writer.AddResource (node);
- }
+ Assert.IsNotNull (returnedNode, "#A1");
+ // get value passing no params
+ object val = returnedNode.GetValue ((ITypeResolutionService) null);
+ Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
+ Assert.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A3");
- return fullfileName;
+ //get value type passing different params
+ string newType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.AreNotEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A4");
+ Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A5");
}
-
- ResXDataNode GetNodeEmdeddedSerializable ()
- {
- serializable ser = new serializable ("testName", "testValue");
- ResXDataNode node = new ResXDataNode ("test", ser);
- return node;
- }
-
}
- [SerializableAttribute]
- public class serializableSubClass : serializable {
- public serializableSubClass ()
- {
- }
-
- public serializableSubClass (SerializationInfo info, StreamingContext ctxt)
- : base (info, ctxt)
- {
- }
-
- public serializableSubClass (Stream stream)
- {
- BinaryFormatter bFormatter = new BinaryFormatter ();
- serializableSubClass deser = (serializableSubClass) bFormatter.Deserialize (stream);
- stream.Close ();
-
- name = deser.name;
- value = deser.value;
- }
- }
-
- public class AlwaysReturnSerializableSubClassTypeResolutionService : ITypeResolutionService {
-
- public Assembly GetAssembly (AssemblyName name, bool throwOnError)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Assembly GetAssembly (AssemblyName name)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public string GetPathOfAssembly (AssemblyName name)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Type GetType (string name, bool throwOnError, bool ignoreCase)
- {
- return typeof (serializableSubClass);
- }
-
- public Type GetType (string name, bool throwOnError)
- {
- return typeof (serializableSubClass);
- }
-
- public Type GetType (string name)
- {
- return typeof (serializableSubClass);
- }
-
- public void ReferenceAssembly (AssemblyName name)
- {
-
- }
-
- }
-
- public class AlwaysReturnIntTypeResolutionService : ITypeResolutionService {
-
- public Assembly GetAssembly (AssemblyName name, bool throwOnError)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Assembly GetAssembly (AssemblyName name)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public string GetPathOfAssembly (AssemblyName name)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Type GetType (string name, bool throwOnError, bool ignoreCase)
- {
- return typeof (Int32);
- }
-
- public Type GetType (string name, bool throwOnError)
- {
- return typeof (Int32);
- }
-
- public Type GetType (string name)
- {
- return typeof (Int32);
- }
-
- public void ReferenceAssembly (AssemblyName name)
- {
-
- }
- }
-
- public class ExceptionalTypeResolutionService : ITypeResolutionService {
-
- public Assembly GetAssembly (AssemblyName name, bool throwOnError)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Assembly GetAssembly (AssemblyName name)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public string GetPathOfAssembly (AssemblyName name)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Type GetType (string name, bool throwOnError, bool ignoreCase)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Type GetType (string name, bool throwOnError)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public Type GetType (string name)
- {
- throw new NotImplementedException ("I was accessed");
- }
-
- public void ReferenceAssembly (AssemblyName name)
- {
-
- }
-
- }
-
}
#endif
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 d640879a68f..9f544c9dba6 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerializedGetValueTests.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeSerializedGetValueTests.cs
@@ -25,75 +25,43 @@
#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;
-using System.Runtime.Serialization.Formatters.Binary;
-namespace MonoTests.System.Resources
-{
+namespace MonoTests.System.Resources {
[TestFixture]
- public class ResXDataNodeSerializedGetValueTests : MonoTests.System.Windows.Forms.TestHelper {
- string _tempDirectory;
- string _otherTempDirectory;
-
+ public class ResXDataNodeSerializedGetValueTests : ResourcesTestHelper {
[Test]
public void ITRSOnlyUsedFirstTimeWithNodeFromReader ()
{
-
ResXDataNode originalNode, returnedNode;
-
originalNode = GetNodeEmdeddedSerializable ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- 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");
- Assert.IsNotNull (returnedNode, "#A1");
+ object defaultVal = returnedNode.GetValue ((ITypeResolutionService) null);
+ Assert.IsInstanceOfType (typeof (serializable), defaultVal, "#A2");
+ Assert.IsNotInstanceOfType (typeof (serializableSubClass), defaultVal, "#A3");
- object defaultVal = returnedNode.GetValue ((ITypeResolutionService) null);
- Assert.IsInstanceOfType (typeof (serializable), defaultVal, "#A2");
- Assert.IsNotInstanceOfType (typeof (serializableSubClass), defaultVal, "#A3");
-
- object newVal = returnedNode.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
- Assert.IsNotInstanceOfType (typeof (serializableSubClass), newVal, "#A4");
- Assert.IsInstanceOfType (typeof (serializable), newVal, "#A5");
- }
+ object newVal = returnedNode.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.IsNotInstanceOfType (typeof (serializableSubClass), newVal, "#A4");
+ Assert.IsInstanceOfType (typeof (serializable), newVal, "#A5");
}
[Test]
public void ITRSUsedWhenNodeReturnedFromReader ()
{
-
ResXDataNode originalNode, returnedNode;
-
originalNode = GetNodeEmdeddedSerializable ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- string fileName = GetResXFileWithNode (originalNode, "test.resx");
-
- using (ResXResourceReader reader = new ResXResourceReader (fileName)) {
- reader.UseResXDataNodes = true;
+ Assert.IsNotNull (returnedNode, "#A1");
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
-
- Assert.IsNotNull (returnedNode, "#A1");
-
- object val = returnedNode.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
- Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A2");
- }
+ object val = returnedNode.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A2");
}
[Test]
@@ -102,41 +70,21 @@ 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, return2;
+ ResXDataNode originalNode, returnedNode, finalNode;
originalNode = GetNodeEmdeddedSerializable ();
-
- 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");
-
- object val = returnedNode.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
- Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A2");
-
- string newResXFile = GetResXFileWithNode (returnedNode, "second.resx");
-
- using (ResXResourceReader read2 = new ResXResourceReader (newResXFile)) {
- read2.UseResXDataNodes = true;
-
- IDictionaryEnumerator enum2 = read2.GetEnumerator ();
- enum2.MoveNext ();
- return2 = (ResXDataNode) ((DictionaryEntry) enum2.Current).Value;
-
- Assert.IsNotNull (return2, "#A3");
-
- object value2 = return2.GetValue ((ITypeResolutionService) null);
-
- Assert.IsNotInstanceOfType (typeof (serializableSubClass), value2, "#A4");
- Assert.IsInstanceOfType (typeof (serializable), value2, "#A5");
- }
- }
+ returnedNode = GetNodeFromResXReader (originalNode);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+ object val = returnedNode.GetValue (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A2");
+
+ finalNode = GetNodeFromResXReader (returnedNode);
+ Assert.IsNotNull (finalNode, "#A3");
+
+ object finalVal = finalNode.GetValue ((ITypeResolutionService) null);
+ Assert.IsNotInstanceOfType (typeof (serializableSubClass), finalVal, "#A4");
+ Assert.IsInstanceOfType (typeof (serializable), finalVal, "#A5");
}
[Test]
@@ -147,28 +95,18 @@ namespace MonoTests.System.Resources
ResXDataNode originalNode, returnedNode;
originalNode = GetNodeEmdeddedSerializable ();
-
- 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");
-
- //get value type passing params
- string newType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
- Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A2");
- Assert.AreNotEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A3");
-
- // get value passing null params
- object val = returnedNode.GetValue ((ITypeResolutionService) null);
- // Assert.IsNotInstanceOfType (typeof (serializable), val, "#A5"); this would fail as subclasses are id-ed as instances of parents
- Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A4");
- }
+ returnedNode = GetNodeFromResXReader (originalNode);
+ Assert.IsNotNull (returnedNode, "#A1");
+
+ //get value type passing params
+ string newType = returnedNode.GetValueTypeName (new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A2");
+ Assert.AreNotEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A3");
+
+ // get value passing null params
+ object val = returnedNode.GetValue ((ITypeResolutionService) null);
+ // Assert.IsNotInstanceOfType (typeof (serializable), val, "#A5"); this would fail as subclasses are id-ed as instances of parents
+ Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A4");
}
[Test]
@@ -176,10 +114,7 @@ namespace MonoTests.System.Resources
{
// check supplied params to GetValue are not touched
// for an instance created manually
-
- ResXDataNode node;
-
- node = GetNodeEmdeddedSerializable ();
+ ResXDataNode node = GetNodeEmdeddedSerializable ();
//would raise exception if param used
Object obj = node.GetValue (new ExceptionalTypeResolutionService ());
@@ -189,94 +124,30 @@ namespace MonoTests.System.Resources
[Test]
public void ChangesToReturnedObjectNotLaterWrittenBack ()
{
+ ResXDataNode originalNode, returnedNode, finalNode;
- ResXDataNode originalNode = GetNodeEmdeddedSerializable ();
+ originalNode = GetNodeEmdeddedSerializable ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- string fileName = GetResXFileWithNode (originalNode, "test.resx");
+ Assert.IsNotNull (returnedNode, "#A1");
+ object val = returnedNode.GetValue ((ITypeResolutionService) null);
+ Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
- string newFileName;
+ serializable ser = (serializable) val;
- using (ResXResourceReader reader = new ResXResourceReader (fileName)) {
- reader.UseResXDataNodes = true;
+ Assert.AreEqual ("testName", ser.name, "A3");
+ ser.name = "changed";
+ finalNode = GetNodeFromResXReader (returnedNode);
+
+ Assert.IsNotNull (finalNode, "#A4");
+ object finalVal = finalNode.GetValue ((ITypeResolutionService) null);
+ Assert.IsInstanceOfType (typeof (serializable), finalVal, "#A5");
- ResXDataNode returnedNode;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
-
- Assert.IsNotNull (returnedNode, "#A1");
-
- object val = returnedNode.GetValue ((ITypeResolutionService) null);
- Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
-
- serializable ser = (serializable) val;
-
- Assert.AreEqual ("testName", ser.name, "A3");
-
- ser.name = "changed";
- newFileName = GetResXFileWithNode (returnedNode, "another.resx");
- }
-
- using (ResXResourceReader reader = new ResXResourceReader (newFileName)) {
- reader.UseResXDataNodes = true;
-
- ResXDataNode returnedNode;
-
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
-
- Assert.IsNotNull (returnedNode, "#A4");
-
- object val = returnedNode.GetValue ((ITypeResolutionService) null);
- Assert.IsInstanceOfType (typeof (serializable), val, "#A5");
-
- serializable ser = (serializable) val;
- // would be "changed" if written back
- Assert.AreEqual ("testName", ser.name, "A6");
- }
+ serializable finalSer = (serializable) finalVal;
+ // would be "changed" if written back
+ Assert.AreEqual ("testName", finalSer.name, "A6");
}
-
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
-
- base.TearDown ();
- }
-
- string GetResXFileWithNode (ResXDataNode node, string filename)
- {
- string fullfileName;
-
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
-
- fullfileName = Path.Combine (_tempDirectory, filename);
-
- using (ResXResourceWriter writer = new ResXResourceWriter (fullfileName)) {
- writer.AddResource (node);
- }
-
- return fullfileName;
- }
-
- ResXDataNode GetNodeEmdeddedSerializable ()
- {
- serializable ser = new serializable ("testName", "testValue");
- ResXDataNode node = new ResXDataNode ("test", ser);
- return node;
- }
-
}
-
-
}
#endif
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 0d40310e39a..2dfcf932117 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTest.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTest.cs
@@ -22,7 +22,7 @@
// ResXFileRefTest.cs: Unit Tests for ResXFileRef.
//
// Authors:
-// Andreia Gaita (avidigal@novell.com)
+// Andreia Gaita (avidigal@novell.com)
// Gary Barnett
@@ -33,22 +33,19 @@ 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;
using System.Runtime.Serialization.Formatters.Binary;
-namespace MonoTests.System.Resources
-{
+namespace MonoTests.System.Resources {
[TestFixture]
- public class ResXDataNodeTest : MonoTests.System.Windows.Forms.TestHelper
+ public class ResXDataNodeTest : ResourcesTestHelper
{
- string _tempDirectory;
- string _otherTempDirectory;
+ string _tempDirectory;
+ string _otherTempDirectory;
- [Test]
+ [Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorEx1 ()
{
@@ -57,11 +54,18 @@ namespace MonoTests.System.Resources
[Test]
[ExpectedException (typeof (ArgumentNullException))]
- public void ConstructorEx2 ()
+ public void ConstructorEx2A ()
{
- ResXDataNode d = new ResXDataNode (null, (ResXFileRef) null);
+ ResXDataNode d = new ResXDataNode (null, new ResXFileRef ("filename", "typename"));
}
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorEx2B ()
+ {
+ ResXDataNode d = new ResXDataNode ("aname", (ResXFileRef) null);
+ }
+
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorEx3 ()
@@ -89,7 +93,57 @@ namespace MonoTests.System.Resources
{
ResXDataNode d = new ResXDataNode ("name", new notserializable ());
}
-
+
+ [Test]
+ public void Name ()
+ {
+ ResXDataNode node = new ResXDataNode ("startname", (object) null);
+ Assert.AreEqual ("startname", node.Name, "#A1");
+ node.Name = "newname";
+ Assert.AreEqual ("newname", node.Name, "#A2");
+ }
+
+ [Test, ExpectedException (typeof (ArgumentNullException))]
+ public void NameCantBeNull ()
+ {
+ ResXDataNode node = new ResXDataNode ("startname", (object) null);
+ node.Name = null;
+ }
+
+ [Test, ExpectedException (typeof (ArgumentException))]
+ public void NameCantBeEmpty ()
+ {
+ ResXDataNode node = new ResXDataNode ("name", (object) null);
+ node.Name = "";
+ }
+
+ //FIXME: according to docs, if no name assigned .Name should return null
+ //where do the ResXDataNodes with no name come from? ResXResourceReader?
+
+ [Test]
+ public void FileRef ()
+ {
+ ResXFileRef fileRef = new ResXFileRef ("fileName", "Type.Name");
+ ResXDataNode node = new ResXDataNode ("name", fileRef);
+ Assert.AreEqual (fileRef, node.FileRef, "#A1");
+ }
+
+ [Test]
+ public void Comment ()
+ {
+ ResXDataNode node = new ResXDataNode ("name", (object) null);
+ node.Comment = "acomment";
+ Assert.AreEqual ("acomment", node.Comment, "#A1");
+ }
+
+ [Test]
+ public void CommentNullToStringEmpty ()
+ {
+ ResXDataNode node = new ResXDataNode ("name", (object) null);
+ node.Comment = null;
+ Assert.AreEqual (String.Empty, node.Comment, "#A1");
+ }
+
[Test]
public void WriteRead1 ()
{
@@ -102,17 +156,17 @@ namespace MonoTests.System.Resources
bool found = false;
ResXResourceReader rr = new ResXResourceReader ("resx.resx");
- rr.UseResXDataNodes = true;
- IDictionaryEnumerator en = rr.GetEnumerator ();
+ rr.UseResXDataNodes = true;
+ IDictionaryEnumerator en = rr.GetEnumerator ();
while (en.MoveNext ()) {
- ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode;
- if (node == null)
- break;
+ ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode;
+ if (node == null)
+ break;
serializable o = node.GetValue ((AssemblyName[]) null) as serializable;
if (o != null) {
found = true;
Assert.AreEqual (ser, o, "#A1");
- Assert.AreEqual ("comment", node.Comment, "#A3");
+ Assert.AreEqual ("comment", node.Comment, "#A3");
}
}
@@ -120,621 +174,377 @@ namespace MonoTests.System.Resources
Assert.IsTrue (found, "#A2 - Serialized object not found on resx");
}
-
+
[Test]
public void ConstructorResXFileRef()
{
- ResXDataNode node = GetNodeFileRefToIcon ();
- Assert.AreEqual (Path.Combine (_tempDirectory, "32x32.ico") , node.FileRef.FileName, "#A1");
+ ResXDataNode node = GetNodeFileRefToIcon ();
+ Assert.IsNotNull (node.FileRef, "#A1");
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, node.FileRef.TypeName, "#A2");
- Assert.AreEqual ("test", node.Name, "#B1");
+ Assert.AreEqual ("test", node.Name, "#A3");
}
-
-
- [Test]
- public void GetValueEmbeddedNullAssemblyNames ()
- {
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- Object ico = node.GetValue ((AssemblyName[])null);
- Assert.IsNotNull (ico, "#A1");
- Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
- }
-
- [Test]
- public void GetValueEmbeddedNullITypeResolutionService ()
- {
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- Object ico = node.GetValue ((ITypeResolutionService)null);
- Assert.IsNotNull (ico, "#A1");
- Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
- }
-
- [Test]
- public void GetValueTypeNameEmbeddedNullAssemblyNames ()
- {
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- string name = node.GetValueTypeName ((AssemblyName[])null);
- Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
- }
-
- [Test]
- public void GetValueTypeNameEmbeddedNullITypeResolutionService ()
- {
-
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- string name = node.GetValueTypeName ((ITypeResolutionService)null);
- Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
- }
-
- [Test]
- public void GetValueTypeNameEmbeddedWrongITypeResolutionService ()
- {
-
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- string name = node.GetValueTypeName (new DummyTypeResolutionService ());
- Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
- }
-
- [Test]
- public void GetValueEmbeddedWrongITypeResolutionService ()
- {
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- Object ico = node.GetValue (new DummyTypeResolutionService ());
- Assert.IsNotNull (ico, "#A1");
- Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
- }
-
- [Test]
- public void GetValueTypeNameEmbeddedWrongAssemblyNames ()
- {
-
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- AssemblyName[] ass = new AssemblyName[1];
-
- ass[0] = new AssemblyName ("System.Design");
-
- string name = node.GetValueTypeName (ass);
- Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
- }
-
- [Test]
- public void GetValueEmbeddedWrongAssemblyNames ()
- {
- ResXDataNode node = GetNodeEmdeddedIcon ();
-
- AssemblyName[] ass = new AssemblyName[1];
-
- ass[0] = new AssemblyName ("System.Design");
-
- Object ico = node.GetValue (ass);
- Assert.IsNotNull (ico, "#A1");
- Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
- }
-
- [Test]
- public void DoesNotRequireResXFileToBeOpen_Serializable ()
- {
-
- serializable ser = new serializable ("aaaaa", "bbbbb");
- ResXDataNode dn = new ResXDataNode ("test", ser);
-
+
+ [Test]
+ public void DoesNotRequireResXFileToBeOpen_Serializable ()
+ {
+ serializable ser = new serializable ("aaaaa", "bbbbb");
+ ResXDataNode dn = new ResXDataNode ("test", ser);
+
string resXFile = GetResXFileWithNode (dn,"resx.resx");
- ResXResourceReader rr = new ResXResourceReader (resXFile);
- rr.UseResXDataNodes = true;
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
-
- ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
- rr.Close ();
+ ResXResourceReader rr = new ResXResourceReader (resXFile);
+ rr.UseResXDataNodes = true;
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- File.Delete ("resx.resx");
+ ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
+ rr.Close ();
- Assert.IsNotNull (node,"#A1");
+ File.Delete ("resx.resx");
+ Assert.IsNotNull (node,"#A1");
- serializable o = node.GetValue ((AssemblyName []) null) as serializable;
-
- Assert.IsNotNull (o, "#A2");
- }
+ serializable o = node.GetValue ((AssemblyName []) null) as serializable;
+ Assert.IsNotNull (o, "#A2");
+ }
- [Test]
- public void DoesNotRequireResXFileToBeOpen_TypeConverter ()
- {
-
- ResXDataNode dn = new ResXDataNode ("test", 34L);
-
+ [Test]
+ public void DoesNotRequireResXFileToBeOpen_TypeConverter ()
+ {
+ ResXDataNode dn = new ResXDataNode ("test", 34L);
string resXFile = GetResXFileWithNode (dn,"resx.resx");
- ResXResourceReader rr = new ResXResourceReader (resXFile);
- rr.UseResXDataNodes = true;
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
+ ResXResourceReader rr = new ResXResourceReader (resXFile);
+ rr.UseResXDataNodes = true;
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
- rr.Close ();
-
- File.Delete ("resx.resx");
-
- Assert.IsNotNull (node, "#A1");
+ ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
+ rr.Close ();
- object o = node.GetValue ((AssemblyName []) null);
+ File.Delete ("resx.resx");
+ Assert.IsNotNull (node, "#A1");
- Assert.IsInstanceOfType (typeof (long), o, "#A2");
- Assert.AreEqual (34L, o, "#A3");
- }
+ object o = node.GetValue ((AssemblyName []) null);
+ Assert.IsInstanceOfType (typeof (long), o, "#A2");
+ Assert.AreEqual (34L, o, "#A3");
+ }
- //FIXME: should move following tests to files associated with ResXResourceReader Tests
+ //FIXME: should move following tests to files associated with ResXResourceReader Tests
[Test,ExpectedException (typeof(TypeLoadException))]
- public void AssemblyNamesPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter ()
- {
- string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
- AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
-
+ public void AssemblyNamesPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter ()
+ {
+ string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
+ AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
+
string resXFile = GetFileFromString ("test.resx", convertableResXWithoutAssemblyName);
- using (ResXResourceReader rr = new ResXResourceReader (resXFile, assemblyNames)) {
- rr.UseResXDataNodes = true;
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
+ using (ResXResourceReader rr = new ResXResourceReader (resXFile, assemblyNames)) {
+ rr.UseResXDataNodes = true;
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
-
- Assert.IsNotNull (node, "#A1");
+ ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
+
+ Assert.IsNotNull (node, "#A1");
//should raise exception
- object o = node.GetValue ((AssemblyName []) null);
+ object o = node.GetValue ((AssemblyName []) null);
}
- }
+ }
[Test]
- public void AssemblyNamesPassedToResourceReaderAffectsDictionary_TypeConverter ()
- {
- string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
- AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
-
+ public void AssemblyNamesPassedToResourceReaderAffectsDictionary_TypeConverter ()
+ {
+ string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
+ AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
+
string resXFile = GetFileFromString ("test.resx", convertableResXWithoutAssemblyName);
- using (ResXResourceReader rr = new ResXResourceReader (resXFile, assemblyNames)) {
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
+ using (ResXResourceReader rr = new ResXResourceReader (resXFile, assemblyNames)) {
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- object obj = ((DictionaryEntry) en.Current).Value;
-
- Assert.IsNotNull (obj, "#A1");
+ object obj = ((DictionaryEntry) en.Current).Value;
+
+ Assert.IsNotNull (obj, "#A1");
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2");
}
- }
+ }
- [Test]
- public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter ()
- {
-
- ResXDataNode dn = new ResXDataNode ("test", 34L);
-
+ [Test]
+ public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter ()
+ {
+
+ ResXDataNode dn = new ResXDataNode ("test", 34L);
+
string resXFile = GetResXFileWithNode (dn,"resx.resx");
- ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnIntTypeResolutionService());
- rr.UseResXDataNodes = true;
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
+ ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnIntTypeResolutionService());
+ rr.UseResXDataNodes = true;
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
-
- Assert.IsNotNull (node, "#A1");
+ ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
+
+ Assert.IsNotNull (node, "#A1");
- object o = node.GetValue ((AssemblyName []) null);
+ object o = node.GetValue ((AssemblyName []) null);
- Assert.IsInstanceOfType (typeof (long), o, "#A2");
- Assert.AreEqual (34L, o, "#A3");
+ Assert.IsInstanceOfType (typeof (long), o, "#A2");
+ Assert.AreEqual (34L, o, "#A3");
- rr.Close ();
- }
+ rr.Close ();
+ }
- [Test]
- public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_Serializable ()
- {
-
- serializable ser = new serializable ("aaaaa", "bbbbb");
- ResXDataNode dn = new ResXDataNode ("test", ser);
-
+ [Test]
+ public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_Serializable ()
+ {
+
+ serializable ser = new serializable ("aaaaa", "bbbbb");
+ ResXDataNode dn = new ResXDataNode ("test", ser);
+
string resXFile = GetResXFileWithNode (dn,"resx.resx");
- ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnSerializableSubClassTypeResolutionService ());
- rr.UseResXDataNodes = true;
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
+ ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ rr.UseResXDataNodes = true;
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
+ ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
- Assert.IsNotNull (node, "#A1");
+ Assert.IsNotNull (node, "#A1");
- object o = node.GetValue ((AssemblyName []) null);
+ object o = node.GetValue ((AssemblyName []) null);
- Assert.IsNotInstanceOfType (typeof (serializableSubClass), o, "#A2");
- Assert.IsInstanceOfType (typeof (serializable), o, "#A3");
- rr.Close ();
- }
+ Assert.IsNotInstanceOfType (typeof (serializableSubClass), o, "#A2");
+ Assert.IsInstanceOfType (typeof (serializable), o, "#A3");
+ rr.Close ();
+ }
- [Test]
- public void ITRSPassedToResourceReaderAffectsDictionary_Serializable ()
- {
-
- serializable ser = new serializable ("aaaaa", "bbbbb");
- ResXDataNode dn = new ResXDataNode ("test", ser);
-
+ [Test]
+ public void ITRSPassedToResourceReaderAffectsDictionary_Serializable ()
+ {
+
+ serializable ser = new serializable ("aaaaa", "bbbbb");
+ ResXDataNode dn = new ResXDataNode ("test", ser);
+
string resXFile = GetResXFileWithNode (dn,"resx.resx");
- ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnSerializableSubClassTypeResolutionService ());
+ ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnSerializableSubClassTypeResolutionService ());
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- object o = ((DictionaryEntry) en.Current).Value;
+ object o = ((DictionaryEntry) en.Current).Value;
- Assert.IsNotNull (o, "#A1");
+ Assert.IsNotNull (o, "#A1");
- Assert.IsInstanceOfType (typeof (serializableSubClass), o,"#A2");
+ Assert.IsInstanceOfType (typeof (serializableSubClass), o,"#A2");
- rr.Close ();
- }
+ rr.Close ();
+ }
[Test]
- public void ITRSPassedToResourceReaderAffectsDictionary_TypeConverter ()
- {
-
- ResXDataNode dn = new ResXDataNode ("test", 34L);
-
+ public void ITRSPassedToResourceReaderAffectsDictionary_TypeConverter ()
+ {
+
+ ResXDataNode dn = new ResXDataNode ("test", 34L);
+
string resXFile = GetResXFileWithNode (dn,"resx.resx");
- ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnIntTypeResolutionService ());
+ ResXResourceReader rr = new ResXResourceReader (resXFile, new AlwaysReturnIntTypeResolutionService ());
- IDictionaryEnumerator en = rr.GetEnumerator ();
- en.MoveNext ();
+ IDictionaryEnumerator en = rr.GetEnumerator ();
+ en.MoveNext ();
- object o = ((DictionaryEntry) en.Current).Value;
+ object o = ((DictionaryEntry) en.Current).Value;
- Assert.IsNotNull (o, "#A1");
+ Assert.IsNotNull (o, "#A1");
- Assert.IsInstanceOfType (typeof (int), o,"#A2");
- Assert.AreEqual (34, o,"#A3");
+ Assert.IsInstanceOfType (typeof (int), o,"#A2");
+ Assert.AreEqual (34, o,"#A3");
- rr.Close ();
- }
+ rr.Close ();
+ }
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
+ [TearDown]
+ protected override void TearDown ()
+ {
+ //teardown
+ if (Directory.Exists (_tempDirectory))
+ Directory.Delete (_tempDirectory, true);
- base.TearDown ();
- }
+ base.TearDown ();
+ }
string GetResXFileWithNode (ResXDataNode node, string filename)
- {
- string fullfileName;
-
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
-
- fullfileName = Path.Combine (_tempDirectory, filename);
-
- using (ResXResourceWriter writer = new ResXResourceWriter (fullfileName)) {
- writer.AddResource (node);
- }
-
- return fullfileName;
- }
-
- ResXDataNode GetNodeFileRefToIcon ()
- {
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory))
- {
- Directory.CreateDirectory (_otherTempDirectory);
- }
-
- string refFile = Path.Combine (_tempDirectory, "32x32.ico");
- WriteEmbeddedResource ("32x32.ico", refFile);
-
- ResXFileRef fileRef = new ResXFileRef (refFile, typeof (Icon).AssemblyQualifiedName);
- ResXDataNode node = new ResXDataNode ("test", fileRef);
-
- return node;
- }
-
- ResXDataNode GetNodeEmdeddedIcon ()
- {
-
- Stream input = typeof (ResXDataNodeTest).Assembly.
- GetManifestResourceStream ("32x32.ico");
-
- Icon ico = new Icon (input);
-
- ResXDataNode node = new ResXDataNode ("test", ico);
-
- return node;
- }
-
- private static void WriteEmbeddedResource (string name, string filename)
{
- const int size = 512;
- byte [] buffer = new byte [size];
- int count = 0;
+ string fullfileName;
- Stream input = typeof (ResXDataNodeTest).Assembly.
- GetManifestResourceStream (name);
- Stream output = File.Open (filename, FileMode.Create);
+ _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
+ _otherTempDirectory = Path.Combine (_tempDirectory, "in");
+ if (!Directory.Exists (_otherTempDirectory)) {
+ Directory.CreateDirectory (_otherTempDirectory);
+ }
- try {
- while ((count = input.Read (buffer, 0, size)) > 0) {
- output.Write (buffer, 0, count);
- }
- } finally {
- output.Close ();
+ fullfileName = Path.Combine (_tempDirectory, filename);
+
+ using (ResXResourceWriter writer = new ResXResourceWriter (fullfileName)) {
+ writer.AddResource (node);
}
+
+ return fullfileName;
}
private string GetFileFromString (string filename, string filecontents)
- {
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
+ {
+ _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
+ _otherTempDirectory = Path.Combine (_tempDirectory, "in");
+ if (!Directory.Exists (_otherTempDirectory)) {
+ Directory.CreateDirectory (_otherTempDirectory);
+ }
- string filepath = Path.Combine (_tempDirectory, filename);
-
- StreamWriter writer = new StreamWriter(filepath,false);
+ string filepath = Path.Combine (_tempDirectory, filename);
+
+ StreamWriter writer = new StreamWriter(filepath,false);
- writer.Write (filecontents);
- writer.Close ();
+ writer.Write (filecontents);
+ writer.Close ();
- return filepath;
- }
+ return filepath;
+ }
- static string convertableResXWithoutAssemblyName =
+ static string convertableResXWithoutAssemblyName =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<!--
- Microsoft ResX Schema
-
- Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
- associated with the data types.
-
- Example:
-
- ... ado.net/XML headers & schema ...
- <resheader name=""resmimetype"">text/microsoft-resx</resheader>
- <resheader name=""version"">2.0</resheader>
- <resheader name=""reader"">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
- <resheader name=""writer"">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
- <data name=""Name1""><value>this is my long string</value><comment>this is a comment</comment></data>
- <data name=""Color1"" type=""System.Drawing.Color, System.Drawing"">Blue</data>
- <data name=""Bitmap1"" mimetype=""application/x-microsoft.net.object.binary.base64"">
- <value>[base64 mime encoded serialized .NET Framework object]</value>
- </data>
- <data name=""Icon1"" type=""System.Drawing.Icon, System.Drawing"" mimetype=""application/x-microsoft.net.object.bytearray.base64"">
- <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
- <comment>This is a comment</comment>
- </data>
-
- There are any number of ""resheader"" rows that contain simple
- name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
- mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
- extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
- read any of the formats listed below.
-
- mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
- : using a System.ComponentModel.TypeConverter
- : and then encoded with base64 encoding.
- -->
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name=""resmimetype"">text/microsoft-resx</resheader>
+ <resheader name=""version"">2.0</resheader>
+ <resheader name=""reader"">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name=""writer"">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name=""Name1""><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name=""Color1"" type=""System.Drawing.Color, System.Drawing"">Blue</data>
+ <data name=""Bitmap1"" mimetype=""application/x-microsoft.net.object.binary.base64"">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name=""Icon1"" type=""System.Drawing.Icon, System.Drawing"" mimetype=""application/x-microsoft.net.object.bytearray.base64"">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of ""resheader"" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
<xsd:schema id=""root"" xmlns="""" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
- <xsd:import namespace=""http://www.w3.org/XML/1998/namespace"" />
- <xsd:element name=""root"" msdata:IsDataSet=""true"">
- <xsd:complexType>
- <xsd:choice maxOccurs=""unbounded"">
- <xsd:element name=""metadata"">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" />
- </xsd:sequence>
- <xsd:attribute name=""name"" use=""required"" type=""xsd:string"" />
- <xsd:attribute name=""type"" type=""xsd:string"" />
- <xsd:attribute name=""mimetype"" type=""xsd:string"" />
- <xsd:attribute ref=""xml:space"" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name=""assembly"">
- <xsd:complexType>
- <xsd:attribute name=""alias"" type=""xsd:string"" />
- <xsd:attribute name=""name"" type=""xsd:string"" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name=""data"">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
- <xsd:element name=""comment"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""2"" />
- </xsd:sequence>
- <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" msdata:Ordinal=""1"" />
- <xsd:attribute name=""type"" type=""xsd:string"" msdata:Ordinal=""3"" />
- <xsd:attribute name=""mimetype"" type=""xsd:string"" msdata:Ordinal=""4"" />
- <xsd:attribute ref=""xml:space"" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name=""resheader"">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
- </xsd:sequence>
- <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" />
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
+ <xsd:import namespace=""http://www.w3.org/XML/1998/namespace"" />
+ <xsd:element name=""root"" msdata:IsDataSet=""true"">
+ <xsd:complexType>
+ <xsd:choice maxOccurs=""unbounded"">
+ <xsd:element name=""metadata"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" use=""required"" type=""xsd:string"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""assembly"">
+ <xsd:complexType>
+ <xsd:attribute name=""alias"" type=""xsd:string"" />
+ <xsd:attribute name=""name"" type=""xsd:string"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""data"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ <xsd:element name=""comment"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""2"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" msdata:Ordinal=""1"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" msdata:Ordinal=""3"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" msdata:Ordinal=""4"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""resheader"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
</xsd:schema>
<resheader name=""resmimetype"">
- <value>text/microsoft-resx</value>
+ <value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
- <value>2.0</value>
+ <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>
+ <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>
+ <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>
+ <value>im a name im a value</value>
</data>
</root>";
}
-
- public class DummyTypeResolutionService : ITypeResolutionService
- {
-
- public Assembly GetAssembly (AssemblyName name, bool throwOnError)
- {
- return null;
- }
-
- public Assembly GetAssembly (AssemblyName name)
- {
- return null;
- }
-
- public string GetPathOfAssembly (AssemblyName name)
- {
- return null;
- }
-
- public Type GetType (string name, bool throwOnError, bool ignoreCase)
- {
- return null;
- }
-
- public Type GetType (string name, bool throwOnError)
- {
- return null;
- }
-
- public Type GetType (string name)
- {
- return null;
- }
-
- public void ReferenceAssembly (AssemblyName name)
- {
-
- }
- }
-
- class notserializable
- {
- public object test;
- public notserializable ()
- {
-
- }
- }
-
- [SerializableAttribute]
- public class serializable : ISerializable
- {
- public string name;
- public string value;
-
- public serializable ()
- {
- }
-
- public serializable (string name, string value)
- {
- this.name = name;
- this.value = value;
- }
-
- public serializable (SerializationInfo info, StreamingContext ctxt)
- {
- name = (string) info.GetValue ("sername", typeof (string));
- value = (String) info.GetValue ("servalue", typeof (string));
- }
-
- public serializable (Stream stream)
- {
- BinaryFormatter bFormatter = new BinaryFormatter ();
- serializable deser = (serializable) bFormatter.Deserialize (stream);
- stream.Close ();
-
- name = deser.name;
- value = deser.value;
- }
-
- public void GetObjectData (SerializationInfo info, StreamingContext ctxt)
- {
- info.AddValue ("sername", name);
- info.AddValue ("servalue", value);
- }
-
- public override string ToString ()
- {
- return String.Format ("name={0};value={1}", this.name, this.value);
- }
-
- public override bool Equals (object obj)
- {
- serializable o = obj as serializable;
- if (o == null)
- return false;
- return this.name.Equals(o.name) && this.value.Equals(o.value);
- }
- }
+
}
#endif
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 e75c3e308ea..f1e0cd1ff55 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTests.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTests.cs
@@ -25,127 +25,114 @@
#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;
-using System.Runtime.Serialization.Formatters.Binary;
+using System.Reflection;
+using System.Drawing;
namespace MonoTests.System.Resources
{
[TestFixture]
- public class ResXDataNodeTypeConverterGetValueTests : MonoTests.System.Windows.Forms.TestHelper {
- string _tempDirectory;
- string _otherTempDirectory;
- /*
- [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;
+ public class ResXDataNodeTypeConverterGetValueTests : ResourcesTestHelper {
+ [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);
+
+ object obj = node.GetValue (new AlwaysReturnIntTypeResolutionService ());
+ Assert.IsInstanceOfType (typeof (long), obj, "#A1");
+ }
+
+ [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);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+
+ object newVal = returnedNode.GetValue (new AlwaysReturnIntTypeResolutionService ());
+ Assert.AreEqual (typeof (int).AssemblyQualifiedName, newVal.GetType ().AssemblyQualifiedName, "#A2");
+
+ object origVal = returnedNode.GetValue ((ITypeResolutionService) null);
+ 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 ();
-
- 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");
+ originalNode = GetNodeEmdeddedIcon ();
+ returnedNode = GetNodeFromResXReader (originalNode);
- Icon ico = (Icon)returnedNode.GetValue (new ExceptionalTypeResolutionService ());
- }
- }
- */
+ Assert.IsNotNull (returnedNode, "#A1");
+ // should raise error
+ Icon ico = (Icon)returnedNode.GetValue (new ExceptionalTypeResolutionService ());
+ }
+
+ #region initial
- [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
+ [Test]
+ public void NullAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
- ResXDataNode node;
- node = new ResXDataNode ("along", 34L);
- object obj = node.GetValue (new AlwaysReturnIntTypeResolutionService ());
- Assert.IsInstanceOfType (typeof(long), obj, "#A1");
- }
+ Object ico = node.GetValue ((AssemblyName []) null);
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
- [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,
+ [Test]
+ public void NullITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
- ResXDataNode returnedNode, originalNode;
+ Object ico = node.GetValue ((ITypeResolutionService) null);
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
- originalNode = new ResXDataNode ("aNumber", 23L);
+ [Test]
+ public void WrongITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
- string fileName = GetResXFileWithNode (originalNode, "long.resx");
+ Object ico = node.GetValue (new DummyTypeResolutionService ());
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
- // should load assembly referenced in file
- using (ResXResourceReader reader = new ResXResourceReader (fileName)) {
- reader.UseResXDataNodes = true;
+ [Test]
+ public void WrongAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
+ AssemblyName [] ass = new AssemblyName [1];
- IDictionaryEnumerator enumerator = reader.GetEnumerator ();
- enumerator.MoveNext ();
- returnedNode = (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
+ ass [0] = new AssemblyName ("System.Design");
- Assert.IsNotNull (returnedNode, "#A1");
+ Object ico = node.GetValue (ass);
+ Assert.IsNotNull (ico, "#A1");
+ Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
+ }
- object newVal = returnedNode.GetValue (new AlwaysReturnIntTypeResolutionService ());
+ #endregion
- Assert.AreEqual (typeof (int).AssemblyQualifiedName, newVal.GetType ().AssemblyQualifiedName, "#A2");
+ }
- object origVal = returnedNode.GetValue ((ITypeResolutionService) null);
- Assert.AreEqual (typeof (long).AssemblyQualifiedName, origVal.GetType().AssemblyQualifiedName, "#A3");
- }
- }
-
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
-
- base.TearDown ();
- }
-
- string GetResXFileWithNode (ResXDataNode node, string filename)
- {
- string fullfileName;
-
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
-
- fullfileName = Path.Combine (_tempDirectory, filename);
-
- using (ResXResourceWriter writer = new ResXResourceWriter (fullfileName)) {
- writer.AddResource (node);
- }
-
- return fullfileName;
- }
-
-
- }
}
#endif
+
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 ff5aff34211..36e13e73474 100644
--- a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTypeNameTests.cs
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeTypeConverterGetValueTypeNameTests.cs
@@ -25,126 +25,103 @@
#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;
-using System.Runtime.Serialization.Formatters.Binary;
+using System.Drawing;
+using System.Reflection;
namespace MonoTests.System.Resources
{
[TestFixture]
- public class ResXDataNodeTypeConverterGetValueTypeNameTests : MonoTests.System.Windows.Forms.TestHelper {
- string _tempDirectory;
- string _otherTempDirectory;
-
+ public class ResXDataNodeTypeConverterGetValueTypeNameTests : ResourcesTestHelper {
[Test]
- public void ITRSUsedWithNodeFromReader ()
+ 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);
- string fileName = GetResXFileWithNode (originalNode, "long.resx");
-
- // should load assembly referenced in file
- 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");
- }
+ Assert.IsNotNull (returnedNode, "#A1");
+ string returnedType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
+ Assert.AreEqual ((typeof (Int32)).AssemblyQualifiedName, returnedType, "#A2");
}
[Test]
- public void ITRSUsedEachTimeWhenNodeFromReader ()
+ 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);
-
- string fileName = GetResXFileWithNode (originalNode, "long.resx");
-
- // should load assembly referenced in file
- 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 newType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
-
- Assert.AreEqual (typeof (int).AssemblyQualifiedName, newType, "#A2");
-
- string origType = returnedNode.GetValueTypeName ((ITypeResolutionService) null);
-
- Assert.AreEqual (typeof (long).AssemblyQualifiedName, origType, "#A3");
- }
+ returnedNode = GetNodeFromResXReader (originalNode);
+
+ Assert.IsNotNull (returnedNode, "#A1");
+ string newType = returnedNode.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
+ Assert.AreEqual (typeof (int).AssemblyQualifiedName, newType, "#A2");
+ string origType = returnedNode.GetValueTypeName ((ITypeResolutionService) null);
+ Assert.AreEqual (typeof (long).AssemblyQualifiedName, origType, "#A3");
+
}
[Test]
- public void ITRSNotUsedWhenNodeCreatedNew ()
+ 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);
+
string returnedType = node.GetValueTypeName (new AlwaysReturnIntTypeResolutionService ());
Assert.AreEqual ((typeof (long)).AssemblyQualifiedName, returnedType, "#A1");
}
- [TearDown]
- protected override void TearDown ()
- {
- //teardown
- if (Directory.Exists (_tempDirectory))
- Directory.Delete (_tempDirectory, true);
+ #region initial
- base.TearDown ();
- }
+ [Test]
+ public void EmbeddedNullITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
- string GetResXFileWithNode (ResXDataNode node, string filename)
- {
- string fullfileName;
+ string name = node.GetValueTypeName ((ITypeResolutionService) null);
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
- _tempDirectory = Path.Combine (Path.GetTempPath (), "ResXDataNodeTest");
- _otherTempDirectory = Path.Combine (_tempDirectory, "in");
- if (!Directory.Exists (_otherTempDirectory)) {
- Directory.CreateDirectory (_otherTempDirectory);
- }
+ [Test]
+ public void EmbeddedWrongITypeResolutionServiceOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
- fullfileName = Path.Combine (_tempDirectory, filename);
+ string name = node.GetValueTypeName (new DummyTypeResolutionService ());
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
- using (ResXResourceWriter writer = new ResXResourceWriter (fullfileName)) {
- writer.AddResource (node);
- }
+ [Test]
+ public void EmbeddedWrongAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
+ AssemblyName [] ass = new AssemblyName [1];
- return fullfileName;
- }
+ ass [0] = new AssemblyName ("System.Design");
+
+ string name = node.GetValueTypeName (ass);
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
+
+ [Test]
+ public void EmbeddedNullAssemblyNamesOK ()
+ {
+ ResXDataNode node = GetNodeEmdeddedIcon ();
+
+ string name = node.GetValueTypeName ((AssemblyName []) null);
+ Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
+ }
- }
+ #endregion
+ }
}
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs
new file mode 100644
index 00000000000..170e75a3af4
--- /dev/null
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResXDataNodeWriteBehavior.cs
@@ -0,0 +1,453 @@
+// 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.Collections;
+using NUnit.Framework;
+
+namespace MonoTests.System.Resources {
+ [TestFixture]
+ public class ResXDataNodeWriteBehavior : ResourcesTestHelper {
+
+ [Test]
+ public void TypeConverterObjectNotLoaded ()
+ {
+ 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 (convertableResXWithoutAssemblyName);
+ Assert.IsNotNull (node, "#A1");
+ // would cause error if object loaded
+ GetNodeFromResXReader (node);
+ }
+
+ [Test]
+ public void SerializedObjectNotLoaded ()
+ {
+ ResXDataNode node = GetNodeFromResXReader (serializedResXCorruped);
+ Assert.IsNotNull (node, "#A1");
+ // would cause error if object loaded
+ GetNodeFromResXReader (node);
+ }
+
+ [Test, ExpectedException (typeof (ArgumentException))]
+ public void FileRefIsLoaded ()
+ {
+ // .NET does instantiate the encoding until the write, as exception not thrown until write
+ ResXDataNode node = GetNodeFromResXReader (fileRefResXCorrupted);
+ Assert.IsNotNull (node, "#A1");
+ // would cause error if object loaded
+ GetNodeFromResXReader (node);
+ }
+
+ static string fileRefResXCorrupted =
+@"<?xml version=""1.0"" encoding=""utf-8""?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name=""resmimetype"">text/microsoft-resx</resheader>
+ <resheader name=""version"">2.0</resheader>
+ <resheader name=""reader"">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name=""writer"">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name=""Name1""><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name=""Color1"" type=""System.Drawing.Color, System.Drawing"">Blue</data>
+ <data name=""Bitmap1"" mimetype=""application/x-microsoft.net.object.binary.base64"">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name=""Icon1"" type=""System.Drawing.Icon, System.Drawing"" mimetype=""application/x-microsoft.net.object.bytearray.base64"">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of ""resheader"" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id=""root"" xmlns="""" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
+ <xsd:import namespace=""http://www.w3.org/XML/1998/namespace"" />
+ <xsd:element name=""root"" msdata:IsDataSet=""true"">
+ <xsd:complexType>
+ <xsd:choice maxOccurs=""unbounded"">
+ <xsd:element name=""metadata"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" use=""required"" type=""xsd:string"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""assembly"">
+ <xsd:complexType>
+ <xsd:attribute name=""alias"" type=""xsd:string"" />
+ <xsd:attribute name=""name"" type=""xsd:string"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""data"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ <xsd:element name=""comment"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""2"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" msdata:Ordinal=""1"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" msdata:Ordinal=""3"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" msdata:Ordinal=""4"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""resheader"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <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>
+ <assembly alias=""System.Windows.Forms"" name=""System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" />
+ <data name=""test"" type=""System.Resources.ResXFileRef, System.Windows.Forms"">
+ <value>.\somethingthatdoesntexist.txt;System.String, System.Windows.Forms_test_net_2_0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null;AValidCultureStringThisIsNot</value>
+ </data>
+</root>";
+
+ static string serializedResXCorruped =
+@"<?xml version=""1.0"" encoding=""utf-8""?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name=""resmimetype"">text/microsoft-resx</resheader>
+ <resheader name=""version"">2.0</resheader>
+ <resheader name=""reader"">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name=""writer"">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name=""Name1""><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name=""Color1"" type=""System.Drawing.Color, System.Drawing"">Blue</data>
+ <data name=""Bitmap1"" mimetype=""application/x-microsoft.net.object.binary.base64"">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name=""Icon1"" type=""System.Drawing.Icon, System.Drawing"" mimetype=""application/x-microsoft.net.object.bytearray.base64"">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of ""resheader"" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id=""root"" xmlns="""" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
+ <xsd:import namespace=""http://www.w3.org/XML/1998/namespace"" />
+ <xsd:element name=""root"" msdata:IsDataSet=""true"">
+ <xsd:complexType>
+ <xsd:choice maxOccurs=""unbounded"">
+ <xsd:element name=""metadata"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" use=""required"" type=""xsd:string"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""assembly"">
+ <xsd:complexType>
+ <xsd:attribute name=""alias"" type=""xsd:string"" />
+ <xsd:attribute name=""name"" type=""xsd:string"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""data"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ <xsd:element name=""comment"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""2"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" msdata:Ordinal=""1"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" msdata:Ordinal=""3"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" msdata:Ordinal=""4"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""resheader"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <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>";
+
+ static string convertableResXWithoutAssemblyName =
+@"<?xml version=""1.0"" encoding=""utf-8""?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name=""resmimetype"">text/microsoft-resx</resheader>
+ <resheader name=""version"">2.0</resheader>
+ <resheader name=""reader"">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name=""writer"">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name=""Name1""><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name=""Color1"" type=""System.Drawing.Color, System.Drawing"">Blue</data>
+ <data name=""Bitmap1"" mimetype=""application/x-microsoft.net.object.binary.base64"">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name=""Icon1"" type=""System.Drawing.Icon, System.Drawing"" mimetype=""application/x-microsoft.net.object.bytearray.base64"">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of ""resheader"" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id=""root"" xmlns="""" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
+ <xsd:import namespace=""http://www.w3.org/XML/1998/namespace"" />
+ <xsd:element name=""root"" msdata:IsDataSet=""true"">
+ <xsd:complexType>
+ <xsd:choice maxOccurs=""unbounded"">
+ <xsd:element name=""metadata"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" use=""required"" type=""xsd:string"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""assembly"">
+ <xsd:complexType>
+ <xsd:attribute name=""alias"" type=""xsd:string"" />
+ <xsd:attribute name=""name"" type=""xsd:string"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""data"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ <xsd:element name=""comment"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""2"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" msdata:Ordinal=""1"" />
+ <xsd:attribute name=""type"" type=""xsd:string"" msdata:Ordinal=""3"" />
+ <xsd:attribute name=""mimetype"" type=""xsd:string"" msdata:Ordinal=""4"" />
+ <xsd:attribute ref=""xml:space"" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name=""resheader"">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
+ </xsd:sequence>
+ <xsd:attribute name=""name"" type=""xsd:string"" use=""required"" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <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>";
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs
new file mode 100644
index 00000000000..be23d6c4554
--- /dev/null
+++ b/mcs/class/Managed.Windows.Forms/Test/System.Resources/ResourcesTestHelper.cs
@@ -0,0 +1,156 @@
+#if NET_2_0
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using System.Windows.Forms;
+using System.IO;
+using System.Resources;
+using System.Collections;
+using System.Drawing;
+using System.Runtime.Serialization.Formatters.Binary;
+
+namespace MonoTests.System.Resources {
+ public class ResourcesTestHelper {
+ string tempFileWithIcon = null;
+ string tempFileWithSerializable = null;
+
+ [SetUp]
+ protected virtual void SetUp ()
+ {
+
+ }
+
+ protected ResXDataNode GetNodeFromResXReader (ResXDataNode node)
+ {
+ StringWriter sw = new StringWriter ();
+ using (ResXResourceWriter writer = new ResXResourceWriter (sw)) {
+ writer.AddResource (node);
+ }
+
+ StringReader sr = new StringReader (sw.GetStringBuilder ().ToString ());
+
+ using (ResXResourceReader reader = new ResXResourceReader (sr)) {
+ reader.UseResXDataNodes = true;
+ IDictionaryEnumerator enumerator = reader.GetEnumerator ();
+ enumerator.MoveNext ();
+
+ return ((DictionaryEntry) enumerator.Current).Value as ResXDataNode;
+ }
+ }
+
+ protected ResXDataNode GetNodeFromResXReader (string contents)
+ {
+ StringReader sr = new StringReader (contents);
+
+ using (ResXResourceReader reader = new ResXResourceReader (sr)) {
+ reader.UseResXDataNodes = true;
+ IDictionaryEnumerator enumerator = reader.GetEnumerator ();
+ enumerator.MoveNext ();
+
+ return (ResXDataNode) ((DictionaryEntry) enumerator.Current).Value;
+ }
+ }
+
+ public ResXDataNode GetNodeEmdeddedIcon ()
+ {
+ Stream input = typeof (ResXDataNodeTest).Assembly.
+ GetManifestResourceStream ("32x32.ico");
+
+ Icon ico = new Icon (input);
+ ResXDataNode node = new ResXDataNode ("test", ico);
+ return node;
+ }
+
+ public ResXDataNode GetNodeFileRefToIcon ()
+ {
+ tempFileWithIcon = Path.GetTempFileName (); // remember to delete file in teardown
+ Path.ChangeExtension (tempFileWithIcon, "ico");
+
+ WriteEmbeddedResource ("32x32.ico", tempFileWithIcon);
+ ResXFileRef fileRef = new ResXFileRef (tempFileWithIcon, typeof (Icon).AssemblyQualifiedName);
+ ResXDataNode node = new ResXDataNode ("test", fileRef);
+
+ return node;
+ }
+
+ 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 ();
+ }
+ }
+
+ public ResXDataNode GetNodeEmdeddedBytes1To10 ()
+ {
+ byte [] someBytes = new byte [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ ResXDataNode node = new ResXDataNode ("test", someBytes);
+ return node;
+ }
+
+ public ResXDataNode GetNodeEmdeddedSerializable ()
+ {
+ serializable ser = new serializable ("testName", "testValue");
+ ResXDataNode node = new ResXDataNode ("test", ser);
+ return node;
+ }
+
+ public ResXDataNode GetNodeFileRefToSerializable (string filename, bool assemblyQualifiedName)
+ {
+ tempFileWithSerializable = Path.GetTempFileName (); // remember to delete file in teardown
+ serializable ser = new serializable ("name", "value");
+
+ SerializeToFile (tempFileWithSerializable, ser);
+
+ string typeName;
+
+ if (assemblyQualifiedName)
+ typeName = typeof (serializable).AssemblyQualifiedName;
+ else
+ typeName = typeof (serializable).FullName;
+
+ ResXFileRef fileRef = new ResXFileRef (tempFileWithSerializable, typeName);
+ ResXDataNode node = new ResXDataNode ("test", fileRef);
+
+ return node;
+ }
+
+ static void SerializeToFile (string filepath, serializable ser)
+ {
+ Stream stream = File.Open (filepath, FileMode.Create);
+ BinaryFormatter bFormatter = new BinaryFormatter ();
+ bFormatter.Serialize (stream, ser);
+ stream.Close ();
+ }
+
+
+ [TearDown]
+ protected virtual void TearDown ()
+ {
+ if (tempFileWithIcon != null) {
+ File.Delete (tempFileWithIcon);
+ tempFileWithIcon = null;
+ }
+
+ if (tempFileWithSerializable != null) {
+ File.Delete (tempFileWithSerializable);
+ tempFileWithSerializable = null;
+ }
+ }
+ }
+}
+#endif
+