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,123 @@
2010-06-16 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test for two instances calling
Remove.
2010-06-07 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test for GetUserStoreForSite.
2010-06-07 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test for DeleteFile.
2010-06-07 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: Update our tests to catch/report the new
exceptions fired in 4.0, as well as a new test to assert that
GetDirectoryNames fires an ArgumentException if '..' is passed as part
of the path.
2010-06-06 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: Include check for paths outside our
storage root in our tests for MoveFile, MoveDirectory and CopyFile.
2010-06-04 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test case for Remove.
2010-06-02 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: Augment our test cases for MoveFile and
MoveDirectory.
2010-05-31 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageTest.cs:
* IsolatedStorageFileTest.cs: New tests for AvailableFreeSpace, Quota,
UsedSize and IncreaseQuotaTo.
2010-05-27 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test case for CopyFile.
2010-05-27 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test case for GetCreationTime.
2010-05-26 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileStreamTest.cs: New test cases for constructor
obtaining a closed/disposed IsolatedStorageFile.
2010-05-24 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test cases for CreateFile,
MoveDirectory and MoveFile.
2010-05-23 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* IsolatedStorageFileTest.cs: New test cases for DirectoryExists and
FileExists.
2008-12-23 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileTest.cs: Add test case when null values are used
in GetStore. Fix bug #430932
2008-04-18 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileTest.cs: Add test cases for creating sub-
directories and to delete them (bug #376188)
2008-03-28 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileTest.cs: Add test cases for creating directory
(bug #372377) and also getting delaing with subdirectories.
2008-01-17 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileTest.cs: Added test case against regression of
bug #354539
2007-11-06 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileStreamTest.cs: Test case for rooted paths by Jay
Miller (bug #324983).
2005-06-14 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileCas.cs: Added MaximumSize unit tests.
2005-06-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* IsolatedStorageFileStreamTest.cs:
* IsolatedStorageFileTest.cs:
* IsolatedStorageTest.cs: fixed namespace names and removed NotWorking
for a test that now works.
2005-05-18 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileStreamCas.cs: Added tests to test stack
propagation for BeginRead and BeginWrite.
2005-03-24 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileStreamCas.cs: Added reflection-based unit tests
to test LinkDemand on Handle and SafeFileHandle (2.0) properties.
2005-03-15 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileStreamCas.cs: New. CAS unit tests for
IsolatedStorageFileStream.
* IsolatedStorageFileCas.cs: New. CAS unit tests for
IsolatedStorageFile.
2005-01-31 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFileStreamTest.cs: New. Unit tests for
IsolatedStorageFileStream.
* IsolatedStorageFileTest.cs: New. Unit tests for IsolatedStorageFile.
* IsolatedStorageTest.cs: New. Unit tests for IsolatedStorage abstract
class.

View File

@@ -0,0 +1,317 @@
//
// IsolatedStorageFileCas.cs - CAS unit tests for
// System.IO.IsolatedStorage.IsolatedStorageFile
//
// 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.IO.IsolatedStorage;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoCasTests.System.IO.IsolatedStorageTest {
[TestFixture]
[Category ("CAS")]
public class IsolatedStorageFileCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
// use the caller stack to execute some read operations
private void Read (IsolatedStorageFile isf)
{
Assert.IsNotNull (isf.GetDirectoryNames ("*"), "GetDirectoryNames");
Assert.IsNotNull (isf.GetFileNames ("*"), "GetFileNames");
try {
Assert.IsTrue (isf.CurrentSize >= 0, "CurrentSize");
Assert.IsTrue (isf.MaximumSize >= isf.CurrentSize, "MaximumSize");
}
catch (InvalidOperationException) {
// roaming
}
}
// use the caller stack to execute some write operations
private void Write (IsolatedStorageFile isf)
{
isf.CreateDirectory ("testdir");
string filename = Path.Combine ("testdir", "file");
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (filename, FileMode.Create, isf)) {
}
isf.DeleteFile (filename);
isf.DeleteDirectory ("testdir");
try {
isf.Remove ();
}
catch (IsolatedStorageException) {
// fx 1.x doesn't like removing when things "could" still be in use
}
}
#if NET_2_0
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByMachine)]
[ExpectedException (typeof (SecurityException))]
[Ignore ("no manifest")]
public void GetMachineStoreForApplication_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForApplication ();
}
[Test]
[Ignore ("no manifest")]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByMachine)]
public void GetMachineStoreForApplication_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForApplication ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByMachine)]
[ExpectedException (typeof (SecurityException))]
public void GetMachineStoreForAssembly_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForAssembly ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByMachine)]
public void GetMachineStoreForAssembly_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForAssembly ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser)]
public void GetMachineStoreForAssembly_Administer ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForAssembly ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.DomainIsolationByMachine)]
[ExpectedException (typeof (SecurityException))]
public void GetMachineStoreForDomain_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForDomain ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.DomainIsolationByMachine)]
public void GetMachineStoreForDomain_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForDomain ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser)]
public void GetMachineStoreForDomain_Administer ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForDomain ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByUser)]
[ExpectedException (typeof (SecurityException))]
[Ignore ("no manifest")]
public void GetUserStoreForApplication_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ();
}
[Test]
[Ignore ("no manifest")]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByUser)]
public void GetUserStoreForApplication_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ();
}
#endif
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
[ExpectedException (typeof (SecurityException))]
public void GetUserStoreForAssembly_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
public void GetUserStoreForAssembly_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByRoamingUser)]
[ExpectedException (typeof (SecurityException))]
public void GetUserStoreForAssembly_Roaming_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser)]
public void GetUserStoreForAssembly_Roaming_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByRoamingUser)]
public void GetUserStoreForAssembly_Administer ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser)]
[ExpectedException (typeof (SecurityException))]
public void GetUserStoreForDomain_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser)]
public void GetUserStoreForDomain_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, UsageAllowed = IsolatedStorageContainment.DomainIsolationByRoamingUser)]
[ExpectedException (typeof (SecurityException))]
public void GetUserStoreForDomain_Roaming_Fail ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.DomainIsolationByRoamingUser)]
public void GetUserStoreForDomain_Roaming_Pass ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser)]
public void GetUserStoreForDomain_Administer ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
Read (isf);
Write (isf);
isf.Dispose ();
isf.Close ();
}
private ulong MaximumSize (SecurityZone zone)
{
IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Assembly;
Evidence ae = new Evidence ();
ae.AddHost (new Zone (zone));
IsolatedStorageFile isf = IsolatedStorageFile.GetStore (scope, null, null, ae, typeof (Zone));
return isf.MaximumSize;
}
[Test]
public void MaximumSize ()
{
Assert.AreEqual (Int64.MaxValue, MaximumSize (SecurityZone.MyComputer), "MyComputer");
Assert.AreEqual (Int64.MaxValue, MaximumSize (SecurityZone.Intranet), "Intranet");
#if NET_2_0
Assert.AreEqual (512000, MaximumSize (SecurityZone.Internet), "Internet");
Assert.AreEqual (512000, MaximumSize (SecurityZone.Trusted), "Trusted");
#else
Assert.AreEqual (10240, MaximumSize (SecurityZone.Internet), "Internet");
Assert.AreEqual (10240, MaximumSize (SecurityZone.Trusted), "Trusted");
#endif
}
[Test]
[ExpectedException (typeof (PolicyException))]
public void MaximumSize_Untrusted ()
{
Assert.AreEqual (Int64.MaxValue, MaximumSize (SecurityZone.Untrusted), "Untrusted");
}
[Test]
[ExpectedException (typeof (PolicyException))]
public void MaximumSize_NoZone ()
{
Assert.AreEqual (Int64.MaxValue, MaximumSize (SecurityZone.NoZone), "NoZone");
}
}
}

View File

@@ -0,0 +1,347 @@
//
// IsolatedStorageFileStreamCas.cs - CAS unit tests for
// System.IO.IsolatedStorage.IsolatedStorageFileStream
//
// 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.IO.IsolatedStorage;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Threading;
#if NET_2_0
using Microsoft.Win32.SafeHandles;
#endif
namespace MonoCasTests.System.IO.IsolatedStorageTest {
[TestFixture]
[Category ("CAS")]
public class IsolatedStorageFileStreamCas {
private const int timeout = 30000;
private string message;
static ManualResetEvent reset;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
reset = new ManualResetEvent (false);
}
[TestFixtureTearDown]
public void FixtureTearDown ()
{
reset.Close ();
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void DenyUnrestricted ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("deny", FileMode.Create);
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void DenyIsolatedStorageFilePermission ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("deny", FileMode.Create);
}
private void Read (string filename)
{
byte[] buffer = new byte[8];
using (IsolatedStorageFileStream read = new IsolatedStorageFileStream (filename, FileMode.Open, FileAccess.Read)) {
Assert.AreEqual (8, read.Length, "Length");
Assert.AreEqual (0, read.Position, "Position");
Assert.IsTrue (read.CanRead, "read.CanRead");
Assert.IsTrue (read.CanSeek, "read.CanSeek");
Assert.IsFalse (read.CanWrite, "read.CanWrite");
Assert.IsFalse (read.IsAsync, "read.IsAync");
Assert.AreEqual (buffer.Length, read.ReadByte (), "ReadByte");
read.Seek (0, SeekOrigin.Begin);
Assert.AreEqual (buffer.Length, read.Read (buffer, 0, buffer.Length), "Read");
read.Close ();
}
}
private void Write (string filename)
{
byte[] buffer = new byte[8];
using (IsolatedStorageFileStream write = new IsolatedStorageFileStream (filename, FileMode.Create, FileAccess.Write)) {
Assert.IsFalse (write.CanRead, "write.CanRead");
Assert.IsTrue (write.CanSeek, "write.CanSeek");
Assert.IsTrue (write.CanWrite, "write.CanWrite");
Assert.IsFalse (write.IsAsync, "write.IsAync");
write.Write (buffer, 0, buffer.Length);
write.Position = 0;
write.WriteByte ((byte)buffer.Length);
write.SetLength (8);
write.Flush ();
write.Close ();
}
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
[ExpectedException (typeof (FileNotFoundException))]
public void ReadUnexistingFile ()
{
string filename = "cas-doesnt-exists";
try {
Read (filename);
}
catch (FileNotFoundException fnfe) {
// check that we do not leak the full path to the missing file
// as we do not have the FileIOPermission's PathDiscovery rights
Assert.AreEqual (filename, fnfe.FileName, "FileName");
throw;
}
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
[ExpectedException (typeof (DirectoryNotFoundException))]
public void ReadInUnexistingDirectory ()
{
string filename = Path.Combine ("unexistingdir", "filename");
try {
Read (filename);
}
catch (DirectoryNotFoundException dnf) {
// check that we do not leak the full path to the missing file
// as we do not have the FileIOPermission's PathDiscovery rights
Assert.IsTrue (dnf.Message.IndexOf (filename) >= 0, "filename");
Assert.IsFalse (dnf.Message.IndexOf ("\\" + filename) >= 0, "fullpath");
throw;
}
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
[ExpectedException (typeof (UnauthorizedAccessException))]
public void ReadDirectoryAsFile ()
{
string dirname = "this-is-a-dir";
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain ();
try {
string[] dirs = isf.GetDirectoryNames (dirname);
if (dirs.Length == 0) {
isf.CreateDirectory (dirname);
}
Read (dirname);
}
catch (UnauthorizedAccessException uae) {
// check that we do not leak the full path to the missing file
// as we do not have the FileIOPermission's PathDiscovery rights
Assert.IsTrue (uae.Message.IndexOf (dirname) >= 0, "dirname");
Assert.IsFalse (uae.Message.IndexOf ("\\" + dirname) >= 0, "fullpath");
try {
isf.DeleteDirectory (dirname);
}
catch (IsolatedStorageException) {
// this isn't where we want ot fail!
// and 1.x isn't always cooperative
}
throw;
}
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void ReWrite ()
{
Write ("cas-rewrite");
Write ("cas-rewrite");
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void WriteThenRead ()
{
Write ("cas-rw");
Read ("cas-rw");
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
[ExpectedException (typeof (DirectoryNotFoundException))]
public void WriteInUnexistingDirectory ()
{
string filename = Path.Combine ("unexistingdir", "filename");
try {
Write (filename);
}
catch (DirectoryNotFoundException dnf) {
// check that we do not leak the full path to the missing file
// as we do not have the FileIOPermission's PathDiscovery rights
Assert.IsTrue (dnf.Message.IndexOf (filename) >= 0, "filename");
Assert.IsFalse (dnf.Message.IndexOf ("\\" + filename) >= 0, "fullpath");
throw;
}
}
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
[ExpectedException (typeof (IsolatedStorageException))]
public void Handle ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-Handle", FileMode.Create);
IntPtr p = isfs.Handle;
// Note: The SecurityException for UnmanagedCode cannot be tested here because it's a LinkDemand
}
#if NET_2_0
[Test]
[IsolatedStorageFilePermission (SecurityAction.PermitOnly, Unrestricted = true)]
[ExpectedException (typeof (IsolatedStorageException))]
public void SafeFileHandle ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-SafeFileHandle", FileMode.Create);
SafeFileHandle sfh = isfs.SafeFileHandle;
// Note: The SecurityException for UnmanagedCode cannot be tested here because it's a LinkDemand
}
#endif
// we use reflection to call IsolatedStorageFileStream as the Handle and SafeFileHandle
// properties are 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, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void Handle_UnmanagedCode ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-Handle-Unmanaged", FileMode.Create);
try {
MethodInfo mi = typeof (IsolatedStorageFileStream).GetProperty ("Handle").GetGetMethod ();
mi.Invoke (isfs, null);
}
finally {
isfs.Close ();
}
}
#if NET_2_0
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void SafeFileHandle_UnmanagedCode ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-SafeFileHandle-Unmanaged", FileMode.Create);
try {
MethodInfo mi = typeof (IsolatedStorageFileStream).GetProperty ("SafeFileHandle").GetGetMethod ();
mi.Invoke (isfs, null);
}
finally {
isfs.Close ();
}
}
#endif
// async tests (for stack propagation)
private void ReadCallback (IAsyncResult ar)
{
IsolatedStorageFileStream s = (IsolatedStorageFileStream)ar.AsyncState;
s.EndRead (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
public void AsyncRead ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-AsyncRead", FileMode.Create);
message = "AsyncRead";
reset.Reset ();
IAsyncResult r = isfs.BeginRead (new byte[0], 0, 0, new AsyncCallback (ReadCallback), isfs);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
isfs.Close ();
}
private void WriteCallback (IAsyncResult ar)
{
IsolatedStorageFileStream s = (IsolatedStorageFileStream)ar.AsyncState;
s.EndWrite (ar);
try {
// can we do something bad here ?
Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
message = "Expected a SecurityException";
}
catch (SecurityException) {
message = null;
reset.Set ();
}
catch (Exception e) {
message = e.ToString ();
}
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
public void AsyncWrite ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-AsyncWrite", FileMode.Create);
message = "AsyncWrite";
reset.Reset ();
IAsyncResult r = isfs.BeginWrite (new byte[0], 0, 0, new AsyncCallback (WriteCallback), isfs);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
isfs.Close ();
}
}
}

View File

@@ -0,0 +1,178 @@
//
// IsolatedStorageFileStreamTest.cs
// - Unit Tests for abstract IsolatedStorageFileStream class
//
// 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 System;
using System.IO;
using System.IO.IsolatedStorage;
#if NET_2_0
using Microsoft.Win32.SafeHandles;
#endif
using NUnit.Framework;
namespace MonoTests.System.IO.IsolatedStorageTest {
[TestFixture]
public class IsolatedStorageFileStreamTest {
private void CheckCommonDetails (string prefix, IsolatedStorageFileStream isfs, bool read, bool write)
{
Assert.AreEqual (read, isfs.CanRead, prefix + ".CanRead");
Assert.IsTrue (isfs.CanSeek, prefix + ".CanSeek");
Assert.AreEqual (write, isfs.CanWrite, prefix + ".CanWrite");
Assert.IsFalse (isfs.IsAsync, prefix + ".IsAsync");
Assert.AreEqual (0, isfs.Length, prefix + ".Length");
Assert.AreEqual ("[Unknown]", isfs.Name, prefix + ".Name");
Assert.AreEqual (0, isfs.Position, prefix + ".Position");
#if NET_2_0_NOTYET
Assert.IsFalse (isfs.CanTimeout, prefix + ".CanTimeout");
#endif
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_StringNullMode ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (null, FileMode.CreateNew);
}
[Test]
[ExpectedException (typeof (ArgumentException))] // Mono's FileStream throw an ArgumentOutOfRangeException
public void Constructor_StringModeBad ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("badmode", (FileMode)Int32.MinValue);
}
[Test]
public void Constructor_StringMode ()
{
string test = "string-filemode";
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (test, FileMode.Create);
CheckCommonDetails (test, isfs, true, true);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void Constructor_StringModeAccessBad ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("badaccess", FileMode.Create, (FileAccess)Int32.MinValue);
}
[Test]
public void Constructor_StringModeAccess ()
{
string test = "string-filemode-fileaccess";
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (test, FileMode.Create, FileAccess.ReadWrite);
CheckCommonDetails (test, isfs, true, true);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void Constructor_StringModeAccessShareBad ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("badshare", FileMode.Create, FileAccess.Read, (FileShare)Int32.MinValue);
}
[Test]
public void Constructor_StringModeAccessShare ()
{
string test = "string-filemode-fileaccess-fileshare";
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (test, FileMode.Create, FileAccess.Write, FileShare.Read);
CheckCommonDetails (test, isfs, false, true);
}
[Test]
[ExpectedException (typeof (IsolatedStorageException))]
public void Handle ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("handle", FileMode.Create);
IntPtr p = isfs.Handle;
}
[Test]
public void RootPath ()
{
new IsolatedStorageFileStream ("/rootpath", FileMode.Create);
}
#if NET_2_0_NOTYET
[Test]
[ExpectedException (typeof (IsolatedStorageException))]
public void SafeFileHandle_ ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("safeFileHandle", FileMode.Create);
SafeFileHandle sfh = isfs.SafeFileHandle;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReadTimeOut ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("readTimeout", FileMode.Create);
int t = isfs.ReadTimeout;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void WriteTimeOut ()
{
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("writeTimeout", FileMode.Create);
int t = isfs.WriteTimeout;
}
#endif
#if NET_4_0
[Test]
public void Constructor_StorageInvalid ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
isf.Close ();
try {
new IsolatedStorageFileStream ("file", FileMode.Create, isf);
} catch (InvalidOperationException) {
}
isf.Dispose ();
try {
new IsolatedStorageFileStream ("file", FileMode.Create, isf);
} catch (InvalidOperationException) {
}
// Re-open and then remove the storage
isf = IsolatedStorageFile.GetUserStoreForAssembly ();
isf.Remove ();
try {
new IsolatedStorageFileStream ("file", FileMode.Create, isf);
} catch (InvalidOperationException) {
}
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,292 @@
//
// IsolatedStorageTest.cs - Unit Tests for abstract IsolatedStorage class
//
// 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 System;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using NUnit.Framework;
namespace MonoTests.System.IO.IsolatedStorageTest {
// note: IsolatedStorage is abstract so we create a
// non-abstract class to test it
// naming a class with the same name as a namespace is a BAD idea
public class NonAbstractIsolatedStorage : global::System.IO.IsolatedStorage.IsolatedStorage
{
public NonAbstractIsolatedStorage ()
{
// no InitStore here
}
public NonAbstractIsolatedStorage (IsolatedStorageScope scope, Type domain, Type assembly)
{
InitStore (scope, domain, assembly);
}
public NonAbstractIsolatedStorage(IsolatedStorageScope scope, Type application)
{
InitStore (scope, application);
}
protected override IsolatedStoragePermission GetPermission (PermissionSet ps)
{
throw new NotImplementedException();
}
public override void Remove ()
{
throw new NotImplementedException();
}
public char PublicSeparatorExternal {
get { return base.SeparatorExternal; }
}
public char PublicSeparatorInternal {
get { return base.SeparatorInternal; }
}
}
[TestFixture]
public class IsolatedStorageTest {
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_Bad_Null ()
{
IsolatedStorageScope bad = (IsolatedStorageScope)Int32.MinValue;
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (bad, null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_None_Null ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.None, null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_None ()
{
Type t = typeof (object);
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.None, t, t);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_User ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.User, null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_Domain ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Domain, null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_Assembly ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Assembly, null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_Roaming ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Roaming, null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsolatedStorage_Machine ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Machine, null, null);
}
[Test]
#if !MOBILE
[ExpectedException (typeof (IsolatedStorageException))]
#endif
public void IsolatedStorage_Application ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Application, null);
}
[Test]
[ExpectedException (typeof (NotImplementedException))]
public void IsolatedStorage_AssemblyUser ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Assembly | IsolatedStorageScope.User, null, null);
}
[Test]
[ExpectedException (typeof (NotImplementedException))]
public void IsolatedStorage_AssemblyUserDomain ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage (IsolatedStorageScope.Assembly | IsolatedStorageScope.User | IsolatedStorageScope.Domain, null, null);
}
[Test]
public void IsolatedStorage ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
Assert.AreEqual (IsolatedStorageScope.None, nais.Scope, "Scope");
Assert.AreEqual (Path.DirectorySeparatorChar, nais.PublicSeparatorExternal, "SeparatorExternal");
Assert.AreEqual ('.', nais.PublicSeparatorInternal, "SeparatorInternal");
}
#if NET_2_0
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_ApplicationIdentity ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
object o = nais.ApplicationIdentity;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_AssemblyIdentity ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
object o = nais.AssemblyIdentity;
}
#else
[Test]
public void IsolatedStorage_AssemblyIdentity ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
Assert.IsNull (nais.AssemblyIdentity, "AssemblyIdentity");
}
#endif
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_CurrentSize ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
ulong ul = nais.CurrentSize;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_DomainIdentity ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
object o = nais.DomainIdentity;
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_MaximumSize ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
ulong ul = nais.MaximumSize;
}
[Test]
public void MultiLevel ()
{
// see bug #4101
IsolatedStorageFile isf;
#if MOBILE
isf = IsolatedStorageFile.GetUserStoreForApplication ();
#else
isf = IsolatedStorageFile.GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain,
typeof (global::System.Security.Policy.Url), typeof (global::System.Security.Policy.Url));
#endif
try {
isf.CreateDirectory ("dir1");
string [] dirs = isf.GetDirectoryNames ("*");
Assert.AreEqual (1, dirs.Length, "1a");
Assert.AreEqual ("dir1", dirs [0], "1b");
isf.CreateDirectory ("dir1/test");
dirs = isf.GetDirectoryNames ("dir1/*");
Assert.AreEqual (1, dirs.Length, "2a");
Assert.AreEqual ("test", dirs [0], "2b");
isf.CreateDirectory ("dir1/test/test2a");
isf.CreateDirectory ("dir1/test/test2b");
dirs = isf.GetDirectoryNames ("dir1/test/*");
Assert.AreEqual (2, dirs.Length, "3a");
Assert.AreEqual ("test2a", dirs [0], "3b");
Assert.AreEqual ("test2b", dirs [1], "3c");
} finally {
isf.DeleteDirectory ("dir1/test/test2a");
isf.DeleteDirectory ("dir1/test/test2b");
isf.DeleteDirectory ("dir1/test");
isf.DeleteDirectory ("dir1");
}
}
#if NET_4_0
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_UsedSize ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
Console.WriteLine (nais.UsedSize);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_AvailableFreeSpace ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
Console.WriteLine (nais.AvailableFreeSpace);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void IsolatedStorage_Quota ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
Console.WriteLine (nais.Quota);
}
[Test]
public void IsolatedStorage_IncreaseQuotaTo ()
{
NonAbstractIsolatedStorage nais = new NonAbstractIsolatedStorage ();
Assert.AreEqual (false, nais.IncreaseQuotaTo (-10), "#A0");
Assert.AreEqual (false, nais.IncreaseQuotaTo (0), "#A1");
Assert.AreEqual (false, nais.IncreaseQuotaTo (100), "#A2");
}
#endif
}
}