From 5a9e3af896d97de31036cac1af5fb416c838a5e4 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Wed, 12 Mar 2014 16:34:00 +0100 Subject: [PATCH] [MWF] Add unit tests for DataGridViewRowHeightInfoNeededEventArgs --- .../System.Windows.Forms_test.dll.sources | 1 + ...idViewRowHeightInfoNeededEventArgsTests.cs | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources b/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources index a18ec387a89..e14341db1a9 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources @@ -63,6 +63,7 @@ System.Windows.Forms/DataGridViewLinkCellTest.cs System.Windows.Forms/DataGridViewImageCellTest.cs System.Windows.Forms/DataGridViewRowCollectionTest.cs System.Windows.Forms/DataGridViewRowHeaderTest.cs +System.Windows.Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs System.Windows.Forms/DataGridViewRowTest.cs System.Windows.Forms/DataGridViewTest.cs System.Windows.Forms/DataGridViewTextBoxCellTest.cs diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs new file mode 100644 index 00000000000..64c28665353 --- /dev/null +++ b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowHeightInfoNeededEventArgsTests.cs @@ -0,0 +1,101 @@ +// Copyright (c) 2014 SIL International +// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) +using System; +using System.Windows.Forms; +using NUnit.Framework; +using CategoryAttribute = NUnit.Framework.CategoryAttribute; + +namespace MonoTests.System.Windows.Forms +{ + [TestFixture] + public class DataGridViewRowHeightInfoNeededEventArgsTests + { + struct RowInfo + { + public RowInfo (DataGridViewRowHeightInfoNeededEventArgs e) + { + Height = e.Height; + MinimumHeight = e.MinimumHeight; + } + + public int Height; + public int MinimumHeight; + } + + class DummyDataGridView : DataGridView + { + public RowInfo RowInfo; + + protected override void OnRowHeightInfoNeeded (DataGridViewRowHeightInfoNeededEventArgs e) + { + base.OnRowHeightInfoNeeded (e); + RowInfo = new RowInfo (e); + } + } + + [Test] + [Category("NotWorking")] + public void HeightCantBeLessThanCurrentMinimumHeight () + { + using (var dgv = new DummyDataGridView ()) { + // Setup + dgv.VirtualMode = true; + dgv.RowCount = 1; + dgv.Rows [0].MinimumHeight = 5; + dgv.Rows [0].Height = 10; + dgv.RowHeightInfoNeeded += (sender, e) => { + e.Height = 2; + e.MinimumHeight = 2; + }; + dgv.UpdateRowHeightInfo (0, false); + + // Execute - this triggers the RowHeightInfoNeeded event + // This test doesn't work because of different implementation details in .NET + // and Mono: on .NET RowHeightInfoNeeded gets called for the first time when + // executing the following line. In Mono RowHeightInfoNeeded got already called + // while executing dgv.UpdateRowHeightInfo. This means that when RowHeightInfoNeeded + // gets called now MinimumHeight is already set to 2, allowing Height to become + // 2 as well. + // On .NET since it is the first time Height will be set to 5 (the current + // MinimumHeight value). + // The .NET behaviour is surprising since the order of setting the information + // in RowHeightInfoNeeded shouldn't matter, therefore I don't think it's worth + // changing the behaviour in Mono. Even more so since there is an easy + // workaround: simply swapping the two lines in the RowHeighInfoNeeded event + // handler works around the problem. + var dummy = dgv.Rows [0].Height; + + // Verify + var rowHeightInfo = dgv.RowInfo; + Assert.AreEqual (5, rowHeightInfo.Height, "#A1"); // 5 because of buggy .NET behaviour + Assert.AreEqual (2, rowHeightInfo.MinimumHeight, "#A2"); + } + } + + [Test] + public void SettingHeightAfterChangingMinimumHeight () + { + using (var dgv = new DummyDataGridView ()) { + // Setup + dgv.VirtualMode = true; + dgv.RowCount = 1; + dgv.Rows [0].MinimumHeight = 5; + dgv.Rows [0].Height = 10; + dgv.RowHeightInfoNeeded += (sender, e) => { + e.MinimumHeight = 2; + e.Height = 2; + }; + dgv.UpdateRowHeightInfo (0, false); + + // Execute - this triggers the RowHeightInfoNeeded event + var dummy = dgv.Rows [0].Height; + + // Verify + var rowHeightInfo = dgv.RowInfo; + Assert.AreEqual (2, rowHeightInfo.Height, "#B1"); + Assert.AreEqual (2, rowHeightInfo.MinimumHeight, "#B2"); + } + } + } +} + -- 2.25.1