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
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
|
//
// Copyright (c) 2005 Novell, Inc.
//
// Authors:
// Ritvik Mayank (mritvik@novell.com)
// Stefan Noack (noackstefan@googlemail.com)
//
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Runtime.Remoting;
using System.Threading;
using System.Windows.Forms;
#if NET_2_0
using System.Windows.Forms.Layout;
#endif
using NUnit.Framework;
using CategoryAttribute = NUnit.Framework.CategoryAttribute;
namespace MonoTests.System.Windows.Forms
{
[TestFixture]
public class ControlTest : TestHelper
{
[Test] // .ctor ()
public void Constructor1 ()
{
MockControl c = new MockControl ();
Assert.AreEqual (0, c.OnLocationChangedCount, "OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "Height");
Assert.AreEqual (0, c.Left, "Left");
Assert.AreEqual (string.Empty, c.Name, "Name");
Assert.IsNull (c.Parent, "Parent");
Assert.AreEqual (string.Empty, c.Text, "#A:Text");
Assert.AreEqual (0, c.Top, "Top");
Assert.AreEqual (0, c.Width, "Width");
}
[Test] // .ctor (String)
public void Constructor2 ()
{
MockControl c = new MockControl ((string) null);
Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#A:Height");
Assert.AreEqual (0, c.Left, "#A:Left");
Assert.AreEqual (string.Empty, c.Name, "#A:Name");
Assert.IsNull (c.Parent, "#A:Parent");
Assert.AreEqual (string.Empty, c.Text, "#A:Text");
Assert.AreEqual (0, c.Top, "#A:Top");
Assert.AreEqual (0, c.Width, "#A:Width");
c = new MockControl ("child");
Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#B:Height");
Assert.AreEqual (0, c.Left, "#B:Left");
Assert.AreEqual (string.Empty, c.Name, "#B:Name");
Assert.IsNull (c.Parent, "#B:Parent");
Assert.AreEqual ("child", c.Text, "#B:Text");
Assert.AreEqual (0, c.Top, "#B:Top");
Assert.AreEqual (0, c.Width, "#B:Width");
}
[Test] // .ctor (Control, String)
public void Constructor3 ()
{
Control parent = new Control ("parent");
MockControl c = new MockControl ((Control) null, (string) null);
Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#A:Height");
Assert.AreEqual (0, c.Left, "#A:Left");
Assert.AreEqual (string.Empty, c.Name, "#A:Name");
Assert.IsNull (c.Parent, "#A:Parent");
Assert.AreEqual (string.Empty, c.Text, "#A:Text");
Assert.AreEqual (0, c.Top, "#A:Top");
Assert.AreEqual (0, c.Width, "#A:Width");
c = new MockControl ((Control) null, "child");
Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#B:Height");
Assert.AreEqual (0, c.Left, "#B:Left");
Assert.AreEqual (string.Empty, c.Name, "#B:Name");
Assert.IsNull (c.Parent, "#B:Parent");
Assert.AreEqual ("child", c.Text, "#B:Text");
Assert.AreEqual (0, c.Top, "#B:Top");
Assert.AreEqual (0, c.Width, "#B:Width");
c = new MockControl (parent, (string) null);
Assert.AreEqual (0, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#C:Height");
Assert.AreEqual (0, c.Left, "#C:Left");
Assert.AreEqual (string.Empty, c.Name, "#C:Name");
Assert.AreSame (parent, c.Parent, "#C:Parent");
Assert.AreEqual (string.Empty, c.Text, "#C:Text");
Assert.AreEqual (0, c.Top, "#C:Top");
Assert.AreEqual (0, c.Width, "#C:Width");
c = new MockControl (parent, "child");
Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#D:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#D:Height");
Assert.AreEqual (0, c.Left, "#D:Left");
Assert.AreEqual (string.Empty, c.Name, "#D:Name");
Assert.AreSame (parent, c.Parent, "#D:Parent");
Assert.AreEqual ("child", c.Text, "#D:Text");
Assert.AreEqual (0, c.Top, "#D:Top");
Assert.AreEqual (0, c.Width, "#D:Width");
}
[Test] // .ctor (String, Int32, Int32, Int32, Int32)
public void Constructor4 ()
{
MockControl c = new MockControl ((string) null, 0, 0, 0, 0);
Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#A:Height");
Assert.AreEqual (0, c.Left, "#A:Left");
Assert.AreEqual (string.Empty, c.Name, "#A:Name");
Assert.IsNull (c.Parent, "#A:Parent");
Assert.AreEqual (string.Empty, c.Text, "#A:Text");
Assert.AreEqual (0, c.Top, "#A:Top");
Assert.AreEqual (0, c.Width, "#A:Width");
c = new MockControl ((string) null, 1, 0, 0, 0);
Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#B:Height");
Assert.AreEqual (1, c.Left, "#B:Left");
Assert.AreEqual (string.Empty, c.Name, "#B:Name");
Assert.IsNull (c.Parent, "#B:Parent");
Assert.AreEqual (string.Empty, c.Text, "#B:Text");
Assert.AreEqual (0, c.Top, "#B:Top");
Assert.AreEqual (0, c.Width, "#B:Width");
c = new MockControl ("child", 0, 1, 0, 0);
Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#C:Height");
Assert.AreEqual (0, c.Left, "#C:Left");
Assert.AreEqual (string.Empty, c.Name, "#C:Name");
Assert.IsNull (c.Parent, "#C:Parent");
Assert.AreEqual ("child", c.Text, "#C:Text");
Assert.AreEqual (1, c.Top, "#C:Top");
Assert.AreEqual (0, c.Width, "#C:Width");
c = new MockControl ("child", 0, 0, 1, 0);
Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#D:Height");
Assert.AreEqual (0, c.Left, "#D:Left");
Assert.AreEqual (string.Empty, c.Name, "#D:Name");
Assert.IsNull (c.Parent, "#D:Parent");
Assert.AreEqual ("child", c.Text, "#D:Text");
Assert.AreEqual (0, c.Top, "#D:Top");
Assert.AreEqual (1, c.Width, "#D:Width");
c = new MockControl ("child", 0, 0, 0, 1);
Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
Assert.AreEqual (1, c.Height, "#E:Height");
Assert.AreEqual (0, c.Left, "#E:Left");
Assert.AreEqual (string.Empty, c.Name, "#E:Name");
Assert.IsNull (c.Parent, "#E:Parent");
Assert.AreEqual ("child", c.Text, "#E:Text");
Assert.AreEqual (0, c.Top, "#E:Top");
Assert.AreEqual (0, c.Width, "#E:Width");
c = new MockControl ("child", 1, 0, 1, 0);
Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#F:Height");
Assert.AreEqual (1, c.Left, "#F:Left");
Assert.AreEqual (string.Empty, c.Name, "#F:Name");
Assert.IsNull (c.Parent, "#F:Parent");
Assert.AreEqual ("child", c.Text, "#F:Text");
Assert.AreEqual (0, c.Top, "#F:Top");
Assert.AreEqual (1, c.Width, "#F:Width");
c = new MockControl ("child", 0, 1, 0, 1);
Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
Assert.AreEqual (1, c.Height, "#G:Height");
Assert.AreEqual (0, c.Left, "#G:Left");
Assert.AreEqual (string.Empty, c.Name, "#G:Name");
Assert.IsNull (c.Parent, "#G:Parent");
Assert.AreEqual ("child", c.Text, "#G:Text");
Assert.AreEqual (1, c.Top, "#G:Top");
Assert.AreEqual (0, c.Width, "#G:Width");
}
[Test] // .ctor (Control, String, Int32, Int32, Int32, Int32)
public void Constructor5 ()
{
Control parent = new Control ("parent");
MockControl c = new MockControl ((Control) null,
(string) null, 0, 0, 0, 0);
Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#A:Height");
Assert.AreEqual (0, c.Left, "#A:Left");
Assert.AreEqual (string.Empty, c.Name, "#A:Name");
Assert.IsNull (c.Parent, "#A:Parent");
Assert.AreEqual (string.Empty, c.Text, "#A:Text");
Assert.AreEqual (0, c.Top, "#A:Top");
Assert.AreEqual (0, c.Width, "#A:Width");
c = new MockControl (parent, (string) null, 1, 0, 0, 0);
Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#B:Height");
Assert.AreEqual (1, c.Left, "#B:Left");
Assert.AreEqual (string.Empty, c.Name, "#B:Name");
Assert.AreSame (parent, c.Parent, "#B:Parent");
Assert.AreEqual (string.Empty, c.Text, "#B:Text");
Assert.AreEqual (0, c.Top, "#B:Top");
Assert.AreEqual (0, c.Width, "#B:Width");
c = new MockControl ((Control) null, "child", 0, 1, 0, 0);
Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#C:Height");
Assert.AreEqual (0, c.Left, "#C:Left");
Assert.AreEqual (string.Empty, c.Name, "#C:Name");
Assert.IsNull (c.Parent, "#C:Parent");
Assert.AreEqual ("child", c.Text, "#C:Text");
Assert.AreEqual (1, c.Top, "#C:Top");
Assert.AreEqual (0, c.Width, "#C:Width");
c = new MockControl (parent, "child", 0, 0, 1, 0);
Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#D:Height");
Assert.AreEqual (0, c.Left, "#D:Left");
Assert.AreEqual (string.Empty, c.Name, "#D:Name");
Assert.AreSame (parent, c.Parent, "#D:Parent");
Assert.AreEqual ("child", c.Text, "#D:Text");
Assert.AreEqual (0, c.Top, "#D:Top");
Assert.AreEqual (1, c.Width, "#D:Width");
c = new MockControl (parent, "child", 0, 0, 0, 1);
Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
Assert.AreEqual (1, c.Height, "#E:Height");
Assert.AreEqual (0, c.Left, "#E:Left");
Assert.AreEqual (string.Empty, c.Name, "#E:Name");
Assert.AreSame (parent, c.Parent, "#E:Parent");
Assert.AreEqual ("child", c.Text, "#E:Text");
Assert.AreEqual (0, c.Top, "#E:Top");
Assert.AreEqual (0, c.Width, "#E:Width");
c = new MockControl (parent, "child", 1, 0, 1, 0);
Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
Assert.AreEqual (0, c.Height, "#F:Height");
Assert.AreEqual (1, c.Left, "#F:Left");
Assert.AreEqual (string.Empty, c.Name, "#F:Name");
Assert.AreSame (parent, c.Parent, "#F:Parent");
Assert.AreEqual ("child", c.Text, "#F:Text");
Assert.AreEqual (0, c.Top, "#F:Top");
Assert.AreEqual (1, c.Width, "#F:Width");
c = new MockControl (parent, "child", 0, 1, 0, 1);
Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
Assert.AreEqual (1, c.Height, "#G:Height");
Assert.AreEqual (0, c.Left, "#G:Left");
Assert.AreEqual (string.Empty, c.Name, "#G:Name");
Assert.AreSame (parent, c.Parent, "#G:Parent");
Assert.AreEqual ("child", c.Text, "#G:Text");
Assert.AreEqual (1, c.Top, "#G:Top");
Assert.AreEqual (0, c.Width, "#G:Width");
}
[Test]
public void DisposeTest ()
{
ControlDisposeTester control = new ControlDisposeTester ();
control.Visible = true;
control.Dispose ();
try {
control.CreateControl ();
} catch (ObjectDisposedException ex) {
Console.WriteLine (ex);
Assert.Fail ("#1");
}
Assert.IsFalse (control.IsHandleCreated, "#2");
// The control remains Visible until WM_DESTROY is received.
Assert.IsTrue (control.Visible, "#3");
try {
control.InvokeCreateHandle ();
Assert.Fail ("#4");
} catch (ObjectDisposedException ex) {
//Console.WriteLine (ex);
}
}
private class ControlDisposeTester : Control
{
public void InvokeCreateHandle ()
{
CreateHandle ();
}
}
#if NET_2_0
[Test]
public void AutoSizeTest ()
{
ControlAutoSizeTester c = new ControlAutoSizeTester (new Size (23, 17), AutoSizeMode.GrowAndShrink);
Form f = new Form();
f.Size = new Size (200, 200);
c.Parent = f;
f.Show();
Size s = new Size (42, 42);
c.Size = s;
Point l = new Point (10, 10);
c.Location = l;
//Check wether normal size setting is OK
Assert.AreEqual (s, c.Size, "#S1");
//Check wether size remains without GetPreferredSize implemented even when AutoSize turned on.
c.AutoSize = true;
f.PerformLayout();
Assert.AreEqual (s, c.Size, "#S2");
//Simulate a Control implementing GetPreferredSize
c.UseCustomPrefSize = true;
f.PerformLayout();
//Check wether size shrinks to preferred size
Assert.AreEqual (c.CustomPrefSize, c.Size, "#S3");
//Check wether Location stays constant
Assert.AreEqual (l, c.Location, "#L1");
//Check wether Dock is respected
c.Dock = DockStyle.Bottom;
Assert.AreEqual (f.ClientSize.Width, c.Width, "#D1");
//Check wether size shrinks to preferred size again
c.Dock = DockStyle.None;
Assert.AreEqual (c.CustomPrefSize, c.Size, "#S4");
//Check wether Anchor is respected for adjusting Locatioon
c.Anchor = AnchorStyles.Bottom;
f.Height += 50;
Assert.AreEqual (l.Y + 50, c.Top, "#A1");
//Check wether size is still OK
Assert.AreEqual (c.CustomPrefSize, c.Size, "#S5");
//just tidy up
c.Anchor = AnchorStyles.Top | AnchorStyles.Left;
c.Location = l;
//Check wether shrinking to zero is possible
c.CustomPrefSize = new Size (0, 0);
f.PerformLayout();
Assert.AreEqual (c.CustomPrefSize, c.Size, "#S6");
//Check wether MinimumSize is honored
c.MinimumSize = new Size (10, 12);
c.CustomPrefSize = new Size (5, 5);
f.PerformLayout();
Assert.AreEqual (c.MinimumSize, c.Size, "#S7");
c.MinimumSize = new Size (0, 0);
//Check wether MaximumSize is honored
c.MaximumSize = new Size (100, 120);
c.CustomPrefSize = new Size (500, 500);
f.PerformLayout();
Assert.AreEqual (c.MaximumSize, c.Size, "#S8");
//Check wether shrinking does not happen when GrowOnly
c.AutoSize = false;
s = new Size (23, 23);
c.Size = s;
c.CustomPrefSize = new Size (5, 5);
c.AutoSizeMode = AutoSizeMode.GrowOnly;
c.AutoSize = true;
f.PerformLayout();
Assert.AreEqual (s, c.Size, "#S9");
f.Close ();
}
public class ControlAutoSizeTester : Control {
public ControlAutoSizeTester (Size customPrefSize, AutoSizeMode autoSizeMode)
{
custom_prefsize = customPrefSize;
AutoSizeMode = autoSizeMode;
}
public AutoSizeMode AutoSizeMode {
set {
base.SetAutoSizeMode (value);
}
}
private bool use_custom_prefsize = false;
public bool UseCustomPrefSize {
set {
use_custom_prefsize = value;
}
}
private Size custom_prefsize;
public Size CustomPrefSize {
get {
return custom_prefsize;
}
set {
custom_prefsize = value;
}
}
public override Size GetPreferredSize (Size proposedSize)
{
if (use_custom_prefsize) {
return custom_prefsize;
} else {
return base.GetPreferredSize(proposedSize);
}
}
}
#endif
[Test]
public void Bug82748 ()
{
Form f = new Form ();
f.ShowInTaskbar = false;
Control c = new Control ();
c.Size = new Size (100, 100);
Control c2 = new Control ();
c2.Size = c.Size;
c2.Controls.Add (c);
c.Anchor = AnchorStyles.Right;
f.Controls.Add (c);
f.Show ();
Assert.AreEqual (0, c.Left, "A1");
f.Close ();
f.Dispose ();
}
[Test]
public void InvokeTestParentHandle ()
{
Control child, parent;
parent = new Control ();
child = new Control ();
parent.Controls.Add (child);
parent.Visible = true;
parent.CreateControl ();
child.Invoke (new CrossAppDomainDelegate (dummy)) ;
}
public void dummy ()
{
}
public class ControlStylesTester : Control {
private WindowStyles style;
private WindowStyles ex_style;
private bool or_styles;
public ControlStylesTester (WindowStyles Style, WindowStyles ExStyle, bool OrStyles)
{
style = Style;
ex_style = ExStyle;
or_styles = OrStyles;
}
protected override CreateParams CreateParams {
get {
CreateParams result = base.CreateParams;
if (or_styles) {
result.Style |= (int) style;
result.ExStyle |= (int) ex_style;
} else {
result.Style = (int) style;
result.ExStyle = (int) ex_style;
}
return result;
}
}
}
[Test]
public void ControlSizeTest ()
{
ControlStylesTester c = new ControlStylesTester (WindowStyles.WS_CHILD, 0, true);
Assert.AreEqual ("{X=0,Y=0}", c.Location.ToString (), "#L1");
Assert.AreEqual ("{Width=0, Height=0}", c.Size.ToString (), "#S1");
}
#if NET_2_0
[Test]
public void CaptureTest ()
{
Form frm = new Form ();
ControlOverrideLogger log = new ControlOverrideLogger ();
frm.Controls.Add (log);
log.Visible = true;
log.Capture = true;
log.Capture = false;
log.BackColor = Color.Blue;
log.Size = new Size (100, 100);
frm.Show ();
Application.DoEvents ();
frm.Dispose ();
Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#01");
log = new ControlOverrideLogger ();
log.Capture = true;
log.Capture = false;
Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#02");
log = new ControlOverrideLogger ();
log.Capture = true;
Assert.IsTrue (log.IsHandleCreated, "#03");
Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#04");
log = new ControlOverrideLogger ();
log.Capture = false;
Assert.IsFalse (log.IsHandleCreated, "#05");
Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#06");
}
#endif
public class OnPaintTester : Form
{
int counter;
int total;
ArrayList list = new ArrayList ();
public bool Recursive;
public bool TestRefresh;
public bool TestInvalidate;
public bool TestUpdate;
#if NET_2_0
public new bool DoubleBuffered {
get {
return base.DoubleBuffered;
}
set {
base.DoubleBuffered = value;
}
}
#endif
protected override void OnPaint (PaintEventArgs pevent)
{
Assert.IsFalse (list.Contains (pevent.Graphics), "OnPaintTester.OnPaint: Got the same Graphics twice");
list.Add (pevent.Graphics);
if (total > 10)
return;
Recursive = counter > 0 || Recursive;
counter++;
if (counter < 2) {
if (TestRefresh)
Refresh ();
else if (TestInvalidate)
Invalidate ();
else {
Update ();
}
}
base.OnPaint (pevent);
counter--;
total++;
}
public new void Show ()
{
base.Show ();
Application.DoEvents ();
}
}
[Test]
public void ControlCollectionTest ()
{
Form frm = new Form ();
frm.IsMdiContainer = true;
Form child = new Form ();
Control.ControlCollection c = new Control.ControlCollection (frm);
child.MdiParent = frm;
c.Add (child);
child.Dispose ();
frm.Dispose ();
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ControlCollectionExceptionTest ()
{
Form frm = new Form ();
frm.IsMdiContainer = true;
Form child = new Form ();
Control.ControlCollection c = new Control.ControlCollection (frm);
//child.MdiParent = frm;
c.Add (child);
child.Dispose ();
frm.Dispose ();
}
[Test]
[Category ("NotWorking")]
public void OnPaintTest ()
{
using (OnPaintTester t = new OnPaintTester ()) {
t.TestRefresh = true;
t.Show ();
Assert.IsTrue (t.Recursive, "#1");
}
using (OnPaintTester t = new OnPaintTester ()) {
t.TestUpdate = true;
t.Show ();
Assert.IsFalse (t.Recursive, "#2");
}
using (OnPaintTester t = new OnPaintTester ()) {
t.TestInvalidate = true;
t.Show ();
Assert.IsFalse (t.Recursive, "#3");
}
}
#if NET_2_0
[Test]
[Category ("Interactive")]
public void OnPaintDoubleBufferedTest ()
{
using (OnPaintTester t = new OnPaintTester ()) {
t.DoubleBuffered = true;
t.TestRefresh = true;
t.Show ();
Assert.IsTrue (t.Recursive, "#1");
}
using (OnPaintTester t = new OnPaintTester ()) {
t.DoubleBuffered = true;
t.TestUpdate = true;
t.Show ();
Assert.IsFalse (t.Recursive, "#2");
}
using (OnPaintTester t = new OnPaintTester ()) {
t.DoubleBuffered = true;
t.TestInvalidate = true;
t.Show ();
Assert.IsFalse (t.Recursive, "#3");
}
}
#endif
public class PaintEventForm : Form
{
public ArrayList overrides = new ArrayList ();
public ArrayList events = new ArrayList ();
public PaintEventForm ()
{
Paint += new PaintEventHandler (DoubleBufferEventForm_Paint);
}
public bool GetControlStyle (ControlStyles style)
{
return base.GetStyle (style);
}
public void SetControlStyle (ControlStyles style, bool value)
{
base.SetStyle (style, value);
}
void DoubleBufferEventForm_Paint (object sender, PaintEventArgs e)
{
events.Add("Paint");
}
protected override void OnPaintBackground (PaintEventArgs e)
{
base.OnPaintBackground (e);
overrides.Add("OnPaintBackground");
}
protected override void OnPaint (PaintEventArgs pevent)
{
base.OnPaint (pevent);
overrides.Add("OnPaint");
}
}
[Test]
[Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
public void EventStyleTest ()
{
#if NET_2_0
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#A1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#A2");
Assert.IsTrue (f.events.Contains ("Paint"), "#A3");
}
#endif
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.DoubleBuffer, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#B1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#B2");
Assert.IsTrue (f.events.Contains ("Paint"), "#B3");
}
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#C1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#C2");
Assert.IsTrue (f.events.Contains ("Paint"), "#C3");
}
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.UserPaint, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#D1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#D2");
Assert.IsTrue (f.events.Contains ("Paint"), "#D3");
}
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#E1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#E2");
Assert.IsTrue (f.events.Contains ("Paint"), "#E3");
}
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#F1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#F2");
Assert.IsTrue (f.events.Contains ("Paint"), "#F3");
}
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#G1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#G2");
Assert.IsTrue (f.events.Contains ("Paint"), "#G3");
}
using (PaintEventForm f = new PaintEventForm ()) {
f.Show ();
f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
f.Refresh ();
Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#H1");
Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#H2");
Assert.IsTrue (f.events.Contains ("Paint"), "#H3");
}
}
#if NET_2_0
public class DoubleBufferedForm : Form
{
public bool painted;
public bool failed;
public DoubleBufferedForm ()
{
this.DoubleBuffered = true;
}
protected override void OnPaint (PaintEventArgs e)
{
if (failed || painted)
return;
painted = true;
Height = Height + 1;
try {
e.Graphics.DrawString (Size.ToString (), Font, Brushes.AliceBlue, new Point (2, 2));
} catch (Exception exception) {
Console.WriteLine (exception.StackTrace);
failed = true;
}
}
}
public class DoubleBufferControl : Control
{
public bool IsDoubleBuffered
{
get { return base.DoubleBuffered; }
set { base.DoubleBuffered = value; }
}
public bool GetControlStyle (ControlStyles style)
{
return base.GetStyle (style);
}
public void SetControlStyle (ControlStyles style, bool value)
{
base.SetStyle (style, value);
}
}
[Test]
[Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
public void DoubleBufferTest ()
{
DoubleBufferedForm f = new DoubleBufferedForm ();
f.ShowInTaskbar = false;
f.Show ();
f.Refresh ();
Assert.IsFalse (f.failed, "#01");
Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
f.Close ();
}
[Test]
public void DoubleBufferedTest ()
{
DoubleBufferControl c = new DoubleBufferControl ();
Assert.IsFalse (c.IsDoubleBuffered, "#A1");
Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#A2");
Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#A3");
Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#A4");
Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
Assert.IsTrue (c.IsDoubleBuffered, "#B1");
Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#B2");
Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#B3");
Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#B4");
Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, false);
c.SetControlStyle (ControlStyles.UserPaint, false);
Assert.IsTrue (c.IsDoubleBuffered, "#C1");
Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#C2");
Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#C3");
Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#C4");
Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#C5");
c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, false);
Assert.IsFalse (c.IsDoubleBuffered, "#D1");
Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#D2");
Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#D3");
Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#D4");
Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#D5");
c.SetControlStyle (ControlStyles.DoubleBuffer, true);
Assert.IsFalse (c.IsDoubleBuffered, "#E1");
Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#E2");
Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#E3");
Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#E4");
Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#E5");
c.SetControlStyle (ControlStyles.DoubleBuffer, false);
Assert.IsFalse (c.IsDoubleBuffered, "#F1");
Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#F2");
Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#F3");
Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#F4");
Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#F5");
c.IsDoubleBuffered = true;
Assert.IsTrue (c.IsDoubleBuffered, "#G1");
Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#G2");
Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#G3");
Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#G4");
Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#G5");
c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
c.SetControlStyle (ControlStyles.DoubleBuffer, true);
c.SetControlStyle (ControlStyles.UserPaint, true);
c.IsDoubleBuffered = false;
Assert.IsFalse (c.IsDoubleBuffered, "#H1");
Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#H2");
Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#H3");
Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#H4");
Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#H5");
}
[Test]
public void DoubleBufferedStyleTest ()
{
DoubleBufferControl c = new DoubleBufferControl ();
TestControlStyle.CheckStyles (c, "#A1", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
c.IsDoubleBuffered = true;
TestControlStyle.CheckStyles (c, "#A2", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility, ControlStyles.OptimizedDoubleBuffer);
c.IsDoubleBuffered = false;
TestControlStyle.CheckStyles (c, "#A3", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
c = new DoubleBufferControl ();
foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
c.SetControlStyle (style, false);
}
TestControlStyle.CheckStyles (c, "#B1");
c.IsDoubleBuffered = true;
TestControlStyle.CheckStyles (c, "#B2", ControlStyles.OptimizedDoubleBuffer, ControlStyles.AllPaintingInWmPaint);
c.IsDoubleBuffered = false;
TestControlStyle.CheckStyles (c, "#B3", ControlStyles.AllPaintingInWmPaint);
}
#endif
class Helper {
public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
{
Assert.IsNotNull (c.AccessibilityObject, "Acc1");
Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
Assert.AreEqual (Name, c.AccessibleName, "Acc4");
Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
}
public static string TestControl(Control container, Control start, bool forward) {
Control ctl;
ctl = container.GetNextControl(start, forward);
if (ctl == null) {
return null;
}
return ctl.Text;
}
}
[Test]
public void CreatedTest ()
{
Control c = new Control ();
Assert.IsFalse (c.Created, "A1");
}
class CustomA11yEnabledControl : Control {
public CustomA11yEnabledControl () : base() { }
protected override AccessibleObject CreateAccessibilityInstance () { return new CustomAccessibleObject (this); }
class CustomAccessibleObject : ControlAccessibleObject {
public CustomAccessibleObject (CustomA11yEnabledControl control) : base(control) { }
public override string Name { get { return "custom name"; } }
public override string DefaultAction { get { return "custom default action"; } }
public override string Description { get { return "custom description"; } }
public override AccessibleRole Role { get { return AccessibleRole.Alert; } }
}
}
[Test]
public void CreatedAccessibilityTest ()
{
CustomA11yEnabledControl c = new CustomA11yEnabledControl ();
Assert.IsFalse(c.Created, "A1");
// Tests default values
Assert.AreEqual (null, c.AccessibleDefaultActionDescription, "A2.0");
Assert.IsFalse(c.IsHandleCreated, "A2.1");
Assert.AreEqual (null, c.AccessibleDescription, "A3.0");
Assert.IsFalse(c.IsHandleCreated, "A3.1");
Assert.AreEqual (null, c.AccessibleName, "A4.0");
Assert.IsFalse(c.IsHandleCreated, "A4.1");
Assert.AreEqual (AccessibleRole.Default, c.AccessibleRole, "A5.0");
Assert.IsFalse(c.IsHandleCreated, "A5.1");
object o = c.AccessibilityObject;
Assert.IsTrue(c.IsHandleCreated, "A6");
// Tests to confirm that:
// - calling Control.AccessibleXXXXX is not returning AccessibleObject.XXXXX
// - Handle is not Created when calling Control.AccessibleXXXXX
c = new CustomA11yEnabledControl ();
string accessibleDefaultActionDescription = "default action description";
c.AccessibleDefaultActionDescription = accessibleDefaultActionDescription;
Assert.IsFalse (c.IsHandleCreated, "A7.0");
Assert.AreEqual (accessibleDefaultActionDescription, c.AccessibleDefaultActionDescription, "A7.1");
string accessibleDescription = "accessible description";
c.AccessibleDescription = accessibleDescription;
Assert.IsFalse (c.IsHandleCreated, "A8.0");
Assert.AreEqual (accessibleDescription, c.AccessibleDescription, "A8.1");
string accessibleName = "accessible name";
c.AccessibleName = accessibleName;
Assert.IsFalse (c.IsHandleCreated, "A9.0");
Assert.AreEqual (accessibleName, c.AccessibleName, "A9.1");
AccessibleRole accessibleRole = AccessibleRole.Diagram;
c.AccessibleRole = accessibleRole;
Assert.AreEqual (accessibleRole, c.AccessibleRole, "A10.0");
Assert.IsFalse (c.IsHandleCreated, "A10.1");
c.Dispose ();
Assert.IsFalse (c.Created, "A11");
}
[Test]
[Category ("NotWorking")]
public void BoundsTest ()
{
Control c = new Control ();
Assert.IsTrue (c.Bounds.IsEmpty, "A1");
Assert.IsTrue (c.Size.IsEmpty, "A2");
Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
/* this part fails on linux because we can't allocate X windows which are 0x0,
and the Control bounds directly reflect the size of the X window */
Assert.IsTrue (c.Bounds.IsEmpty, "A6");
Assert.IsTrue (c.Size.IsEmpty, "A7");
Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
}
[Test]
[Ignore ("Depends on specific DPI")]
public void FontHeightTest ()
{
MockControl c = new MockControl ();
Assert.AreEqual (13, c.font_height);
}
[Test]
public void FontTest ()
{
Control c = new Control ();
Assert.IsFalse (c.Font.Bold, "#A1");
//Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
Assert.IsFalse (c.Font.Italic, "#A3");
//Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
Assert.AreEqual (8.25, c.Font.Size, "#A5");
Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
Assert.IsFalse (c.Font.Strikeout, "#A7");
Assert.IsFalse (c.Font.Underline, "#A8");
Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
#if NET_2_0
Assert.IsTrue (c.Font.IsSystemFont, "#A10");
#endif
c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
Assert.IsFalse (c.Font.Bold, "#B1");
//Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
Assert.IsTrue (c.Font.Italic, "#B3");
//Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
Assert.AreEqual (3, c.Font.Size, "#B5");
Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
Assert.IsFalse (c.Font.Strikeout, "#B7");
Assert.IsFalse (c.Font.Underline, "#B8");
Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
#if NET_2_0
Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
#endif
}
[Test]
[Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
public void FontTest_Names ()
{
Control c = new Control ();
Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
}
[Test]
public void PubPropTest()
{
Control c = new Control();
Assert.IsFalse (c.AllowDrop , "A1");
Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
Assert.AreEqual ("Control", c.BackColor.Name , "B1");
Assert.IsNull (c.BackgroundImage, "B2");
Assert.IsNull (c.BindingContext, "B3");
#if NET_2_0
Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
#endif
Assert.IsFalse (c.CanFocus, "C1");
Assert.IsTrue (c.CanSelect, "C2");
Assert.IsFalse (c.Capture, "C3");
Assert.IsTrue (c.CausesValidation, "C4");
Assert.IsNotNull (c.CompanyName, "C7");
Assert.IsNull (c.Container, "C8");
Assert.IsFalse (c.ContainsFocus, "C9");
Assert.IsNull (c.ContextMenu, "C10");
Assert.AreEqual (0, c.Controls.Count, "C11");
Assert.IsFalse (c.Created, "C12");
Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
Assert.IsNotNull(c.DataBindings, "D1");
Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
Assert.IsFalse (c.Disposing, "D6");
Assert.AreEqual(DockStyle.None, c.Dock, "D7");
Assert.IsTrue (c.Enabled, "E1");
Assert.IsFalse (c.Focused, "F1");
Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
Assert.IsFalse (c.HasChildren, "H2");
Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
Assert.IsFalse (c.InvokeRequired, "I2");
Assert.IsFalse (c.IsAccessible, "I3");
Assert.IsFalse (c.IsDisposed, "I4");
Assert.IsFalse (c.IsHandleCreated, "I5");
Assert.AreEqual(Point.Empty, c.Location, "L2");
#if NET_2_0
Assert.IsTrue(c.MaximumSize.IsEmpty);
Assert.IsTrue(c.MinimumSize.IsEmpty);
#endif
Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
Assert.IsTrue (Control.MousePosition.X >= 0 && Control.MousePosition.Y >= 0, "M2");
Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
Assert.AreEqual("", c.Name, "N1");
c.Name = "Control Name";
Assert.AreEqual("Control Name", c.Name, "N2");
Assert.IsNull (c.Parent, "P1");
Assert.IsNotNull (c.ProductName, "P2");
Assert.IsTrue (c.ProductName != "", "P3");
Assert.IsNotNull (c.ProductVersion, "P4");
Assert.IsTrue (c.ProductVersion != "", "P5");
Assert.IsFalse (c.RecreatingHandle, "R1");
Assert.IsNull (c.Region, "R2");
Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
Assert.IsNull (c.Site, "S1");
Assert.AreEqual (0, c.TabIndex , "T1");
Assert.IsTrue (c.TabStop, "T2");
Assert.IsNull (c.Tag, "T3");
Assert.AreEqual ("", c.Text, "T4");
Assert.IsTrue (c.Visible, "V1");
}
[Test]
public void SizeChangeTest ()
{
Form f = new Form ();
Control c = new Control ();
f.Controls.Add(c);
f.Show();
c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
c.Tag = true;
c.Size = c.Size;
Assert.AreEqual (true, (bool) c.Tag, "#1");
f.Close ();
}
private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
{
((Control) sender).Tag = false;
}
[Test]
public void NegativeHeightTest ()
{
Control c = new Control ();
IntPtr handle = c.Handle;
c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
c.Tag = -2;
c.Height = 2;
c.Height = -2;
Assert.AreEqual (0, (int) c.Tag, "#1");
c.Dispose ();
Assert.AreEqual (handle, handle, "Removes warning.");
}
private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
{
Control c = (Control) sender;
c.Tag = c.Height;
}
[Test]
public void TopLevelControlTest () {
Control c = new Control ();
Assert.AreEqual(null, c.TopLevelControl, "T1");
Panel p = new Panel ();
p.Controls.Add (c);
Assert.AreEqual(null, c.TopLevelControl, "T2");
Form f = new Form ();
f.ShowInTaskbar = false;
f.Controls.Add (p);
Assert.AreEqual (f, c.TopLevelControl, "T3");
Assert.AreEqual (f, f.TopLevelControl, "T4");
f.Dispose ();
}
[Test]
public void RelationTest() {
Control c1;
Control c2;
c1 = new Control();
c2 = new Control();
Assert.AreEqual(true , c1.Visible , "Rel1");
Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
c1.Controls.Add(c2);
Assert.AreEqual(true , c2.Visible , "Rel4");
Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
c1.Anchor = AnchorStyles.Top;
c1.SuspendLayout ();
c1.Anchor = AnchorStyles.Left ;
c1.ResumeLayout ();
Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
c1.SetBounds(10, 20, 30, 40) ;
Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
Assert.AreEqual(c1, c2.Parent, "Rel8");
}
[Test]
public void AnchorDockTest ()
{
Control c = new Control ();
Assert.AreEqual (DockStyle.None, c.Dock, "1");
Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
c.Dock = DockStyle.Top;
Assert.AreEqual (DockStyle.Top, c.Dock, "3");
Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
c.Anchor = AnchorStyles.Top;
Assert.AreEqual (DockStyle.None, c.Dock, "5");
Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
}
[Test]
[Category ("NotWorking")]
public void TabOrder()
{
Form form;
//Control active;
Label label1 = new Label(); // To test non-tabstop items as well
Label label2 = new Label();
GroupBox group1 = new GroupBox();
GroupBox group2 = new GroupBox();
GroupBox group3 = new GroupBox();
TextBox text1 = new TextBox();
RadioButton radio11 = new RadioButton();
RadioButton radio12 = new RadioButton();
RadioButton radio13 = new RadioButton();
RadioButton radio14 = new RadioButton();
RadioButton radio21 = new RadioButton();
RadioButton radio22 = new RadioButton();
RadioButton radio23 = new RadioButton();
RadioButton radio24 = new RadioButton();
RadioButton radio31 = new RadioButton();
RadioButton radio32 = new RadioButton();
RadioButton radio33 = new RadioButton();
RadioButton radio34 = new RadioButton();
form = new Form();
form.ShowInTaskbar = false;
form.ClientSize = new Size (520, 520);
Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
form.Text = "SWF Taborder Test App Form";
Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
label1.Location = new Point(10, 10);
Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
label1.Text = "Label1";
form.Controls.Add(label1);
label2.Location = new Point(200, 10);
label2.Text = "Label2";
form.Controls.Add(label2);
group1.Text = "Group1";
group2.Text = "Group2";
group3.Text = "Group3";
group1.Size = new Size(200, 400);
group2.Size = new Size(200, 400);
group3.Size = new Size(180, 180);
Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
group1.Location = new Point(10, 40);
group2.Location = new Point(220, 40);
group3.Location = new Point(10, 210);
group1.TabIndex = 30;
Assert.AreEqual(30, group1.TabIndex, "Tab5");
group1.TabStop = true;
// Don't assign, test automatic assignment
//group2.TabIndex = 0;
group2.TabStop = true;
Assert.AreEqual(0, group2.TabIndex, "Tab6");
group3.TabIndex = 35;
group3.TabStop = true;
// Test default tab index
Assert.AreEqual(0, radio11.TabIndex, "Tab7");
text1.Text = "Edit Control";
radio11.Text = "Radio 1-1 [Tab1]";
radio12.Text = "Radio 1-2 [Tab2]";
radio13.Text = "Radio 1-3 [Tab3]";
radio14.Text = "Radio 1-4 [Tab4]";
radio21.Text = "Radio 2-1 [Tab4]";
radio22.Text = "Radio 2-2 [Tab3]";
radio23.Text = "Radio 2-3 [Tab2]";
radio24.Text = "Radio 2-4 [Tab1]";
radio31.Text = "Radio 3-1 [Tab1]";
radio32.Text = "Radio 3-2 [Tab3]";
radio33.Text = "Radio 3-3 [Tab2]";
radio34.Text = "Radio 3-4 [Tab4]";
// We don't assign TabIndex for radio1X; test automatic assignment
text1.TabStop = true;
radio11.TabStop = true;
radio21.TabIndex = 4;
radio22.TabIndex = 3;
radio23.TabIndex = 2;
radio24.TabIndex = 1;
radio24.TabStop = true;
radio31.TabIndex = 11;
radio31.TabStop = true;
radio32.TabIndex = 13;
radio33.TabIndex = 12;
radio34.TabIndex = 14;
text1.Location = new Point(10, 100);
radio11.Location = new Point(10, 20);
radio12.Location = new Point(10, 40);
radio13.Location = new Point(10, 60);
radio14.Location = new Point(10, 80);
radio21.Location = new Point(10, 20);
radio22.Location = new Point(10, 40);
radio23.Location = new Point(10, 60);
radio24.Location = new Point(10, 80);
radio31.Location = new Point(10, 20);
radio32.Location = new Point(10, 40);
radio33.Location = new Point(10, 60);
radio34.Location = new Point(10, 80);
text1.Size = new Size(150, text1.PreferredHeight);
radio11.Size = new Size(150, 20);
radio12.Size = new Size(150, 20);
radio13.Size = new Size(150, 20);
radio14.Size = new Size(150, 20);
radio21.Size = new Size(150, 20);
radio22.Size = new Size(150, 20);
radio23.Size = new Size(150, 20);
radio24.Size = new Size(150, 20);
radio31.Size = new Size(150, 20);
radio32.Size = new Size(150, 20);
radio33.Size = new Size(150, 20);
radio34.Size = new Size(150, 20);
group1.Controls.Add(text1);
group1.Controls.Add(radio11);
group1.Controls.Add(radio12);
group1.Controls.Add(radio13);
group1.Controls.Add(radio14);
group2.Controls.Add(radio21);
group2.Controls.Add(radio22);
group2.Controls.Add(radio23);
group2.Controls.Add(radio24);
group3.Controls.Add(radio31);
group3.Controls.Add(radio32);
group3.Controls.Add(radio33);
group3.Controls.Add(radio34);
form.Controls.Add(group1);
form.Controls.Add(group2);
group2.Controls.Add(group3);
// Perform some tests, the TabIndex stuff below will alter the outcome
Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
Assert.AreEqual(31, group2.TabIndex, "Tab9");
// Does the taborder of containers and non-selectable things change behaviour?
label1.TabIndex = 5;
label2.TabIndex = 4;
group1.TabIndex = 3;
group2.TabIndex = 1;
// Start verification
Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
// Sanity checks
Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
Assert.AreEqual(4, radio21.TabIndex, "Tab24");
Assert.AreEqual(1, radio11.TabIndex, "Tab25");
Assert.AreEqual(3, radio13.TabIndex, "Tab26");
Assert.AreEqual(35, group3.TabIndex, "Tab27");
Assert.AreEqual(1, group2.TabIndex, "Tab28");
Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
form.Dispose ();
}
[Test]
public void ScaleTest()
{
Control r1 = new Control();
r1.Width = 40;
r1.Height = 20;
r1.Scale(2);
Assert.AreEqual(80, r1.Width, "Scale1");
Assert.AreEqual(40, r1.Height, "Scale2");
}
#if NET_2_0
[Test]
public void ScaleChildrenTest ()
{
ScaleChildrenControl c = new ScaleChildrenControl ();
Assert.AreEqual (true, c.PublicScaleChildren, "A1");
}
private class ScaleChildrenControl : Control
{
public bool PublicScaleChildren {
get { return base.ScaleChildren; }
}
}
[Test]
public void ScaleControlTest ()
{
ScaleControl c = new ScaleControl ();
c.Location = new Point (5, 10);
c.Size = new Size (15, 20);
Assert.AreEqual (new Rectangle (5, 10, 15, 20), c.Bounds, "A1");
c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.All);
Assert.AreEqual (new Rectangle (8, 13, 22, 26), c.Bounds, "A2");
c.PublicScaleControl (new SizeF (2f, 1.5f), BoundsSpecified.Location);
Assert.AreEqual (new Rectangle (16, 20, 22, 26), c.Bounds, "A3");
c.PublicScaleControl (new SizeF (1.5f, 2f), BoundsSpecified.Size);
Assert.AreEqual (new Rectangle (16, 20, 33, 52), c.Bounds, "A4");
c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.Width);
Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A5");
c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.None);
Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A6");
// Test with ScaleChildren
c = new ScaleControl ();
c.Location = new Point (5, 10);
c.Size = new Size (50, 50);
Control c2 = new Control ();
c2.Location = new Point (15, 15);
c2.Size = new Size (25, 25);
c.Controls.Add (c2);
Assert.AreEqual (new Rectangle (5, 10, 50, 50), c.Bounds, "B1");
Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B2");
c.scale_children = false;
c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
Assert.AreEqual (new Rectangle (10, 20, 100, 100), c.Bounds, "B3");
Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B4");
c.scale_children = true;
// Will not scale children in ScaleControl
c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
Assert.AreEqual (new Rectangle (20, 40, 200, 200), c.Bounds, "B5");
Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B6");
// Does scale children in Scale
c.Scale (new SizeF (2f, 2f));
Assert.AreEqual (new Rectangle (40, 80, 400, 400), c.Bounds, "B7");
Assert.AreEqual (new Rectangle (30, 30, 50, 50), c2.Bounds, "B8");
}
[Test]
public void GetScaledBoundsTest ()
{
ScaleControl c = new ScaleControl ();
Rectangle r = new Rectangle (10, 20, 30, 40);
Assert.AreEqual (new Rectangle (20, 10, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
c.PublicSetTopLevel (true);
Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A7");
Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A8");
Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A9");
Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A10");
Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A11");
Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A12");
c = new ScaleControl ();
c.PublicSetStyle (ControlStyles.FixedHeight, true);
c.PublicSetStyle (ControlStyles.FixedWidth, true);
Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A13");
Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A14");
Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A15");
Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A16");
Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A17");
Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A18");
}
private class ScaleControl : Control
{
public bool scale_children = true;
public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
{
base.ScaleControl (factor, specified);
}
public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
{
return base.GetScaledBounds (bounds, factor, specified);
}
public void PublicSetStyle (ControlStyles flag, bool value)
{
base.SetStyle (flag, value);
}
public void PublicSetTopLevel (bool value)
{
base.SetTopLevel (value);
}
protected override bool ScaleChildren {
get { return scale_children; }
}
}
#endif
[Test] // Bug #347282
public void ScaleHierarchy ()
{
Form f = new Form ();
Panel p = new Panel ();
Button b = new Button ();
f.ClientSize = new Size (300, 300);
f.Controls.Add (p);
p.Controls.Add (b);
f.AutoScaleBaseSize = new Size (3, 11);
f.Show ();
// Due to font differences, all we can guarantee is that
// the button is larger that the default.
Assert.IsTrue (b.Width > 75, "A1");
Assert.IsTrue (b.Height > 23, "A2");
f.Dispose ();
}
class TestWindowTarget : IWindowTarget
{
public void OnHandleChange (IntPtr newHandle) {
}
public void OnMessage (ref Message m) {
}
}
[Test]
public void WindowTargetTest()
{
Control c = new Control ();
Assert.IsNotNull (c.WindowTarget, "WindowTarget1");
c.WindowTarget = null;
Assert.IsNull (c.WindowTarget, "WindowTarget2");
IWindowTarget existing_target = c.WindowTarget;
IWindowTarget new_target = new TestWindowTarget ();
c.WindowTarget = new_target;
Assert.AreSame (new_target, c.WindowTarget, "WindowTarget3");
TestHelper.RemoveWarning (existing_target);
}
[Test]
public void TextTest()
{
Control r1 = new Control();
r1.Text = "Hi" ;
Assert.AreEqual("Hi" , r1.Text , "Text1");
r1.ResetText();
Assert.AreEqual("" , r1.Text , "Text2");
}
[Test]
public void PubMethodTest7()
{
Control r1 = new Control();
r1.RightToLeft = RightToLeft.Yes ;
r1.ResetRightToLeft() ;
Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
r1.ImeMode = ImeMode.Off ;
r1.ResetImeMode () ;
Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
r1.ForeColor= SystemColors.GrayText ;
r1.ResetForeColor() ;
Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
//r1.Font = Font.FromHdc();
r1.ResetFont () ;
//Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
r1.Cursor = Cursors.Hand ;
r1.ResetCursor () ;
Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
//r1.DataBindings = System.Windows.Forms.Binding ;
//r1.ResetBindings() ;
//Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
r1.BackColor = Color.Black ;
r1.ResetBackColor() ;
Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
r1.BackColor = Color.Black ;
r1.Refresh() ;
Assert.AreEqual( null , r1.Region , "#85");
Rectangle M = new Rectangle(10, 20, 30 ,40);
r1.RectangleToScreen(M) ;
Assert.AreEqual( null , r1.Region , "#86");
}
[Test]
public void ScreenClientCoords()
{
Label l;
Point p1;
Point p2;
Point p3;
l = new Label();
l.Left = 10;
l.Top = 12;
l.Visible = true;
p1 = new Point (10,10);
p2 = l.PointToScreen(p1);
p3 = l.PointToClient(p2);
Assert.AreEqual (p1, p3, "SC1");
}
[Test]
public void ContainsTest ()
{
Control t = new Control ();
Control s = new Control ();
t.Controls.Add (s);
Assert.AreEqual (true, t.Contains (s), "Con1");
Assert.AreEqual (false, s.Contains (t), "Con2");
Assert.AreEqual (false, s.Contains (null), "Con3");
Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
}
[Test]
public void IsHandleCreated_NotVisible ()
{
Control c = new Control ();
c.Visible = false;
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (c);
form.Show ();
Assert.IsFalse (c.IsHandleCreated, "#1");
c.Visible = true;
Assert.IsTrue (c.IsHandleCreated, "#2");
c.Visible = false;
Assert.IsTrue (c.IsHandleCreated, "#3");
form.Close ();
}
class OnCreateControlTest : Control {
public bool reached = false;
protected override void OnCreateControl () {
reached = true;
}
}
[Test]
public void CreateControlVisibleTest ()
{
OnCreateControlTest test = new OnCreateControlTest ();
test.Visible = false;
Assert.IsFalse (test.IsHandleCreated, "0");
Assert.IsFalse (test.Visible, "1");
test.Visible = true;
Assert.IsTrue (test.Visible, "2");
Assert.IsTrue (test.reached, "3");
}
[Test]
public void CreateGraphicsTest ()
{
Graphics g = null;
Pen p = null;
try {
Control c = new Control ();
c.SetBounds (0,0, 20, 20);
g = c.CreateGraphics ();
Assert.IsNotNull (g, "Graph1");
} finally {
if (p != null)
p.Dispose ();
if (g != null)
g.Dispose ();
}
}
bool delegateCalled = false;
public delegate void TestDelegate ();
public void delegate_call () {
delegateCalled = true;
TestHelper.RemoveWarning (delegateCalled);
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void InvokeException1 () {
Control c = new Control ();
IAsyncResult result;
result = c.BeginInvoke (new TestDelegate (delegate_call));
c.EndInvoke (result);
}
[Test]
public void FindFormTest () {
Form f = new Form ();
f.ShowInTaskbar = false;
f.Name = "form";
Control c = null;
try {
f.Controls.Add (c = new Control ());
Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
f.Controls.Remove (c);
GroupBox g = new GroupBox ();
g.Name = "box";
f.Controls.Add (g);
g.Controls.Add (c);
Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
g.Controls.Remove (c);
Assert.IsNull(c.FindForm (), "Find3");
} finally {
if (c != null)
c.Dispose ();
if (f != null)
f.Dispose ();
}
}
[Test]
public void FocusTest ()
{
Form f = null;
Button c = null, d = null;
try {
f = new Form ();
f.ShowInTaskbar = false;
f.Visible = true;
c = new Button ();
c.Visible = true;
f.Controls.Add (c);
d = new Button ();
d.Visible = false;
f.Controls.Add (d);
Assert.IsTrue (c.CanFocus, "Focus1");
Assert.IsFalse (c.Focused, "Focus2");
c.Focus ();
Assert.IsTrue (c.Focused, "Focus3");
d.Focus ();
Assert.IsFalse (d.Focused, "Focus4");
d.Visible = true;
d.Focus ();
Assert.IsTrue (d.Focused, "Focus5");
Assert.IsFalse (c.Focused, "Focus6");
c.Enabled = false;
Assert.IsFalse (c.Focused, "Focus7");
} finally {
if (f != null)
f.Dispose ();
if (c != null)
c.Dispose ();
if (d != null)
d.Dispose ();
}
}
[Test]
public void FromHandleTest ()
{
Control c1 = null;
Control c2 = null;
try {
c1 = new Control ();
c2 = new Control ();
c1.Name = "parent";
c2.Name = "child";
c1.Controls.Add(c2);
// Handle
Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
// ChildHandle
Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
} finally {
if (c1 != null)
c1.Dispose ();
if (c2 != null)
c2.Dispose ();
}
}
[Test]
public void GetChildAtPointTest ()
{
Control c = null, d = null;
TransparentControl e = null;
try {
c = new Control ();
c.Name = "c1";
c.SetBounds (0, 0, 100, 100);
d = new Control ();
d.Name = "d1";
d.SetBounds (10, 10, 40, 40);
c.Controls.Add (d);
e = new TransparentControl ();
e.Name = "e1";
e.SetBounds (55, 55, 10, 10);
Control l = c.GetChildAtPoint (new Point (15, 15));
Assert.AreEqual (d.Name, l.Name, "Child1");
Assert.IsFalse (e.Name == l.Name, "Child2");
l = c.GetChildAtPoint (new Point (57, 57));
Assert.AreEqual (null, l, "Child3");
l = c.GetChildAtPoint (new Point (10, 10));
Assert.AreEqual (d.Name, l.Name, "Child4");
// GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
#if NET_2_0
c.Controls.Add (e);
e.Visible = false;
l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
Assert.IsNull (l, "Child5");
e.Visible = true;
l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
Assert.AreSame (e.Name, l.Name, "Child6");
e.Enabled = false;
l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
Assert.IsNull (l, "Child7");
e.Enabled = true;
l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
Assert.AreSame (e.Name, l.Name, "Child8");
e.BackColor = Color.Transparent;
l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
Assert.IsNull (l, "Child9");
e.BackColor = Color.Green;
l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
Assert.AreSame (e.Name, l.Name, "Child10");
#endif // NET_2_0
} finally {
if (c != null)
c.Dispose ();
if (d != null)
d.Dispose ();
}
}
private class TransparentControl : Control
{
public TransparentControl ()
{
SetStyle (ControlStyles.SupportsTransparentBackColor, true);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020;
return cp;
}
}
}
[Test]
public void ResetFontTest ()
{
Control c = new Control ();
c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
c.ResetFont ();
Assert.IsFalse (c.Font.Bold, "#1");
//Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
Assert.IsFalse (c.Font.Italic, "#3");
//Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
Assert.AreEqual (8.25, c.Font.Size, "#5");
Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
Assert.IsFalse (c.Font.Strikeout, "#7");
Assert.IsFalse (c.Font.Underline, "#8");
Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
#if NET_2_0
Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
#endif
}
public class LayoutTestControl : Control {
public int LayoutCount;
public LayoutTestControl () : base() {
LayoutCount = 0;
}
protected override void OnLayout(LayoutEventArgs levent) {
LayoutCount++;
base.OnLayout (levent);
}
}
[Test]
public void LayoutTest() {
LayoutTestControl c;
c = new LayoutTestControl();
c.SuspendLayout();
c.SuspendLayout();
c.SuspendLayout();
c.SuspendLayout();
c.ResumeLayout(true);
c.PerformLayout();
c.ResumeLayout(true);
c.PerformLayout();
c.ResumeLayout(true);
c.PerformLayout();
c.ResumeLayout(true);
c.PerformLayout();
c.ResumeLayout(true);
c.PerformLayout();
c.ResumeLayout(true);
c.PerformLayout();
c.ResumeLayout(true);
c.PerformLayout();
c.SuspendLayout();
c.PerformLayout();
Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void TransparentBackgroundTest1() {
Control c;
c = new Control();
c.BackColor = Color.Transparent;
}
[Test]
public void TransparentBackgroundTest2() {
Panel c;
c = new Panel();
c.BackColor = Color.Transparent;
Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
}
[Test]
public void TransparentBackgroundTest3() {
Control c;
c = new Control();
c.BackColor = Color.Empty;
Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
}
[Test]
public void Dock_Value_Invalid ()
{
Control c = new Control ();
try {
c.Dock = (DockStyle) 666;
Assert.Fail ("#1");
} catch (InvalidEnumArgumentException ex) {
Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
Assert.IsNotNull (ex.Message, "#3");
Assert.IsNotNull (ex.ParamName, "#4");
Assert.AreEqual ("value", ex.ParamName, "#5");
Assert.IsNull (ex.InnerException, "#6");
}
}
[Test]
public void EnabledTest1() {
Control child;
Control parent;
Control grandma;
grandma = new Control();
parent = new Control();
child = new Control();
grandma.Controls.Add(parent);
parent.Controls.Add(child);
grandma.Enabled = false;
Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
}
int EnabledCalledCount = 0;
private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
EnabledCalledCount++;
}
[Test]
public void EnabledTest2() {
// Check nesting of enabled calls
// OnEnabled is not called for disabled child controls
Control child;
Control parent;
Control grandma;
EnabledCalledCount = 0;
grandma = new Control();
parent = new Control();
child = new Control();
child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
grandma.Controls.Add(parent);
parent.Controls.Add(child);
grandma.Enabled = false;
Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
grandma.Enabled = true;
Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
child.Enabled = false;
grandma.Enabled = false;
Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
}
[Test]
public void ControlsRemoveNullTest ()
{
Control c = new Control ();
c.Controls.Remove (null);
}
[Test]
public void ControlsAddNullTest ()
{
Control c = new Control ();
c.Controls.Add (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ControlsSetChildIndexNullTest ()
{
Control c = new Control ();
c.Controls.SetChildIndex (null, 1);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ControlsAddRangeNullTest ()
{
Control c = new Control ();
c.Controls.AddRange (null);
}
[Test]
public void ControlsAddRangeNullElementTest ()
{
Control c = new Control ();
Control[] subcontrols = new Control[2];
subcontrols[0] = new Control ();
subcontrols[1] = null;
c.Controls.AddRange (subcontrols);
}
[Test]
public void RegionTest () {
Form f = new Form ();
f.ShowInTaskbar = false;
Control c = new Control ();
f.Controls.Add (c);
Assert.IsNull (c.Region, "#A1");
f.Show ();
Assert.IsNull (c.Region, "#A2");
c.Region = null;
Assert.IsNull (c.Region, "#A3");
f.Dispose ();
Region region = new Region ();
f = new Form ();
f.ShowInTaskbar = false;
c = new Control ();
f.Controls.Add (c);
c.Region = region;
Assert.IsNotNull (c.Region, "#B1");
Assert.AreSame (region, c.Region, "#B2");
f.Show ();
c.Region = null;
Assert.IsNull (c.Region, "#B3");
f.Dispose ();
}
[Test] // bug #330501
public void OnValidating_Parent_Close ()
{
MockControl control = new MockControl ();
Form f = new Form ();
f.Controls.Add (control);
f.ShowInTaskbar = false;
f.Show ();
Assert.AreEqual (0, control.OnValidatingCount, "#A1");
f.Close ();
Assert.AreEqual (1, control.OnValidatingCount, "#A2");
f.Dispose ();
}
[Test] // bug #80280
public void Validated_Multiple_Containers ()
{
Form form = new Form ();
form.ShowInTaskbar = false;
UserControl control1 = new UserControl();
UserControl container1 = new UserControl();
control1.Tag = true;
control1.Validated += new EventHandler (Control_ValidatedHandler);
container1.Controls.Add(control1);
form.Controls.Add (container1);
UserControl container2 = new UserControl();
UserControl control2 = new UserControl();
container2.Controls.Add(control2);
form.Controls.Add (container2);
Assert.IsTrue ((bool) control1.Tag, "#1");
control1.Select();
Assert.IsTrue ((bool) control1.Tag, "#2");
control2.Select();
Assert.IsFalse ((bool) control1.Tag, "#3");
form.Dispose ();
}
private void Control_ValidatedHandler (object sender, EventArgs e)
{
((Control) sender).Tag = false;
}
[Test]
public void ControlReparentLocationTest ()
{
Form form = new Form ();
Label l = new Label ();
l.Location = new Point (0, 0);
form.Controls.Add (l);
form.Show ();
Assert.AreEqual (0, l.Left, "#A1");
Assert.AreEqual (0, l.Top, "#A2");
form.Hide ();
form.Controls.Remove (l);
form.Show ();
form.Controls.Add (l);
Assert.AreEqual (0, l.Left, "#A3");
Assert.AreEqual (0, l.Top, "#A4");
form.Dispose ();
}
#if NET_2_0
[Test]
public void UseWaitCursorTest ()
{
Control c = new Control ();
Assert.IsFalse (c.UseWaitCursor, "#1");
c.Cursor = Cursors.Hand;
c.UseWaitCursor = true;
Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#2");
c.UseWaitCursor = false;
Assert.AreEqual (Cursors.Hand, c.Cursor, "#3");
c.UseWaitCursor = true;
c.Cursor = Cursors.Help;
Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#4");
Assert.AreEqual (true, c.UseWaitCursor, "#5");
c.UseWaitCursor = false;
Assert.AreEqual (Cursors.Help, c.Cursor, "#6");
}
[Test] // bug #80621, #81125
public void DontCallSizeFromClientSize ()
{
SizeControl sc = new SizeControl ();
Assert.AreEqual (0, sc.size_from_client_size_count, "A1");
sc.ClientSize = new Size (300, 300);
Assert.AreEqual (0, sc.size_from_client_size_count, "A2");
SizeForm sf = new SizeForm ();
sf.ShowInTaskbar = false;
sf.Show ();
Assert.AreEqual (0, sc.size_from_client_size_count, "A3");
sc.ClientSize = new Size (300, 300);
Assert.AreEqual (0, sc.size_from_client_size_count, "A4");
sf.Dispose ();
}
private class SizeControl : Control
{
public int size_from_client_size_count = 0;
protected override Size SizeFromClientSize (Size clientSize)
{
size_from_client_size_count++;
return base.SizeFromClientSize (clientSize);
}
}
private class SizeForm : Form
{
public int size_from_client_size_count = 0;
protected override Size SizeFromClientSize (Size clientSize)
{
size_from_client_size_count++;
return base.SizeFromClientSize (clientSize);
}
}
#endif
public class MockControl : Control
{
public int OnValidatingCount;
public int OnSizeChangedCount;
public int OnResizeCount;
public int OnLocationChangedCount;
public MockControl ()
{
}
public MockControl (string text)
: base (text)
{
}
public MockControl (Control parent, string text)
: base (parent, text)
{
}
public MockControl (string text, int left, int top, int width, int height)
: base (text, left, top, width, height)
{
}
public MockControl (Control parent, string text, int left, int top, int width, int height)
: base (parent, text, left, top, width, height)
{
}
public int font_height
{
get { return base.FontHeight; }
set { base.FontHeight = value; }
}
protected override void OnLocationChanged (EventArgs e)
{
OnLocationChangedCount++;
base.OnLocationChanged (e);
}
protected override void OnSizeChanged (EventArgs e)
{
OnSizeChangedCount++;
base.OnSizeChanged (e);
}
protected override void OnResize (EventArgs e)
{
OnResizeCount++;
base.OnResize (e);
}
protected override void OnValidating (CancelEventArgs e)
{
OnValidatingCount++;
}
}
const int WM_KEYDOWN = 0x0100;
const int WM_CHAR = 0x0102;
const int WM_SYSCHAR = 0x0106;
const int WM_KEYUP = 0x0101;
#if NET_2_0
[Test]
public void MethodPreProcessControlMessage ()
{
bool testing_callstack = false;
MyControl c = new MyControl ();
Message m = new Message ();
m.HWnd = c.Handle;
m.Msg = WM_KEYDOWN;
m.WParam = (IntPtr)Keys.Down;
m.LParam = IntPtr.Zero;
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A1");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.OnPreviewKeyDown);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A2");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessCmdKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A3");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A4");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A5");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
m.Msg = WM_CHAR;
c.SetState (State.None);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A6");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A7");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A8");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
m.Msg = WM_SYSCHAR;
c.SetState (State.None);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A9");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A10");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A11");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
m.Msg = WM_KEYUP;
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A12");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.OnPreviewKeyDown);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A13");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessCmdKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A14");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A15");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A16");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
}
#endif
[Test]
public void MethodPreProcessMessage ()
{
bool testing_callstack = false;
MyControl c = new MyControl ();
Message m = new Message ();
m.HWnd = c.Handle;
m.Msg = WM_KEYDOWN;
m.WParam = (IntPtr)Keys.Down;
m.LParam = IntPtr.Zero;
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A1");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.OnPreviewKeyDown);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A2");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessCmdKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (true, c.PreProcessMessage (ref m), "A3");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A4");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (true, c.PreProcessMessage (ref m), "A5");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
m.Msg = WM_CHAR;
c.SetState (State.None);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A6");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A7");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (true, c.PreProcessMessage (ref m), "A8");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
m.Msg = WM_SYSCHAR;
c.SetState (State.None);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A9");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A10");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogChar);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (true, c.PreProcessMessage (ref m), "A11");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
m.Msg = WM_KEYUP;
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A12");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.OnPreviewKeyDown);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A13");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessCmdKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A14");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.IsInputKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A15");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
c.SetState (State.ProcessDialogKey);
if (testing_callstack) Console.WriteLine ("Start");
Assert.AreEqual (false, c.PreProcessMessage (ref m), "A16");
if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
}
private enum State
{
None,
ProcessCmdKey,
OnPreviewKeyDown,
IsInputChar,
IsInputKey,
PreProcessMessage,
ProcessDialogKey,
ProcessDialogChar
}
private class MyControl : Control
{
private State current_state;
bool testing_callstack = false;
public void SetState (State state)
{
current_state = state;
}
protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
{
if (testing_callstack) Console.Write ("ProcessCmdKey[");
if (current_state == State.ProcessCmdKey) {
if (testing_callstack) Console.WriteLine ("]");
return true;
}
bool retval = base.ProcessCmdKey (ref msg, keyData);
if (testing_callstack) Console.WriteLine ("]");
return retval;
}
#if NET_2_0
protected override void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
{
if (testing_callstack) Console.Write ("OnPreviewKeyDown[");
if (current_state == State.OnPreviewKeyDown) {
e.IsInputKey = true;
if (testing_callstack) Console.WriteLine ("]");
return;
}
base.OnPreviewKeyDown (e);
if (testing_callstack) Console.WriteLine ("]");
}
#endif
protected override bool IsInputChar (char charCode)
{
if (testing_callstack) Console.Write ("IsInputChar[");
if (current_state == State.IsInputChar) {
if (testing_callstack) Console.WriteLine ("true]");
return true;
}
bool retval = base.IsInputChar (charCode);
if (testing_callstack) Console.WriteLine ("{0}]", retval.ToString ());
return retval;
}
protected override bool IsInputKey (Keys keyData)
{
if (testing_callstack) Console.Write ("IsInputKey[");
if (current_state == State.IsInputKey) {
if (testing_callstack) Console.WriteLine ("]");
return true;
}
bool retval = base.IsInputKey (keyData);
if (testing_callstack) Console.WriteLine ("]");
return retval;
}
public override bool PreProcessMessage (ref Message msg)
{
if (testing_callstack) Console.Write ("PreProcessMessage[");
if (current_state == State.PreProcessMessage) {
if (testing_callstack) Console.WriteLine ("]");
return true;
}
bool retval = base.PreProcessMessage (ref msg);
if (testing_callstack) Console.WriteLine ("]");
return retval;
}
protected override bool ProcessDialogKey (Keys keyData)
{
if (testing_callstack) Console.Write ("ProcessDialogKey[");
if (current_state == State.ProcessDialogKey) {
if (testing_callstack) Console.WriteLine ("]");
return true;
}
bool retval = base.ProcessDialogKey (keyData);
if (testing_callstack) Console.WriteLine ("]");
return retval;
}
protected override bool ProcessDialogChar (char charCode)
{
if (testing_callstack) Console.Write ("ProcessDialogChar[");
if (current_state == State.ProcessDialogChar) {
if (testing_callstack) Console.WriteLine ("]");
return true;
}
bool retval = base.ProcessDialogChar (charCode);
if (testing_callstack) Console.WriteLine ("]");
return retval;
}
}
[Test]
public void MethodIsInputChar ()
{
// Basically, show that this method always returns false
InputCharControl m = new InputCharControl ();
bool result = false;
for (int i = 0; i < 256; i++)
result |= m.PublicIsInputChar ((char)i);
Assert.AreEqual (false, result, "I1");
}
private class InputCharControl : Control
{
public bool PublicIsInputChar (char charCode)
{
return base.IsInputChar (charCode);
}
}
[Test] // bug #81118, 81718
public void VisibleTriggersLayout ()
{
Form f = new Form ();
f.ShowInTaskbar = false;
Control c = new Control ();
c.Visible = false;
f.Controls.Add (c);
c.Dock = DockStyle.Fill;
c.Visible = true;
Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
f.Dispose ();
}
[Test]
public void ResumeLayoutEffects ()
{
Form f = new Form ();
f.ShowInTaskbar = false;
f.ClientSize = new Size (300, 300);
Button button1 = new Button ();
f.Controls.Add (button1);
button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
button1.Location = new Point (f.ClientSize.Width - button1.Width, f.ClientSize.Height - button1.Height);
f.Show ();
Assert.AreEqual (new Point (225, 277), button1.Location, "A1");
f.SuspendLayout ();
f.Height += 10;
f.ResumeLayout (false);
f.PerformLayout ();
Assert.AreEqual (new Point (225, 277), button1.Location, "A2");
f.SuspendLayout ();
f.Height += 10;
f.ResumeLayout ();
Assert.AreEqual (new Point (225, 287), button1.Location, "A3");
f.Dispose ();
}
[Test]
public void DisposeEnumerator ()
{
// We can modify the collection while looping through it without crashing
Control c = new Control ();
c.Controls.Add (new Control ());
c.Controls.Add (new Control ());
foreach (Control c1 in c.Controls)
c.Controls.Remove (c1);
}
[Test]
public void MethodSetBounds ()
{
Control myControl = new Control();
myControl.SetBounds(10, 20, 30, 40);
myControl.SetBounds(50, 60, 70, 70, BoundsSpecified.Location);
Assert.AreEqual (new Rectangle (50, 60, 30, 40), myControl.Bounds, "A1");
}
[Test]
public void Bug386450 ()
{
// Should not crash. We have to check for the font object
// being different, not just if they represent the same font.
Form f = new Form ();
Label l = new Label ();
l.Text = "Hello";
Font f1 = new Font ("Arial", 12);
Font f2 = new Font ("Arial", 12);
l.Font = f1;
l.Font = f2;
f1.Dispose ();
f.Controls.Add (l);
f.Show ();
f.Dispose ();
}
[Test]
public void DisplayRectangle_SamePadding ()
{
// The MSDN documentation says that for a control ClientRectangle == DisplayRectangle
using (var c = new Control ())
{
c.Size = new Size (100, 100);
c.Padding = new Padding (4);
Assert.AreEqual (new Rectangle (0, 0, 100, 100), c.ClientRectangle);
Assert.AreEqual (c.ClientRectangle, c.DisplayRectangle);
}
}
[Test]
public void Remove_NoChangeIfNoChild () // #19818
{
var c1 = new Control();
var c2 = new Control();
var c3 = new Control();
c2.Controls.Add(c3);
c1.Controls.Add(c2);
Assert.AreEqual (c2, c3.Parent);
c1.Controls.Remove(c3);
Assert.AreEqual (c2, c3.Parent);
}
}
[TestFixture]
public class ControlSetTopLevelTest : TestHelper
{
class ControlPoker : Control {
public void DoSetTopLevel ()
{
SetTopLevel (true);
}
public bool DoGetTopLevel ()
{
return GetTopLevel ();
}
}
[Test]
public void TestControl ()
{
ControlPoker c = new ControlPoker ();
c.Visible = false;
c.DoSetTopLevel ();
Assert.IsTrue (c.DoGetTopLevel (), "1");
Assert.IsFalse (c.Visible, "2");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TestChildControl ()
{
Control c1 = new Control();
ControlPoker c2 = new ControlPoker ();
c1.Controls.Add (c2);
c2.DoSetTopLevel ();
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TestTopLevelAdd () {
Form f = new Form();
Form f1 = new Form();
f.Controls.Add(f1);
}
[Test]
[Category ("NotWorking")]
public void TestForm ()
{
Form f = new Form ();
Assert.IsFalse (f.Visible, "3");
f.TopLevel = true;
Assert.IsFalse (f.Visible, "4");
f.Dispose ();
}
}
[TestFixture]
public class ControlResizeLayoutTest : TestHelper
{
class ControlPoker : Control {
public void DoOnResize ()
{
OnResize (EventArgs.Empty);
}
}
int child_event;
string child_affected_property;
void ChildLayoutEvent (object sender, LayoutEventArgs e)
{
child_event ++;
child_affected_property = e.AffectedProperty;
}
int parent_event;
string parent_affected_property;
void ParentLayoutEvent (object sender, LayoutEventArgs e)
{
parent_event ++;
parent_affected_property = e.AffectedProperty;
TestHelper.RemoveWarning (parent_affected_property);
}
[Test]
public void Test ()
{
Panel p = new Panel ();
ControlPoker c = new ControlPoker();
p.Controls.Add (c);
p.Layout += new LayoutEventHandler (ParentLayoutEvent);
c.Layout += new LayoutEventHandler (ChildLayoutEvent);
c.DoOnResize ();
Assert.AreEqual (1, child_event, "1");
Assert.AreEqual ("Bounds", child_affected_property, "2");
Assert.AreEqual (0, parent_event, "3");
}
}
[TestFixture]
[Category ("NotWorking")]
public class ControlInvokeTest : TestHelper {
[TearDown]
protected override void TearDown ()
{
if (f != null && !f.IsDisposed)
f.Dispose ();
base.TearDown ();
}
public delegate void TestDelegate ();
Form f;
Control c;
Thread control_t;
ApplicationContext control_context;
bool delegateCalled = false;
bool threadDied = false;
object m;
void CreateControl ()
{
try {
f = new Form ();
f.ShowInTaskbar = false;
c = new Control ();
f.Controls.Add (c);
Console.WriteLine ("f.Handle = {0}", f.Handle);
Console.WriteLine ("c.Handle = {0}", c.Handle);
control_context = new ApplicationContext (f);
Monitor.Enter (m);
Console.WriteLine ("pulsing");
Monitor.Pulse (m);
Monitor.Exit (m);
Console.WriteLine ("control thread running");
Application.Run (control_context);
c.Dispose ();
Console.WriteLine ("dying");
threadDied = true;
Monitor.Enter (m);
Console.WriteLine ("pulsing again");
Monitor.Pulse (m);
Monitor.Exit (m);
} catch (Exception e) { Console.WriteLine (e); }
}
[Test]
public void InvokeTest ()
{
m = new object ();
control_t = new Thread(new ThreadStart(CreateControl));
Monitor.Enter (m);
control_t.Start ();
Console.WriteLine ("waiting on monitor");
Monitor.Wait (m);
Console.WriteLine ("making async call");
IAsyncResult result;
result = c.BeginInvoke (new TestDelegate (delegate_call));
c.EndInvoke (result);
Assert.IsTrue (delegateCalled, "Invoke1");
Monitor.Wait (m);
Assert.IsTrue (threadDied, "Invoke2");
}
public void delegate_call () {
try {
/* invoked on control_context's thread */
delegateCalled = true;
f.Dispose ();
Console.WriteLine ("calling Application.Exit");
control_context.ExitThread ();
} catch (Exception e) { Console.WriteLine (e); }
}
}
[TestFixture]
public class ControlWMTest : TestHelper
{
[Test]
public void WM_PARENTNOTIFY_Test ()
{
WMTester tester;
Control child;
int child_handle;
tester = new WMTester ();
child = new Control ();
tester.Controls.Add (child);
tester.Visible = true;
child.Visible = true;
child_handle = child.Handle.ToInt32 ();
ArrayList msgs;
Message m1;
msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
Assert.AreEqual (1, msgs.Count, "#1");
m1 = (Message) msgs [0];
Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
//Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
child.Dispose ();
msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
Assert.AreEqual (2, msgs.Count, "#5");
m1 = (Message) msgs [1];
Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
//Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
tester.Dispose ();
}
internal static int LowOrder (int param)
{
return ((int)(short)(param & 0xffff));
}
internal static int HighOrder (int param)
{
return ((int)(short)(param >> 16));
}
internal static int LowOrder (IntPtr param)
{
return ((int)(short)(param.ToInt32 () & 0xffff));
}
internal static int HighOrder (IntPtr param)
{
return ((int)(short)(param.ToInt32 () >> 16));
}
internal class WMTester : Form
{
internal ArrayList Messages = new ArrayList ();
internal bool Contains (WndMsg msg)
{
return Contains (msg, Messages);
}
internal bool Contains (WndMsg msg, ArrayList list)
{
foreach (Message m in Messages)
{
if (m.Msg == (int) msg)
return true;
}
return false;
}
internal ArrayList Find (WndMsg msg)
{
ArrayList result = new ArrayList ();
foreach (Message m in Messages)
{
if (m.Msg == (int) msg)
result.Add (m);
}
return result;
}
protected override void WndProc(ref Message m)
{
Console.WriteLine ("WndProc: " + m.ToString ());
Messages.Add (m);
base.WndProc (ref m);
}
}
}
#if NET_2_0
[TestFixture]
public class ControlLayoutTest : TestHelper
{
[SetUp]
protected override void SetUp ()
{
_layoutCount = 0;
base.SetUp ();
}
[Test] // bug #80456
public void LayoutTest ()
{
MockLayoutEngine layoutEngine = new MockLayoutEngine ();
MockControl c = new MockControl (layoutEngine);
c.Layout += new LayoutEventHandler (LayoutEvent);
Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
Assert.AreEqual (0, _layoutCount, "#A2");
c.PerformLayout ();
Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
Assert.AreEqual (1, _layoutCount, "#A4");
layoutEngine.Reset ();
c.OverrideOnLayout = true;
Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
c.PerformLayout ();
Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
Assert.AreEqual (1, _layoutCount, "#B3");
}
void LayoutEvent (object sender, LayoutEventArgs e)
{
_layoutCount++;
}
private int _layoutCount;
class MockControl : Control
{
public MockControl (LayoutEngine layoutEngine)
{
_layoutEngine = layoutEngine;
}
public bool OverrideOnLayout
{
get { return _overrideOnLayout; }
set { _overrideOnLayout = value; }
}
protected override void OnLayout (LayoutEventArgs levent)
{
if (!OverrideOnLayout)
base.OnLayout (levent);
}
public override LayoutEngine LayoutEngine {
get {
if (_layoutEngine == null)
return base.LayoutEngine;
return _layoutEngine;
}
}
private bool _overrideOnLayout;
private LayoutEngine _layoutEngine;
}
class MockLayoutEngine : LayoutEngine
{
public bool LayoutInvoked {
get { return _layoutInvoked; }
}
public void Reset ()
{
_layoutInvoked = false;
}
public override bool Layout (object container, LayoutEventArgs args)
{
_layoutInvoked = true;
return true;
}
private bool _layoutInvoked;
}
}
#endif
}
|