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,80 @@
//
// AppDomainTools.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://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.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Policy;
using System.Text;
using NUnit.Framework;
namespace MonoTests.Common
{
class AppDomainTools
{
public static void RunInSeparateDomain (Action handler, string format, params object[] parms)
{
var setup = AppDomain.CurrentDomain.SetupInformation;
setup.ShadowCopyDirectories = null;
setup.ShadowCopyFiles = null;
setup.ApplicationBase = Path.GetDirectoryName (typeof (AppDomainTools).Assembly.Location);
var ad = AppDomain.CreateDomain ("Test", new Evidence (AppDomain.CurrentDomain.Evidence) , setup);
ad.SetData ("testHandler", handler);
string message;
if (parms != null && parms.Length > 0)
message = String.Format (format, parms);
else
message = format;
ad.SetData ("failureMessage", message);
//ad.AssemblyResolve += ResolveAssemblyEventHandler;
ad.DoCallBack (RunTest);
}
static Assembly ResolveAssemblyEventHandler (object sender, ResolveEventArgs args)
{
string path = Path.Combine (AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "nunit.framework.dll");
if (File.Exists (path))
return Assembly.LoadFrom (path);
return null;
}
static void RunTest ()
{
Action handler = AppDomain.CurrentDomain.GetData ("testHandler") as Action;
if (handler == null) {
string message = AppDomain.CurrentDomain.GetData ("failureMessage") as string;
Assert.Fail (message);
}
handler ();
}
}
}

View File

@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace MonoTests.Common
{
delegate void AssertThrowsDelegate();
static class AssertExtensions
{
public static void AreEqual (byte[] expected, byte[] data, string message)
{
if (expected == null) {
if (data == null)
return;
Assert.Fail ("{0}{1}Expected: null{1}Got: byte array with {2} elements and of rank {3}{1}",
message, Environment.NewLine, data.Length, data.Rank);
}
if (data == null)
Assert.Fail ("{0}{1}Expected: byte array with {2} elements and rank {3}{1}Got: null{1}",
message, Environment.NewLine, expected.Length, expected.Rank);
if (expected.Rank > 1)
Assert.Fail ("Only single-dimensional arrays are supported.");
if (expected.Rank != data.Rank || expected.Length != data.Length)
Assert.Fail ("{0}{1}Expected: byte array with {2} elements and rank {3}{1}Got: byte array with {4} elements and rank {5}{1}",
message, Environment.NewLine, expected.Length, expected.Rank, data.Length, data.Rank);
int max = expected.Length;
for (int i = 0; i < max; i++) {
if (expected[i] != data[i])
Assert.Fail ("{0}{1}Arrays differ at index {2}.{1}Expected 0x{3:X} got 0x{4:X}{1}",
message, Environment.NewLine, i, expected[i], data[i]);
}
}
public static void Throws<ET> (AssertThrowsDelegate code, string message)
{
Throws(typeof(ET), code, message);
}
public static void Throws(Type exceptionType, AssertThrowsDelegate code, string message)
{
if (code == null)
Assert.Fail("No code provided for the test.");
Exception exception = null;
try
{
code();
}
catch (Exception ex)
{
exception = ex;
}
if (exceptionType == null)
{
if (exception == null)
Assert.Fail("{0}{1}Expected: any exception thrown{1}But was: no exception thrown{1}",
message, Environment.NewLine);
return;
}
if (exception == null || exception.GetType() != exceptionType)
Assert.Fail("{0}{1}Expected: {2}{1}But was: {3}{1}{4}{1}",
message,
Environment.NewLine,
exceptionType,
exception == null ? "no exception" : exception.GetType().ToString(),
exception == null ? "no exception" : exception.ToString());
}
public static void Throws(AssertThrowsDelegate code, string message)
{
Throws(null, code, message);
}
}
}

View File

@@ -0,0 +1,6 @@
2010-04-24 Marek Habersack <mhabersack@novell.com>
* AppDomainTools.cs, AssertExtensions.cs, PokerChangeMonitor.cs,
PokerMemoryCache.cs, PokerObjectCache.cs,
TestNotificationSystem.cs: added

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Runtime.Caching;
using System.Text;
namespace MonoTests.Common
{
class PokerChangeMonitor : ChangeMonitor
{
List <string> calls;
string uniqueId;
public List<string> Calls
{
get
{
if (calls == null)
calls = new List<string> ();
return calls;
}
}
public override string UniqueId
{
get { return uniqueId; }
}
public PokerChangeMonitor ()
{
uniqueId = "UniqueID";
InitializationComplete ();
}
public void SignalChange ()
{
OnChanged (null);
}
protected override void Dispose (bool disposing)
{
Calls.Add ("Dispose (bool disposing)");
}
}
}

View File

@@ -0,0 +1,158 @@
//
// PokerMemoryCache.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://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.Generic;
using System.Collections.Specialized;
using System.Runtime.Caching;
using System.Text;
namespace MonoTests.Common
{
class PokerMemoryCache : MemoryCache
{
List<string> calls;
public List<string> Calls
{
get
{
if (calls == null)
calls = new List<string> ();
return calls;
}
}
public override object this [string key]
{
get
{
Calls.Add ("get_this [string key]");
return base [key];
}
set
{
Calls.Add ("set_this [string key]");
base [key] = value;
}
}
public PokerMemoryCache (string name, NameValueCollection config = null)
: base (name, config)
{ }
public override CacheItem AddOrGetExisting (CacheItem item, CacheItemPolicy policy)
{
Calls.Add ("AddOrGetExisting (CacheItem item, CacheItemPolicy policy)");
return base.AddOrGetExisting (item, policy);
}
public override object AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)
{
Calls.Add ("AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)");
return base.AddOrGetExisting (key, value, policy, regionName);
}
public override object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
Calls.Add ("AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)");
return base.AddOrGetExisting (key, value, absoluteExpiration, regionName);
}
public override object Get (string key, string regionName = null)
{
Calls.Add ("Get (string key, string regionName = null)");
return base.Get (key, regionName);
}
public override CacheItem GetCacheItem (string key, string regionName = null)
{
Calls.Add ("GetCacheItem (string key, string regionName = null)");
return base.GetCacheItem (key, regionName);
}
public override long GetCount (string regionName = null)
{
Calls.Add ("GetCount (string regionName = null)");
return base.GetCount (regionName);
}
public override bool Contains (string key, string regionName = null)
{
Calls.Add ("Contains (string key, string regionName = null)");
return base.Contains (key, regionName);
}
public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor (IEnumerable<string> keys, string regionName = null)
{
Calls.Add ("CreateCacheEntryChangeMonitor (IEnumerable<string> keys, string regionName = null)");
return base.CreateCacheEntryChangeMonitor (keys, regionName);
}
protected override IEnumerator<KeyValuePair<string, object>> GetEnumerator ()
{
Calls.Add ("IEnumerator<KeyValuePair<string, object>> GetEnumerator ()");
return base.GetEnumerator ();
}
public IEnumerator<KeyValuePair<string, object>> DoGetEnumerator ()
{
return GetEnumerator ();
}
public override IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)
{
Calls.Add ("IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)");
return base.GetValues (keys, regionName);
}
public override IDictionary<string, object> GetValues (string regionName, params string [] keys)
{
Calls.Add ("IDictionary<string, object> GetValues (string regionName, params string [] keys)");
return base.GetValues (regionName, keys);
}
public override void Set (CacheItem item, CacheItemPolicy policy)
{
Calls.Add ("Set (CacheItem item, CacheItemPolicy policy)");
base.Set (item, policy);
}
public override void Set (string key, object value, CacheItemPolicy policy, string regionName = null)
{
Calls.Add ("Set (string key, object value, CacheItemPolicy policy, string regionName = null)");
base.Set (key, value, policy, regionName);
}
public override void Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
Calls.Add ("Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)");
base.Set (key, value, absoluteExpiration, regionName);
}
}
}

View File

@@ -0,0 +1,186 @@
//
// PokerObjectCache.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://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.Generic;
using System.Reflection;
using System.Runtime.Caching;
namespace MonoTests.Common
{
class PokerObjectCache : ObjectCache
{
Dictionary <string, object> cache;
Dictionary<string, object> Cache {
get
{
if (cache == null)
cache = new Dictionary<string, object> ();
return cache;
}
}
public string MethodCalled { get; private set; }
public override object AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)
{
MethodCalled = "AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)";
if (String.IsNullOrEmpty (key) || value == null)
return null;
object item;
if (Cache.TryGetValue (key, out item))
return item;
Cache.Add (key, value);
return null;
}
public override CacheItem AddOrGetExisting (CacheItem value, CacheItemPolicy policy)
{
MethodCalled = "AddOrGetExisting (CacheItem value, CacheItemPolicy policy)";
if (value == null)
return null;
object item;
if (Cache.TryGetValue (value.Key, out item))
return item as CacheItem;
Cache.Add (value.Key, value);
return null;
}
public override object AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
MethodCalled = "AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)";
if (String.IsNullOrEmpty (key) || value == null)
return null;
object item;
if (Cache.TryGetValue (key, out item))
return item;
Cache.Add (key, value);
return null;
}
public override bool Contains (string key, string regionName = null)
{
throw new NotImplementedException ();
}
public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor (IEnumerable<string> keys, string regionName = null)
{
throw new NotImplementedException ();
}
public override DefaultCacheCapabilities DefaultCacheCapabilities
{
get { throw new NotImplementedException (); }
}
public override object Get (string key, string regionName = null)
{
throw new NotImplementedException ();
}
public override CacheItem GetCacheItem (string key, string regionName = null)
{
throw new NotImplementedException ();
}
public override long GetCount (string regionName = null)
{
throw new NotImplementedException ();
}
protected override IEnumerator<KeyValuePair<string, object>> GetEnumerator ()
{
throw new NotImplementedException ();
}
public override IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)
{
MethodCalled = "IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)";
var ret = new Dictionary<string, object> ();
if (keys == null)
return ret;
Dictionary <string, object> cache = Cache;
if (cache.Count == 0)
return ret;
object value;
foreach (string key in keys) {
if (!cache.TryGetValue (key, out value))
continue;
ret.Add (key, value);
}
return ret;
}
public override string Name
{
get { throw new NotImplementedException (); }
}
public override object Remove (string key, string regionName = null)
{
throw new NotImplementedException ();
}
public override void Set (string key, object value, CacheItemPolicy policy, string regionName = null)
{
throw new NotImplementedException ();
}
public override void Set (CacheItem item, CacheItemPolicy policy)
{
throw new NotImplementedException ();
}
public override void Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
throw new NotImplementedException ();
}
public override object this [string key]
{
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
}
}

View File

@@ -0,0 +1,91 @@
//
// TestNotificationSystem.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://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.Runtime.Caching;
using System.Runtime.Caching.Hosting;
namespace MonoTests.Common
{
class TestNotificationSystem : IServiceProvider, IFileChangeNotificationSystem
{
OnChangedCallback callback;
public bool StartMonitoringCalled { get; private set; }
public uint StartMonitoringCallCount { get; private set; }
public bool StopMonitoringCalled { get; private set; }
public uint StopMonitoringCallCount { get; private set; }
public bool UseNullState { get; set; }
public object GetService (Type serviceType)
{
return this;
}
object IServiceProvider.GetService (Type serviceType)
{
return GetService (serviceType);
}
public void FakeChanged (string filePath)
{
if (callback == null)
return;
callback (null);
}
public void StartMonitoring (string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
{
if (UseNullState)
state = null;
else
state = filePath;
lastWriteTime = DateTimeOffset.FromFileTime (DateTime.Now.Ticks);
callback = onChangedCallback;
fileSize = 10;
StartMonitoringCalled = true;
StartMonitoringCallCount++;
}
public void StopMonitoring (string filePath, object state)
{
StopMonitoringCalled = true;
StopMonitoringCallCount++;
}
void IFileChangeNotificationSystem.StartMonitoring (string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
{
StartMonitoring (filePath, onChangedCallback, out state, out lastWriteTime, out fileSize);
}
void IFileChangeNotificationSystem.StopMonitoring (string filePath, object state)
{
StopMonitoring (filePath, state);
}
}
}