2008-02-19 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Tue, 19 Feb 2008 17:06:32 +0000 (17:06 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Tue, 19 Feb 2008 17:06:32 +0000 (17:06 -0000)
* SelectionRange.cs: Apply patch from Andy Hume to make
constructor behavior more accurate.  [Fixes bug #362117]

2008-02-19  Jonathan Pobst  <monkey@jpobst.com>

* SelectionRangeTest.cs: Add tests from Andy Hume.

2008-02-19  Jonathan Pobst  <monkey@jpobst.com>

* System.Windows.Forms_test.dll.sources: Added SelectionRangeTest.cs.

svn path=/trunk/mcs/; revision=96166

mcs/class/Managed.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/SelectionRange.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms_test.dll.sources
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/SelectionRangeTest.cs [new file with mode: 0644]

index 549b48fb0181b14a54f735255e956b19d6d6bf2c..3fadc89acd9acdb54e70b87cb581a96bd1f30837 100644 (file)
@@ -1,3 +1,7 @@
+2008-02-19  Jonathan Pobst  <monkey@jpobst.com>
+
+       * System.Windows.Forms_test.dll.sources: Added SelectionRangeTest.cs.
+
 2008-02-06  Andreia Gaita <avidigal@novell.com>
 
        * build-csproj2k5: fixed mono.mozilla project guid
index 2d4effdbefcbb920c2b12431ba535cae234ddb33..5f0716d93dfe67e3098131be7f15d0f4514f04e7 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-19  Jonathan Pobst  <monkey@jpobst.com>
+
+       * SelectionRange.cs: Apply patch from Andy Hume to make
+       constructor behavior more accurate.  [Fixes bug #362117]
+
 2008-02-19  Andreia Gaita <avidigal@novell.com> 
 
        * Control.cs: Added a new flag is_disposing to track if the
index 92c152f20debb8ead1720ad74e173348026cd34c..bf3d6a0926bd7ca6100499c4ec8cce418e891233 100644 (file)
@@ -40,6 +40,8 @@ namespace System.Windows.Forms {
 
                // default parameterless construcor, use default values
                public SelectionRange () {
+                       end = DateTime.MaxValue.Date;
+                       start = DateTime.MinValue.Date;
                }       
        
                // constructor that receives another range, copies it's Start and End values
@@ -51,11 +53,11 @@ namespace System.Windows.Forms {
                // constructor that receives two dates, uses the lower of the two as start
                public SelectionRange (DateTime lower, DateTime upper) {
                        if (lower <= upper) {
-                               end = upper;
-                               start = lower;
+                               end = upper.Date;
+                               start = lower.Date;
                        } else {
-                               end = lower;
-                               start = upper;
+                               end = lower.Date;
+                               start = upper.Date;
                        }
                }
 
index 926c622f46cff6772d73b9b716ce7aea03ef02e5..7c0108a3b283191d3b2afd7e0c8a4bb3afcff8bd 100644 (file)
@@ -121,6 +121,7 @@ System.Windows.Forms/RichTextBoxTest.cs
 System.Windows.Forms/SaveFileDialogTest.cs
 System.Windows.Forms/ScrollableControlTest.cs
 System.Windows.Forms/ScrollBarTest.cs
+System.Windows.Forms/SelectionRangeTest.cs
 System.Windows.Forms/SendKeysTest.cs
 System.Windows.Forms/SplitterTest.cs
 System.Windows.Forms/SplitContainerTests.cs
index b3203b4aa3944973400899599f37e48a4fc43977..8468e2eec522f2c7c686d0db9047105bbafd3745 100644 (file)
@@ -1,3 +1,7 @@
+2008-02-19  Jonathan Pobst  <monkey@jpobst.com>
+
+       * SelectionRangeTest.cs: Add tests from Andy Hume.
+
 2008-02-19  Jonathan Pobst  <monkey@jpobst.com> 
 
        * ComboBoxTest.cs: Use PreferredHeight in MethodScaleControl.
diff --git a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/SelectionRangeTest.cs b/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/SelectionRangeTest.cs
new file mode 100644 (file)
index 0000000..800e26b
--- /dev/null
@@ -0,0 +1,137 @@
+//
+// SelectionRangeTest.cs
+//
+// 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.
+//
+// Copyright (c) 2008 Andy Hume
+//
+// Authors:
+//     Andy Hume  <andyhume32@yahoo.co.uk>
+
+using System;
+using System.Windows.Forms;
+using NUnit.Framework;
+
+namespace MonoTests.System.Windows.Forms
+{
+       [TestFixture]
+       public class SelectionRangeTest
+       {
+
+               [Test]
+               public void DefaultConstructor ()
+               {
+                       SelectionRange sr = new SelectionRange ();
+                       Assert.AreEqual (DateTime.MinValue, sr.Start, "Start");
+                       // "9999-12-31 00:00:00", note not 23:59:59.
+                       Assert.AreEqual (DateTime.MaxValue.Date, sr.End, "End");
+
+                       Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
+                       Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
+               }
+
+               [Test]
+               public void DefaultConstructor_ToString ()
+               {
+                       SelectionRange sr = new SelectionRange ();
+                       // "9999-12-31 00:00:00", note not 23:59:59.
+                       Assert.AreEqual (string.Format ("SelectionRange: Start: {0}, End: {1}", new DateTime (1, 1, 1).ToString (), new DateTime (9999, 12, 31).ToString ()),
+                          sr.ToString (), "ToString");
+               }
+
+               [Test]
+               public void TwoDatesConstructor ()
+               {
+                       SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17));
+                       Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
+                       Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
+               }
+
+               [Test]
+               public void TwoDatesConstructor_Backwards () // start > end
+               {
+                       SelectionRange sr = new SelectionRange (new DateTime (2008, 2, 17), new DateTime (2001, 1, 11));
+                       Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
+                       Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
+               }
+
+               [Test]
+               public void TwoDatesConstructor_WithTime ()
+               {
+                       // Apparenly any time value is stripped, found while testing PropertyGrid.
+                       SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15), new DateTime (2008, 2, 17));
+                       Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
+                       Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
+               }
+
+               [Test]
+               public void TwoDatesConstructor_WithTime2 ()
+               {
+                       // Apparenly any time value is stripped, found while testing PropertyGrid.
+                       SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3));
+                       Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
+                       Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
+
+                       Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
+                       Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
+               }
+
+#if NET_2_0
+               [Test]
+               public void TwoDatesConstructor_WithTimeWithKindLocal ()
+               {
+                       // Apparenly any time value is stripped, found while testing PropertyGrid.
+                       SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15, DateTimeKind.Local), new DateTime (2008, 2, 17));
+                       Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
+                       Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
+                       //
+                       Assert.AreEqual (DateTimeKind.Local, sr.Start.Kind, "Start Kind");
+                       Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
+               }
+
+               [Test]
+               public void TwoDatesConstructor_WithTime2WithKindUtc ()
+               {
+                       // Apparenly any time value is stripped, found while testing PropertyGrid.
+                       SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Utc));
+                       Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
+                       Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
+                       //
+                       Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
+                       Assert.AreEqual (DateTimeKind.Utc, sr.End.Kind, "End Kind");
+               }
+
+               [Test]
+               public void TwoDatesConstructor_WithTwoTimeWithTwoKinds ()
+               {
+                       // Apparenly any time value is stripped, found while testing PropertyGrid.
+                       SelectionRange sr = new SelectionRange (
+                           new DateTime (2001, 1, 11, 1, 2, 3, DateTimeKind.Utc),
+                           new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Local));
+                       Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
+                       Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
+                       //
+                       Assert.AreEqual (DateTimeKind.Utc, sr.Start.Kind, "Start Kind");
+                       Assert.AreEqual (DateTimeKind.Local, sr.End.Kind, "End Kind");
+               }
+#endif
+
+       }
+}
\ No newline at end of file