Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,177 @@
2010-07-07 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* ResourceWriterTest.cs: In our new AddResource_Stream_Default test
store the resource file under Test/resources/, instead of the base
dir, so we avoid filling the dir with not needed files.
2010-07-05 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* ResourceWriterTest.cs: New tests for our new 4.0 AddResource
overloads.
2008-10-27 Gonzalo Paniagua Javier <gonzalo@novell.com>
* ResourceReaderTest.cs: use the current directory to locate the
resources.
2008-03-15 Gert Driesen <drieseng@users.sourceforge.net>
* ResourceManagerTest.cs: Enabled and added ResourceSetType asserts.
Added test for disposed ResourceSet. Avoid using ExpectedException.
* ResourceSetTest.cs: Improved tests for ctor argument checks. Avoid
using ExpectedException.
2008-03-04 Sebastien Pouliot <sebastien@ximian.com>
* ResourceManagerTest.cs: Add test case for ResourceSetType which
shows that an internal type, not the basic ResourceSet, is being used
* ResourceSetTest.cs: New. Unit tests for ResourceSet
2008-01-26 Gert Driesen <drieseng@users.sourceforge.net>
* ResourceWriterTest.cs: Enabled test for writing enum value on 2.0
profile.
2007-11-10 Gert Driesen <drieseng@users.sourceforge.net>
* ResourceWriterTest.cs: Added ctor tests. Added tests for AddResource
overloads. Added test for argument null checks. Added test for bug
#339074. Added test for invoking Generate () multiple times.
2007-10-27 Gert Driesen <drieseng@users.sourceforge.net>
* ResourceManagerTest.cs: Added tests for null argument checks. Added test
for GetStream with resource file that does not exist.
2007-09-17 Gert Driesen <drieseng@users.sourceforge.net>
* ResourceManagerTest.cs: Restore the original UI Culture on TearDown.
Added ctor tests. Added tests for CreateFileBasedResourceManager.
Added tests for GetObject, GetString and GetResourceFileName.
Improved tests for GetStream. Added test for IgnoreCase.
2007-08-24 Gert Driesen <drieseng@users.sourceforge.net>
* ResourceManagerTest.cs: Improved existing tests. Ensure all resources
are released. Fixes test failures on Windows.
* ResourceWriterTest.cs: Added test for bug #82566.
* ResourceReaderTest.cs: Improved existing tests. Ensure all resources
are released. Fixed test failures on Windows.
2007-08-09 Atsushi Enomoto <atsushi@ximian.com>
* ResourceReaderTest.cs : added tests for GetResourceData()
2007-07-16 Rodrigo Kumpera <rkumpera@novell.com>
* ResourceReaderTest.cs: new test, related to 2.0 bug of #81757
2007-05-28 Atsushi Enomoto <atsushi@ximian.com>
* ResourceWriterTest.cs : new test, contains one for bug #81759.
2007-05-28 Atsushi Enomoto <atsushi@ximian.com>
* ResourceManagerTest.cs : added tests for GetStream() (including
2.0 resource format tests).
2006-12-30 Alexander Olk <alex.olk@googlemail.com>
* ResourceManagerTest.cs: add one new test and remove NotWorking.
All tests pass now.
2006-12-30 Gert Driesen <drieseng@users.sourceforge.net>
* ResourceReaderTest.cs: Added test for reading byte array.
No longer derive from Assertion class.
2006-10-09 Chris Toshok <toshok@ximian.com>
* ResourceManagerTest.cs: add some (NotWorking) tests for
ResourceManager.
2006-03-14 Robert Jordan <robertj@gmx.net>
* ResourceManagerTest.cs: Reactivated tests. eol-style.
2006-01-13 Robert Jordan <robertj@gmx.net>
* ResourceManagerTest.cs: New. Unit tests for ResourceManager.
See bug #77242.
2005-03-31 Sebastien Pouliot <sebastien@ximian.com>
* ResourceReaderCas.cs: New. CAS unit tests for ResourceReader.
* ResourceReaderTest.cs: Changed filename to internal so the "normal"
tests case can be reused, with partial trust, by the CAS tests.
* ResourceSetCas.cs: : New. CAS unit tests for ResourceSet.
2005-01-28 Nick Drochak <ndrochak@ieee.org>
* ResourceReaderTest.cs: Not sure about a zero-byte length file.
2004-08-29 Nick Drochak <ndrochak@ieee.org>
* ResourceReaderTest.cs: Make tests pass (correct path to resources)
on MS.NET 1.1.
2004-06-14 Sebastien Pouliot <sebastien@ximian.com>
* ResourceReaderTest.cs: Un-ignored an old test case (probably fixed a
long time ago). Converted tests to NUnit 2.x format to be more
specific when checking exceptions.
2004-02-25 Jackson Harper <jackson@ximian.com>
* ResourceReaderTest.cs: Make work on windows.
2004-02-18 Jackson Harper <jackson@ximian.com>
* ResourceReaderTest.cs: Add a little logic for finding
resources. This works on MS and with mono and fixes these tests
for 'make run-test'.
2003-06-23 Nick Drochak <ndrochak@gol.com>
* ResourceReaderTest.cs: Put it back the way it was, doesn't work on
.NET, and it works fine on both if you cd to the proper dir before
running these tests.
2003-06-16 Nick Drochak <ndrochak@gol.com>
* ResourceReaderTest.cs: Help tests find input files.
2003-01-28 Nick Drochak <ndrochak@gol.com>
* ResourceReaderTest.cs: Ignore part of a test that hangs mono.
2002-12-21 Nick Drochak <ndrochak@gol.com>
* all: make tests build and run under nunit2
2002/06/14 Nick Drochak <ndrochak@gol.com>
* AllTests.cs: Disable ResourceReaderTest for now. The class is not
ready yet.
2002-05-22 Nick Drochak <ndrochak@gol.com>
* ResourceReaderTest.cs: Fix path name to resource files (again).
2002-02-09 Nick Drochak <ndrochak@gol.com>
* ResourceReaderTest.cs: Fix path name to resource files
2002-01-25 Nick Drochak <ndrochak@gol.com>
* AllTests.cs:
* Empty.resources:
* MyResources.resources: Added files
* ResourceReaderTest.cs: Test the enumerator
2002-01-24 Nick Drochak <ndrochak@gol.com>
* ResourceReaderTest.cs: Add new file. This test is not done yet.
Wanted to save it in cvs for 'disaster recovery' purposes.
Just in case.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
//
// ResourceReaderCas.cs - CAS unit tests for System.Resources.ResourceReader
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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 NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.Resources {
[TestFixture]
[Category ("CAS")]
public class ResourceReaderCas {
private MonoTests.System.Resources.ResourceReaderTest rrt;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
rrt = new MonoTests.System.Resources.ResourceReaderTest ();
rrt.FixtureSetUp ();
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// Partial Trust Tests - i.e. call "normal" unit with reduced privileges
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void PartialTrust_PermitOnly_FileIOPermission ()
{
rrt.ConstructorString ();
rrt.Stream ();
rrt.Close ();
rrt.Enumerator ();
}
// we use reflection to call ResourceReader as the Stream constructor is
// protected by LinkDemand (which will be converted into full demand, i.e.
// a stack walk) when reflection is used (i.e. it gets testable).
[Test]
[SecurityPermission (SecurityAction.Deny, SerializationFormatter = true)]
[ExpectedException (typeof (SecurityException))]
public void Constructor_Stream ()
{
ConstructorInfo ci = typeof (ResourceReader).GetConstructor (new Type [1] { typeof (Stream) });
ci.Invoke (new object [1] { Stream.Null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, SerializationFormatter = true)]
public void Constructor_String ()
{
ConstructorInfo ci = typeof (ResourceReader).GetConstructor (new Type [1] { typeof (string) });
ci.Invoke (new object [1] { MonoTests.System.Resources.ResourceReaderTest.m_ResourceFile });
// works - i.e. no LinkDemand
}
}
}

View File

@@ -0,0 +1,361 @@
//
// MonoTests.System.Resources.ResourceReaderTest.cs
//
// Author:
// Nick Drochak (ndrochak@gol.com)
//
// (C) 2001 Nick Drochak II
// Copyright (C) 2004 Novell (http://www.novell.com)
//
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Resources;
using NUnit.Framework;
namespace MonoTests.System.Resources
{
[TestFixture]
public class ResourceReaderTest
{
internal static string m_ResourceFile;
private static string m_BadResourceFile;
private string _tempResourceFile;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
char ds = Path.DirectorySeparatorChar;
if (ds == '/') {
string base_path = Path.Combine (Directory.GetCurrentDirectory (), Path.Combine ("Test", "resources"));
m_ResourceFile = Path.Combine (base_path, "MyResources.resources");
m_BadResourceFile = Path.Combine (base_path, "Empty.resources");
} else {
m_ResourceFile = Path.Combine ("Test", Path.Combine ("resources", "MyResources.resources"));
m_BadResourceFile = "resources" + ds + "Empty.resources";
}
}
[SetUp]
public void SetUp ()
{
_tempResourceFile = Path.GetTempFileName ();
}
[TearDown]
public void TearDown ()
{
File.Delete (_tempResourceFile);
}
[Test]
public void ConstructorString_Path_Null ()
{
try {
new ResourceReader ((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.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("path", ex.ParamName, "#6");
}
}
[Test]
public void ConstructorString_Path_Empty ()
{
try {
new ResourceReader (String.Empty);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Empty path name is not legal
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
[Test]
[ExpectedException (typeof (FileNotFoundException))]
public void ConstructorString_NotFound ()
{
// use a file name that is *very* unlikely to exsist
new ResourceReader ("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");
}
[Test]
[Ignore ("Not covered in the docs, not sure what the correct behavior should be for this")]
[ExpectedException (typeof (DirectoryNotFoundException))]
public void ConstructorString_Bad ()
{
Assert.IsTrue (File.Exists (m_BadResourceFile));
new ResourceReader (m_BadResourceFile);
}
[Test]
[Category ("MobileNotWorking")]
public void ConstructorString ()
{
if (!File.Exists (m_ResourceFile)) {
Assert.Fail ("Resource file is not where it should be:" + Path.Combine (Directory.GetCurrentDirectory (), m_ResourceFile));
}
ResourceReader r = new ResourceReader (m_ResourceFile);
Assert.IsNotNull (r, "ResourceReader");
r.Close ();
}
[Test]
public void ConstructorStream_Null ()
{
try {
new ResourceReader ((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.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("stream", ex.ParamName, "#6");
}
}
[Test]
[Category ("MobileNotWorking")]
public void ConstructorStream_Closed ()
{
Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
stream.Close ();
try {
new ResourceReader (stream);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Stream was not readable
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
[Test]
[Category ("MobileNotWorking")]
public void Stream ()
{
Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
ResourceReader r = new ResourceReader (stream);
Assert.IsNotNull (r, "ResourceReader");
r.Close ();
}
[Test]
[Category ("MobileNotWorking")]
public void Close ()
{
Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
ResourceReader r = new ResourceReader (stream);
r.Close ();
stream = new FileStream (m_ResourceFile, FileMode.Open);
Assert.IsNotNull (stream, "FileStream");
stream.Close ();
}
[Test]
[Category ("MobileNotWorking")]
public void Enumerator ()
{
Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
ResourceReader reader = new ResourceReader (stream);
IDictionaryEnumerator en = reader.GetEnumerator ();
// Goes through the enumerator, printing out the key and value pairs.
while (en.MoveNext ()) {
DictionaryEntry de = (DictionaryEntry) en.Current;
Assert.IsTrue (String.Empty != (string) de.Key, "Current.Key should not be empty");
Assert.IsTrue (String.Empty != (string) de.Value, "Current.Value should not be empty");
Assert.IsTrue (String.Empty != (string) en.Key, "Entry.Key should not be empty");
Assert.IsTrue (String.Empty != (string) en.Value, "Entry.Value should not be empty");
}
reader.Close ();
}
#if NET_2_0
[Test] // bug #81757
public void ReadNullResource ()
{
MemoryStream stream = new MemoryStream ();
object value = null;
ResourceWriter rw = new ResourceWriter (stream);
rw.AddResource ("NullTest", value);
rw.Generate ();
stream.Position = 0;
using (ResourceReader rr = new ResourceReader (stream)) {
int entryCount = 0;
foreach (DictionaryEntry de in rr) {
Assert.AreEqual ("NullTest", de.Key, "#1");
Assert.IsNull (de.Value, "#2");
Assert.AreEqual (0, entryCount, "#3");
entryCount++;
}
Assert.AreEqual (1, entryCount, "#4");
}
}
#endif
[Test] // bug #79976
public void ByteArray ()
{
byte [] content = new byte [] { 1, 2, 3, 4, 5, 6 };
Stream stream = null;
#if NET_2_0
// we currently do not support writing v2 resource files
stream = new MemoryStream ();
stream.Write (byte_resource_v2, 0, byte_resource_v2.Length);
stream.Position = 0;
#else
using (IResourceWriter rw = new ResourceWriter (_tempResourceFile)) {
rw.AddResource ("byteArrayTest", content);
rw.Generate ();
}
stream = File.OpenRead (_tempResourceFile);
#endif
using (stream) {
int entryCount = 0;
using (IResourceReader rr = new ResourceReader (stream)) {
foreach (DictionaryEntry de in rr) {
Assert.AreEqual ("byteArrayTest", de.Key, "#1");
Assert.AreEqual (content, de.Value, "#2");
entryCount++;
}
}
Assert.AreEqual (1, entryCount, "#3");
}
}
[Test]
[Category ("MobileNotWorking")]
public void GetResourceDataNullName ()
{
ResourceReader r = new ResourceReader ("Test/resources/StreamTest.resources");
string type;
byte [] bytes;
try {
r.GetResourceData (null, out type, out bytes);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("resourceName", ex.ParamName, "#6");
} finally {
r.Close ();
}
}
[Test]
[Category ("MobileNotWorking")]
public void GetResourceData ()
{
byte [] t1 = new byte [] {0x16, 0x00, 0x00, 0x00, 0x76, 0x65, 0x72, 0x69, 0x74, 0x61, 0x73, 0x20, 0x76, 0x6F, 0x73, 0x20, 0x6C, 0x69, 0x62, 0x65, 0x72, 0x61, 0x62, 0x69, 0x74, 0x0A};
byte [] t2 = new byte [] {0x0A, 0x73, 0x6F, 0x6D, 0x65, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67};
byte [] t3 = new byte [] {0x0E, 0x00, 0x00, 0x00, 0x73, 0x68, 0x61, 0x72, 0x64, 0x65, 0x6E, 0x66, 0x72, 0x65, 0x75, 0x64, 0x65, 0x0A};
ResourceReader r = new ResourceReader ("Test/resources/StreamTest.resources");
Hashtable items = new Hashtable ();
foreach (DictionaryEntry de in r) {
string type;
byte [] bytes;
r.GetResourceData ((string) de.Key, out type, out bytes);
items [de.Key] = new DictionaryEntry (type, bytes);
}
DictionaryEntry p = (DictionaryEntry) items ["test"];
Assert.AreEqual ("ResourceTypeCode.Stream", p.Key as string, "#1-1");
Assert.AreEqual (t1, p.Value as byte [], "#1-2");
p = (DictionaryEntry) items ["test2"];
Assert.AreEqual ("ResourceTypeCode.String", p.Key as string, "#2-1");
Assert.AreEqual (t2, p.Value as byte [], "#2-2");
p = (DictionaryEntry) items ["test3"];
Assert.AreEqual ("ResourceTypeCode.ByteArray", p.Key as string, "#3-1");
Assert.AreEqual (t3, p.Value as byte [], "#3-2");
r.Close ();
}
[Test]
[Category ("MobileNotWorking")]
public void GetResourceData2 ()
{
byte [] expected = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x51, 0x53,
0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x72,
0x61, 0x77, 0x69, 0x6E, 0x67, 0x2C, 0x20, 0x56,
0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x32,
0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x30, 0x2C, 0x20,
0x43, 0x75, 0x6C, 0x74, 0x75, 0x72, 0x65, 0x3D,
0x6E, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6C, 0x2C,
0x20, 0x50, 0x75, 0x62, 0x6C, 0x69, 0x63, 0x4B,
0x65, 0x79, 0x54, 0x6F, 0x6B, 0x65, 0x6E, 0x3D,
0x62, 0x30, 0x33, 0x66, 0x35, 0x66, 0x37, 0x66,
0x31, 0x31, 0x64, 0x35, 0x30, 0x61, 0x33, 0x61,
0x05, 0x01, 0x00, 0x00, 0x00, 0x13, 0x53, 0x79,
0x73, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x72, 0x61,
0x77, 0x69, 0x6E, 0x67, 0x2E, 0x53, 0x69, 0x7A,
0x65, 0x02, 0x00, 0x00, 0x00, 0x05, 0x77, 0x69,
0x64, 0x74, 0x68, 0x06, 0x68, 0x65, 0x69, 0x67,
0x68, 0x74, 0x00, 0x00, 0x08, 0x08, 0x02, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x0B};
ResourceReader r = new ResourceReader ("Test/resources/bug81759.resources");
string type;
byte [] bytes;
r.GetResourceData ("imageList.ImageSize", out type, out bytes);
// Note that const should not be used here.
Assert.AreEqual ("System.Drawing.Size, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", type, "#1");
Assert.AreEqual (expected, bytes, "#2");
r.Close ();
}
// we currently do not support writing v2 resource files
private static readonly byte [] byte_resource_v2 = new byte [] {
0xce, 0xca, 0xef, 0xbe, 0x01, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00,
0x00, 0x6c, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x52, 0x65,
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x73,
0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72,
0x2c, 0x20, 0x6d, 0x73, 0x63, 0x6f, 0x72, 0x6c, 0x69, 0x62, 0x2c,
0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e,
0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74,
0x75, 0x72, 0x65, 0x3d, 0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c,
0x2c, 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79,
0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35,
0x63, 0x35, 0x36, 0x31, 0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39,
0x23, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x52, 0x65, 0x73,
0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x52, 0x75, 0x6e, 0x74,
0x69, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x53, 0x65, 0x74, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x41, 0x44, 0x50, 0x41, 0x44, 0x50,
0x80, 0x88, 0x5a, 0x0e, 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00,
0x00, 0x1a, 0x62, 0x00, 0x79, 0x00, 0x74, 0x00, 0x65, 0x00, 0x41,
0x00, 0x72, 0x00, 0x72, 0x00, 0x61, 0x00, 0x79, 0x00, 0x54, 0x00,
0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x06, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
}
}

View File

@@ -0,0 +1,83 @@
//
// ResourceSetCas.cs - CAS unit tests for System.Resources.ResourceSet
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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 NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.Resources {
[TestFixture]
[Category ("CAS")]
public class ResourceSetCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// we use reflection to call ResourceSet as the Stream constructor is
// protected by LinkDemand (which will be converted into full demand, i.e.
// a stack walk) when reflection is used (i.e. it gets testable).
[Test]
[SecurityPermission (SecurityAction.Deny, SerializationFormatter = true)]
[ExpectedException (typeof (SecurityException))]
public void Constructor_Stream ()
{
ConstructorInfo ci = typeof (ResourceSet).GetConstructor (new Type [1] { typeof (Stream) });
ci.Invoke (new object [1] { Stream.Null });
}
[Test]
[SecurityPermission (SecurityAction.Deny, SerializationFormatter = true)]
public void Constructor_String ()
{
ConstructorInfo ci = typeof (ResourceSet).GetConstructor (new Type [1] { typeof (string) });
ci.Invoke (new object [1] { MonoTests.System.Resources.ResourceReaderTest.m_ResourceFile });
// works - i.e. no LinkDemand
}
[Test]
[SecurityPermission (SecurityAction.Deny, SerializationFormatter = true)]
public void Constructor_IResourceReader ()
{
ResourceReader r = new ResourceReader (MonoTests.System.Resources.ResourceReaderTest.m_ResourceFile);
ConstructorInfo ci = typeof (ResourceSet).GetConstructor (new Type [1] { typeof (IResourceReader) });
ci.Invoke (new object [1] { r });
// works - i.e. no LinkDemand
}
}
}

View File

@@ -0,0 +1,293 @@
//
// ResourceSetTest.cs: NUnit Test Cases for System.Resources.ResourceSet
//
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2008 Novell, Inc. (http://www.novell.com)
//
// 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;
using System.IO;
using System.Resources;
using NUnit.Framework;
namespace MonoTests.System.Resources {
public class DefaultResourceSet : ResourceSet {
public DefaultResourceSet ()
{
}
public Hashtable GetTable ()
{
return base.Table;
}
public IResourceReader GetReader ()
{
return base.Reader;
}
}
public class ClonableObject : ICloneable {
private int n = 0;
private ClonableObject (int value)
{
n = value;
}
public ClonableObject ()
: this (0)
{
}
public int Value {
get { return n; }
}
public object Clone ()
{
object clone = new ClonableObject (n);
n++;
return (ClonableObject) clone;
}
}
public class CloneResourceSet : ResourceSet {
public CloneResourceSet (ClonableObject c)
{
Table.Add ("clone", c);
}
}
[TestFixture]
public class ResourceSetTest {
[Test] // ctor (IResourceReader)
public void Constructor1_Reader_Null ()
{
try {
new ResourceSet ((IResourceReader) 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 ("reader", ex.ParamName, "#5");
}
}
[Test] // ctor (Stream)
public void Constructor2_Stream_Closed ()
{
MemoryStream ms = new MemoryStream ();
ms.Close ();
try {
new ResourceSet (ms);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Stream was not readable
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
[Test] // ctor (Stream)
public void Constructor2_Stream_Null ()
{
try {
new ResourceSet ((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 (String)
public void Constructor3_FileName_Null ()
{
try {
new ResourceSet ((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 ("path", ex.ParamName, "#5");
}
}
[Test] // ctor (String)
public void Constructor3_FileName_Empty ()
{
try {
new ResourceSet (string.Empty);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Empty path name is not legal
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
[Test]
public void Defaults ()
{
DefaultResourceSet rs = new DefaultResourceSet ();
Assert.IsNotNull (rs.GetTable (), "Table");
Assert.IsNull (rs.GetReader (), "Reader");
Assert.AreEqual (typeof (ResourceReader), rs.GetDefaultReader (), "DefaultReaderType");
Assert.AreEqual (typeof (ResourceWriter), rs.GetDefaultWriter (), "DefaultWriterType");
rs.Dispose ();
Assert.IsNull (rs.GetTable (), "Disposed/Table");
Assert.IsNull (rs.GetReader (), "Disposed/Reader");
Assert.AreEqual (typeof (ResourceReader), rs.GetDefaultReader (), "Disposed/DefaultReaderType");
Assert.AreEqual (typeof (ResourceWriter), rs.GetDefaultWriter (), "Disposed/DefaultWriterType");
}
[Test]
public void Clonable ()
{
ClonableObject c0 = new ClonableObject ();
Assert.AreEqual (0, c0.Value, "Original");
CloneResourceSet rs = new CloneResourceSet (c0);
ClonableObject c1 = (ClonableObject) rs.GetObject ("clone");
Assert.AreEqual (c1.Value, c0.Value, "Clone");
Assert.IsTrue (Object.ReferenceEquals (c0, c1), "Same");
}
[Test]
public void Dispose ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
rs.Dispose ();
rs.Dispose ();
}
[Test]
public void GetEnumerator ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
Assert.IsNotNull (rs.GetEnumerator ());
}
[Test]
public void GetEnumerator_Disposed ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
rs.Dispose ();
try {
rs.GetEnumerator ();
Assert.Fail ("#1");
} catch (ObjectDisposedException ex) {
// Cannot access a closed resource set
Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
[Test]
public void GetObject_DoesNotExists ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
Assert.IsNull (rs.GetObject ("doesnotexists"), "default");
Assert.IsNull (rs.GetObject ("doesnotexists", true), "case");
Assert.IsNull (rs.GetObject ("doesnotexists", false), "!case");
}
[Test]
public void GetObject_Disposed ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
rs.Dispose ();
try {
rs.GetObject ("doesnotexists");
Assert.Fail ("#1");
} catch (ObjectDisposedException ex) {
// Cannot access a closed resource set
Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
[Test]
public void GetString_DoesNotExists ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
Assert.IsNull (rs.GetString ("doesnotexists"), "default");
Assert.IsNull (rs.GetString ("doesnotexists", true), "case");
Assert.IsNull (rs.GetString ("doesnotexists", false), "!case");
}
[Test]
public void GetString_NotAString ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
try {
rs.GetString ("clone");
Assert.Fail ("#1");
} catch (InvalidOperationException ex) {
// This particular resource was not a String -
// call GetObject instead. Resource name: clone
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf ("String") != -1, "#5");
Assert.IsTrue (ex.Message.IndexOf ("GetObject") != -1, "#6");
Assert.IsTrue (ex.Message.IndexOf ("clone") != -1, "#7");
}
}
[Test]
public void GetString_Disposed ()
{
CloneResourceSet rs = new CloneResourceSet (new ClonableObject ());
rs.Dispose ();
try {
rs.GetString ("doesnotexists");
Assert.Fail ("#1");
} catch (ObjectDisposedException ex) {
// Cannot access a closed resource set
Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
}
}

File diff suppressed because it is too large Load Diff