You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
ikvm-native
libgc
llvm
m4
man
mcs
build
class
Accessibility
Commons.Xml.Relaxng
Cscompmgd
CustomMarshalers
Facades
I18N
IBM.Data.DB2
ICSharpCode.SharpZipLib
Microsoft.Build
Microsoft.Build.Engine
Microsoft.Build.Framework
Microsoft.Build.Tasks
Microsoft.Build.Utilities
Microsoft.CSharp
Microsoft.NuGet.Build.Tasks
Microsoft.VisualC
Microsoft.Web.Infrastructure
MicrosoftAjaxLibrary
Mono.Btls.Interface
Mono.C5
Mono.CSharp
Mono.Cairo
Mono.Cecil
Mono.Cecil.Mdb
Mono.CodeContracts
Mono.CompilerServices.SymbolWriter
Mono.Data.Sqlite
Mono.Data.Tds
Mono.Debugger.Soft
Mono.Http
Mono.Management
Mono.Messaging
Mono.Messaging.RabbitMQ
Mono.Options
Mono.Parallel
Mono.Posix
Mono.Profiler.Log
Mono.Runtime.Tests
Mono.Security
Mono.Security.Win32
Mono.Simd
Mono.Tasklets
Mono.WebBrowser
Mono.XBuild.Tasks
Novell.Directory.Ldap
PEAPI
RabbitMQ.Client
SMDiagnostics
System
System.ComponentModel.Composition.4.5
System.ComponentModel.DataAnnotations
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.OracleClient
System.Data.Services
System.Data.Services.Client
System.Deployment
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.Dynamic
System.EnterpriseServices
System.IO.Compression
System.IO.Compression.FileSystem
System.IdentityModel
System.IdentityModel.Selectors
System.Json
System.Json.Microsoft
System.Management
System.Messaging
System.Net
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.WebRequest
System.Net.Http.WinHttpHandler
System.Numerics
System.Numerics.Vectors
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reflection.Context
System.Runtime.Caching
System.Runtime.CompilerServices.Unsafe
System.Runtime.DurableInstancing
System.Runtime.Remoting
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Soap
System.Security
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.Web
System.ServiceProcess
System.Threading.Tasks.Dataflow
System.Transactions
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Extensions
System.Web.Extensions.Design
System.Web.Http
System.Web.Http.SelfHost
System.Web.Http.WebHost
System.Web.Mobile
System.Web.Mvc3
System.Web.Razor
System.Web.RegularExpressions
System.Web.Routing
System.Web.Services
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Windows
System.Windows.Forms
System.Windows.Forms.DataVisualization
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.XML
System.Xaml
System.Xml.Linq
System.Xml.Serialization
SystemWebTestShim
WebMatrix.Data
WindowsBase
aot-compiler
corlib
Assembly
CommonCrypto
CoreFoundation
Documentation
LinkerDescriptor
Microsoft.Win32
Mono
Mono.Globalization.Unicode
Mono.Interop
Mono.Security
Mono.Security.Cryptography
Mono.Xml
ReferenceSources
System
System.Configuration.Assemblies
System.Deployment.Internal
System.Diagnostics
System.Diagnostics.SymbolStore
System.Diagnostics.Tracing
System.Globalization
System.IO
System.IO.IsolatedStorage
System.Reflection
System.Reflection.Emit
System.Reflection.Metadata
System.Resources
System.Runtime
System.Runtime.CompilerServices
System.Runtime.Hosting
System.Runtime.InteropServices
System.Runtime.InteropServices.RuntimeInformation
System.Runtime.InteropServices.WindowsRuntime
System.Runtime.Remoting
System.Runtime.Remoting.Activation
System.Runtime.Remoting.Channels
System.Runtime.Remoting.Contexts
System.Runtime.Remoting.Lifetime
System.Runtime.Remoting.Messaging
System.Runtime.Remoting.Metadata
System.Runtime.Remoting.Metadata.W3cXsd2001
System.Runtime.Remoting.Proxies
System.Runtime.Remoting.Services
System.Runtime.Versioning
System.Security
System.Security.AccessControl
System.Security.Cryptography
System.Security.Cryptography.X509Certificates
System.Security.Permissions
System.Security.Policy
System.Security.Principal
System.Text
System.Threading
Test
Microsoft.Win32
Mono
System
System.Collections
ArrayListTest.cs
BitArrayTest.cs
CaseInsensitiveComparerTest.cs
CaseInsensitiveHashCodeProviderTest.cs
CollectionBaseTest.cs
ComparerTest.cs
DictionaryBaseTest.cs
DictionaryEntryTest.cs
HashtableTest.cs
NewArrayListTest.cs
QueueTest.cs
ReadOnlyCollectionBaseTest.cs
SortedListTest.cs
StackTest.cs
StructuralComparisonsTest.cs
System.Collections.Concurrent
System.Collections.Generic
System.Collections.ObjectModel
System.Diagnostics
System.Diagnostics.Contracts
System.Globalization
System.IO
System.IO.IsolatedStorage
System.Reflection
System.Reflection.Emit
System.Resources
System.Runtime.CompilerServices
System.Runtime.ExceptionServices
System.Runtime.InteropServices
System.Runtime.Remoting
System.Runtime.Remoting.Channels
System.Runtime.Remoting.Contexts
System.Runtime.Remoting.Messaging
System.Runtime.Remoting.Metadata.W3cXsd2001
System.Runtime.Remoting.Proxies
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Binary
System.Runtime.Versioning
System.Security
System.Security.AccessControl
System.Security.Claims
System.Security.Cryptography
System.Security.Cryptography.X509Certificates
System.Security.Permissions
System.Security.Policy
System.Security.Principal
System.Text
System.Threading
System.Threading.Tasks
resources
coreclr
corefx
corert
il
resources
Makefile
corlib.dll.sources.REMOVED.git-id
corlib_test.dll.sources
corlib_xtest.dll.sources
linux_net_4_x_corlib.dll.exclude.sources
linux_net_4_x_corlib.dll.sources
macos_net_4_x_corlib.dll.exclude.sources
macos_net_4_x_corlib.dll.sources
monodroid_corlib_test.dll.exclude.sources
monodroid_corlib_test.dll.sources
monotouch_corlib.dll.exclude.sources
monotouch_corlib.dll.sources
monotouch_corlib_test.dll.exclude.sources
monotouch_corlib_xtest.dll.exclude.sources
monotouch_runtime_corlib.dll.exclude.sources
monotouch_runtime_corlib.dll.sources
monotouch_tv_corlib.dll.exclude.sources
monotouch_tv_corlib.dll.sources
monotouch_tv_corlib_test.dll.exclude.sources
monotouch_tv_corlib_xtest.dll.exclude.sources
monotouch_tv_runtime_corlib.dll.exclude.sources
monotouch_tv_runtime_corlib.dll.sources
monotouch_watch_corlib.dll.exclude.sources
monotouch_watch_corlib.dll.sources
monotouch_watch_corlib_test.dll.exclude.sources
monotouch_watch_corlib_xtest.dll.exclude.sources
monotouch_watch_runtime_corlib.dll.exclude.sources
monotouch_watch_runtime_corlib.dll.sources
net_4_x_corlib.dll.sources
orbis_corlib_test.dll.exclude.sources
orbis_corlib_test.dll.sources
testing_aot_full_corlib_test.dll.exclude.sources
testing_aot_full_corlib_test.dll.sources
testing_aot_hybrid_corlib_test.dll.exclude.sources
unix_net_4_x_corlib.dll.exclude.sources
unix_net_4_x_corlib.dll.sources
wasm_corlib_test.dll.exclude.sources
wasm_corlib_test.dll.sources
wasm_corlib_xtest.dll.exclude.sources
win32_net_4_x_corlib.dll.exclude.sources
win32_net_4_x_corlib.dll.sources
win32_net_4_x_corlib_test.dll.exclude.sources
win32_net_4_x_corlib_test.dll.sources
win32_net_4_x_corlib_xtest.dll.sources
winaot_corlib.dll.exclude.sources
winaot_corlib.dll.sources
winaot_corlib_test.dll.exclude.sources
winaot_corlib_test.dll.sources
xammac_corlib.dll.exclude.sources
xammac_corlib.dll.sources
xammac_net_4_5_corlib.dll.exclude.sources
dlr
doc
legacy
lib
monodoc
notes
reference-assemblies
referencesource
test-helpers
LICENSE
Makefile
Open.snk
README
ecma.pub
mono.pub
mono.snk
msfinal.pub
reactive.pub
silverlight.pub
winfx.pub
winfx3.pub
docs
errors
ilasm
jay
mcs
nunit24
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
341 lines
8.4 KiB
C#
341 lines
8.4 KiB
C#
![]() |
//
|
||
|
// System.Collections.CollectionBase
|
||
|
// Test suite for System.Collections.CollectionBase
|
||
|
//
|
||
|
// Authors:
|
||
|
// Nick D. Drochak II
|
||
|
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
|
||
|
//
|
||
|
// (C) 2001 Nick D. Drochak II
|
||
|
// (c) 2003 Ximian, Inc. (http://www.ximian.com)
|
||
|
//
|
||
|
|
||
|
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using NUnit.Framework;
|
||
|
|
||
|
namespace MonoTests.System.Collections
|
||
|
{
|
||
|
|
||
|
[TestFixture]
|
||
|
public class CollectionBaseTest
|
||
|
{
|
||
|
// We need a concrete class to test the abstract base class
|
||
|
public class ConcreteCollection : CollectionBase
|
||
|
{
|
||
|
// These fields are used as markers to test the On* hooks.
|
||
|
public bool onClearFired;
|
||
|
public bool onClearCompleteFired;
|
||
|
|
||
|
public bool onInsertFired;
|
||
|
public int onInsertIndex;
|
||
|
public bool onInsertCompleteFired;
|
||
|
public int onInsertCompleteIndex;
|
||
|
|
||
|
public bool onRemoveFired;
|
||
|
public int onRemoveIndex;
|
||
|
public bool onRemoveCompleteFired;
|
||
|
public int onRemoveCompleteIndex;
|
||
|
|
||
|
public bool onSetFired;
|
||
|
public int onSetOldValue;
|
||
|
public int onSetNewValue;
|
||
|
public bool onSetCompleteFired;
|
||
|
public int onSetCompleteOldValue;
|
||
|
public int onSetCompleteNewValue;
|
||
|
public int mustThrowException;
|
||
|
public bool onValidateFired;
|
||
|
|
||
|
// This constructor is used to test OnValid()
|
||
|
public ConcreteCollection()
|
||
|
{
|
||
|
IList listObj;
|
||
|
listObj = this;
|
||
|
listObj.Add(null);
|
||
|
}
|
||
|
|
||
|
// This constructor puts consecutive integers into the list
|
||
|
public ConcreteCollection(int i) {
|
||
|
IList listObj;
|
||
|
listObj = this;
|
||
|
|
||
|
int j;
|
||
|
for (j = 0; j< i; j++) {
|
||
|
listObj.Add(j);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CheckIfThrow ()
|
||
|
{
|
||
|
if (mustThrowException > 0) {
|
||
|
mustThrowException--;
|
||
|
if (mustThrowException == 0)
|
||
|
throw new Exception ();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// A helper method to look at a value in the list at a specific index
|
||
|
public int PeekAt(int index)
|
||
|
{
|
||
|
IList listObj;
|
||
|
listObj = this;
|
||
|
return (int) listObj[index];
|
||
|
}
|
||
|
|
||
|
protected override void OnValidate (object value) {
|
||
|
this.onValidateFired = true;
|
||
|
CheckIfThrow ();
|
||
|
base.OnValidate (value);
|
||
|
}
|
||
|
|
||
|
// Mark the flag if this hook is fired
|
||
|
protected override void OnClear() {
|
||
|
this.onClearFired = true;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
// Mark the flag if this hook is fired
|
||
|
protected override void OnClearComplete()
|
||
|
{
|
||
|
this.onClearCompleteFired = true;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
// Mark the flag, and save the paramter if this hook is fired
|
||
|
protected override void OnInsert(int index, object value)
|
||
|
{
|
||
|
this.onInsertFired = true;
|
||
|
this.onInsertIndex = index;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
// Mark the flag, and save the paramter if this hook is fired
|
||
|
protected override void OnInsertComplete(int index, object value)
|
||
|
{
|
||
|
this.onInsertCompleteFired = true;
|
||
|
this.onInsertCompleteIndex = index;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
// Mark the flag, and save the paramter if this hook is fired
|
||
|
protected override void OnRemove(int index, object value)
|
||
|
{
|
||
|
this.onRemoveFired = true;
|
||
|
this.onRemoveIndex = index;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
// Mark the flag, and save the paramter if this hook is fired
|
||
|
protected override void OnRemoveComplete(int index, object value)
|
||
|
{
|
||
|
this.onRemoveCompleteFired = true;
|
||
|
this.onRemoveCompleteIndex = index;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
// Mark the flag, and save the paramters if this hook is fired
|
||
|
protected override void OnSet(int index, object oldValue, object newValue)
|
||
|
{
|
||
|
this.onSetFired = true;
|
||
|
this.onSetOldValue = (int) oldValue;
|
||
|
this.onSetNewValue = (int) newValue;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
// Mark the flag, and save the paramters if this hook is fired
|
||
|
protected override void OnSetComplete(int index, object oldValue, object newValue)
|
||
|
{
|
||
|
this.onSetCompleteFired = true;
|
||
|
this.onSetCompleteOldValue = (int) oldValue;
|
||
|
this.onSetCompleteNewValue = (int) newValue;
|
||
|
CheckIfThrow ();
|
||
|
}
|
||
|
|
||
|
public IList BaseList {
|
||
|
get { return base.List; }
|
||
|
}
|
||
|
} // public class ConcreteCollection
|
||
|
|
||
|
// Check the count property
|
||
|
[Test]
|
||
|
public void Count() {
|
||
|
ConcreteCollection myCollection;
|
||
|
myCollection = new ConcreteCollection(4);
|
||
|
Assert.IsTrue (4 == myCollection.Count);
|
||
|
}
|
||
|
|
||
|
// Make sure GetEnumerator returns an object
|
||
|
[Test]
|
||
|
public void GetEnumerator() {
|
||
|
ConcreteCollection myCollection;
|
||
|
myCollection = new ConcreteCollection(4);
|
||
|
Assert.IsTrue (null != myCollection.GetEnumerator());
|
||
|
}
|
||
|
|
||
|
// OnValid disallows nulls
|
||
|
[Test]
|
||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||
|
public void OnValid() {
|
||
|
ConcreteCollection myCollection;
|
||
|
myCollection = new ConcreteCollection();
|
||
|
}
|
||
|
|
||
|
// Test various Insert paths
|
||
|
[Test]
|
||
|
public void Insert() {
|
||
|
ConcreteCollection myCollection;
|
||
|
int numberOfItems;
|
||
|
numberOfItems = 3;
|
||
|
// The constructor inserts
|
||
|
myCollection = new ConcreteCollection(numberOfItems);
|
||
|
Assert.IsTrue (myCollection.onInsertFired);
|
||
|
Assert.IsTrue (myCollection.onInsertCompleteFired);
|
||
|
|
||
|
// Using the IList interface, check inserts in the middle
|
||
|
IList listObj = myCollection;
|
||
|
listObj.Insert(1, 9);
|
||
|
Assert.IsTrue (myCollection.onInsertIndex == 1);
|
||
|
Assert.IsTrue (myCollection.onInsertCompleteIndex == 1);
|
||
|
Assert.IsTrue (myCollection.PeekAt(1) == 9);
|
||
|
}
|
||
|
|
||
|
// Test Clear and it's hooks
|
||
|
[Test]
|
||
|
public void Clear()
|
||
|
{
|
||
|
ConcreteCollection myCollection;
|
||
|
int numberOfItems;
|
||
|
numberOfItems = 1;
|
||
|
myCollection = new ConcreteCollection(numberOfItems);
|
||
|
myCollection.Clear();
|
||
|
Assert.IsTrue (myCollection.Count == 0);
|
||
|
Assert.IsTrue (myCollection.onClearFired);
|
||
|
Assert.IsTrue (myCollection.onClearCompleteFired);
|
||
|
}
|
||
|
|
||
|
// Test RemoveAt, other removes and the hooks
|
||
|
[Test]
|
||
|
public void Remove()
|
||
|
{
|
||
|
ConcreteCollection myCollection;
|
||
|
int numberOfItems;
|
||
|
numberOfItems = 3;
|
||
|
// Set up a test collection
|
||
|
myCollection = new ConcreteCollection(numberOfItems);
|
||
|
|
||
|
// The list is 0-based. So if we remove the second one
|
||
|
myCollection.RemoveAt(1);
|
||
|
|
||
|
// We should see the original third one in it's place
|
||
|
Assert.IsTrue (myCollection.PeekAt(1) == 2);
|
||
|
Assert.IsTrue (myCollection.onRemoveFired);
|
||
|
Assert.IsTrue (myCollection.onRemoveIndex == 1);
|
||
|
Assert.IsTrue (myCollection.onRemoveCompleteFired);
|
||
|
Assert.IsTrue (myCollection.onRemoveCompleteIndex == 1);
|
||
|
IList listObj = myCollection;
|
||
|
listObj.Remove(0);
|
||
|
// Confirm parameters are being passed to the hooks
|
||
|
Assert.IsTrue (myCollection.onRemoveIndex == 0);
|
||
|
Assert.IsTrue (myCollection.onRemoveCompleteIndex == 0);
|
||
|
}
|
||
|
|
||
|
// Test the random access feature
|
||
|
[Test]
|
||
|
public void Set()
|
||
|
{
|
||
|
ConcreteCollection myCollection;
|
||
|
int numberOfItems;
|
||
|
numberOfItems = 3;
|
||
|
myCollection = new ConcreteCollection(numberOfItems);
|
||
|
IList listObj = myCollection;
|
||
|
listObj[0] = 99;
|
||
|
Assert.IsTrue ((int) listObj[0] == 99);
|
||
|
Assert.IsTrue (myCollection.onSetFired);
|
||
|
Assert.IsTrue (myCollection.onSetCompleteFired);
|
||
|
Assert.IsTrue (myCollection.onSetOldValue == 0);
|
||
|
Assert.IsTrue (myCollection.onSetCompleteOldValue == 0);
|
||
|
Assert.IsTrue (myCollection.onSetNewValue == 99);
|
||
|
Assert.IsTrue (myCollection.onSetCompleteNewValue == 99);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void InsertComplete_Add ()
|
||
|
{
|
||
|
ConcreteCollection coll = new ConcreteCollection (0);
|
||
|
coll.mustThrowException = 1;
|
||
|
|
||
|
try {
|
||
|
coll.BaseList.Add (0);
|
||
|
} catch {
|
||
|
}
|
||
|
Assert.AreEqual (0, coll.Count);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
[ExpectedException (typeof (ArgumentOutOfRangeException))]
|
||
|
public void ValidateCalled ()
|
||
|
{
|
||
|
ConcreteCollection coll = new ConcreteCollection (0);
|
||
|
coll.mustThrowException = 1;
|
||
|
|
||
|
try {
|
||
|
coll.BaseList [5] = 8888;
|
||
|
} catch (ArgumentOutOfRangeException) {
|
||
|
throw;
|
||
|
} finally {
|
||
|
Assert.AreEqual (false, coll.onValidateFired);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void SetCompleteCalled ()
|
||
|
{
|
||
|
ConcreteCollection coll = new ConcreteCollection (0);
|
||
|
|
||
|
coll.BaseList.Add (88);
|
||
|
coll.mustThrowException = 1;
|
||
|
try {
|
||
|
coll.BaseList [0] = 11;
|
||
|
} catch {
|
||
|
} finally {
|
||
|
Assert.AreEqual (false, coll.onSetCompleteFired);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void SetCompleteUndo ()
|
||
|
{
|
||
|
ConcreteCollection coll = new ConcreteCollection (0);
|
||
|
|
||
|
bool throwsException = true;
|
||
|
|
||
|
coll.BaseList.Add (88);
|
||
|
coll.onValidateFired = false;
|
||
|
coll.onInsertFired = false;
|
||
|
coll.onSetCompleteFired = false;
|
||
|
coll.mustThrowException = 3;
|
||
|
try {
|
||
|
coll.BaseList [0] = 11;
|
||
|
throwsException = false;
|
||
|
} catch {
|
||
|
} finally {
|
||
|
Assert.IsTrue (throwsException);
|
||
|
Assert.IsTrue (coll.onValidateFired);
|
||
|
Assert.IsTrue (coll.onSetFired);
|
||
|
Assert.IsTrue (coll.onSetCompleteFired);
|
||
|
Assert.AreEqual (88, coll.BaseList [0]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
[ExpectedException (typeof (ArgumentException))]
|
||
|
public void InvalidRemove ()
|
||
|
{
|
||
|
ConcreteCollection coll = new ConcreteCollection (0);
|
||
|
coll.BaseList.Remove (10);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|