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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
|
//
// TabControlTest.cs: Test cases for TabControl.
//
// Author:
// Ritvik Mayank (mritvik@novell.com)
//
// (C) 2005 Novell, Inc. (http://www.novell.com)
//
using System;
using System.Drawing;
using System.Windows.Forms;
using NUnit.Framework;
namespace MonoTests.System.Windows.Forms
{
[TestFixture]
public class TabControlTest : TestHelper
{
private int _selected_index_changed = 0;
private class TabControlPoker : TabControl {
public bool CheckIsInputKey (Keys key)
{
return IsInputKey (key);
}
protected override void WndProc (ref Message m)
{
base.WndProc (ref m);
}
}
[SetUp]
protected override void SetUp () {
_selected_index_changed = 0;
base.SetUp ();
}
[Test]
public void TabControlPropertyTest ()
{
Form myForm = new Form ();
myForm.ShowInTaskbar = false;
TabControl myTabControl = new TabControl ();
myTabControl.Visible = true;
myTabControl.Name = "Mono TabControl";
// A
Assert.AreEqual (TabAlignment.Top, myTabControl.Alignment, "A1");
Assert.AreEqual (TabAppearance.Normal, myTabControl.Appearance, "#A2");
// D
Assert.AreEqual (TabDrawMode.Normal, myTabControl.DrawMode, "#D5");
// H
Assert.AreEqual (false, myTabControl.HotTrack, "#H1");
// I
Assert.AreEqual (null, myTabControl.ImageList, "#I1");
// M
Assert.AreEqual (false, myTabControl.Multiline, "#M1");
// P
Assert.AreEqual (6, myTabControl.Padding.X, "#P1");
Assert.AreEqual (3, myTabControl.Padding.Y, "#P1");
// R
Assert.AreEqual (0, myTabControl.RowCount, "#R1");
// S
Assert.AreEqual (-1, myTabControl.SelectedIndex, "#S1");
Assert.AreEqual (null, myTabControl.SelectedTab, "#S2");
Assert.AreEqual (false, myTabControl.ShowToolTips, "#S3");
Assert.AreEqual (TabSizeMode.Normal, myTabControl.SizeMode, "#S4");
// T
Assert.AreEqual (0, myTabControl.TabCount, "#T1");
Assert.AreEqual (0, myTabControl.TabPages.Count, "#T2");
myForm.Dispose ();
}
[Test]
[Category ("NotWorking")]
public void GetTabRectTest ()
{
TabControl myTabControl = new TabControl ();
TabPage myTabPage = new TabPage();
myTabControl.Controls.Add(myTabPage);
myTabPage.TabIndex = 0;
Rectangle myTabRect = myTabControl.GetTabRect (0);
Assert.AreEqual (2, myTabRect.X, "#GetT1");
Assert.AreEqual (2, myTabRect.Y, "#GetT2");
Assert.AreEqual (42, myTabRect.Width, "#GetT3");
// It is environment dependent
//Assert.AreEqual (18, myTabRect.Height, "#GetT4");
}
[Test]
public void ToStringTest ()
{
TabControl myTabControl = new TabControl ();
Assert.AreEqual ("System.Windows.Forms.TabControl, TabPages.Count: 0", myTabControl.ToString(), "#1");
}
[Test]
public void ItemSizeTestPadding ()
{
TabControl tc = new TabControl ();
tc.TabPages.Add ("One"); // Need to add a page to force to calc the width
tc.CreateControl (); // And create the control as well
Assert.IsTrue (tc.ItemSize != Size.Empty, "#A0");
Size item_size = tc.ItemSize;
tc.Padding = new Point (tc.Padding.X * 2, tc.Padding.Y * 2);
Assert.IsTrue (tc.ItemSize.Height > item_size.Height, "#B0");
Assert.IsTrue (tc.ItemSize.Width > item_size.Width, "#B1");
}
[Test]
public void ItemSizeTest ()
{
TabControl tc = new TabControl ();
Assert.AreEqual (Size.Empty, tc.ItemSize, "#A0");
tc.CreateControl ();
Assert.IsTrue (tc.ItemSize.Width == 0, "#B0");
Assert.IsTrue (tc.ItemSize.Height > 0, "#B1");
tc.TabPages.Add ("A");
Assert.IsTrue (tc.ItemSize.Width > 0, "#C0");
Assert.IsTrue (tc.ItemSize.Height > 0, "#C1");
// ItemSize.Height can change, depending on Font
Size prev_size = tc.ItemSize;
tc.Font = new Font (tc.Font.FontFamily, tc.Font.Height * 2);
Assert.IsTrue (tc.ItemSize.Height > prev_size.Height, "#D0");
// Images can cause a change as well
prev_size = tc.ItemSize;
ImageList image_list = new ImageList ();
image_list.ImageSize = new Size (image_list.ImageSize.Width, tc.Font.Height * 2);
tc.ImageList = image_list;
Assert.IsTrue (tc.ItemSize.Height > prev_size.Height, "#E0");
}
[Test]
public void ItemSizeFixedTest ()
{
TabControl tc = new TabControl ();
tc.SizeMode = TabSizeMode.Fixed;
Assert.AreEqual (Size.Empty, tc.ItemSize, "#A0");
tc.CreateControl ();
Assert.IsTrue (tc.ItemSize.Width == 0, "#B0");
Assert.IsTrue (tc.ItemSize.Height > 0, "#B1");
tc.TabPages.Add ("A");
Assert.IsTrue (tc.ItemSize.Width == 96, "#C0");
Assert.IsTrue (tc.ItemSize.Width > 0, "#C1");
// Height can change automatically depending on Font,
// but not Width
Size prev_size = tc.ItemSize;
tc.Font = new Font (tc.Font.FontFamily, tc.Font.Height * 2);
Assert.IsTrue (tc.ItemSize.Width == 96, "#D0");
Assert.IsTrue (tc.ItemSize.Height > prev_size.Height, "#D1");
// Manually set ItemSize
tc.ItemSize = new Size (100, 35);
Assert.AreEqual (100, tc.ItemSize.Width, "#E0");
Assert.AreEqual (35, tc.ItemSize.Height, "#E1");
// Font size is decreased, but since we manually set
// the size we can't automatically update it.
tc.Font = new Font (tc.Font.FontFamily, tc.Font.Height / 2);
Assert.AreEqual (100, tc.ItemSize.Width, "#F0");
Assert.AreEqual (35, tc.ItemSize.Height, "#F1");
// Manually set even if control has not been created.
tc = new TabControl ();
tc.SizeMode = TabSizeMode.Fixed;
tc.ItemSize = new Size (100, 35);
Assert.AreEqual (100, tc.ItemSize.Width, "#G0");
Assert.AreEqual (35, tc.ItemSize.Height, "#G1");
}
[Test]
public void ClearTabPagesTest ()
{
// no tab pages
TabControl tab = new TabControl ();
tab.TabPages.Clear ();
Assert.AreEqual (-1, tab.SelectedIndex, "#A1");
Assert.AreEqual (0, tab.TabPages.Count, "#A2");
// single tab page
tab.Controls.Add (new TabPage ());
Assert.AreEqual (0, tab.SelectedIndex, "#B1");
Assert.AreEqual (1, tab.TabPages.Count, "#B2");
tab.TabPages.Clear();
Assert.AreEqual (-1, tab.SelectedIndex, "#B3");
Assert.AreEqual (0, tab.TabPages.Count, "#B4");
// multiple tab pages
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
Assert.AreEqual (0, tab.SelectedIndex, "#C1");
Assert.AreEqual (3, tab.TabPages.Count, "#C2");
tab.SelectedIndex = 1;
tab.TabPages.Clear ();
Assert.AreEqual (-1, tab.SelectedIndex, "#C3");
Assert.AreEqual (0, tab.TabPages.Count, "#C4");
}
[Test]
[Category ("NotWorking")]
public void Controls_Remove_HandleCreated ()
{
TabControl tab = new TabControl ();
tab.SelectedIndexChanged += new EventHandler (SelectedIndexChanged);
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (tab);
form.Show ();
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
Assert.AreEqual (0, tab.SelectedIndex, "#A1");
Assert.AreEqual (6, tab.TabPages.Count, "#A2");
Assert.AreEqual (0, _selected_index_changed, "#A3");
// remove selected tab
tab.SelectedIndex = 2;
Assert.AreEqual (2, tab.SelectedIndex, "#B1");
Assert.AreEqual (1, _selected_index_changed, "#B2");
tab.Controls.RemoveAt (2);
#if NET_2_0
Assert.AreEqual (0, tab.SelectedIndex, "#B3");
#else
Assert.AreEqual (1, tab.SelectedIndex, "#B3");
#endif
Assert.AreEqual (5, tab.TabPages.Count, "#B4");
Assert.AreEqual (2, _selected_index_changed, "#B5");
// remove not-selected tab
#if NET_2_0
Assert.AreEqual (0, tab.SelectedIndex, "#C1");
#else
Assert.AreEqual (1, tab.SelectedIndex, "#C1");
#endif
Assert.AreEqual (2, _selected_index_changed, "#C2");
tab.Controls.RemoveAt (3);
#if NET_2_0
Assert.AreEqual (0, tab.SelectedIndex, "#C3");
#else
Assert.AreEqual (2, tab.SelectedIndex, "#C3");
#endif
Assert.AreEqual (4, tab.TabPages.Count, "#C4");
#if NET_2_0
Assert.AreEqual (2, _selected_index_changed, "#C5");
#else
Assert.AreEqual (3, _selected_index_changed, "#C5");
#endif
// remove last tab
tab.Controls.RemoveAt (3);
#if NET_2_0
Assert.AreEqual (0, tab.SelectedIndex, "#D1");
#else
Assert.AreEqual (2, tab.SelectedIndex, "#D1");
#endif
Assert.AreEqual (3, tab.TabPages.Count, "#D2");
#if NET_2_0
Assert.AreEqual (2, _selected_index_changed, "#D3");
#else
Assert.AreEqual (3, _selected_index_changed, "#D3");
#endif
// remove first tab
tab.Controls.RemoveAt (0);
Assert.AreEqual (0, tab.SelectedIndex, "#E1");
Assert.AreEqual (2, tab.TabPages.Count, "#E2");
#if NET_2_0
Assert.AreEqual (3, _selected_index_changed, "#E3");
#else
Assert.AreEqual (4, _selected_index_changed, "#E3");
#endif
// remove remaining tabs
tab.Controls.RemoveAt (1);
tab.Controls.RemoveAt (0);
Assert.AreEqual (-1, tab.SelectedIndex, "#F1");
Assert.AreEqual (0, tab.TabPages.Count, "#F2");
#if NET_2_0
Assert.AreEqual (4, _selected_index_changed, "#F3");
#else
Assert.AreEqual (5, _selected_index_changed, "#F3");
#endif
}
[Test]
[Category ("NotWorking")]
public void Controls_Remove_HandleNotCreated ()
{
TabControl tab = new TabControl ();
tab.SelectedIndexChanged += new EventHandler (SelectedIndexChanged);
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
Assert.AreEqual (-1, tab.SelectedIndex, "#A1");
Assert.AreEqual (6, tab.TabPages.Count, "#A2");
Assert.AreEqual (0, _selected_index_changed, "#A3");
// remove selected tab
tab.SelectedIndex = 2;
Assert.AreEqual (2, tab.SelectedIndex, "#B1");
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#B2");
#else
Assert.AreEqual (1, _selected_index_changed, "#B2");
#endif
tab.Controls.RemoveAt (2);
#if NET_2_0
Assert.AreEqual (0, tab.SelectedIndex, "#B3");
#else
Assert.AreEqual (1, tab.SelectedIndex, "#B3");
#endif
Assert.AreEqual (5, tab.TabPages.Count, "#B4");
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#B5");
#else
Assert.AreEqual (2, _selected_index_changed, "#B5");
#endif
// remove not-selected tab
tab.Controls.RemoveAt (3);
#if NET_2_0
Assert.AreEqual (0, tab.SelectedIndex, "#C3");
#else
Assert.AreEqual (2, tab.SelectedIndex, "#C3");
#endif
Assert.AreEqual (4, tab.TabPages.Count, "#C4");
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#C5");
#else
Assert.AreEqual (3, _selected_index_changed, "#C5");
#endif
// remove last tab
tab.Controls.RemoveAt (3);
#if NET_2_0
Assert.AreEqual (0, tab.SelectedIndex, "#D1");
#else
Assert.AreEqual (2, tab.SelectedIndex, "#D1");
#endif
Assert.AreEqual (3, tab.TabPages.Count, "#D2");
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#D3");
#else
Assert.AreEqual (3, _selected_index_changed, "#D3");
#endif
// remove first tab
tab.Controls.RemoveAt (0);
Assert.AreEqual (0, tab.SelectedIndex, "#E1");
Assert.AreEqual (2, tab.TabPages.Count, "#E2");
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#E3");
#else
Assert.AreEqual (4, _selected_index_changed, "#E3");
#endif
// remove remaining tabs
tab.Controls.RemoveAt (1);
tab.Controls.RemoveAt (0);
Assert.AreEqual (0, tab.SelectedIndex, "#F1");
Assert.AreEqual (0, tab.TabPages.Count, "#F2");
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#F3");
#else
Assert.AreEqual (4, _selected_index_changed, "#F3");
#endif
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (tab);
form.Show ();
Assert.AreEqual (-1, tab.SelectedIndex, "#G1");
Assert.AreEqual (0, tab.TabPages.Count, "#G2");
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#G3");
#else
Assert.AreEqual (4, _selected_index_changed, "#G3");
#endif
}
[Test]
public void SelectedIndex ()
{
TabControl tab = new TabControl ();
tab.SelectedIndexChanged += new EventHandler (SelectedIndexChanged);
tab.Controls.Add (new TabPage ());
tab.Controls.Add (new TabPage ());
tab.SelectedIndex = 0;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#A1");
#else
Assert.AreEqual (1, _selected_index_changed, "#A1");
#endif
Assert.AreEqual (0, tab.SelectedIndex, "#A2");
tab.SelectedIndex = -1;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#B1");
#else
Assert.AreEqual (2, _selected_index_changed, "#B1");
#endif
Assert.AreEqual (-1, tab.SelectedIndex, "#B2");
tab.SelectedIndex = 1;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#C1");
#else
Assert.AreEqual (3, _selected_index_changed, "#C1");
#endif
Assert.AreEqual (1, tab.SelectedIndex, "#C2");
tab.SelectedIndex = 1;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#D1");
#else
Assert.AreEqual (3, _selected_index_changed, "#D1");
#endif
Assert.AreEqual (1, tab.SelectedIndex, "#D2");
tab.SelectedIndex = 6;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#E1");
#else
Assert.AreEqual (4, _selected_index_changed, "#E1");
#endif
Assert.AreEqual (6, tab.SelectedIndex, "#E2");
tab.SelectedIndex = 6;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#E31");
#else
Assert.AreEqual (4, _selected_index_changed, "#E3");
#endif
Assert.AreEqual (6, tab.SelectedIndex, "#E4");
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (tab);
form.Show ();
Assert.AreEqual (0, tab.SelectedIndex, "#E5");
tab.SelectedIndex = 0;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#F1");
#else
Assert.AreEqual (4, _selected_index_changed, "#F1");
#endif
Assert.AreEqual (0, tab.SelectedIndex, "#F2");
tab.SelectedIndex = -1;
#if NET_2_0
Assert.AreEqual (1, _selected_index_changed, "#G1");
#else
Assert.AreEqual (5, _selected_index_changed, "#G1");
#endif
Assert.AreEqual (-1, tab.SelectedIndex, "#G2");
tab.SelectedIndex = 1;
#if NET_2_0
Assert.AreEqual (2, _selected_index_changed, "#H1");
#else
Assert.AreEqual (6, _selected_index_changed, "#H1");
#endif
Assert.AreEqual (1, tab.SelectedIndex, "#H2");
tab.SelectedIndex = 1;
#if NET_2_0
Assert.AreEqual (2, _selected_index_changed, "#I1");
#else
Assert.AreEqual (6, _selected_index_changed, "#I1");
#endif
Assert.AreEqual (1, tab.SelectedIndex, "#I2");
form.Dispose ();
}
[Test] // bug #78395
public void SelectedIndex_Ignore ()
{
TabControl c = new TabControl ();
c.SelectedIndexChanged += new EventHandler (SelectedIndexChanged);
c.SelectedIndex = 0;
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#1");
#else
Assert.AreEqual (1, _selected_index_changed, "#1");
#endif
c.TabPages.Add (new TabPage ());
c.TabPages.Add (new TabPage ());
Assert.AreEqual (0, c.SelectedIndex, "#2");
Form f = new Form ();
f.ShowInTaskbar = false;
f.Controls.Add (c);
f.Show ();
#if NET_2_0
Assert.AreEqual (0, _selected_index_changed, "#3");
#else
Assert.AreEqual (1, _selected_index_changed, "#3");
#endif
c.SelectedIndex = 2; // beyond the pages - ignored
#if NET_2_0
Assert.AreEqual (1, _selected_index_changed, "#4");
#else
Assert.AreEqual (2, _selected_index_changed, "#4");
#endif
Assert.AreEqual (0, c.SelectedIndex, "#4");
f.Dispose ();
}
[Test]
public void SelectedIndex_Negative ()
{
Form form = new Form ();
form.ShowInTaskbar = false;
TabControl tab = new TabControl ();
tab.SelectedIndexChanged += new EventHandler (SelectedIndexChanged);
form.Controls.Add (tab);
Assert.AreEqual (-1, tab.SelectedIndex, "#A1");
tab.SelectedIndex = -1;
Assert.AreEqual (-1, tab.SelectedIndex, "#A2");
Assert.AreEqual (0, _selected_index_changed, "#A3");
try {
tab.SelectedIndex = -2;
Assert.Fail ("#B1");
#if NET_2_0
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNotNull (ex.Message, "#B3");
Assert.IsTrue (ex.Message.IndexOf ("'-2'") != -1, "#B4");
Assert.IsTrue (ex.Message.IndexOf ("'SelectedIndex'") != -1, "#B5");
Assert.IsTrue (ex.Message.IndexOf ("-1") != -1, "#B6");
Assert.IsNotNull (ex.ParamName, "#B7");
Assert.AreEqual ("SelectedIndex", ex.ParamName, "#B8");
}
#else
} catch (ArgumentException ex) {
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
Assert.IsNotNull (ex.Message, "#B3");
Assert.IsTrue (ex.Message.IndexOf ("'-2'") != -1, "#B4");
Assert.IsTrue (ex.Message.IndexOf ("'value'") != -1, "#B5");
Assert.IsTrue (ex.Message.IndexOf ("-1") != -1, "#B6");
Assert.IsNull (ex.ParamName, "#B7");
}
#endif
Assert.AreEqual (0, _selected_index_changed, "#C1");
Assert.AreEqual (-1, tab.SelectedIndex, "#C2");
form.Show ();
Assert.AreEqual (0, _selected_index_changed, "#C3");
Assert.AreEqual (-1, tab.SelectedIndex, "#C4");
try {
tab.SelectedIndex = -5;
Assert.Fail ("#D1");
#if NET_2_0
} catch (ArgumentOutOfRangeException ex) {
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#D2");
Assert.IsNotNull (ex.Message, "#D3");
Assert.IsTrue (ex.Message.IndexOf ("'-5'") != -1, "#D4");
Assert.IsTrue (ex.Message.IndexOf ("'SelectedIndex'") != -1, "#D5");
Assert.IsTrue (ex.Message.IndexOf ("-1") != -1, "#D6");
Assert.IsNotNull (ex.ParamName, "#D7");
Assert.AreEqual ("SelectedIndex", ex.ParamName, "#D8");
}
#else
} catch (ArgumentException ex) {
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
Assert.IsNotNull (ex.Message, "#D3");
Assert.IsTrue (ex.Message.IndexOf ("'-5'") != -1, "#D4");
Assert.IsTrue (ex.Message.IndexOf ("'value'") != -1, "#D5");
Assert.IsTrue (ex.Message.IndexOf ("-1") != -1, "#D6");
Assert.IsNull (ex.ParamName, "#D7");
}
#endif
Assert.AreEqual (-1, tab.SelectedIndex, "#E1");
tab.SelectedIndex = -1;
Assert.AreEqual (-1, tab.SelectedIndex, "#E2");
Assert.AreEqual (0, _selected_index_changed, "#E3");
form.Dispose ();
}
[Test]
[Category ("NotWorking")]
public void InputKeyTest ()
{
TabControlPoker p = new TabControlPoker ();
foreach (Keys key in Enum.GetValues (typeof (Keys))) {
switch (key) {
case Keys.PageUp:
case Keys.PageDown:
case Keys.End:
case Keys.Home:
continue;
}
Assert.IsFalse (p.CheckIsInputKey (key), "FALSE- " + key);
}
Assert.IsTrue (p.CheckIsInputKey (Keys.PageUp), "TRUE-pageup");
Assert.IsTrue (p.CheckIsInputKey (Keys.PageDown), "TRUE-pagedown");
Assert.IsTrue (p.CheckIsInputKey (Keys.End), "TRUE-end");
Assert.IsTrue (p.CheckIsInputKey (Keys.Home), "TRUE-home");
// Create the handle, things are a little different with
// the handle created
IntPtr dummy = p.Handle;
TestHelper.RemoveWarning (dummy);
foreach (Keys key in Enum.GetValues (typeof (Keys))) {
switch (key) {
case Keys.Left:
case Keys.Right:
case Keys.Up:
case Keys.Down:
case Keys.PageUp:
case Keys.PageDown:
case Keys.End:
case Keys.Home:
continue;
}
Assert.IsFalse (p.CheckIsInputKey (key), "PH-FALSE- " + key);
}
Assert.IsTrue (p.CheckIsInputKey (Keys.Left), "PH-TRUE-left");
Assert.IsTrue (p.CheckIsInputKey (Keys.Right), "PH-TRUE-right");
Assert.IsTrue (p.CheckIsInputKey (Keys.Up), "PH-TRUE-up");
Assert.IsTrue (p.CheckIsInputKey (Keys.Down), "PH-TRUE-down");
Assert.IsTrue (p.CheckIsInputKey (Keys.PageUp), "PH-TRUE-pageup");
Assert.IsTrue (p.CheckIsInputKey (Keys.PageDown), "PH-TRUE-pagedown");
Assert.IsTrue (p.CheckIsInputKey (Keys.End), "PH-TRUE-end");
Assert.IsTrue (p.CheckIsInputKey (Keys.Home), "PH-TRUE-home");
}
[Test] // bug #79847
public void NoTabPages ()
{
Form form = new Form ();
TabControl tab = new TabControl ();
tab.SelectedIndex = 0;
Assert.AreEqual (0, tab.SelectedIndex, "#A1");
form.Controls.Add (tab);
Assert.AreEqual (0, tab.SelectedIndex, "#A2");
form.ShowInTaskbar = false;
form.Show ();
Assert.AreEqual (-1, tab.SelectedIndex, "#A3");
form.Dispose ();
}
[Test] // bug #81802. should not throw an exception
public void NoTabPages2 ()
{
Form form = new Form ();
form.Font = new Font ("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte) (0)));
TabControl tab = new TabControl ();
form.Controls.Add (tab);
tab.Dispose ();
form.Dispose ();
}
private void SelectedIndexChanged (object sender, EventArgs e)
{
_selected_index_changed++;
}
#if NET_2_0
[Test]
public void MethodSelectTab ()
{
TabControl tc = new TabControl ();
tc.TabPages.Add ("One", "One");
tc.TabPages.Add ("Two", "Two");
tc.TabPages.Add ("Three", "Three");
tc.SelectTab (1);
Assert.AreEqual (1, tc.SelectedIndex, "A1");
tc.SelectTab (tc.TabPages[2]);
Assert.AreEqual (2, tc.SelectedIndex, "A2");
tc.SelectTab ("One");
Assert.AreEqual (0, tc.SelectedIndex, "A3");
tc.SelectTab (1);
tc.DeselectTab (1);
Assert.AreEqual (2, tc.SelectedIndex, "A4");
tc.DeselectTab (2);
Assert.AreEqual (0, tc.SelectedIndex, "A5");
tc.DeselectTab (tc.TabPages[0]);
Assert.AreEqual (1, tc.SelectedIndex, "A6");
tc.DeselectTab (tc.TabPages[0]);
Assert.AreEqual (1, tc.SelectedIndex, "A7");
tc.DeselectTab (tc.TabPages[1]);
Assert.AreEqual (2, tc.SelectedIndex, "A7");
tc.DeselectTab ("Two");
Assert.AreEqual (2, tc.SelectedIndex, "A8");
tc.DeselectTab ("Three");
Assert.AreEqual (0, tc.SelectedIndex, "A8");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void MethodSelectTabAOORE ()
{
TabControl tc = new TabControl ();
tc.TabPages.Add (new TabPage ("One"));
tc.TabPages.Add (new TabPage ("Two"));
tc.SelectTab (-1);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void MethodSelectTabAOORE2 ()
{
TabControl tc = new TabControl ();
tc.TabPages.Add (new TabPage ("One"));
tc.TabPages.Add (new TabPage ("Two"));
tc.SelectTab (2);
}
[Test]
public void EventSelected ()
{
Form f = new Form ();
TabControl tc = new TabControl ();
TabControlEventArgs tcea1 = new TabControlEventArgs (null, 0, TabControlAction.Deselected);
TabControlEventArgs tcea2 = new TabControlEventArgs (null, 0, TabControlAction.Selected);
TabControlCancelEventArgs tccea1 = new TabControlCancelEventArgs (null, 0, false, TabControlAction.Deselecting);
TabControlCancelEventArgs tccea2 = new TabControlCancelEventArgs (null, 0, false, TabControlAction.Selecting);
f.Controls.Add (tc);
string events = string.Empty;
tc.SelectedIndexChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("SelectedIndexChanged;"); });
tc.Deselecting += new TabControlCancelEventHandler (delegate (Object obj, TabControlCancelEventArgs e) { events += ("Deselecting;"); tccea1 = e; });
tc.Deselected += new TabControlEventHandler (delegate (Object obj, TabControlEventArgs e) { events += ("Deselected;"); tcea1 = e; });
tc.Selecting += new TabControlCancelEventHandler (delegate (Object obj, TabControlCancelEventArgs e) { events += ("Selecting;"); tccea2 = e; });
tc.Selected += new TabControlEventHandler (delegate (Object obj, TabControlEventArgs e) { events += ("Selected;"); tcea2 = e; });
TabPage tp1 = new TabPage ("One");
TabPage tp2 = new TabPage ("Two");
tc.TabPages.Add (tp1);
tc.TabPages.Add (tp2);
f.Show ();
tc.SelectTab (1);
Assert.AreEqual ("Deselecting;Deselected;Selecting;Selected;SelectedIndexChanged;", events, "A1");
Assert.AreEqual (TabControlAction.Deselecting, tccea1.Action, "A2");
Assert.AreEqual (TabControlAction.Deselected, tcea1.Action, "A2");
Assert.AreEqual (TabControlAction.Selecting, tccea2.Action, "A2");
Assert.AreEqual (TabControlAction.Selected, tcea2.Action, "A2");
Assert.AreSame (tp2, tcea2.TabPage, "A3");
Assert.AreEqual (1, tcea2.TabPageIndex, "A4");
f.Close ();
}
[Test]
[Category ("NotWorking")]
public void EnterLeaveEvents ()
{
Form f = new Form ();
TabControl tc = new TabControl ();
TabPage p1 = new TabPage ();
string events = string.Empty;
tc.Enter += new EventHandler (delegate (Object obj, EventArgs e) { events += ("tc_OnEnter;"); });
tc.Leave += new EventHandler (delegate (Object obj, EventArgs e) { events += ("tc_OnLeave;"); });
p1.Enter += new EventHandler (delegate (Object obj, EventArgs e) { events += ("p1_OnEnter;");});
p1.Leave += new EventHandler (delegate (Object obj, EventArgs e) { events += ("p1_OnLeave;"); });
tc.TabPages.Add (p1);
Button b1 = new Button ();
tc.TabIndex = 0;
b1.TabIndex = 1;
f.Controls.Add (b1);
f.Controls.Add (tc);
f.Show ();
Assert.AreEqual ("tc_OnEnter;p1_OnEnter;", events, "A1");
b1.Focus ();
Assert.AreEqual ("tc_OnEnter;p1_OnEnter;p1_OnLeave;tc_OnLeave;", events, "A2");
}
[Test] // bug #499887
public void SelectedIndexChangeFiresFocus ()
{
Form f = new Form ();
TabControl tc = new TabControl ();
TabPage p1 = new TabPage ();
TabPage p2 = new TabPage ();
string events = string.Empty;
tc.TabPages.Add (p1);
tc.TabPages.Add (p2);
tc.SelectedIndex = 0;
Button b1 = new Button ();
Button b2 = new Button ();
f.Controls.Add (b1);
f.Controls.Add (b2);
f.Controls.Add (tc);
f.Show ();
b1.Focus ();
b2.GotFocus += new EventHandler (delegate (Object obj, EventArgs e) {
tc.SelectedIndex = 1;
});
tc.GotFocus += new EventHandler(delegate (Object obj, EventArgs e) { events += ("tc_OnGotFocus" + tc.SelectedIndex + ";"); });
tc.SelectedIndexChanged += new EventHandler(delegate (Object obj, EventArgs e) { events += ("tc_OnSelectedIndexChanged" + tc.SelectedIndex + ";"); });
p2.Enter += new EventHandler(delegate (Object obj, EventArgs e) { events += ("p2_OnEnter" + tc.SelectedIndex + ";"); });
p2.Leave += new EventHandler (delegate (Object obj, EventArgs e) { events += ("p2_OnLeave;"); });
b2.Focus ();
Assert.AreEqual ("tc_OnGotFocus0;p2_OnEnter1;tc_OnSelectedIndexChanged1;", events, "A1");
Assert.IsTrue (tc.Focused, "A2");
}
// Make sure that setting focus for TabControl is *not* resetting SelectedIndex when
// the value is -1
[Test]
public void GotFocusSelectedIndex ()
{
TabControl tc = new TabControl ();
tc.TabPages.Add ("A");
tc.TabPages.Add ("B");
Button b = new Button (); // Dummy button to receive focus by default
Form f = new Form ();
f.Controls.AddRange (new Control [] { b, tc });
f.Show ();
tc.SelectedIndex = -1;
// Make sure focus goes back to button
b.Focus ();
// Finally give focus back to TabControl
tc.Focus ();
Assert.AreEqual (-1, tc.SelectedIndex, "#A0");
}
#endif
}
[TestFixture]
public class TabPageCollectionTest : TestHelper
{
[Test]
public void Indexer ()
{
TabControl tab = new TabControl ();
TabControl.TabPageCollection tabPages = new TabControl.TabPageCollection (tab);
TabPage tabPageA = new TabPage ();
TabPage tabPageB = new TabPage ();
TabPage tabPageC = new TabPage ();
TabPage tabPageD = new TabPage ();
tabPages.Add (tabPageA);
Assert.AreSame (tabPageA, tabPages [0], "#1");
tabPages [0] = tabPageB;
Assert.AreSame (tabPageB, tabPages [0], "#2");
tabPages.Add (tabPageC);
Assert.AreSame (tabPageB, tabPages [0], "#3");
Assert.AreSame (tabPageC, tabPages [1], "#4");
tabPages.Remove (tabPageB);
Assert.AreSame (tabPageC, tabPages [0], "#5");
tabPages [0] = tabPageD;
Assert.AreSame (tabPageD, tabPages [0], "#6");
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (tab);
form.Show ();
form.Dispose ();
}
}
}
|