Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <lluis@xamarin.com>2013-10-11 11:22:02 +0400
committerLluis Sanchez <lluis@xamarin.com>2013-10-11 11:22:46 +0400
commit466853ea9d86459e7a72799b2d3b1ca49f0d40ff (patch)
treeb341467bea8e4a8eb13381acdb0dc022459a0ad7 /Testing
parentb573bcf842788e5ab030ab7783d80e2efe9878d4 (diff)
Added support for internal children
Internal children of a container are not included in the children list and the parent hierarchy chain. Internal children are useful for implementing containers that depend on other containers to lay out widgets.
Diffstat (limited to 'Testing')
-rw-r--r--Testing/GtkTestRunner.csproj1
-rw-r--r--Testing/Tests/InternalChildrenTests.cs211
2 files changed, 212 insertions, 0 deletions
diff --git a/Testing/GtkTestRunner.csproj b/Testing/GtkTestRunner.csproj
index 62ff5717..8e060068 100644
--- a/Testing/GtkTestRunner.csproj
+++ b/Testing/GtkTestRunner.csproj
@@ -106,6 +106,7 @@
<Compile Include="Tests\WidgetTests.cs" />
<Compile Include="Tests\WindowTests.cs" />
<Compile Include="Tests\XwtTest.cs" />
+ <Compile Include="Tests\InternalChildrenTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
diff --git a/Testing/Tests/InternalChildrenTests.cs b/Testing/Tests/InternalChildrenTests.cs
new file mode 100644
index 00000000..9a6a7a73
--- /dev/null
+++ b/Testing/Tests/InternalChildrenTests.cs
@@ -0,0 +1,211 @@
+//
+// InternalChildrenTests.cs
+//
+// Author:
+// Lluis Sanchez <lluis@xamarin.com>
+//
+// Copyright (c) 2013 Xamarin Inc.
+//
+// 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.Linq;
+using NUnit.Framework;
+
+namespace Xwt
+{
+ public class InternalChildrenTests
+ {
+ [Test]
+ public void ChildrenExcludesInternal ()
+ {
+ MyContainer co = new MyContainer ();
+ var c1 = new Label ("hi1");
+ var c2 = new Label ("hi2");
+ Assert.AreEqual (0, co.Surface.Children.Count ());
+ co.Add (c1);
+ Assert.AreEqual (1, co.Surface.Children.Count ());
+ co.AddInner (c2);
+ Assert.AreEqual (2, co.Surface.Children.Count ());
+ Assert.IsTrue (co.Surface.Children.Contains (c1));
+ Assert.IsTrue (co.Surface.Children.Contains (c2));
+ }
+
+ [Test]
+ public void ParentIsSet ()
+ {
+ MyContainer co = new MyContainer ();
+ var c1 = new Label ("hi1");
+ var c2 = new Label ("hi2");
+ co.Add (c1);
+ co.AddInner (c2);
+ Assert.AreSame (co, c1.Parent);
+ Assert.AreSame (co, c2.Parent);
+ }
+
+ [Test]
+ [ExpectedException (typeof(InvalidOperationException))]
+ public void InvalidAdd1 ()
+ {
+ MyContainer co = new MyContainer ();
+ var c1 = new Label ("hi1");
+ co.InternalAdd (c1);
+ }
+
+ [Test]
+ [ExpectedException (typeof(InvalidOperationException))]
+ public void InvalidAdd2 ()
+ {
+ MyContainer co = new MyContainer ();
+ var c1 = new Label ("hi1");
+ HBox b = new HBox ();
+ b.PackStart (c1);
+ co.InternalAdd (c1);
+ }
+
+ [Test]
+ [ExpectedException (typeof(InvalidOperationException))]
+ public void InvalidAdd3 ()
+ {
+ MyContainer co = new MyContainer ();
+ var c1 = new Label ("hi1");
+ HBox b = new HBox ();
+ b.PackStart (c1);
+ co.Add (c1);
+ }
+
+ [Test]
+ public void Remove ()
+ {
+ MyContainer co = new MyContainer ();
+ var c1 = new Label ("hi1");
+ var c2 = new Label ("hi2");
+ co.Add (c1);
+ co.AddInner (c2);
+ Assert.AreEqual (2, co.Surface.Children.Count ());
+ co.RemoveInner (c2);
+ Assert.AreEqual (1, co.Surface.Children.Count ());
+ Assert.IsNull (c2.Parent);
+ co.Remove (c1);
+ Assert.AreEqual (0, co.Surface.Children.Count ());
+ Assert.IsNull (c1.Parent);
+ }
+
+ [Test]
+ [ExpectedException (typeof(InvalidOperationException))]
+ public void InvalidRemove ()
+ {
+ MyContainer co = new MyContainer ();
+ var c1 = new Label ("hi1");
+ co.Add (c1);
+ co.WrongRemove (c1);
+ }
+
+ [Test]
+ public void InternalRemoveAdd ()
+ {
+ // The a child can be removed from internal containers and still
+ // be a child of the container
+
+ MyContainer co = new MyContainer ();
+ Assert.AreEqual (0, co.Surface.Children.Count ());
+
+ var c1 = new Label ("hi1");
+ co.Add (c1);
+ Assert.AreEqual (1, co.Surface.Children.Count ());
+
+ co.InternalRemove (c1);
+ Assert.AreEqual (1, co.Surface.Children.Count ());
+ Assert.AreSame (co, c1.Parent);
+
+ co.InternalAdd (c1);
+ Assert.AreEqual (1, co.Surface.Children.Count ());
+ Assert.AreSame (co, c1.Parent);
+ }
+
+ [Test]
+ [ExpectedException (typeof(InvalidOperationException))]
+ public void CantSetIternalBeforeAdding ()
+ {
+ new MyContainerWrong1 ();
+ }
+ }
+
+ class MyContainer: Widget
+ {
+ internal HBox box = new HBox ();
+ internal VBox inner = new VBox ();
+
+ public MyContainer ()
+ {
+ Content = SetInternalChild (box);
+ box.PackStart (SetInternalChild (inner));
+ }
+
+ public void Add (Widget w)
+ {
+ RegisterChild (w);
+ box.PackStart (w);
+ }
+
+ public void AddInner (Widget w)
+ {
+ RegisterChild (w);
+ inner.PackStart (w);
+ }
+
+ public void Remove (Widget w)
+ {
+ box.Remove (w);
+ UnregisterChild (w);
+ }
+
+ public void RemoveInner (Widget w)
+ {
+ inner.Remove (w);
+ UnregisterChild (w);
+ }
+
+ public void WrongRemove (Widget w)
+ {
+ UnregisterChild (w);
+ box.Remove (w);
+ }
+
+ public void InternalRemove (Widget w)
+ {
+ box.Remove (w);
+ }
+
+ public void InternalAdd (Widget w)
+ {
+ box.PackStart (w);
+ }
+ }
+
+ class MyContainerWrong1: Widget
+ {
+ public MyContainerWrong1 ()
+ {
+ HBox box = new HBox ();
+ Content = box;
+ SetInternalChild (box);
+ }
+ }
+}
+