File: LinkLabelTest.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (394 lines) | stat: -rw-r--r-- 11,810 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
//
// LinkLabelTest.cs: MWF LinkLabel unit tests.
//
// Author:
//   Everaldo Canuto (ecanuto@novell.com)
//
// (C) 2007 Novell, Inc. (http://www.novell.com)
//

using System;
using NUnit.Framework;
using System.Windows.Forms;
using System.Drawing;

namespace MonoTests.System.Windows.Forms
{
	[TestFixture]
	public class LinkLabelTest : TestHelper
	{
		[Test]
		public void LinkLabelAccessibility ()
		{
			LinkLabel l = new LinkLabel ();
			Assert.IsNotNull (l.AccessibilityObject, "#1");
		}

		[Test]
		public void TestTabStop ()
		{
			LinkLabel l = new LinkLabel();

			Assert.IsFalse (l.TabStop, "#1");
			l.Text = "Hello";
			Assert.IsTrue (l.TabStop, "#2");
			l.Text = "";
			Assert.IsFalse (l.TabStop, "#3");
		}
		
		[Test]
		public void TestLinkArea ()
		{
			LinkLabel l = new LinkLabel();

			Assert.AreEqual (0, l.LinkArea.Start, "#1");
			Assert.AreEqual (0, l.LinkArea.Length, "#2");
			l.Text = "Hello";
			Assert.AreEqual (0, l.LinkArea.Start, "#3");
			Assert.AreEqual (5, l.LinkArea.Length, "#4");
			l.Text = "";
			Assert.AreEqual (0, l.LinkArea.Start, "#5");
			Assert.AreEqual (0, l.LinkArea.Length, "#6");
		}

		[Test] // bug #344012
		public void InvalidateManualLinks ()
		{
			Form form = new Form ();
			form.ShowInTaskbar = false;

			LinkLabel l = new LinkLabel ();
			l.Text = "linkLabel1";
			form.Controls.Add (l);

			LinkLabel.Link link = new LinkLabel.Link (2, 5);
			l.Links.Add (link);

			form.Show ();
			form.Dispose ();
		}
		
		[Test]	// bug 410709
		public void LinkAreaSetter ()
		{
			// Basically this test is to show that setting LinkArea erased
			// any previous links
			LinkLabel l = new LinkLabel ();
			
			l.Text = "Really long text";
			
			Assert.AreEqual (1, l.Links.Count, "A1");
			
			l.Links.Clear ();
			l.Links.Add (0, 3);
			l.Links.Add (5, 3);

			Assert.AreEqual (2, l.Links.Count, "A2");
		
			l.LinkArea = new LinkArea (1, 7);

			Assert.AreEqual (1, l.Links.Count, "A3");
			Assert.AreEqual (1, l.LinkArea.Start, "A4");
			Assert.AreEqual (7, l.LinkArea.Length, "A5");
		}
	}


	[TestFixture]
	public class LinkTest : TestHelper
	{
		[Test]
		public void Constructor ()
		{
			LinkLabel.Link l = new LinkLabel.Link ();
			
			Assert.AreEqual (null, l.Description, "A1");
			Assert.AreEqual (true, l.Enabled, "A2");
			Assert.AreEqual (0, l.Length, "A3");
			Assert.AreEqual (null, l.LinkData, "A4");
			Assert.AreEqual (string.Empty, l.Name, "A5");
			Assert.AreEqual (0, l.Start, "A6");
			Assert.AreEqual (null, l.Tag, "A7");
			Assert.AreEqual (false, l.Visited, "A8");

			l = new LinkLabel.Link (5, 20);

			Assert.AreEqual (null, l.Description, "A9");
			Assert.AreEqual (true, l.Enabled, "A10");
			Assert.AreEqual (20, l.Length, "A11");
			Assert.AreEqual (null, l.LinkData, "A12");
			Assert.AreEqual (string.Empty, l.Name, "A13");
			Assert.AreEqual (5, l.Start, "A14");
			Assert.AreEqual (null, l.Tag, "A15");
			Assert.AreEqual (false, l.Visited, "A16");

			l = new LinkLabel.Link (3, 7, "test");

			Assert.AreEqual (null, l.Description, "A17");
			Assert.AreEqual (true, l.Enabled, "A18");
			Assert.AreEqual (7, l.Length, "A19");
			Assert.AreEqual ("test", l.LinkData, "A20");
			Assert.AreEqual (string.Empty, l.Name, "A21");
			Assert.AreEqual (3, l.Start, "A22");
			Assert.AreEqual (null, l.Tag, "A23");
			Assert.AreEqual (false, l.Visited, "A24");
		}
	}

	[TestFixture]
	public class LinkCollectionTest : TestHelper
	{
		[Test] // ctor (LinkLabel)
		public void Constructor1 ()
		{
			LinkLabel l = new LinkLabel ();
			l.Text = "Managed Windows Forms";

			LinkLabel.LinkCollection links1 = new LinkLabel.LinkCollection (
				l);
			LinkLabel.LinkCollection links2 = new LinkLabel.LinkCollection (
				l);

			Assert.AreEqual (1, links1.Count, "#A1");
			Assert.IsFalse (links1.IsReadOnly, "#A2");
			Assert.IsFalse (links1.LinksAdded, "#A3");

			LinkLabel.Link link = links1 [0];
			Assert.IsNull (link.Description, "#B1");
			Assert.IsTrue (link.Enabled, "#B2");
			Assert.AreEqual (21, link.Length, "#B3");
			Assert.IsNull (link.LinkData, "#B4");
			Assert.IsNotNull (link.Name, "#B5");
			Assert.AreEqual (string.Empty, link.Name, "#B6");
			Assert.AreEqual (0, link.Start, "#B7");
			Assert.IsNull (link.Tag, "#B8");
			Assert.IsFalse (link.Visited, "#B9");

			Assert.AreEqual (1, links2.Count, "#C1");
			Assert.IsFalse (links2.IsReadOnly, "#C2");
			Assert.IsFalse (links2.LinksAdded, "#C3");
			Assert.AreSame (link, links2 [0], "#C4");
		}

		[Test] // ctor (LinkLabel)
		public void Constructor1_Owner_Null ()
		{
			try {
				new LinkLabel.LinkCollection ((LinkLabel) null);
				Assert.Fail ("#1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.IsNotNull (ex.ParamName, "#5");
				Assert.AreEqual ("owner", ex.ParamName, "#6");
			}
		}

		[Test] // Add (LinkLabel.Link)
		public void Add1 ()
		{
			LinkLabel l = new LinkLabel ();
			l.Text = "Managed Windows Forms";

			LinkLabel.LinkCollection links1 = new LinkLabel.LinkCollection (
				l);
			LinkLabel.LinkCollection links2 = new LinkLabel.LinkCollection (
				l);

			LinkLabel.Link linkA = new LinkLabel.Link (0, 7);
			Assert.AreEqual (0, links1.Add (linkA), "#A1");
			Assert.AreEqual (1, links1.Count, "#A2");
			Assert.AreEqual (1, links2.Count, "#A3");
			Assert.IsTrue (links1.LinksAdded, "#A4");
			Assert.IsFalse (links2.LinksAdded, "#A5");
			Assert.AreSame (linkA, links1 [0], "#A6");
			Assert.AreSame (linkA, links2 [0], "#A7");

			LinkLabel.Link linkB = new LinkLabel.Link (8, 7);
			Assert.AreEqual (1, links1.Add (linkB), "#B1");
			Assert.AreEqual (2, links1.Count, "#B2");
			Assert.AreEqual (2, links2.Count, "#B3");
			Assert.IsTrue (links1.LinksAdded, "#B4");
			Assert.IsFalse (links2.LinksAdded, "#B5");
			Assert.AreSame (linkA, links1 [0], "#B6");
			Assert.AreSame (linkA, links2 [0], "#B7");
			Assert.AreSame (linkB, links1 [1], "#B8");
			Assert.AreSame (linkB, links2 [1], "#B9");

			LinkLabel.LinkCollection links3 = new LinkLabel.LinkCollection (
				l);
			Assert.AreEqual (2, links3.Count, "#C1");
			Assert.IsFalse (links3.LinksAdded, "#C2");
			Assert.AreSame (linkA, links3 [0], "#C3");
			Assert.AreSame (linkB, links3 [1], "#C4");
		}

		[Test] // Add (LinkLabel.Link)
		public void Add1_Overlap ()
		{
			LinkLabel l = new LinkLabel ();
			l.Text = "Managed Windows Forms";

			LinkLabel.LinkCollection links = new LinkLabel.LinkCollection (
				l);

			LinkLabel.Link linkA = new LinkLabel.Link (0, 7);
			links.Add (linkA);
			Assert.AreEqual (1, links.Count, "#A1");
			Assert.IsTrue (links.LinksAdded, "#A2");
			Assert.AreSame (linkA, links [0], "#A3");

			LinkLabel.Link linkB = new LinkLabel.Link (5, 4);
			try {
				links.Add (linkB);
				Assert.Fail ("#B1");
			} catch (InvalidOperationException ex) {
				// Overlapping link regions
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
			}

			Assert.AreEqual (2, links.Count, "#B5");
			Assert.IsTrue (links.LinksAdded, "#B6");
			Assert.AreSame (linkA, links [0], "#B7");
			Assert.AreSame (linkB, links [1], "#B8");
			Assert.AreEqual (0, linkA.Start, "#B9");
			Assert.AreEqual (7, linkA.Length, "#B10");
			Assert.AreEqual (5, linkB.Start, "#B11");
			Assert.AreEqual (4, linkB.Length, "#B12");

			LinkLabel.Link linkC = new LinkLabel.Link (14, 3);
			try {
				links.Add (linkC);
				Assert.Fail ("#C1");
			} catch (InvalidOperationException ex) {
				// Overlapping link regions
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
				Assert.IsNull (ex.InnerException, "#C3");
				Assert.IsNotNull (ex.Message, "#C4");
			}

			Assert.AreEqual (3, links.Count, "#C5");
			Assert.IsTrue (links.LinksAdded, "#C6");
			Assert.AreSame (linkA, links [0], "#C7");
			Assert.AreSame (linkB, links [1], "#C8");
			Assert.AreSame (linkC, links [2], "#C9");
			Assert.AreEqual (0, linkA.Start, "#C10");
			Assert.AreEqual (7, linkA.Length, "#C11");
			Assert.AreEqual (5, linkB.Start, "#C12");
			Assert.AreEqual (4, linkB.Length, "#C13");
			Assert.AreEqual (14, linkC.Start, "#C14");
			Assert.AreEqual (3, linkC.Length, "#C15");
		}

		[Test] // Add (LinkLabel.Link)
		public void Add1_Value_Null ()
		{
			LinkLabel l = new LinkLabel ();
			l.Text = "Managed Windows Forms";

			LinkLabel.LinkCollection links = new LinkLabel.LinkCollection (
				l);
			try {
				links.Add ((LinkLabel.Link) null);
				Assert.Fail ("#1");
			} catch (NullReferenceException) {
			}
		}

		[Test] // Add (int, int)
		public void Add2 ()
		{
			LinkLabel l = new LinkLabel ();
			l.Text = "Managed Windows Forms";

			LinkLabel.LinkCollection links1 = new LinkLabel.LinkCollection (
				l);
			LinkLabel.LinkCollection links2 = new LinkLabel.LinkCollection (
				l);

			LinkLabel.Link linkA = links1.Add (0, 7);
			Assert.AreEqual (1, links1.Count, "#A1");
			Assert.AreEqual (1, links2.Count, "#A2");
			Assert.IsTrue (links1.LinksAdded, "#A3");
			Assert.IsFalse (links2.LinksAdded, "#A4");
			Assert.AreSame (linkA, links1 [0], "#A5");
			Assert.AreSame (linkA, links2 [0], "#A6");

			LinkLabel.Link linkB = links1.Add (8, 7);
			Assert.AreEqual (2, links1.Count, "#B1");
			Assert.AreEqual (2, links2.Count, "#B2");
			Assert.IsTrue (links1.LinksAdded, "#B3");
			Assert.IsFalse (links2.LinksAdded, "#B4");
			Assert.AreSame (linkA, links1 [0], "#B5");
			Assert.AreSame (linkA, links2 [0], "#B6");
			Assert.AreSame (linkB, links1 [1], "#B7");
			Assert.AreSame (linkB, links2 [1], "#B8");

			LinkLabel.LinkCollection links3 = new LinkLabel.LinkCollection (
				l);
			Assert.AreEqual (2, links3.Count, "#C1");
			Assert.IsFalse (links3.LinksAdded, "#C2");
			Assert.AreSame (linkA, links3 [0], "#C3");
			Assert.AreSame (linkB, links3 [1], "#C4");
		}

		[Test] // Add (int, int)
		public void Add2_Overlap ()
		{
			LinkLabel l = new LinkLabel ();
			l.Text = "Managed Windows Forms";

			LinkLabel.LinkCollection links = new LinkLabel.LinkCollection (
				l);

			LinkLabel.Link linkA = links.Add (0, 7);
			Assert.AreEqual (1, links.Count, "#A1");
			Assert.IsTrue (links.LinksAdded, "#A2");
			Assert.AreSame (linkA, links [0], "#A3");

			try {
				links.Add (5, 4);
				Assert.Fail ("#B1");
			} catch (InvalidOperationException ex) {
				// Overlapping link regions
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
			}

			Assert.AreEqual (2, links.Count, "#B5");
			Assert.IsTrue (links.LinksAdded, "#B6");
			Assert.AreSame (linkA, links [0], "#B7");
			Assert.IsNotNull (links [1], "#B8");
			Assert.AreEqual (0, linkA.Start, "#B9");
			Assert.AreEqual (7, linkA.Length, "#B10");
			Assert.AreEqual (5, links [1].Start, "#B11");
			Assert.AreEqual (4, links [1].Length, "#B12");

			try {
				links.Add (14, 3);
				Assert.Fail ("#C1");
			} catch (InvalidOperationException ex) {
				// Overlapping link regions
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
				Assert.IsNull (ex.InnerException, "#C3");
				Assert.IsNotNull (ex.Message, "#C4");
			}

			Assert.AreEqual (3, links.Count, "#C5");
			Assert.IsTrue (links.LinksAdded, "#C6");
			Assert.AreSame (linkA, links [0], "#C7");
			Assert.IsNotNull (links [1], "#C8");
			Assert.IsNotNull (links [2], "#C9");
			Assert.AreEqual (0, linkA.Start, "#C10");
			Assert.AreEqual (7, linkA.Length, "#C11");
			Assert.AreEqual (5, links [1].Start, "#C12");
			Assert.AreEqual (4, links [1].Length, "#C13");
			Assert.AreEqual (14, links [2].Start, "#C14");
			Assert.AreEqual (3, links [2].Length, "#C15");
		}
	}
}