public void AddTest() { var eTarget = new DockBayLayoutEngine(new DockBayBase()); //AddTest //DockPaneNeighs var tmp = new[] { new {LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Top}, new {LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Left}, new {LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Top}, new {LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Right} } .ToArray(); //TestDatas var testDtIdx = 0; var testDt = new[] { new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = tmp[1].LayoutEngine }, new { Top = (DockPaneLayoutEngine)null, Bottom = tmp[2].LayoutEngine, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = tmp[3].LayoutEngine, Right = (DockPaneLayoutEngine)null }, }; //MargeCollection var children = tmp .Select(n => new { Align = n.Align, LayoutEngine = n.LayoutEngine, TestData = testDt[testDtIdx++], }); foreach (var item in children) { eTarget.Add(item.LayoutEngine, item.Align); Assert.AreEqual(eTarget, item.LayoutEngine.Parent); Assert.AreEqual(item.TestData.Top, item.LayoutEngine.Top); Assert.AreEqual(item.TestData.Bottom, item.LayoutEngine.Bottom); Assert.AreEqual(item.TestData.Left, item.LayoutEngine.Left); Assert.AreEqual(item.TestData.Right, item.LayoutEngine.Right); } //InsertTest var lyout = new DockPaneLayoutEngine(new DockPaneBase()); eTarget.Add(lyout, DockDirection.Left, 1); Assert.AreEqual(tmp[2].LayoutEngine, lyout.Top); Assert.AreEqual(tmp[1].LayoutEngine, lyout.Left); Assert.AreEqual(lyout, lyout.Right); Assert.AreEqual(null, lyout.Bottom); Assert.AreEqual(tmp[0].LayoutEngine.Left, lyout); Assert.AreEqual(eTarget, lyout.Parent); }
public void AddTest() { var target = new DockBayLayoutEngine(new DockBayBase()); var flg_PaneAdded = false; target.PaneAdded += (sender, e) => flg_PaneAdded = true; var testDt = new[] { new { Neigh = new DockPaneLayoutEngine(new DockPaneBase()), Index = 0, Count = 1, Align = DockDirection.Left }, new { Neigh = new DockPaneLayoutEngine(new DockPaneBase()), Index = 1, Count = 2, Align = DockDirection.Top }, new { Neigh = new DockPaneLayoutEngine(new DockPaneBase()), Index = 1, Count = 3, Align = DockDirection.Top }, }; foreach (var item in testDt) { target.Add(item.Neigh, item.Align, item.Index); Assert.AreEqual(item.Align, item.Neigh.Align); Assert.AreEqual(target, item.Neigh.Parent); Assert.AreEqual(target, item.Neigh.Owner); Assert.AreEqual(item.Index, target.Children.IndexOf(item.Neigh)); Assert.AreEqual(item.Count, target.Children.Count); } Assert.IsTrue(flg_PaneAdded, "子要素追加時にPaneAddedイベントが発動されていません。"); //不正引数用 var exCnter = 0; try { target.Add((DockPaneLayoutEngine)null, DockDirection.Top, 0); } catch (ArgumentNullException) { exCnter++; } catch { } try { target.Add(testDt[0].Neigh, DockDirection.Left, 0); } catch (ArgumentException) { exCnter++; } catch { } try { target.Add(new DockPaneLayoutEngine(new DockPaneBase()), DockDirection.None, 0); } catch (ArgumentException) { exCnter++; } catch { } try { target.Add(new DockPaneLayoutEngine(new DockPaneBase()), DockDirection.Bottom, -1); } catch (ArgumentException) { exCnter++; } catch { } Assert.AreEqual(4, exCnter, "無効な引数に対して適切な対処が取れていません。"); }
public void AddTest() { var target = new DockPaneLayoutEngine(new DockPaneBase()); //AddTest //DockPaneNeighs var tmp = new[] { new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Left, Index = 0, Count = 1 }, new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Top, Index = 1, Count = 2 }, new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Right, Index = 2, Count = 3 }, new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Bottom, Index = 3, Count = 4 }, new { LayoutEngine = new DockPaneLayoutEngine(new DockPaneBase()), Align = DockDirection.Right, Index = 3, Count = 5 }, } .ToArray(); //TestDatas var testDtIdx = 0; var testDt = new[] { new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = tmp[0].LayoutEngine }, new { Top = (DockPaneLayoutEngine)null, Bottom = tmp[1].LayoutEngine, Left = tmp[0].LayoutEngine, Right = (DockPaneLayoutEngine)null }, new { Top = tmp[1].LayoutEngine, Bottom = (DockPaneLayoutEngine)null, Left = tmp[2].LayoutEngine, Right = (DockPaneLayoutEngine)null }, new { Top = tmp[3].LayoutEngine, Bottom = (DockPaneLayoutEngine)null, Left = tmp[0].LayoutEngine, Right = tmp[2].LayoutEngine }, new { Top = tmp[1].LayoutEngine, Bottom = (DockPaneLayoutEngine)null, Left = tmp[4].LayoutEngine, Right = tmp[2].LayoutEngine }, }; //MargeCollection var children = tmp .Select(n => new { Align = n.Align, LayoutEngine = n.LayoutEngine, TestData = testDt[testDtIdx++], Index = n.Index, Count = n.Count, }) .ToArray(); foreach (var item in children) { target.Add(item.LayoutEngine, item.Align, item.Index); Assert.AreEqual(target, item.LayoutEngine.Parent); Assert.AreEqual(item.Align, item.LayoutEngine.Align); Assert.AreEqual(target, item.LayoutEngine.Parent); Assert.IsNull(item.LayoutEngine.Owner); Assert.AreEqual(item.Index, target.Children.IndexOf(item.LayoutEngine)); Assert.AreEqual(item.Count, target.Children.Count); Assert.AreEqual(item.TestData.Top, item.LayoutEngine.Top); Assert.AreEqual(item.TestData.Bottom, item.LayoutEngine.Bottom); Assert.AreEqual(item.TestData.Left, item.LayoutEngine.Left); Assert.AreEqual(item.TestData.Right, item.LayoutEngine.Right); switch (item.Align) { case DockDirection.Top: Assert.AreEqual(0, target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1) .Select(n => n.Top) .Where(n => n != item.LayoutEngine) .Count()); break; case DockDirection.Bottom: Assert.AreEqual(0, target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1) .Select(n => n.Bottom) .Where(n => n != item.LayoutEngine) .Count()); break; case DockDirection.Left: Assert.AreEqual(0, target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1) .Select(n => n.Left) .Where(n => n != item.LayoutEngine) .Count()); break; case DockDirection.Right: Assert.AreEqual(0, target.GetChildrenOf(item.Align, target.Children.IndexOf(item.LayoutEngine) + 1) .Select(n => n.Right) .Where(n => n != item.LayoutEngine) .Count()); break; } } //InsertTest var lyout = new DockPaneLayoutEngine(new DockPaneBase()); target.Add(lyout, DockDirection.Left, 3); Assert.AreEqual(tmp[1].LayoutEngine, lyout.Top); Assert.AreEqual(tmp[0].LayoutEngine, lyout.Left); Assert.AreEqual(lyout, lyout.Right); Assert.AreEqual(null, lyout.Bottom); Assert.AreEqual(target.Left, lyout); Assert.AreEqual(tmp[3].LayoutEngine.Left, lyout); Assert.AreEqual(target, lyout.Parent); var bay = new DockBayLayoutEngine(new DockBayBase()); bay.Add(target, DockDirection.Top); foreach (var item in children) Assert.AreEqual(bay, item.LayoutEngine.Owner); //不正引数用 var exCnter = 0; try { target.Add((DockPaneLayoutEngine)null, DockDirection.Top, 0); } catch (ArgumentNullException) { exCnter++; } catch { } try { target.Add(children[0].LayoutEngine, DockDirection.Bottom, 0); } catch (ArgumentException) { exCnter++; } catch { } try { target.Add(new DockPaneLayoutEngine(new DockPaneBase()), DockDirection.None, 0); } catch (ArgumentException) { exCnter++; } catch { } try { target.Add(new DockPaneLayoutEngine(new DockPaneBase()), DockDirection.Left, -1); } catch (ArgumentException) { exCnter++; } catch { } Assert.AreEqual(4, exCnter, "無効な引数に対して適切な対処が取れていません。"); }
public void RemoveTest() { //テスト事項 //Bay: 子要素の最初の時 //Pane: 子要素がある場合の処理, 独身の場合 var bay = new DockBayLayoutEngine(new DockBayBase()); var lv1A = new DockPaneLayoutEngine(new DockPaneBase()); var lv1B = new DockPaneLayoutEngine(new DockPaneBase()); var lv2A = new DockPaneLayoutEngine(new DockPaneBase()); var flg_removed = false; bay.PaneRemoved += (sender, e) => flg_removed = true; //lv0A //-lv1A(Top) //-lv1B(Left) // -lv2A(Bottom) bay.Add(lv1A, DockDirection.Top); bay.Add(lv1B, DockDirection.Left); lv1B.Add(lv2A, DockDirection.Bottom); var lv1ASeq = new[] { new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = lv2A, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Top, Parent = (DockNodeLayoutEngine)bay }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = lv2A, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Top, Parent = (DockNodeLayoutEngine)bay }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = lv2A, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Top, Parent = (DockNodeLayoutEngine)bay }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null }, }; var lv1BSeq = new[] { new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null }, new { Top = lv1B, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Bottom, Parent = (DockNodeLayoutEngine)lv2A }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.None, Parent = (DockNodeLayoutEngine)null }, }; var lv2ASeq = new[] { new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay }, new { Top = (DockPaneLayoutEngine)null, Bottom = lv1B, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = lv2A, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay }, new { Top = (DockPaneLayoutEngine)null, Bottom = (DockPaneLayoutEngine)null, Left = (DockPaneLayoutEngine)null, Right = (DockPaneLayoutEngine)null, Align = DockDirection.Left, Parent = (DockNodeLayoutEngine)bay }, }; var testFunc = (Action<int>)(idx => { Assert.AreEqual(lv1ASeq[idx].Align, lv1A.Align); Assert.AreEqual(lv1ASeq[idx].Parent, lv1A.Parent); Assert.AreEqual(lv1ASeq[idx].Top, lv1A.Top); Assert.AreEqual(lv1ASeq[idx].Bottom, lv1A.Bottom); Assert.AreEqual(lv1ASeq[idx].Left, lv1A.Left); Assert.AreEqual(lv1ASeq[idx].Right, lv1A.Right); Assert.AreEqual(lv1BSeq[idx].Align, lv1B.Align); Assert.AreEqual(lv1BSeq[idx].Parent, lv1B.Parent); Assert.AreEqual(lv1BSeq[idx].Top, lv1B.Top); Assert.AreEqual(lv1BSeq[idx].Bottom, lv1B.Bottom); Assert.AreEqual(lv1BSeq[idx].Left, lv1B.Left); Assert.AreEqual(lv1BSeq[idx].Right, lv1B.Right); Assert.AreEqual(lv2ASeq[idx].Align, lv2A.Align); Assert.AreEqual(lv2ASeq[idx].Parent, lv2A.Parent); Assert.AreEqual(lv2ASeq[idx].Top, lv2A.Top); Assert.AreEqual(lv2ASeq[idx].Bottom, lv2A.Bottom); Assert.AreEqual(lv2ASeq[idx].Left, lv2A.Left); Assert.AreEqual(lv2ASeq[idx].Right, lv2A.Right); }); //lv0A //-lv1A(Top) //-lv2A(Bottom->Left) bay.Remove(lv1B); testFunc(0); //lv0A //-lv1A(Top) //-lv2A(Bottom->Left) // -lv1B(Left->Bottom) lv2A.Add(lv1B, DockDirection.Bottom); testFunc(1); //lv0A //-lv1A(Top) //-lv2A(Bottom->Left) lv2A.Remove(lv1B); testFunc(2); //lv0A //-lv2A(Bottom->Left) bay.Remove(lv1A); testFunc(3); Assert.IsTrue(flg_removed, "Removed eventが発生してません。"); }