You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
committed by
Jo Shields
parent
183bba2c9a
commit
6992685b86
105
mcs/class/System.Windows.Forms/Test/System.Resources/ChangeLog
Normal file
105
mcs/class/System.Windows.Forms/Test/System.Resources/ChangeLog
Normal file
@@ -0,0 +1,105 @@
|
||||
2008-10-31 Andreia Gaita <shana@jitted.com>
|
||||
|
||||
* CompatTest.cs, CultureTest.cs, ResXDataNodeTest.cs,
|
||||
ResXFileRefTest.cs, ResXResourceReaderTest.cs, WriterTest.cs:
|
||||
All tests now inherit from TestHelper so that the setup and
|
||||
teardown routines are always called (barring one or two that already
|
||||
inherit from swf classes that needs to be fixed)
|
||||
|
||||
2008-08-24 Gert Driesen <drieseng@users.sourceforge.net>
|
||||
|
||||
* ResXFileRefTest.cs: Fixed/added attributes on SetUp and TearDown
|
||||
methods.
|
||||
|
||||
2008-07-07 Jonathan Pobst <monkey@jpobst.com>
|
||||
|
||||
* ResXResourceReaderTest.cs: Ignore test that is dependent on
|
||||
hashtable ordering.
|
||||
|
||||
2008-01-27 Gert Driesen <drieseng@users.sourceforge.net>
|
||||
|
||||
* ResXResourceReaderTest.cs: Added Mono-only ctor tests. Fixed
|
||||
and improved UseResXDataNodes test. Improved GetMetadataEnumerator
|
||||
test.
|
||||
* WriterTest.cs: Added Mono-only ctor tests.
|
||||
* ResXFileRefTest.cs: Conversion to MemoryStream is only supported on
|
||||
2.0 profile.
|
||||
* ResXDataNodeTest.cs: Fixed line endings.
|
||||
|
||||
2008-01-23 Olivier Dufour <olivier.duff@gmail.com>
|
||||
|
||||
* ResXResourceReaderTest.cs: Fix the value for test GetNodePosition.
|
||||
|
||||
2008-01-21 Zoltan Varga <vargaz@gmail.com>
|
||||
|
||||
* ResXFileRefTest.cs: Add a test for #354994.
|
||||
|
||||
2008-01-20 Olivier Dufour <olivier.duff@gmail.com>
|
||||
|
||||
* ResXResourceReaderTest.cs: Add tests to check GetNodePosition.
|
||||
|
||||
2007-05-23 Andreia Gaita <avidigal@novell.com>
|
||||
|
||||
* ResXResourceReaderTest.cs, CompatTest.cs: Fix tests so they can run
|
||||
in make run-test and with the tests scripts.
|
||||
|
||||
2007-05-21 Andreia Gaita <avidigal@novell.com>
|
||||
|
||||
* ResXDataNodeTest.cs: Added tests
|
||||
|
||||
2007-04-25 Rolf Bjarne Kvinge <RKvinge@novell.com>
|
||||
|
||||
* WriterTest.cs: Add a message if anyone forgets to close a form again.
|
||||
|
||||
2007-03-10 Gert Driesen <drieseng@users.sourceforge.net>
|
||||
|
||||
* ResXResourceReaderTest.cs: Added test for special casing of .ico
|
||||
files.
|
||||
|
||||
2007-02-13 Rolf Bjarne Kvinge <RKvinge@novell.com>
|
||||
|
||||
* ResXFileRefTest.cs: Removed warnings.
|
||||
|
||||
2007-02-10 Gert Driesen <drieseng@users.sourceforge.net>
|
||||
|
||||
* ResXResourceReaderTest.cs: Fixed warnings, improve existing tests. Added
|
||||
test for invalid reader and writer.
|
||||
|
||||
2007-02-04 Gert Driesen <drieseng@users.sourceforge.net>
|
||||
|
||||
* ResXResourceReaderTest.cs: Added large set of tests.
|
||||
* ResXFileRefTest.cs: Added tests for ResXFileRef and converter.
|
||||
|
||||
2006-12-29 Gert Driesen <drieseng@users.sourceforge.net>
|
||||
|
||||
* CultureTest.cs: Added SetUp and TearDown. Spaces to tabs.
|
||||
* WriterTest.cs Added SetUp and TearDown. Spaces to tabs.
|
||||
|
||||
2006-12-29 Gert Driesen <drieseng@users.sourceforge.net>
|
||||
|
||||
* CompatTest.cs: Fixed test for 2.0 profile and 1.0 profile. Enabled
|
||||
test for 1.0 profile. Spaces to tabs.
|
||||
|
||||
2006-10-03 Robert Jordan <robertj@gmx.net>
|
||||
|
||||
* compat_2_0.resx, compat_1_1.resx: Add an Image element to test the
|
||||
type converter. Add InvalidMimeType, an element with an invalid
|
||||
mimetype attribute.
|
||||
|
||||
* CompatTest.cs: Add assert for the InvalidMimeType and Image elements.
|
||||
Fix the test for the 2.0 profile.
|
||||
|
||||
* WriterTest.cs: Add type converter tests.
|
||||
|
||||
2006-01-14 Robert Jordan <robertj@gmx.net>
|
||||
|
||||
* compat_2_0.resx: Added a CDATA element as a test for bug #77253.
|
||||
|
||||
2005-12-01 Robert Jordan <robertj@gmx.net>
|
||||
|
||||
* CompatTest.cs, compat*.resx: Compatibility unit tests.
|
||||
* WriterTest.cs: Unit tests for ResXResourceWriter.
|
||||
|
||||
2005-11-30 Robert Jordan <robertj@gmx.net>
|
||||
|
||||
* CultureTest.cs: Unit tests for the culture-invariance.
|
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// CompatTest.cs: Compatibility unit tests for ResXResourceReader.
|
||||
//
|
||||
// Authors:
|
||||
// Robert Jordan <robertj@gmx.net>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Resources
|
||||
{
|
||||
[TestFixture]
|
||||
public class CompatTest : MonoTests.System.Windows.Forms.TestHelper
|
||||
{
|
||||
class Helper
|
||||
{
|
||||
public static void TestReader (string fileName)
|
||||
{
|
||||
ResXResourceReader r = new ResXResourceReader (fileName);
|
||||
Hashtable h = new Hashtable ();
|
||||
foreach (DictionaryEntry e in r) {
|
||||
h.Add (e.Key, e.Value);
|
||||
}
|
||||
r.Close ();
|
||||
|
||||
Assert.AreEqual ("hola", (string) h ["String"], fileName + "#1");
|
||||
Assert.AreEqual ("hello", (string) h ["String2"], fileName + "#2");
|
||||
Assert.AreEqual (42, (int) h ["Int"], fileName + "#3");
|
||||
Assert.AreEqual (PlatformID.Win32NT, (PlatformID) h ["Enum"], fileName + "#4");
|
||||
Assert.AreEqual (43, ((Point) h ["Convertible"]).X, fileName + "#5");
|
||||
Assert.AreEqual (2, (byte) ((ArrayList) h ["Serializable"]) [1], fileName + "#6");
|
||||
Assert.AreEqual (13, ((byte []) h ["ByteArray"]) [1], fileName + "#7");
|
||||
Assert.AreEqual (16, ((byte []) h ["ByteArray2"]) [1], fileName + "#8");
|
||||
Assert.AreEqual (1013, ((int []) h ["IntArray"]) [1], fileName + "#9");
|
||||
Assert.AreEqual ("world", ((string []) h ["StringArray"]) [1], fileName + "#10");
|
||||
Assert.IsNull (h ["InvalidMimeType"], "#11");
|
||||
Assert.IsNotNull (h ["Image"], fileName + "#12");
|
||||
Assert.AreEqual (typeof (Bitmap), h ["Image"].GetType (), fileName + "#13");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReader ()
|
||||
{
|
||||
string fileName = Path.Combine (Path.Combine ("Test", "System.Resources"), "compat_1_1.resx");
|
||||
if (!File.Exists (fileName))
|
||||
fileName = String.Format ("..{0}System.Resources{0}compat_1_1.resx", Path.DirectorySeparatorChar);
|
||||
|
||||
Helper.TestReader (fileName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReader_2_0 ()
|
||||
{
|
||||
string fileName = Path.Combine (Path.Combine ("Test", "System.Resources"), "compat_2_0.resx");
|
||||
if (!File.Exists (fileName))
|
||||
fileName = String.Format ("..{0}System.Resources{0}compat_2_0.resx", Path.DirectorySeparatorChar);
|
||||
|
||||
Helper.TestReader (fileName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// CultureTest.cs: Test cases for culture-invariant string convertions
|
||||
//
|
||||
// Authors:
|
||||
// Robert Jordan <robertj@gmx.net>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Threading;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Resources
|
||||
{
|
||||
[TestFixture]
|
||||
public class CultureTest : MonoTests.System.Windows.Forms.TestHelper
|
||||
{
|
||||
string fileName = null;
|
||||
|
||||
[SetUp]
|
||||
protected override void SetUp ()
|
||||
{
|
||||
fileName = Path.GetTempFileName ();
|
||||
base.SetUp ();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
protected override void TearDown ()
|
||||
{
|
||||
File.Delete (fileName);
|
||||
base.TearDown ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test ()
|
||||
{
|
||||
Thread.CurrentThread.CurrentCulture =
|
||||
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("de-DE");
|
||||
|
||||
ResXResourceWriter w = new ResXResourceWriter (fileName);
|
||||
w.AddResource ("point", new Point (42, 43));
|
||||
w.Generate ();
|
||||
w.Close ();
|
||||
|
||||
int count = 0;
|
||||
ResXResourceReader r = new ResXResourceReader (fileName);
|
||||
IDictionaryEnumerator e = r.GetEnumerator ();
|
||||
while (e.MoveNext ()) {
|
||||
if ((string) e.Key == "point") {
|
||||
Assert.AreEqual (typeof (Point), e.Value.GetType (), "#1");
|
||||
Point p = (Point) e.Value;
|
||||
Assert.AreEqual (42, p.X, "#2");
|
||||
Assert.AreEqual (43, p.Y, "#3");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
r.Close ();
|
||||
Assert.AreEqual (1, count, "#100");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,183 @@
|
||||
//
|
||||
// HelperClasses_ITRS.cs : Various ITypeResolutionService implementations
|
||||
// for use during testing.
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MonoTests.System.Resources {
|
||||
public class DummyITRS : 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 ReturnSerializableSubClassITRS : 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 ReturnIntITRS : 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 ExceptionalITRS : 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,194 @@
|
||||
//
|
||||
// HelperClasses_Resources.cs : Various types to use as resources during
|
||||
// testing. Note some more are present in DummyAssembly project and
|
||||
// WriterTest.cs
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,173 @@
|
||||
//
|
||||
// ResXDataNodeAliasTests.cs : These tests are not a lot of use. Support for
|
||||
// Aliases not implemented as of Aug 2012.
|
||||
// FIXME: delete these tests?
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Resources {
|
||||
[TestFixture]
|
||||
public class ResXDataNodeAliasTests : ResourcesTestHelper {
|
||||
|
||||
[Test, ExpectedException (typeof (TypeLoadException))]
|
||||
public void CantAccessValueWereOnlyFullNameInResXForEmbedded () // same as validity check in assemblynames tests
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResX);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object obj = node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
|
||||
[Test, ExpectedException (typeof (TypeLoadException))]
|
||||
public void CantAccessValueWereOnlyFullNameAndAliasInResXForEmbedded ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResXAlias);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object obj = node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanAccessValueWereOnlyFullNameAndAssemblyInResXForEmbedded ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResXAssembly);
|
||||
|
||||
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";
|
||||
|
||||
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanAccessValueWereFullNameAndQualifiedAssemblyInResXForEmbedded ()
|
||||
{
|
||||
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";
|
||||
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2");
|
||||
}
|
||||
|
||||
static string convertableResX =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
|
||||
static string convertableResXAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable, DummyAssembly"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
|
||||
static string convertableResXAlias =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias=""DummyAssembly"" name=""DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" />
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string convertableResXQualifiedAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable, DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// ResXDataNodeByteArrayTests.cs : Tests how ResXDataNode handles byte[]
|
||||
// type resources.
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using System.ComponentModel.Design;
|
||||
|
||||
namespace MonoTests.System.Resources {
|
||||
[TestFixture]
|
||||
public class ResXDataNodeByteArrayTests : ResourcesTestHelper {
|
||||
|
||||
[Test]
|
||||
public void GetValueITRSNotUsedWhenNodeReturnedFromReader ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeEmdeddedBytes1To10 ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
object val = returnedNode.GetValue (new ReturnIntITRS ());
|
||||
Assert.IsInstanceOfType (typeof (byte[]), val, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueITRSNotTouchedWhenNodeCreatedNew ()
|
||||
{
|
||||
ResXDataNode node;
|
||||
node = GetNodeEmdeddedBytes1To10 ();
|
||||
|
||||
//would raise exception if param used
|
||||
Object obj = node.GetValue (new ExceptionalITRS ());
|
||||
Assert.IsInstanceOfType (typeof (byte[]), obj, "#A1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueTypeNameITRSIsUsedWithNodeFromReader ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeEmdeddedBytes1To10 ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
string returnedType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
|
||||
Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueTypeNameITRSIsUsedAfterGetValueCalledWithNodeFromReader ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeEmdeddedBytes1To10 ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
object obj = returnedNode.GetValue ((ITypeResolutionService) null);
|
||||
string returnedType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
|
||||
Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueTypeNameITRSNotUsedWhenNodeCreatedNew ()
|
||||
{
|
||||
ResXDataNode node;
|
||||
node = GetNodeEmdeddedBytes1To10 ();
|
||||
|
||||
string returnedType = node.GetValueTypeName (new ReturnIntITRS ());
|
||||
Assert.AreEqual ((typeof (byte[])).AssemblyQualifiedName, returnedType, "#A1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// ResXDataNodeFileRefGetValueTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
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]
|
||||
public void ITRSNotUsedWhenNodeFromReader ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeFileRefToSerializable ("ser.bbb",true);
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
object val = returnedNode.GetValue (new ReturnSerializableSubClassITRS ());
|
||||
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]
|
||||
public void ITRSNotUsedWhenNodeCreatedNew ()
|
||||
{
|
||||
ResXDataNode node;
|
||||
node = GetNodeFileRefToSerializable ("ser.bbb",true);
|
||||
|
||||
object val = node.GetValue (new ReturnSerializableSubClassITRS ());
|
||||
Assert.IsNotInstanceOfType (typeof (serializableSubClass), val, "#A1");
|
||||
Assert.IsInstanceOfType (typeof (serializable), val, "#A2");
|
||||
}
|
||||
|
||||
[Test, ExpectedException (typeof (TargetInvocationException))]
|
||||
public void LoadingFileFails ()
|
||||
{
|
||||
string corruptFile = Path.GetTempFileName ();
|
||||
ResXFileRef fileRef = new ResXFileRef (corruptFile, typeof (serializable).AssemblyQualifiedName);
|
||||
|
||||
File.AppendAllText (corruptFile, "corrupt");
|
||||
ResXDataNode node = new ResXDataNode ("aname", fileRef);
|
||||
node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
|
||||
#region initial
|
||||
|
||||
[Test]
|
||||
public void NullAssemblyNamesOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
|
||||
Object ico = node.GetValue ((AssemblyName []) null);
|
||||
Assert.IsNotNull (ico, "#A1");
|
||||
Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullITRSOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
|
||||
Object ico = node.GetValue ((ITypeResolutionService) null);
|
||||
Assert.IsNotNull (ico, "#A1");
|
||||
Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongITRSOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
|
||||
Object ico = node.GetValue (new DummyITRS ());
|
||||
Assert.IsNotNull (ico, "#A1");
|
||||
Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongAssemblyNamesOK ()
|
||||
{
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// ResXDataNodeFileRefGetValueTypeNameTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
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 = this.GetType ().Assembly.FullName;
|
||||
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 ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeFileRefToSerializable ("ser.bbb",true);
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
string returnedType = returnedNode.GetValueTypeName (new ReturnSerializableSubClassITRS ());
|
||||
Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, returnedType, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSUsedWhenNodeCreatedNew ()
|
||||
{
|
||||
ResXDataNode node;
|
||||
node = GetNodeFileRefToSerializable ("ser.bbb",true);
|
||||
|
||||
string returnedType = node.GetValueTypeName (new ReturnSerializableSubClassITRS ());
|
||||
Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, returnedType, "#A1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IfTypeResolutionFailsReturnsOrigString()
|
||||
{
|
||||
ResXFileRef fileRef = new ResXFileRef ("afile.name", "a.type.name");
|
||||
ResXDataNode node = new ResXDataNode ("aname", fileRef);
|
||||
|
||||
string returnedType = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual ("a.type.name", returnedType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AttemptsTypeResolution ()
|
||||
{
|
||||
ResXFileRef fileRef = new ResXFileRef ("afile.name", "System.String");
|
||||
ResXDataNode node = new ResXDataNode ("aname", fileRef);
|
||||
|
||||
string returnedType = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual (typeof (string).AssemblyQualifiedName, returnedType);
|
||||
}
|
||||
|
||||
#region Initial Exploratory Tests
|
||||
|
||||
[Test]
|
||||
public void NullAssemblyNamesOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
|
||||
string name = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullITRSOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
|
||||
string name = node.GetValueTypeName ((ITypeResolutionService) null);
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongITRSOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
|
||||
string name = node.GetValueTypeName (new DummyITRS ());
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongAssemblyNamesOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
AssemblyName [] ass = new AssemblyName [1];
|
||||
ass [0] = new AssemblyName ("DummyAssembly");
|
||||
|
||||
string name = node.GetValueTypeName (ass);
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,332 @@
|
||||
//
|
||||
// ResXDataNodeSerializedGetValueTypeNameTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace MonoTests.System.Resources {
|
||||
[TestFixture]
|
||||
public class ResXDataNodeSerializedGetValueTypeNameTests : ResourcesTestHelper {
|
||||
[Test]
|
||||
public void ITRSUsedWithNodeFromReader ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeEmdeddedSerializable ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
string returnedType = returnedNode.GetValueTypeName (new ReturnSerializableSubClassITRS ());
|
||||
Assert.AreEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, returnedType, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSOnlyUsedFirstTimeWithNodeFromReader ()
|
||||
{
|
||||
// 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);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
string defaultType = returnedNode.GetValueTypeName ((ITypeResolutionService) null);
|
||||
Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, defaultType, "#A2");
|
||||
|
||||
string newType = returnedNode.GetValueTypeName (new ReturnSerializableSubClassITRS ());
|
||||
Assert.AreNotEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A3");
|
||||
Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A4");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSNotUsedWhenNodeCreatedNew ()
|
||||
{
|
||||
ResXDataNode node;
|
||||
node = GetNodeEmdeddedSerializable ();
|
||||
|
||||
string returnedType = node.GetValueTypeName (new ReturnSerializableSubClassITRS ());
|
||||
Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, returnedType, "#A1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSIsIgnoredIfGetValueAlreadyCalledWithAnotherITRS ()
|
||||
{
|
||||
// check that first call to GetValue sets the type for GetValueTypeName
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeEmdeddedSerializable ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
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 ReturnSerializableSubClassITRS ());
|
||||
Assert.AreNotEqual ((typeof (serializableSubClass)).AssemblyQualifiedName, newType, "#A4");
|
||||
Assert.AreEqual ((typeof (serializable)).AssemblyQualifiedName, newType, "#A5");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoapFormattedObject ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (serializedResXSOAP);
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
// hard coded assembly name value refers to that generated under 2.0 prefix, so use compatible available class
|
||||
string name = node.GetValueTypeName (new ReturnSerializableSubClassITRS ());
|
||||
Assert.AreEqual (typeof (serializableSubClass).AssemblyQualifiedName, name, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializationErrorReturnsObjectType ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (serializedResXCorruped);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string type = node.GetValueTypeName ((AssemblyName []) null);
|
||||
|
||||
Assert.AreEqual (typeof (object).AssemblyQualifiedName,type, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidMimeTypeFromReaderReturnsNull ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (serializedResXInvalidMimeType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string type = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.IsNull (type, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssemblyAutomaticallyLoaded ()
|
||||
{
|
||||
// DummyAssembly must be in the same directory as current assembly to work correctly
|
||||
ResXDataNode node = GetNodeFromResXReader (anotherSerializableFromDummyAssembly);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string type = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual ("DummyAssembly.AnotherSerializable, DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", type, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsObjectAssemblyMissing ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (missingSerializableFromMissingAssembly);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string type = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual (typeof (object).AssemblyQualifiedName, type, "#A2");
|
||||
}
|
||||
|
||||
static string serializedResXInvalidMimeType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<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/xxxx"">
|
||||
<value>
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string serializedResXCorruped =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string serializedResXSOAP =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" mimetype=""application/x-microsoft.net.object.soap.base64"">
|
||||
<value>
|
||||
PFNPQVAtRU5WOkVudmVsb3BlIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2Ui
|
||||
IHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zOlNPQVAtRU5DPSJodHRwOi8vc2No
|
||||
ZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VuY29kaW5nLyIgeG1sbnM6U09BUC1FTlY9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAu
|
||||
b3JnL3NvYXAvZW52ZWxvcGUvIiB4bWxuczpjbHI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vc29hcC9lbmNvZGlu
|
||||
Zy9jbHIvMS4wIiBTT0FQLUVOVjplbmNvZGluZ1N0eWxlPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VuY29k
|
||||
aW5nLyI+DQo8U09BUC1FTlY6Qm9keT4NCjxhMTpzZXJpYWxpemFibGUgaWQ9InJlZi0xIiB4bWxuczphMT0iaHR0cDovL3Nj
|
||||
aGVtYXMubWljcm9zb2Z0LmNvbS9jbHIvbnNhc3NlbS9Nb25vVGVzdHMuU3lzdGVtLlJlc291cmNlcy9TeXN0ZW0uV2luZG93
|
||||
cy5Gb3Jtc190ZXN0X25ldF8yXzAlMkMlMjBWZXJzaW9uJTNEMC4wLjAuMCUyQyUyMEN1bHR1cmUlM0RuZXV0cmFsJTJDJTIw
|
||||
UHVibGljS2V5VG9rZW4lM0RudWxsIj4NCjxzZXJuYW1lIGlkPSJyZWYtMyI+YW5hbWU8L3Nlcm5hbWU+DQo8c2VydmFsdWUg
|
||||
aWQ9InJlZi00Ij5hdmFsdWU8L3NlcnZhbHVlPg0KPC9hMTpzZXJpYWxpemFibGU+DQo8L1NPQVAtRU5WOkJvZHk+DQo8L1NP
|
||||
QVAtRU5WOkVudmVsb3BlPg==
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string missingSerializableFromMissingAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs
|
||||
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n
|
||||
U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs
|
||||
dWUL
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string anotherSerializableFromDummyAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
|
||||
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl
|
||||
cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl
|
||||
Cw==
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string convertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string thisAssemblyConvertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,355 @@
|
||||
//
|
||||
// ResXDataNodeSerializedGetValueTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Runtime.Serialization.Formatters.Soap;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace MonoTests.System.Resources {
|
||||
[TestFixture]
|
||||
public class ResXDataNodeSerializedGetValueTests : ResourcesTestHelper {
|
||||
[Test]
|
||||
public void ITRSOnlyUsedFirstTimeWithNodeFromReader ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeEmdeddedSerializable ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
|
||||
object defaultVal = returnedNode.GetValue ((ITypeResolutionService) null);
|
||||
Assert.IsInstanceOfType (typeof (serializable), defaultVal, "#A2");
|
||||
Assert.IsNotInstanceOfType (typeof (serializableSubClass), defaultVal, "#A3");
|
||||
|
||||
object newVal = returnedNode.GetValue (new ReturnSerializableSubClassITRS ());
|
||||
Assert.IsNotInstanceOfType (typeof (serializableSubClass), newVal, "#A4");
|
||||
Assert.IsInstanceOfType (typeof (serializable), newVal, "#A5");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSUsedWhenNodeReturnedFromReader ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
originalNode = GetNodeEmdeddedSerializable ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
|
||||
object val = returnedNode.GetValue (new ReturnSerializableSubClassITRS ());
|
||||
Assert.IsInstanceOfType (typeof (serializableSubClass), val, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSIsIgnoredIfGetValueTypeNameAlreadyCalledWithAnotherITRS ()
|
||||
{
|
||||
// check that first call to GetValueTypeName sets the type for GetValue
|
||||
|
||||
ResXDataNode originalNode, returnedNode;
|
||||
|
||||
originalNode = GetNodeEmdeddedSerializable ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
|
||||
//get value type passing params
|
||||
string newType = returnedNode.GetValueTypeName (new ReturnSerializableSubClassITRS ());
|
||||
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]
|
||||
public void ITRSNotTouchedWhenNodeCreatedNew ()
|
||||
{
|
||||
// check supplied params to GetValue are not touched
|
||||
// for an instance created manually
|
||||
ResXDataNode node = GetNodeEmdeddedSerializable ();
|
||||
|
||||
//would raise exception if param used
|
||||
Object obj = node.GetValue (new ExceptionalITRS ());
|
||||
Assert.IsInstanceOfType (typeof (serializable), obj, "#A1");
|
||||
}
|
||||
|
||||
[Test, ExpectedException (typeof (SerializationException))]
|
||||
public void DeserializationError ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (serializedResXCorruped);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object val = node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidMimeTypeFromReaderReturnsNull ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (serializedResXInvalidMimeType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object val = node.GetValue ((AssemblyName []) null);
|
||||
Assert.IsNull (val, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoapFormattedObject ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (serializedResXSOAP);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
// hard coded assembly name value refers to that generated under 2.0 prefix, so use compatible available class
|
||||
object val = node.GetValue (new ReturnSerializableSubClassITRS ());
|
||||
Assert.AreEqual ("name=aname;value=avalue", val.ToString (), "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssemblyAutomaticallyLoaded ()
|
||||
{
|
||||
// DummyAssembly must be in the same directory as current assembly to work correctly
|
||||
ResXDataNode node = GetNodeFromResXReader (anotherSerializableFromDummyAssembly);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object value = node.GetValue ((AssemblyName []) null);
|
||||
Assert.AreEqual ("DummyAssembly.AnotherSerializable, DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", value.GetType ().AssemblyQualifiedName, "#A2");
|
||||
}
|
||||
|
||||
[Test, ExpectedException (typeof (ArgumentException))]
|
||||
public void ErrorWhenAssemblyMissing ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (missingSerializableFromMissingAssembly);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object val = node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RefToSameObjectNotHeld ()
|
||||
{
|
||||
ResXDataNode node = GetNodeEmdeddedSerializable ();
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
serializable ser1 = (serializable) returnedNode.GetValue ((AssemblyName []) null);
|
||||
ser1.name = "beenchanged";
|
||||
serializable ser2 = (serializable) returnedNode.GetValue ((AssemblyName []) null);
|
||||
Assert.AreNotSame (ser1, ser2, "#A2");
|
||||
}
|
||||
|
||||
static string serializedResXInvalidMimeType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" mimetype=""application/xxxx"">
|
||||
<value>
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string serializedResXCorruped =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string soapSerializedSerializable =
|
||||
@"<SOAP-ENV:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:clr=""http://schemas.microsoft.com/soap/encoding/clr/1.0"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">
|
||||
<SOAP-ENV:Body>
|
||||
<a1:serializable id=""ref-1"" xmlns:a1=""http://schemas.microsoft.com/clr/nsassem/MonoTests.System.Resources/System.Windows.Forms_test_net_2_0%2C%20Version%3D0.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull"">
|
||||
<sername id=""ref-3"">aname</sername>
|
||||
<servalue id=""ref-4"">avalue</servalue>
|
||||
</a1:serializable>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>";
|
||||
|
||||
static string serializedResXSOAP =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" mimetype=""application/x-microsoft.net.object.soap.base64"">
|
||||
<value>
|
||||
PFNPQVAtRU5WOkVudmVsb3BlIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2Ui
|
||||
IHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zOlNPQVAtRU5DPSJodHRwOi8vc2No
|
||||
ZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VuY29kaW5nLyIgeG1sbnM6U09BUC1FTlY9Imh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAu
|
||||
b3JnL3NvYXAvZW52ZWxvcGUvIiB4bWxuczpjbHI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vc29hcC9lbmNvZGlu
|
||||
Zy9jbHIvMS4wIiBTT0FQLUVOVjplbmNvZGluZ1N0eWxlPSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VuY29k
|
||||
aW5nLyI+DQo8U09BUC1FTlY6Qm9keT4NCjxhMTpzZXJpYWxpemFibGUgaWQ9InJlZi0xIiB4bWxuczphMT0iaHR0cDovL3Nj
|
||||
aGVtYXMubWljcm9zb2Z0LmNvbS9jbHIvbnNhc3NlbS9Nb25vVGVzdHMuU3lzdGVtLlJlc291cmNlcy9TeXN0ZW0uV2luZG93
|
||||
cy5Gb3Jtc190ZXN0X25ldF8yXzAlMkMlMjBWZXJzaW9uJTNEMC4wLjAuMCUyQyUyMEN1bHR1cmUlM0RuZXV0cmFsJTJDJTIw
|
||||
UHVibGljS2V5VG9rZW4lM0RudWxsIj4NCjxzZXJuYW1lIGlkPSJyZWYtMyI+YW5hbWU8L3Nlcm5hbWU+DQo8c2VydmFsdWUg
|
||||
aWQ9InJlZi00Ij5hdmFsdWU8L3NlcnZhbHVlPg0KPC9hMTpzZXJpYWxpemFibGU+DQo8L1NPQVAtRU5WOkJvZHk+DQo8L1NP
|
||||
QVAtRU5WOkVudmVsb3BlPg==
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string missingSerializableFromMissingAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs
|
||||
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n
|
||||
U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs
|
||||
dWUL
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string anotherSerializableFromDummyAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
|
||||
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl
|
||||
cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl
|
||||
Cw==
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string convertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string thisAssemblyConvertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,414 @@
|
||||
// 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) 2007 Novell, Inc. (http://www.novell.com)
|
||||
//
|
||||
// ResXFileRefTest.cs: Unit Tests for ResXFileRef.
|
||||
//
|
||||
// Authors:
|
||||
// Andreia Gaita (avidigal@novell.com)
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Drawing;
|
||||
using System.Resources;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace MonoTests.System.Resources {
|
||||
[TestFixture]
|
||||
public class ResXDataNodeTest : ResourcesTestHelper
|
||||
{
|
||||
string _tempDirectory;
|
||||
string _otherTempDirectory;
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (ArgumentNullException))]
|
||||
public void ConstructorEx1 ()
|
||||
{
|
||||
ResXDataNode d = new ResXDataNode (null, (object)null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (ArgumentNullException))]
|
||||
public void ConstructorEx2A ()
|
||||
{
|
||||
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 ()
|
||||
{
|
||||
ResXDataNode d = new ResXDataNode ("", (object) null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (ArgumentNullException))]
|
||||
public void ConstructorEx4 ()
|
||||
{
|
||||
ResXDataNode d = new ResXDataNode ("", (ResXFileRef) null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (ArgumentException))]
|
||||
public void ConstructorEx5 ()
|
||||
{
|
||||
ResXDataNode d = new ResXDataNode ("", new ResXFileRef ("filename", "typename"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (InvalidOperationException))]
|
||||
public void ConstructorEx6 ()
|
||||
{
|
||||
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 = "";
|
||||
}
|
||||
|
||||
[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 ()
|
||||
{
|
||||
serializable ser = new serializable ("aaaaa", "bbbbb");
|
||||
ResXDataNode dn = new ResXDataNode ("test", ser);
|
||||
dn.Comment = "comment";
|
||||
|
||||
string resXFile = GetResXFileWithNode (dn, "resx.resx");
|
||||
|
||||
bool found = false;
|
||||
ResXResourceReader rr = new ResXResourceReader (resXFile);
|
||||
rr.UseResXDataNodes = true;
|
||||
IDictionaryEnumerator en = rr.GetEnumerator ();
|
||||
while (en.MoveNext ()) {
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
rr.Close ();
|
||||
|
||||
Assert.IsTrue (found, "#A2 - Serialized object not found on resx");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConstructorResXFileRef()
|
||||
{
|
||||
ResXDataNode node = GetNodeFileRefToIcon ();
|
||||
Assert.IsNotNull (node.FileRef, "#A1");
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, node.FileRef.TypeName, "#A2");
|
||||
Assert.AreEqual ("test", node.Name, "#A3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullObjectGetValueTypeNameIsNull ()
|
||||
{
|
||||
ResXDataNode node = new ResXDataNode ("aname", (object) null);
|
||||
Assert.IsNull (node.GetValueTypeName ((AssemblyName []) null), "#A1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullObjectWrittenToResXOK ()
|
||||
{
|
||||
ResXDataNode node = new ResXDataNode ("aname", (object) null);
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.IsNull (returnedNode.GetValue ((AssemblyName []) null), "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullObjectReturnedFromResXGetValueTypeNameReturnsObject ()
|
||||
{
|
||||
ResXDataNode node = new ResXDataNode ("aname", (object) null);
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.IsNull (returnedNode.GetValue ((AssemblyName []) null), "#A2");
|
||||
string type = returnedNode.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual (typeof (object).AssemblyQualifiedName, type, "#A3");
|
||||
}
|
||||
|
||||
[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 ();
|
||||
|
||||
Assert.IsNotNull (node,"#A1");
|
||||
|
||||
serializable o = node.GetValue ((AssemblyName []) null) as serializable;
|
||||
Assert.IsNotNull (o, "#A2");
|
||||
}
|
||||
|
||||
[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 ();
|
||||
|
||||
ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
|
||||
rr.Close ();
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
|
||||
object o = node.GetValue ((AssemblyName []) null);
|
||||
Assert.IsInstanceOfType (typeof (long), o, "#A2");
|
||||
Assert.AreEqual (34L, o, "#A3");
|
||||
}
|
||||
|
||||
[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) };
|
||||
|
||||
string resXFile = GetFileFromString ("test.resx", convertableResXWithoutAssemblyName);
|
||||
|
||||
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");
|
||||
|
||||
//should raise exception
|
||||
object o = node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSPassedToResourceReaderDoesNotAffectResXDataNode_TypeConverter ()
|
||||
{
|
||||
ResXDataNode dn = new ResXDataNode ("test", 34L);
|
||||
|
||||
string resXFile = GetResXFileWithNode (dn,"resx.resx");
|
||||
|
||||
ResXResourceReader rr = new ResXResourceReader (resXFile, new ReturnIntITRS ());
|
||||
rr.UseResXDataNodes = true;
|
||||
IDictionaryEnumerator en = rr.GetEnumerator ();
|
||||
en.MoveNext ();
|
||||
|
||||
ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
|
||||
object o = node.GetValue ((AssemblyName []) null);
|
||||
|
||||
Assert.IsInstanceOfType (typeof (long), o, "#A2");
|
||||
Assert.AreEqual (34L, o, "#A3");
|
||||
|
||||
rr.Close ();
|
||||
}
|
||||
|
||||
[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 ReturnSerializableSubClassITRS ());
|
||||
rr.UseResXDataNodes = true;
|
||||
IDictionaryEnumerator en = rr.GetEnumerator ();
|
||||
en.MoveNext ();
|
||||
|
||||
ResXDataNode node = ((DictionaryEntry) en.Current).Value as ResXDataNode;
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
|
||||
object o = node.GetValue ((AssemblyName []) null);
|
||||
|
||||
Assert.IsNotInstanceOfType (typeof (serializableSubClass), o, "#A2");
|
||||
Assert.IsInstanceOfType (typeof (serializable), o, "#A3");
|
||||
rr.Close ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePathSetOnResXResourceReaderDoesAffectResXDataNode ()
|
||||
{
|
||||
ResXFileRef fileRef = new ResXFileRef ("file.name", "type.name");
|
||||
ResXDataNode node = new ResXDataNode("anode", fileRef);
|
||||
string resXFile = GetResXFileWithNode (node, "afilename.xxx");
|
||||
|
||||
using (ResXResourceReader rr = new ResXResourceReader (resXFile)) {
|
||||
rr.BasePath = "basePath";
|
||||
rr.UseResXDataNodes = true;
|
||||
IDictionaryEnumerator en = rr.GetEnumerator ();
|
||||
en.MoveNext ();
|
||||
|
||||
ResXDataNode returnedNode = ((DictionaryEntry) en.Current).Value as ResXDataNode;
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
Assert.AreEqual (Path.Combine ("basePath", "file.name"), returnedNode.FileRef.FileName, "#A2");
|
||||
}
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static string convertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,323 @@
|
||||
//
|
||||
// ResXDataNodeTypeConverterGetValueTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Reflection;
|
||||
using System.Drawing;
|
||||
|
||||
namespace MonoTests.System.Resources
|
||||
{
|
||||
[TestFixture]
|
||||
public class ResXDataNodeTypeConverterGetValueTests : ResourcesTestHelper {
|
||||
[Test]
|
||||
public void ITRSNotUsedWhenCreatedNew ()
|
||||
{
|
||||
ResXDataNode node;
|
||||
node = new ResXDataNode ("along", 34L);
|
||||
|
||||
object obj = node.GetValue (new ReturnIntITRS ());
|
||||
Assert.IsInstanceOfType (typeof (long), obj, "#A1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSUsedEachTimeWithNodeFromReader ()
|
||||
{
|
||||
ResXDataNode returnedNode, originalNode;
|
||||
originalNode = new ResXDataNode ("aNumber", 23L);
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
|
||||
object newVal = returnedNode.GetValue (new ReturnIntITRS ());
|
||||
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]
|
||||
public void InvalidMimeTypeAndTypeReturnedFromReader_ObjectIsNull ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (typeconResXInvalidMimeTypeAndType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object obj = node.GetValue ((AssemblyName []) null);
|
||||
Assert.IsNull (obj, "#A2");
|
||||
}
|
||||
|
||||
[Test, ExpectedException (typeof (TypeLoadException))]
|
||||
public void InvalidTypeReturnedFromReader_Exceptions ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (typeconResXInvalidType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object obj = node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssemblyNameUsedWhereOnlyFullNameInResX ()
|
||||
{
|
||||
// DummyAssembly must be in the same directory as current assembly to work correctly
|
||||
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
|
||||
AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
|
||||
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object obj = node.GetValue (assemblyNames);
|
||||
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName);
|
||||
}
|
||||
|
||||
[Test, ExpectedException (typeof (TypeLoadException))]
|
||||
public void AssemblyNameRequiredEachTimeWhereOnlyFullNameInResX ()
|
||||
{
|
||||
// DummyAssembly must be in the same directory as current assembly to work correctly
|
||||
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
|
||||
AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
|
||||
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object obj = node.GetValue (assemblyNames);
|
||||
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, obj.GetType ().AssemblyQualifiedName, "#A2");
|
||||
object obj2 = node.GetValue ((AssemblyName []) null); //should cause exception here
|
||||
|
||||
}
|
||||
//FIXME: does the way this test is run by NUnit affect the validity of the results showing that you need assembly name to pull type from current assembly?
|
||||
[Test, ExpectedException (typeof (TypeLoadException))]
|
||||
public void CantLoadTypeFromThisAssemblyWithOnlyFullName ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
object obj = node.GetValue ((AssemblyName []) null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanLoadTypeFromThisAssemblyWithOnlyFullNamePassingAssemblyNames ()
|
||||
{
|
||||
string aName = this.GetType ().Assembly.FullName;
|
||||
AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
|
||||
|
||||
ResXDataNode node = GetNodeFromResXReader (thisAssemblyConvertableResXWithoutAssemblyName);
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
// would cause exception if couldnt find type
|
||||
object obj = node.GetValue (assemblyNames);
|
||||
Assert.IsInstanceOfType (typeof (ThisAssemblyConvertable), obj, "#A2");
|
||||
}
|
||||
|
||||
#region initial
|
||||
|
||||
[Test]
|
||||
public void NullAssemblyNamesOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeEmdeddedIcon ();
|
||||
|
||||
Object ico = node.GetValue ((AssemblyName []) null);
|
||||
Assert.IsNotNull (ico, "#A1");
|
||||
Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullITRSOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeEmdeddedIcon ();
|
||||
|
||||
Object ico = node.GetValue ((ITypeResolutionService) null);
|
||||
Assert.IsNotNull (ico, "#A1");
|
||||
Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongITRSOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeEmdeddedIcon ();
|
||||
|
||||
Object ico = node.GetValue (new DummyITRS ());
|
||||
Assert.IsNotNull (ico, "#A1");
|
||||
Assert.IsInstanceOfType (typeof (Icon), ico, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongAssemblyNamesOK ()
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
static string typeconResXInvalidType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" type=""A.type"">
|
||||
<value>42</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string typeconResXInvalidMimeTypeAndType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" type=""A.type"" mimetype=""application/xxxx"">
|
||||
<value>42</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string missingSerializableFromMissingAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs
|
||||
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n
|
||||
U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs
|
||||
dWUL
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string anotherSerializableFromDummyAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
|
||||
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl
|
||||
cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl
|
||||
Cw==
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string convertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string thisAssemblyConvertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,320 @@
|
||||
//
|
||||
// ResXDataNodeTypeConverterGetValueTypeNameTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MonoTests.System.Resources
|
||||
{
|
||||
[TestFixture]
|
||||
public class ResXDataNodeTypeConverterGetValueTypeNameTests : ResourcesTestHelper {
|
||||
[Test]
|
||||
public void ITRSUsedWithNodeFromReader ()
|
||||
{
|
||||
ResXDataNode returnedNode, originalNode;
|
||||
originalNode = new ResXDataNode ("aNumber", 23L);
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
string returnedType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
|
||||
Assert.AreEqual ((typeof (Int32)).AssemblyQualifiedName, returnedType, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSUsedEachTimeWhenNodeFromReader ()
|
||||
{
|
||||
ResXDataNode returnedNode, originalNode;
|
||||
originalNode = new ResXDataNode ("aNumber", 23L);
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
string newType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
|
||||
Assert.AreEqual (typeof (int).AssemblyQualifiedName, newType, "#A2");
|
||||
string origType = returnedNode.GetValueTypeName ((ITypeResolutionService) null);
|
||||
Assert.AreEqual (typeof (long).AssemblyQualifiedName, origType, "#A3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ITRSNotUsedWhenNodeCreatedNew ()
|
||||
{
|
||||
ResXDataNode node;
|
||||
node = new ResXDataNode ("along", 34L);
|
||||
|
||||
string returnedType = node.GetValueTypeName (new ReturnIntITRS ());
|
||||
Assert.AreEqual ((typeof (long)).AssemblyQualifiedName, returnedType, "#A1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidMimeTypeReturnedFromReader_ReturnsStringIfCantResolveType ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (typeconResXInvalidMimeTypeAndType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string type = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual ("A.type", type, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidMimeTypeReturnedFromReader_TriesToResolve ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (typeconResXInvalidMimeType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string type = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual (typeof (string).AssemblyQualifiedName, type, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsFullNameWereOnlyFullNameInResX ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string returnedType = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual ("DummyAssembly.Convertable", returnedType, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssemblyNameUsedWhereOnlyFullNameInResX ()
|
||||
{
|
||||
// DummyAssembly must be in the same directory as current assembly to work correctly
|
||||
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
|
||||
AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
|
||||
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string returnedType = node.GetValueTypeName (assemblyNames);
|
||||
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedType, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssemblyNameUsedEachTimeWhereOnlyFullNameInResX ()
|
||||
{
|
||||
// DummyAssembly must be in the same directory as current assembly to work correctly
|
||||
string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
|
||||
AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName (aName) };
|
||||
|
||||
ResXDataNode node = GetNodeFromResXReader (convertableResXWithoutAssemblyName);
|
||||
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
string returnedName = node.GetValueTypeName (assemblyNames);
|
||||
Assert.AreEqual ("DummyAssembly.Convertable, " + aName, returnedName, "#A2");
|
||||
string nameWithNullParam = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual ("DummyAssembly.Convertable", nameWithNullParam, "#A3");
|
||||
}
|
||||
|
||||
#region initial
|
||||
|
||||
[Test]
|
||||
public void NullITRSServiceOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeEmdeddedIcon ();
|
||||
|
||||
string name = node.GetValueTypeName ((ITypeResolutionService) null);
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongITRSOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeEmdeddedIcon ();
|
||||
|
||||
string name = node.GetValueTypeName (new DummyITRS ());
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrongAssemblyNamesOK ()
|
||||
{
|
||||
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 NullAssemblyNamesOK ()
|
||||
{
|
||||
ResXDataNode node = GetNodeEmdeddedIcon ();
|
||||
|
||||
string name = node.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual (typeof (Icon).AssemblyQualifiedName, name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
static string typeconResXInvalidMimeTypeAndType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" type=""A.type"" mimetype=""application/xxxx"">
|
||||
<value>42</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string typeconResXInvalidMimeType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" type=""System.String"" mimetype=""application/xxxx"">
|
||||
<value>42</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
|
||||
static string missingSerializableFromMissingAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEZNaXNzaW5nQXNzZW1ibHksIFZlcnNpb249MS4wLjAuMCwgQ3Vs
|
||||
dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAAhRHVtbXlBc3NlbWJseS5NaXNzaW5n
|
||||
U2VyaWFsaXphYmxlAgAAAAdzZXJuYW1lCHNlcnZhbHVlAQECAAAABgMAAAAFYW5hbWUGBAAAAAZhdmFs
|
||||
dWUL
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string anotherSerializableFromDummyAssembly =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""aname"" mimetype=""application/x-microsoft.net.object.binary.base64"">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEREdW1teUFzc2VtYmx5LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1
|
||||
cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAIUR1bW15QXNzZW1ibHkuQW5vdGhlclNl
|
||||
cmlhbGl6YWJsZQIAAAAHc2VybmFtZQhzZXJ2YWx1ZQEBAgAAAAYDAAAABWFuYW1lBgQAAAAGYXZhbHVl
|
||||
Cw==
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string convertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string thisAssemblyConvertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""MonoTests.System.Resources.ThisAssemblyConvertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,399 @@
|
||||
//
|
||||
// ResXDataNodeWriteBehavior.cs : Tests how ResXDataNode's are written to
|
||||
// resx files.
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using System.Text;
|
||||
using System.ComponentModel.Design;
|
||||
|
||||
namespace MonoTests.System.Resources {
|
||||
[TestFixture]
|
||||
public class ResXDataNodeWriteBehavior : ResourcesTestHelper {
|
||||
|
||||
[Test]
|
||||
public void TypeConverterObjectNotLoaded ()
|
||||
{
|
||||
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 doesnt instantiate the encoding until the write
|
||||
ResXDataNode node = GetNodeFromResXReader (fileRefResXCorrupted);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
// would cause error if object loaded
|
||||
GetNodeFromResXReader (node);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResXNullRef_WriteBack ()
|
||||
{
|
||||
ResXDataNode node = new ResXDataNode ("NullRef", (object) null);
|
||||
node.Comment = "acomment";
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.IsNull (returnedNode.GetValue ((AssemblyName []) null), "#A2");
|
||||
Assert.AreEqual ("acomment", returnedNode.Comment,"#A3");
|
||||
ResXDataNode finalNode = GetNodeFromResXReader (returnedNode);
|
||||
Assert.IsNotNull (finalNode, "#A4");
|
||||
Assert.IsNull (finalNode.GetValue ((AssemblyName []) null), "#A5");
|
||||
Assert.AreEqual ("acomment", finalNode.Comment,"#A6");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidMimeType_WriteBack ()
|
||||
{
|
||||
//FIXME: should check the ResX output to ensure mime type / value info still there
|
||||
ResXDataNode node = GetNodeFromResXReader (serializedResXInvalidMimeType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A2");
|
||||
object obj = returnedNode.GetValue ((AssemblyName []) null);
|
||||
Assert.IsNull (obj, "#A3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvalidMimeTypeAndType_WriteBack ()
|
||||
{
|
||||
ResXDataNode node = GetNodeFromResXReader (typeconResXInvalidMimeTypeAndType);
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A2");
|
||||
string type = returnedNode.GetValueTypeName ((AssemblyName []) null);
|
||||
Assert.AreEqual ("A.type", type, "#A3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BinTypeConverter_WriteBack ()
|
||||
{
|
||||
MyBinType mb = new MyBinType ("contents");
|
||||
ResXDataNode node = new ResXDataNode ("aname", mb);
|
||||
node.Comment = "acomment";
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
MyBinType returnedMB = (MyBinType) returnedNode.GetValue ((AssemblyName []) null);
|
||||
Assert.AreEqual ("contents", returnedMB.Value, "#A2");
|
||||
Assert.AreEqual ("acomment", returnedNode.Comment, "#A3");
|
||||
ResXDataNode finalNode = GetNodeFromResXReader (returnedNode);
|
||||
Assert.IsNotNull (finalNode, "#A4");
|
||||
MyBinType finalMB = (MyBinType) finalNode.GetValue ((AssemblyName []) null);
|
||||
Assert.AreEqual ("contents", finalMB.Value, "#A5");
|
||||
Assert.AreEqual ("acomment", finalNode.Comment, "#A6");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FileRefWithEncoding_WriteBack ()
|
||||
{
|
||||
ResXFileRef fileRef = new ResXFileRef ("afilename", "A.Type.Name", Encoding.UTF7);
|
||||
ResXDataNode node = new ResXDataNode ("aname", fileRef);
|
||||
node.Comment = "acomment";
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual ("afilename", returnedNode.FileRef.FileName, "#A2");
|
||||
Assert.AreEqual ("A.Type.Name", returnedNode.FileRef.TypeName, "#A3");
|
||||
Assert.AreEqual ("acomment", returnedNode.Comment, "#A4");
|
||||
Assert.IsInstanceOfType (Encoding.UTF7.GetType (), returnedNode.FileRef.TextFileEncoding, "#A5");
|
||||
ResXDataNode finalNode = GetNodeFromResXReader (returnedNode);
|
||||
Assert.IsNotNull (finalNode, "#A6");
|
||||
Assert.AreEqual ("afilename", finalNode.FileRef.FileName, "#A7");
|
||||
Assert.AreEqual ("A.Type.Name", finalNode.FileRef.TypeName, "#A8");
|
||||
Assert.AreEqual ("acomment", finalNode.Comment, "#A9");
|
||||
Assert.IsInstanceOfType (Encoding.UTF7.GetType (), finalNode.FileRef.TextFileEncoding, "#A10");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ByteArray_WriteBack ()
|
||||
{
|
||||
byte [] testBytes = new byte [] { 1,2,3,4,5,6,7,8,9,10 };
|
||||
ResXDataNode node = new ResXDataNode ("aname", testBytes);
|
||||
node.Comment = "acomment";
|
||||
ResXDataNode returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (testBytes, returnedNode.GetValue ((AssemblyName []) null), "#A2");
|
||||
Assert.AreEqual ("acomment", returnedNode.Comment, "#A3");
|
||||
ResXDataNode finalNode = GetNodeFromResXReader (returnedNode);
|
||||
Assert.IsNotNull (finalNode,"#A4");
|
||||
Assert.AreEqual (testBytes, finalNode.GetValue ((AssemblyName []) null), "#A5");
|
||||
Assert.AreEqual ("acomment", finalNode.Comment, "#A6");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePathSetOnResXReaderAffectsFileRef_WriteBack ()
|
||||
{
|
||||
ResXDataNode returnedNode;
|
||||
StringWriter sw = new StringWriter ();
|
||||
sw.Write (fileRefResX);
|
||||
|
||||
StringReader sr = new StringReader (sw.GetStringBuilder ().ToString ());
|
||||
|
||||
using (ResXResourceReader reader = new ResXResourceReader (sr)) {
|
||||
reader.UseResXDataNodes = true;
|
||||
reader.BasePath = "basePath";
|
||||
IDictionaryEnumerator enumerator = reader.GetEnumerator ();
|
||||
enumerator.MoveNext ();
|
||||
|
||||
ResXDataNode node = ((DictionaryEntry) enumerator.Current).Value as ResXDataNode;
|
||||
Assert.IsNotNull (node, "#A1");
|
||||
Assert.AreEqual (Path.Combine ("basePath","file.name"), node.FileRef.FileName, "#A2");
|
||||
returnedNode = GetNodeFromResXReader (node);
|
||||
}
|
||||
|
||||
Assert.AreEqual (Path.Combine ("basePath","file.name"), returnedNode.FileRef.FileName, "#A3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Serialized_WriteBack ()
|
||||
{
|
||||
|
||||
ResXDataNode node, returnedNode, finalNode;
|
||||
node = GetNodeEmdeddedSerializable ();
|
||||
node.Comment = "acomment";
|
||||
returnedNode = GetNodeFromResXReader (node);
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual ("acomment", returnedNode.Comment, "#A2");
|
||||
object returnedObj = returnedNode.GetValue ((ITypeResolutionService) null);
|
||||
Assert.IsInstanceOfType (typeof (serializable), returnedObj, "#A3");
|
||||
serializable returnedSer = (serializable) returnedObj;
|
||||
Assert.AreEqual ("testName", returnedSer.name, "A4");
|
||||
|
||||
finalNode = GetNodeFromResXReader (returnedNode);
|
||||
Assert.IsNotNull (finalNode, "#A5");
|
||||
Assert.AreEqual ("acomment", finalNode.Comment, "#A6");
|
||||
object finalObj = finalNode.GetValue ((ITypeResolutionService) null);
|
||||
Assert.IsInstanceOfType (typeof (serializable), finalObj, "#A7");
|
||||
serializable finalSer = (serializable) finalObj;
|
||||
Assert.AreEqual ("testName", finalSer.name, "A7");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChangesToReturnedByteArrayNotLaterWrittenBack ()
|
||||
{
|
||||
ResXDataNode originalNode, returnedNode, finalNode;
|
||||
originalNode = GetNodeEmdeddedBytes1To10 ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
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;
|
||||
|
||||
finalNode = GetNodeFromResXReader (returnedNode);
|
||||
|
||||
Assert.IsNotNull (finalNode, "#A4");
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OriginalTypeUsedSerializableWhenWritingBackToResX ()
|
||||
{
|
||||
// check although calls subsequent to an ITRS being supplied to GetValue return that resolved type
|
||||
// when the node is written back using ResXResourceWriter it uses the original type
|
||||
ResXDataNode originalNode, returnedNode, finalNode;
|
||||
|
||||
originalNode = GetNodeEmdeddedSerializable ();
|
||||
returnedNode = GetNodeFromResXReader (originalNode);
|
||||
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
object val = returnedNode.GetValue (new ReturnSerializableSubClassITRS ());
|
||||
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");
|
||||
}
|
||||
|
||||
static string typeconResXInvalidMimeTypeAndType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" type=""A.type"" mimetype=""application/xxxx"">
|
||||
<value>42</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string fileRefResX =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias=""System.Windows.Forms"" name=""System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" />
|
||||
<data name=""anode"" type=""System.Resources.ResXFileRef, System.Windows.Forms"">
|
||||
<value>file.name;type.name</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string fileRefResXCorrupted =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<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>
|
||||
|
||||
<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 serializedResXInvalidMimeType =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name=""test"" mimetype=""application/xxxx"">
|
||||
<value>
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
static string convertableResXWithoutAssemblyName =
|
||||
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<root>
|
||||
|
||||
<resheader name=""resmimetype"">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name=""version"">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name=""reader"">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name=""writer"">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
|
||||
<data name=""test"" type=""DummyAssembly.Convertable"">
|
||||
<value>im a name im a value</value>
|
||||
</data>
|
||||
</root>";
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,289 @@
|
||||
//
|
||||
// ResXFileRefTest.cs: Unit Tests for ResXFileRef.
|
||||
//
|
||||
// Authors:
|
||||
// Gert Driesen <drieseng@users.sourceforge.net>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Resources
|
||||
{
|
||||
[TestFixture]
|
||||
public class ResXFileRefTest : MonoTests.System.Windows.Forms.TestHelper
|
||||
{
|
||||
[Test]
|
||||
public void Constructor1 ()
|
||||
{
|
||||
ResXFileRef r = new ResXFileRef ("mono.bmp", "Bitmap");
|
||||
MonoTests.System.Windows.Forms.TestHelper.RemoveWarning (r);
|
||||
Assert.AreEqual ("mono.bmp", r.FileName, "#1");
|
||||
Assert.AreEqual ("Bitmap", r.TypeName, "#2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor1_FileName_Null ()
|
||||
{
|
||||
try {
|
||||
new ResXFileRef ((string) null, "Bitmap");
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
|
||||
Assert.IsNotNull (ex.Message, "#3");
|
||||
Assert.IsNotNull (ex.ParamName, "#4");
|
||||
Assert.AreEqual ("fileName", ex.ParamName, "#5");
|
||||
Assert.IsNull (ex.InnerException, "#6");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor1_TypeName_Null ()
|
||||
{
|
||||
try {
|
||||
new ResXFileRef ("mono.bmp", (string) null);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
|
||||
Assert.IsNotNull (ex.Message, "#3");
|
||||
Assert.IsNotNull (ex.ParamName, "#4");
|
||||
Assert.AreEqual ("typeName", ex.ParamName, "#5");
|
||||
Assert.IsNull (ex.InnerException, "#6");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor2 ()
|
||||
{
|
||||
Encoding utf8 = Encoding.UTF8;
|
||||
|
||||
ResXFileRef r = new ResXFileRef ("mono.bmp", "Bitmap", utf8);
|
||||
Assert.AreEqual ("mono.bmp", r.FileName, "#A1");
|
||||
Assert.AreSame (utf8, r.TextFileEncoding, "#A2");
|
||||
Assert.AreEqual ("Bitmap", r.TypeName, "#A3");
|
||||
|
||||
r = new ResXFileRef ("mono.bmp", "Bitmap", (Encoding) null);
|
||||
Assert.AreEqual ("mono.bmp", r.FileName, "#B1");
|
||||
Assert.IsNull (r.TextFileEncoding, "#B2");
|
||||
Assert.AreEqual ("Bitmap", r.TypeName, "#B3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor2_FileName_Null ()
|
||||
{
|
||||
try {
|
||||
new ResXFileRef ((string) null, "Bitmap", Encoding.UTF8);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
|
||||
Assert.IsNotNull (ex.Message, "#3");
|
||||
Assert.IsNotNull (ex.ParamName, "#4");
|
||||
Assert.AreEqual ("fileName", ex.ParamName, "#5");
|
||||
Assert.IsNull (ex.InnerException, "#6");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor2_TypeName_Null ()
|
||||
{
|
||||
try {
|
||||
new ResXFileRef ("mono.bmp", (string) null, Encoding.UTF8);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
|
||||
Assert.IsNotNull (ex.Message, "#3");
|
||||
Assert.IsNotNull (ex.ParamName, "#4");
|
||||
Assert.AreEqual ("typeName", ex.ParamName, "#5");
|
||||
Assert.IsNull (ex.InnerException, "#6");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToStringTest ()
|
||||
{
|
||||
ResXFileRef r = new ResXFileRef ("mono.bmp", "Bitmap");
|
||||
Assert.AreEqual ("mono.bmp;Bitmap", r.ToString (), "#1");
|
||||
|
||||
r = new ResXFileRef ("mono.bmp", "Bitmap", Encoding.UTF8);
|
||||
Assert.AreEqual ("mono.bmp;Bitmap;utf-8", r.ToString (), "#2");
|
||||
|
||||
r = new ResXFileRef ("mono.bmp", "Bitmap", (Encoding) null);
|
||||
Assert.AreEqual ("mono.bmp;Bitmap", r.ToString (), "#3");
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class ResXFileRefConverterTest : MonoTests.System.Windows.Forms.TestHelper
|
||||
{
|
||||
[SetUp]
|
||||
protected override void SetUp () {
|
||||
_converter = new ResXFileRef.Converter ();
|
||||
_tempDirectory = Path.Combine (Path.GetTempPath (), "ResXResourceReaderTest");
|
||||
if (!Directory.Exists (_tempDirectory)) {
|
||||
Directory.CreateDirectory (_tempDirectory);
|
||||
}
|
||||
_tempFileUTF7 = Path.Combine (_tempDirectory, "string_utf7.txt");
|
||||
using (StreamWriter sw = new StreamWriter (_tempFileUTF7, false, Encoding.UTF7)) {
|
||||
sw.Write ("\u0021\u0026\u002A\u003B");
|
||||
}
|
||||
base.SetUp ();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
protected override void TearDown ()
|
||||
{
|
||||
if (Directory.Exists (_tempDirectory))
|
||||
Directory.Delete (_tempDirectory, true);
|
||||
base.TearDown ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanConvertFrom ()
|
||||
{
|
||||
Assert.IsTrue (_converter.CanConvertFrom (typeof (string)), "#1");
|
||||
Assert.IsFalse (_converter.CanConvertFrom (typeof (byte [])), "#2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanConvertTo ()
|
||||
{
|
||||
Assert.IsTrue (_converter.CanConvertTo (typeof (string)), "#1");
|
||||
Assert.IsFalse (_converter.CanConvertTo (typeof (MemoryStream)), "#2");
|
||||
Assert.IsFalse (_converter.CanConvertTo (typeof (Bitmap)), "#3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertFrom_File_DoesNotExist ()
|
||||
{
|
||||
// file does not exist
|
||||
string fileRef = "doesnotexist.txt;" + typeof (string).AssemblyQualifiedName;
|
||||
try {
|
||||
_converter.ConvertFrom (fileRef);
|
||||
Assert.Fail ("#A1");
|
||||
} catch (FileNotFoundException ex) {
|
||||
Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#A2");
|
||||
Assert.IsNull (ex.InnerException, "#A3");
|
||||
Assert.IsNotNull (ex.FileName, "#A4");
|
||||
Assert.AreEqual (Path.Combine (Directory.GetCurrentDirectory (), "doesnotexist.txt"), ex.FileName, "#A5");
|
||||
Assert.IsNotNull (ex.Message, "#A6");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertFrom_Type_NotSet ()
|
||||
{
|
||||
string fileRef = "doesnotexist.txt";
|
||||
try {
|
||||
_converter.ConvertFrom (fileRef);
|
||||
Assert.Fail ("#B1");
|
||||
} catch (ArgumentException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
|
||||
Assert.IsNull (ex.InnerException, "#B3");
|
||||
Assert.IsNotNull (ex.Message, "#B4");
|
||||
Assert.AreEqual ("value", ex.Message, "#B5");
|
||||
Assert.IsNull (ex.ParamName, "#B6");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertFrom_NotString ()
|
||||
{
|
||||
Assert.IsNull (_converter.ConvertFrom (null), "#G1");
|
||||
Assert.IsNull (_converter.ConvertFrom (1), "#G2");
|
||||
Assert.IsNull (_converter.ConvertFrom (true), "#G3");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertFrom_Type_String ()
|
||||
{
|
||||
// read UTF-7 content without setting encoding
|
||||
string fileRef = _tempFileUTF7 + ";" + typeof (string).AssemblyQualifiedName;
|
||||
string result = _converter.ConvertFrom (fileRef) as string;
|
||||
Assert.IsNotNull (result, "#A1");
|
||||
Assert.IsFalse (result == "\u0021\u0026\u002A\u003B", "#A2");
|
||||
|
||||
// read UTF-7 content using UTF-7 encoding
|
||||
fileRef = _tempFileUTF7 + ";" + typeof (string).AssemblyQualifiedName + ";utf-7";
|
||||
result = _converter.ConvertFrom (fileRef) as string;
|
||||
Assert.IsNotNull (result, "#B1");
|
||||
Assert.AreEqual ("\u0021\u0026\u002A\u003B", result, "#B2");
|
||||
|
||||
// invalid encoding
|
||||
fileRef = _tempFileUTF7 + ";" + typeof (string).AssemblyQualifiedName + ";utf-99";
|
||||
try {
|
||||
_converter.ConvertFrom (fileRef);
|
||||
Assert.Fail ("#D1");
|
||||
} catch (ArgumentException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
|
||||
Assert.IsNull (ex.InnerException, "#D3");
|
||||
Assert.IsNotNull (ex.Message, "#D4");
|
||||
Assert.IsTrue (ex.Message.IndexOf ("'utf-99'") != -1, "#D5");
|
||||
Assert.IsNotNull (ex.ParamName, "#D6");
|
||||
Assert.AreEqual ("name", ex.ParamName, "#D7");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertFrom_Type_StreamReader ()
|
||||
{
|
||||
// read UTF-7 content without setting encoding
|
||||
string fileRef = _tempFileUTF7 + ";" + typeof (StreamReader).AssemblyQualifiedName;
|
||||
using (StreamReader sr = (StreamReader) _converter.ConvertFrom (fileRef)) {
|
||||
string result = sr.ReadToEnd ();
|
||||
Assert.IsTrue (result.Length > 0, "#D1");
|
||||
Assert.IsFalse (result == "\u0021\u0026\u002A\u003B", "#D2");
|
||||
}
|
||||
|
||||
// UTF-7 encoding is set, but not used
|
||||
fileRef = _tempFileUTF7 + ";" + typeof (StreamReader).AssemblyQualifiedName + ";utf-7";
|
||||
using (StreamReader sr = (StreamReader) _converter.ConvertFrom (fileRef)) {
|
||||
string result = sr.ReadToEnd ();
|
||||
Assert.IsTrue (result.Length > 0, "#F1");
|
||||
Assert.IsFalse (result == "\u0021\u0026\u002A\u003B", "#F2");
|
||||
}
|
||||
|
||||
// invalid encoding is set, no error
|
||||
fileRef = _tempFileUTF7 + ";" + typeof (StreamReader).AssemblyQualifiedName + ";utf-99";
|
||||
using (StreamReader sr = (StreamReader) _converter.ConvertFrom (fileRef)) {
|
||||
string result = sr.ReadToEnd ();
|
||||
Assert.IsTrue (result.Length > 0, "#A1");
|
||||
Assert.IsFalse (result == "\u0021\u0026\u002A\u003B", "#A2");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertFrom_Type_MemoryStream ()
|
||||
{
|
||||
string fileRef = _tempFileUTF7 + ";" + typeof (MemoryStream).AssemblyQualifiedName;
|
||||
using (MemoryStream ms = (MemoryStream) _converter.ConvertFrom (fileRef)) {
|
||||
Assert.IsTrue (ms.Length > 0);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertTo ()
|
||||
{
|
||||
ResXFileRef r = new ResXFileRef ("mono.bmp", "Bitmap");
|
||||
Assert.AreEqual ("mono.bmp;Bitmap", (string) _converter.ConvertTo (
|
||||
r, typeof (string)), "#1");
|
||||
|
||||
r = new ResXFileRef ("mono.bmp", "Bitmap", Encoding.UTF8);
|
||||
Assert.AreEqual ("mono.bmp;Bitmap;utf-8", (string) _converter.ConvertTo (
|
||||
r, typeof (string)), "#2");
|
||||
|
||||
r = new ResXFileRef ("mono.bmp", "Bitmap", (Encoding) null);
|
||||
Assert.AreEqual ("mono.bmp;Bitmap", (string) _converter.ConvertTo (
|
||||
r, typeof (string)), "#3");
|
||||
}
|
||||
|
||||
private TypeConverter _converter;
|
||||
private string _tempDirectory;
|
||||
private string _tempFileUTF7;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,181 @@
|
||||
//
|
||||
// ResourcesTestHelper.cs : Base class for new resource tests with methods
|
||||
// required across many.
|
||||
//
|
||||
// Author:
|
||||
// Gary Barnett (gary.barnett.mono@gmail.com)
|
||||
//
|
||||
// Copyright (C) Gary Barnett (2012)
|
||||
//
|
||||
// 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.
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,433 @@
|
||||
//
|
||||
// WriterTest.cs: Unit Tests for ResXResourceWriter.
|
||||
//
|
||||
// Authors:
|
||||
// Robert Jordan <robertj@gmx.net>
|
||||
// Gary Barnett <gary.barnett.mono@gmail.com>
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.System.Resources
|
||||
{
|
||||
[TestFixture]
|
||||
public class WriterTest : MonoTests.System.Windows.Forms.TestHelper
|
||||
{
|
||||
string fileName;
|
||||
|
||||
[SetUp]
|
||||
protected override void SetUp ()
|
||||
{
|
||||
fileName = Path.GetTempFileName ();
|
||||
base.SetUp ();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
protected override void TearDown ()
|
||||
{
|
||||
File.Delete (fileName);
|
||||
base.TearDown ();
|
||||
}
|
||||
|
||||
[Test] // ctor (Stream)
|
||||
[NUnit.Framework.Category ("NotDotNet")]
|
||||
public void Constructor1_Stream_Null ()
|
||||
{
|
||||
try {
|
||||
new ResXResourceWriter ((Stream) null);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
|
||||
Assert.IsNull (ex.InnerException, "#3");
|
||||
Assert.IsNotNull (ex.Message, "#4");
|
||||
Assert.AreEqual ("stream", ex.ParamName, "#5");
|
||||
}
|
||||
}
|
||||
|
||||
[Test] // ctor (Stream)
|
||||
[NUnit.Framework.Category ("NotDotNet")]
|
||||
public void Constructor1_Stream_NotWritable ()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream (new byte [0], false);
|
||||
|
||||
try {
|
||||
new ResXResourceWriter (ms);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
|
||||
Assert.IsNull (ex.InnerException, "#3");
|
||||
Assert.IsNotNull (ex.Message, "#4");
|
||||
Assert.AreEqual ("stream", ex.ParamName, "#5");
|
||||
}
|
||||
}
|
||||
|
||||
[Test] // ctor (TextWriter)
|
||||
[NUnit.Framework.Category ("NotDotNet")]
|
||||
public void Constructor2_TextWriter_Null ()
|
||||
{
|
||||
try {
|
||||
new ResXResourceWriter ((TextWriter) null);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
|
||||
Assert.IsNull (ex.InnerException, "#3");
|
||||
Assert.IsNotNull (ex.Message, "#4");
|
||||
Assert.AreEqual ("textWriter", ex.ParamName, "#5");
|
||||
}
|
||||
}
|
||||
|
||||
[Test] // ctor (String)
|
||||
[NUnit.Framework.Category ("NotDotNet")]
|
||||
public void Constructor3_FileName_Null ()
|
||||
{
|
||||
try {
|
||||
new ResXResourceWriter ((string) null);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException ex) {
|
||||
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
|
||||
Assert.IsNull (ex.InnerException, "#3");
|
||||
Assert.IsNotNull (ex.Message, "#4");
|
||||
Assert.AreEqual ("fileName", ex.ParamName, "#5");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddResource_WithComment ()
|
||||
{
|
||||
ResXResourceWriter w = new ResXResourceWriter (fileName);
|
||||
ResXDataNode node = new ResXDataNode ("key", "value");
|
||||
node.Comment = "comment is preserved";
|
||||
w.AddResource (node);
|
||||
w.Generate ();
|
||||
w.Close ();
|
||||
|
||||
ResXResourceReader r = new ResXResourceReader (fileName);
|
||||
ITypeResolutionService typeres = null;
|
||||
r.UseResXDataNodes = true;
|
||||
|
||||
int count = 0;
|
||||
foreach (DictionaryEntry o in r)
|
||||
{
|
||||
string key = o.Key.ToString();
|
||||
node = (ResXDataNode)o.Value;
|
||||
string value = node.GetValue (typeres).ToString ();
|
||||
string comment = node.Comment;
|
||||
|
||||
Assert.AreEqual ("key", key, "key");
|
||||
Assert.AreEqual ("value", value, "value");
|
||||
Assert.AreEqual ("comment is preserved", comment, "comment");
|
||||
Assert.AreEqual (0, count, "too many nodes");
|
||||
count++;
|
||||
}
|
||||
r.Close ();
|
||||
|
||||
File.Delete (fileName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWriter ()
|
||||
{
|
||||
ResXResourceWriter w = new ResXResourceWriter (fileName);
|
||||
w.AddResource ("String", "hola");
|
||||
w.AddResource ("String2", (object) "hello");
|
||||
w.AddResource ("Int", 42);
|
||||
w.AddResource ("Enum", PlatformID.Win32NT);
|
||||
w.AddResource ("Convertible", new Point (43, 45));
|
||||
w.AddResource ("Serializable", new ArrayList (new byte [] { 1, 2, 3, 4 }));
|
||||
w.AddResource ("ByteArray", new byte [] { 12, 13, 14 });
|
||||
w.AddResource ("ByteArray2", (object) new byte [] { 15, 16, 17 });
|
||||
w.AddResource ("IntArray", new int [] { 1012, 1013, 1014 });
|
||||
w.AddResource ("StringArray", new string [] { "hello", "world" });
|
||||
w.AddResource ("Image", new Bitmap (1, 1));
|
||||
w.AddResource ("StrType", new MyStrType ("hello"));
|
||||
w.AddResource ("BinType", new MyBinType ("world"));
|
||||
|
||||
try {
|
||||
w.AddResource ("NonSerType", new MyNonSerializableType ());
|
||||
Assert.Fail ("#0");
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
|
||||
w.Generate ();
|
||||
w.Close ();
|
||||
|
||||
ResXResourceReader r = new ResXResourceReader (fileName);
|
||||
Hashtable h = new Hashtable ();
|
||||
foreach (DictionaryEntry e in r) {
|
||||
h.Add (e.Key, e.Value);
|
||||
}
|
||||
r.Close ();
|
||||
|
||||
Assert.AreEqual ("hola", (string) h ["String"], "#1");
|
||||
Assert.AreEqual ("hello", (string) h ["String2"], "#2");
|
||||
Assert.AreEqual (42, (int) h ["Int"], "#3");
|
||||
Assert.AreEqual (PlatformID.Win32NT, (PlatformID) h ["Enum"], "#4");
|
||||
Assert.AreEqual (43, ((Point) h ["Convertible"]).X, "#5");
|
||||
Assert.AreEqual (2, (byte) ((ArrayList) h ["Serializable"]) [1], "#6");
|
||||
Assert.AreEqual (13, ((byte []) h ["ByteArray"]) [1], "#7");
|
||||
Assert.AreEqual (16, ((byte []) h ["ByteArray2"]) [1], "#8");
|
||||
Assert.AreEqual (1013, ((int []) h ["IntArray"]) [1], "#9");
|
||||
Assert.AreEqual ("world", ((string []) h ["StringArray"]) [1], "#10");
|
||||
Assert.AreEqual (typeof (Bitmap), h ["Image"].GetType (), "#11");
|
||||
Assert.AreEqual ("hello", ((MyStrType) h ["StrType"]).Value, "#12");
|
||||
Assert.AreEqual ("world", ((MyBinType) h ["BinType"]).Value, "#13");
|
||||
|
||||
File.Delete (fileName);
|
||||
}
|
||||
|
||||
ResXDataNode GetNodeFromResXWithBasePath (ResXDataNode node, string basePath)
|
||||
{
|
||||
StringWriter sw = new StringWriter ();
|
||||
using (ResXResourceWriter writer = new ResXResourceWriter (sw)) {
|
||||
writer.BasePath = basePath;
|
||||
writer.AddResource (node);
|
||||
}
|
||||
|
||||
StringReader sr = new StringReader (sw.ToString ());
|
||||
|
||||
using (ResXResourceReader reader = new ResXResourceReader (sr)) {
|
||||
reader.UseResXDataNodes = true;
|
||||
IDictionaryEnumerator enumerator = reader.GetEnumerator ();
|
||||
enumerator.MoveNext ();
|
||||
return ((DictionaryEntry) enumerator.Current).Value as ResXDataNode;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_ChangesAbsoluteFileRef_Node ()
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"/dir/dir/filename.ext", "System.String"));
|
||||
var returnedNode = GetNodeFromResXWithBasePath (node, @"/dir");
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (@"dir/filename.ext", returnedNode.FileRef.FileName, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_ChangesAbsoluteFileRef_Object ()
|
||||
{
|
||||
var fileref = new ResXFileRef (@"/dir/dir/filename.ext", "System.String");
|
||||
|
||||
string basePath = @"/dir";
|
||||
|
||||
StringWriter sw = new StringWriter ();
|
||||
using (ResXResourceWriter writer = new ResXResourceWriter (sw)) {
|
||||
writer.BasePath = basePath;
|
||||
writer.AddResource ("name", fileref);
|
||||
}
|
||||
|
||||
StringReader sr = new StringReader (sw.ToString ());
|
||||
|
||||
using (ResXResourceReader reader = new ResXResourceReader (sr)) {
|
||||
reader.UseResXDataNodes = true;
|
||||
IDictionaryEnumerator enumerator = reader.GetEnumerator ();
|
||||
enumerator.MoveNext ();
|
||||
var returnedNode = ((DictionaryEntry) enumerator.Current).Value as ResXDataNode;
|
||||
Assert.AreEqual (@"dir/filename.ext", returnedNode.FileRef.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_ChangesAbsoluteFileRef_Deeper ()
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"/adir/filename.ext", "System.String"));
|
||||
var returnedNode = GetNodeFromResXWithBasePath (node, @"/dir1/dir2");
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (@"../../adir/filename.ext", returnedNode.FileRef.FileName, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_ComplexPath ()
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"/dir/dir/../filename.ext", "System.String"));
|
||||
var returnedNode = GetNodeFromResXWithBasePath (node, @"/dir");
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (@"dir/../filename.ext", returnedNode.FileRef.FileName, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_IgnoresTrailingSeparator ()
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"/dir/filename.ext", "System.String"));
|
||||
var nonTrailNode = GetNodeFromResXWithBasePath (node, @"/dir");
|
||||
Assert.IsNotNull (nonTrailNode, "#A1");
|
||||
Assert.AreEqual (@"filename.ext", nonTrailNode.FileRef.FileName, "#A2");
|
||||
|
||||
var trailingNode = GetNodeFromResXWithBasePath (node, @"/dir/");
|
||||
Assert.IsNotNull (trailingNode, "#A3");
|
||||
Assert.AreEqual (@"filename.ext", trailingNode.FileRef.FileName, "#A4");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_IgnoredIfNotPartOfPath () // not really a valid test on linux systems
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"/dir/filename.ext", "System.String"));
|
||||
var returnedNode = GetNodeFromResXWithBasePath (node, @"D/");
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (@"/dir/filename.ext", returnedNode.FileRef.FileName, "#A2");
|
||||
}
|
||||
|
||||
[Test] // FIXME: this fails on mono ("/dir/filename.ext" is returned) but passes on .net
|
||||
[NUnit.Framework.Category ("NotWorking")]
|
||||
public void BasePath_Root ()
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"/dir/filename.ext", "System.String"));
|
||||
var returnedNode = GetNodeFromResXWithBasePath (node, @"/");
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (@"dir/filename.ext", returnedNode.FileRef.FileName, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_RelativeFileRef ()
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"../../filename.ext", "System.String"));
|
||||
var returnedNode = GetNodeFromResXWithBasePath (node, @"../");
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (@"../filename.ext", returnedNode.FileRef.FileName, "#A2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasePath_DoesntAffectOriginalNode ()
|
||||
{
|
||||
var node = new ResXDataNode ("name", new ResXFileRef (@"/dir/dir/filename.ext", "System.String"));
|
||||
var returnedNode = GetNodeFromResXWithBasePath (node, @"/dir");
|
||||
Assert.IsNotNull (returnedNode, "#A1");
|
||||
Assert.AreEqual (@"dir/filename.ext", returnedNode.FileRef.FileName, "#A2");
|
||||
Assert.AreEqual (@"/dir/dir/filename.ext", node.FileRef.FileName, "#A3");
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[TypeConverter (typeof (MyStrTypeConverter))]
|
||||
public class MyStrType
|
||||
{
|
||||
public string Value;
|
||||
|
||||
public MyStrType (string s)
|
||||
{
|
||||
Value = s;
|
||||
}
|
||||
}
|
||||
|
||||
public class MyStrTypeConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof (string))
|
||||
return true;
|
||||
return base.CanConvertTo (context, destinationType);
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof (string))
|
||||
return true;
|
||||
return base.CanConvertFrom (context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof (string))
|
||||
return ((MyStrType) value).Value;
|
||||
return base.ConvertTo (context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value.GetType () == typeof (string))
|
||||
return new MyStrType ((string) value);
|
||||
return base.ConvertFrom (context, culture, value);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[TypeConverter (typeof (MyBinTypeConverter))]
|
||||
public class MyBinType
|
||||
{
|
||||
public string Value;
|
||||
|
||||
public MyBinType (string s)
|
||||
{
|
||||
Value = s;
|
||||
}
|
||||
}
|
||||
|
||||
public class MyBinTypeConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof (byte []))
|
||||
return true;
|
||||
return base.CanConvertTo (context, destinationType);
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof (byte []))
|
||||
return true;
|
||||
return base.CanConvertFrom (context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof (byte []))
|
||||
return Encoding.Default.GetBytes (((MyBinType) value).Value);
|
||||
return base.ConvertTo (context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value.GetType () == typeof (byte []))
|
||||
return new MyBinType (Encoding.Default.GetString ((byte []) value));
|
||||
return base.ConvertFrom (context, culture, value);
|
||||
}
|
||||
}
|
||||
|
||||
[TypeConverter (typeof (MyNonSerializableTypeConverter))]
|
||||
public class MyNonSerializableType
|
||||
{
|
||||
public MyNonSerializableType ()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class MyNonSerializableTypeConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof (byte []))
|
||||
return true;
|
||||
return base.CanConvertTo (context, destinationType);
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof (byte []))
|
||||
return true;
|
||||
return base.CanConvertFrom (context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof (byte []))
|
||||
return new byte [] { 0, 1, 2, 3 };
|
||||
return base.ConvertTo (context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value.GetType () == typeof (byte []))
|
||||
return new MyNonSerializableType ();
|
||||
return base.ConvertFrom (context, culture, value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 1.3 (NET_1_1)
|
||||
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<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" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</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>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="String">
|
||||
<value>hola</value>
|
||||
</data>
|
||||
<data name="String2">
|
||||
<value>hello</value>
|
||||
</data>
|
||||
<data name="Int" type="System.Int32, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>42</value>
|
||||
</data>
|
||||
<data name="Enum" type="System.PlatformID, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>Win32NT</value>
|
||||
</data>
|
||||
<data name="Convertible" type="System.Drawing.Point, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>43, 45</value>
|
||||
</data>
|
||||
<data name="Serializable" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAEAQAAABxTeXN0ZW0uQ29sbGVjdGlvbnMuQXJyYXlMaXN0AwAAAAZfaXRl
|
||||
bXMFX3NpemUIX3ZlcnNpb24FAAAICAkCAAAABAAAAAEAAAAQAgAAAAQAAAAIAgEIAgIIAgMIAgQL
|
||||
</value>
|
||||
</data>
|
||||
<data name="ByteArray" type="System.Byte[], mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>DA0O</value>
|
||||
</data>
|
||||
<data name="ByteArray2" type="System.Byte[], mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>DxAR</value>
|
||||
</data>
|
||||
<data name="IntArray" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>AAEAAAD/////AQAAAAAAAAAPAQAAAAMAAAAI9AMAAPUDAAD2AwAACw==</value>
|
||||
</data>
|
||||
<data name="StringArray" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>AAEAAAD/////AQAAAAAAAAARAQAAAAIAAAAGAgAAAAVoZWxsbwYDAAAABXdvcmxkCw==</value>
|
||||
</data>
|
||||
<data name="InvalidMimeType" mimetype="foo">
|
||||
<value>AAEAAAD/////AQAAAAAAAAARAQAAAAIAAAAGAgAAAAVoZWxsbwYDAAAABXdvcmxkCw==</value>
|
||||
</data>
|
||||
<data name="Image" type="System.Drawing.Bitmap, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAtJREFUGFdjYAAC
|
||||
AAAFAAGq1chRAAAAAElFTkSuQmCCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
AAAAAAAAAAAAAAAAAAAAAA==
|
||||
</value>
|
||||
</data>
|
||||
</root>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user