Merge pull request #82 from Unity-Technologies/master-gc-race
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / SelectionRangeTest.cs
1 //
2 // SelectionRangeTest.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2008 Andy Hume
24 //
25 // Authors:
26 //      Andy Hume  <andyhume32@yahoo.co.uk>
27
28 using System;
29 using System.Windows.Forms;
30 using NUnit.Framework;
31
32 namespace MonoTests.System.Windows.Forms
33 {
34         [TestFixture]
35         public class SelectionRangeTest : TestHelper
36         {
37
38                 [Test]
39                 public void DefaultConstructor ()
40                 {
41                         SelectionRange sr = new SelectionRange ();
42                         Assert.AreEqual (DateTime.MinValue, sr.Start, "Start");
43                         // "9999-12-31 00:00:00", note not 23:59:59.
44                         Assert.AreEqual (DateTime.MaxValue.Date, sr.End, "End");
45
46 #if NET_2_0
47                         Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
48                         Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
49 #endif
50                 }
51
52                 [Test]
53                 public void DefaultConstructor_ToString ()
54                 {
55                         SelectionRange sr = new SelectionRange ();
56                         // "9999-12-31 00:00:00", note not 23:59:59.
57                         Assert.AreEqual (string.Format ("SelectionRange: Start: {0}, End: {1}", new DateTime (1, 1, 1).ToString (), new DateTime (9999, 12, 31).ToString ()),
58                            sr.ToString (), "ToString");
59                 }
60
61                 [Test]
62                 public void TwoDatesConstructor ()
63                 {
64                         SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17));
65                         Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
66                         Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
67                 }
68
69                 [Test]
70                 public void TwoDatesConstructor_Backwards () // start > end
71                 {
72                         SelectionRange sr = new SelectionRange (new DateTime (2008, 2, 17), new DateTime (2001, 1, 11));
73                         Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
74                         Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
75                 }
76
77                 [Test]
78                 public void TwoDatesConstructor_WithTime ()
79                 {
80                         // Apparenly any time value is stripped, found while testing PropertyGrid.
81                         SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15), new DateTime (2008, 2, 17));
82                         Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
83                         Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
84                 }
85
86                 [Test]
87                 public void TwoDatesConstructor_WithTime2 ()
88                 {
89                         // Apparenly any time value is stripped, found while testing PropertyGrid.
90                         SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3));
91                         Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
92                         Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
93 #if NET_2_0
94                         Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
95                         Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
96 #endif
97                 }
98
99 #if NET_2_0
100                 [Test]
101                 public void TwoDatesConstructor_WithTimeWithKindLocal ()
102                 {
103                         // Apparenly any time value is stripped, found while testing PropertyGrid.
104                         SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15, DateTimeKind.Local), new DateTime (2008, 2, 17));
105                         Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
106                         Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
107                         //
108                         Assert.AreEqual (DateTimeKind.Local, sr.Start.Kind, "Start Kind");
109                         Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
110                 }
111
112                 [Test]
113                 public void TwoDatesConstructor_WithTime2WithKindUtc ()
114                 {
115                         // Apparenly any time value is stripped, found while testing PropertyGrid.
116                         SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Utc));
117                         Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
118                         Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
119                         //
120                         Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
121                         Assert.AreEqual (DateTimeKind.Utc, sr.End.Kind, "End Kind");
122                 }
123
124                 [Test]
125                 public void TwoDatesConstructor_WithTwoTimeWithTwoKinds ()
126                 {
127                         // Apparenly any time value is stripped, found while testing PropertyGrid.
128                         SelectionRange sr = new SelectionRange (
129                             new DateTime (2001, 1, 11, 1, 2, 3, DateTimeKind.Utc),
130                             new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Local));
131                         Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
132                         Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
133                         //
134                         Assert.AreEqual (DateTimeKind.Utc, sr.Start.Kind, "Start Kind");
135                         Assert.AreEqual (DateTimeKind.Local, sr.End.Kind, "End Kind");
136                 }
137 #endif
138
139         }
140 }