Index: mcs/class/System/Test/System.ComponentModel/ChangeLog =================================================================== --- mcs/class/System/Test/System.ComponentModel/ChangeLog (revision 78989) +++ mcs/class/System/Test/System.ComponentModel/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2007-06-10 Ivan Zlatev + + * NestedContainerTest.cs: Added. + 2006-05-31 Atsushi Enomoto * LookupBindingPropertiesAttributeTest.cs: Index: mcs/class/System/Test/System.ComponentModel/NestedContainerTest.cs =================================================================== --- mcs/class/System/Test/System.ComponentModel/NestedContainerTest.cs (revision 0) +++ mcs/class/System/Test/System.ComponentModel/NestedContainerTest.cs (revision 0) @@ -0,0 +1,161 @@ +// +// ControlDesignerTest +// +// Authors: +// Ivan N. Zlatev (contact i-nZ.net) +// +// (C) 2007 Ivan N. Zlatev + +// +// 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. +// + +#if NET_2_0 + +using System; +using System.ComponentModel; +using System.Collections; +using NUnit.Core; +using NUnit.Framework; + + +namespace MonoTests.System.ComponentModel +{ + + [TestFixture] + public class NestedContainerTest : NestedContainer + { + + private class ContainerWithService : Container + { + + public class DesignModeEnabledSite : ISite { + + private IComponent _component; + private ContainerWithService _container; + private string _name; + + public DesignModeEnabledSite (string name, IComponent component, ContainerWithService container) + { + _component = component; + _container = container; + _name = name; + } + + public IComponent Component { + get { return _component; } + } + + public IContainer Container { + get { return _container; } + } + + public bool DesignMode { + get { return true; } + } + + public string Name { + get { return _name; } + set { _name = value; } + } + + public virtual object GetService (Type t) + { + if (typeof (ISite) == t) + return this; + + return _container.GetService (t); + } + } + + protected override object GetService (Type type) + { + if (typeof (ContainerWithService) == type) + return this; + else + return null; + } + + protected override ISite CreateSite (IComponent component, string name) + { + return new ContainerWithService.DesignModeEnabledSite (name, component, this); + } + } + + public NestedContainerTest () : base (new Component()) + { + } + + public NestedContainerTest (IComponent owner) : base (owner) + { + } + + [Test] + public void NameTest () + { + Container container = new Container (); + Component owner = new Component (); + container.Add (owner, "OwnerName"); + NestedContainerTest nestedContainer = new NestedContainerTest (owner); + Component nestedComponent = new Component (); + nestedContainer.Add (nestedComponent, "NestedComponentName"); + + Assert.AreEqual ("OwnerName", nestedContainer.OwnerName, "#1"); + Assert.AreEqual ("OwnerName.NestedComponentName", ((INestedSite)nestedComponent.Site).FullName, "#2"); + // Prooves that MSDN is wrong. + Assert.AreEqual ("NestedComponentName", nestedComponent.Site.Name, "#3"); + + container.Remove (owner); + Assert.AreEqual (null, nestedContainer.OwnerName, "#4"); + Assert.AreEqual ("NestedComponentName", ((INestedSite)nestedComponent.Site).FullName, "#5"); + } + + [Test] + public void GetServiceTest () + { + ContainerWithService container = new ContainerWithService (); + Component owner = new Component (); + container.Add (owner, "OwnerName"); + NestedContainerTest nestedContainer = new NestedContainerTest (owner); + Component nestedComponent = new Component (); + nestedContainer.Add (nestedComponent, "NestedComponentName"); + + Assert.IsNotNull (nestedComponent.Site.GetService (typeof (INestedContainer)), "#1"); + // test who provides the ISite service. + Assert.AreEqual (nestedComponent.Site, nestedComponent.Site.GetService (typeof (ISite)), "#2"); + // test GetService forwarding to owner. Prooves that MSDN is wrong + Assert.IsNull (nestedComponent.Site.GetService (typeof (ContainerWithService)), "#3"); + } + + [Test] + public void DesignModeTest () + { + ContainerWithService container = new ContainerWithService (); + Component owner = new Component (); + container.Add (owner, "OwnerName"); + NestedContainerTest nestedContainer = new NestedContainerTest (owner); + Component nestedComponent = new Component (); + nestedContainer.Add (nestedComponent, "NestedComponentName"); + + Assert.IsTrue (nestedComponent.Site.DesignMode, "#1"); + } + } +} +#endif Index: mcs/class/System/System.ComponentModel/ChangeLog =================================================================== --- mcs/class/System/System.ComponentModel/ChangeLog (revision 78989) +++ mcs/class/System/System.ComponentModel/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2007-06-10 Ivan Zlatev + + * NestedContainer.cs: added implementation. + 2007-05-31 Atsushi Enomoto * LookupBindingPropertiesAttribute.cs: Index: mcs/class/System/System.ComponentModel/NestedContainer.cs =================================================================== --- mcs/class/System/System.ComponentModel/NestedContainer.cs (revision 78989) +++ mcs/class/System/System.ComponentModel/NestedContainer.cs (working copy) @@ -1,11 +1,10 @@ // -// NestedContainer.cs +// System.ComponentModel.NestedContainer // -// Author: -// Atsushi Enomoto +// Authors: +// Ivan N. Zlatev (contact i-nZ.net) // -// Copyright (C) 2007 Novell, Inc. http://www.novell.com -// +// (C) 2006-2007 Ivan N. Zlatev // // Permission is hereby granted, free of charge, to any person obtaining @@ -31,49 +30,149 @@ #if NET_2_0 using System; +using System.Collections; namespace System.ComponentModel { - public class NestedContainer : Container, INestedContainer + // Differences compared to Container: + // * Site's DesignMode property is routed through the owning component's site. Note that even though MSDN + // says that GetService is routed as well, but in reality it is not. The unit tests proof that. + // * According to MSDN the site's Name property is a qualified name that includes the owning component's name followed by a + // period (.) and the child component's name. It is not again according to the tests. + // * GetService provides support for the INestedContainer as a service. + // * When the owning component is disposed, the container is disposed as well. + + public class NestedContainer : Container, INestedContainer, IContainer, IDisposable { - IComponent owner; - [MonoTODO] +#region Site : INestedSite, ISite, IServiceProvider + + private class Site : INestedSite, ISite, IServiceProvider + { + + private IComponent _component; + private NestedContainer _nestedContainer; + private string _componentName; + + public Site (IComponent component, NestedContainer container, string name) + { + _component = component; + _nestedContainer = container; + _componentName = name; + } + + public IComponent Component { + get { return _component; } + } + + public IContainer Container { + get { return _nestedContainer; } + } + + public bool DesignMode { + get { + if (_nestedContainer.Owner != null + && _nestedContainer.Owner.Site != null) { + + return _nestedContainer.Owner.Site.DesignMode; + } + else { + return false; + } + } + } + + public string Name { + get { return _componentName; } + set { _componentName = value; } + } + + // [owner].[component] + // + public string FullName { + get { + if (_componentName == null) { + return null; + } + if (_nestedContainer.OwnerName == null) { + return _componentName; + } + + return _nestedContainer.OwnerName + "." + _componentName; + } + } + + public virtual object GetService (Type service) + { + if (service == typeof (ISite)) { + return this; + } + + return _nestedContainer.GetService (service); + } + } // Site + +#endregion + + + + private IComponent _owner; + + public NestedContainer (IComponent owner) { if (owner == null) - throw new ArgumentNullException ("component"); - this.owner = owner; + throw new ArgumentNullException ("owner"); + + _owner = owner; + _owner.Disposed += new EventHandler (OnOwnerDisposed); } - - [MonoTODO] + public IComponent Owner { - get { return owner; } + get { return _owner; } } - [MonoTODO] protected virtual string OwnerName { - get { throw new NotImplementedException (); } - } + get { + if (_owner.Site is INestedSite) + return ((INestedSite) _owner.Site).FullName; + if (_owner == null || _owner.Site == null) + return null; + + return _owner.Site.Name; + } + } - [MonoTODO] protected override ISite CreateSite (IComponent component, string name) { - throw new NotImplementedException (); + if (component == null) + throw new ArgumentNullException("component"); + + return new NestedContainer.Site (component, this, name); } + + protected override object GetService (Type service) + { + if (service == typeof (INestedContainer)) + return this; + + return base.GetService (service); + } - [MonoTODO] protected override void Dispose (bool disposing) { - throw new NotImplementedException (); + if (disposing) + _owner.Disposed -= new EventHandler (OnOwnerDisposed); + + base.Dispose (disposing); } - [MonoTODO] - protected override object GetService (Type serviceType) + private void OnOwnerDisposed (object sender, EventArgs e) { - throw new NotImplementedException (); + this.Dispose (); } } + } #endif Index: mcs/class/System/System_test.dll.sources =================================================================== --- mcs/class/System/System_test.dll.sources (revision 78989) +++ mcs/class/System/System_test.dll.sources (working copy) @@ -126,6 +126,7 @@ System.ComponentModel/LicenseManagerTests.cs System.ComponentModel/LookupBindingPropertiesAttributeTest.cs System.ComponentModel/MaskedTextProviderTest.cs +System.ComponentModel/NestedContainerTest.cs System.ComponentModel/PropertyDescriptorCollectionTests.cs System.ComponentModel/PropertyDescriptorTests.cs System.ComponentModel/SByteConverterTests.cs