[corlib] Fix a few NSLogWriter issues. (#13799)
[mono-project.git] / mcs / tests / test-49.cs
blob9800ffd3d61399cbed524df4108aae3f89d538d0
1 //
2 // This tests excercises a number of switch things:
3 //
4 // Code to test for multiple-labels is different that
5 // code for a single label.
6 //
7 // Code for switching on strings is different from the integer
8 // code.
9 //
10 // nulls (for strings) need to be handled specially since ceq will
11 // throw an exception if there.
13 // null as a case statement needs to be caught specially
14 //
15 using System;
17 class X {
18 enum A {
19 a = 23333,
21 public const string One = "one";
23 static int s (byte b)
25 switch (b){
26 case 0: return 255-0;
27 case 1: return 255-1;
28 case 2: return 255-2;
29 case 3: return 255-3;
30 case 4: return 255-4;
31 case 5: return 255-5;
32 case 6: return 255-6;
33 case 7: return 255-7;
34 case 8: return 255-8;
35 case 9: return 255-9;
36 case 10: return 255-10;
37 case 11: return 255-11;
38 case 12: return 255-12;
39 case 13: return 255-13;
40 case 14: return 255-14;
41 case 15: return 255-15;
42 case 16: return 255-16;
43 case 17: return 255-17;
44 case 18: return 255-18;
45 case 19: return 255-19;
46 case 20: return 255-20;
47 case 21: return 255-21;
48 case 22: return 255-22;
49 case 23: return 255-23;
50 case 24: return 255-24;
51 case 25: return 255-25;
52 case 26: return 255-26;
53 case 27: return 255-27;
54 case 28: return 255-28;
55 case 29: return 255-29;
56 case 30: return 255-30;
57 case 31: return 255-31;
58 case 32: return 255-32;
59 case 33: return 255-33;
60 case 34: return 255-34;
61 case 35: return 255-35;
62 case 36: return 255-36;
63 case 37: return 255-37;
64 case 38: return 255-38;
65 case 39: return 255-39;
66 case 40: return 255-40;
67 case 41: return 255-41;
68 case 42: return 255-42;
69 case 43: return 255-43;
70 case 44: return 255-44;
71 case 45: return 255-45;
72 case 46: return 255-46;
73 case 47: return 255-47;
74 case 48: return 255-48;
75 case 49: return 255-49;
76 case 50: return 255-50;
77 case 51: return 255-51;
78 case 52: return 255-52;
79 case 53: return 255-53;
80 case 54: return 255-54;
81 case 55: return 255-55;
82 case 56: return 255-56;
83 case 57: return 255-57;
84 case 58: return 255-58;
85 case 59: return 255-59;
86 case 60: return 255-60;
87 case 61: return 255-61;
88 case 62: return 255-62;
89 case 63: return 255-63;
90 case 64: return 255-64;
91 case 65: return 255-65;
92 case 66: return 255-66;
93 case 67: return 255-67;
94 case 68: return 255-68;
95 case 69: return 255-69;
96 case 70: return 255-70;
97 case 71: return 255-71;
98 case 72: return 255-72;
99 case 73: return 255-73;
100 case 74: return 255-74;
101 case 75: return 255-75;
102 case 76: return 255-76;
103 case 77: return 255-77;
104 case 78: return 255-78;
105 case 79: return 255-79;
106 case 80: return 255-80;
107 case 81: return 255-81;
108 case 82: return 255-82;
109 case 83: return 255-83;
110 case 84: return 255-84;
111 case 85: return 255-85;
112 case 86: return 255-86;
113 case 87: return 255-87;
114 case 88: return 255-88;
115 case 89: return 255-89;
116 case 90: return 255-90;
117 case 91: return 255-91;
118 case 92: return 255-92;
119 case 93: return 255-93;
120 case 94: return 255-94;
121 case 95: return 255-95;
122 case 96: return 255-96;
123 case 97: return 255-97;
124 case 98: return 255-98;
125 case 99: return 255-99;
126 case 100: return 255-100;
127 case 101: return 255-101;
128 case 102: return 255-102;
129 case 103: return 255-103;
130 case 104: return 255-104;
131 case 105: return 255-105;
132 case 106: return 255-106;
133 case 107: return 255-107;
134 case 108: return 255-108;
135 case 109: return 255-109;
136 case 110: return 255-110;
137 case 111: return 255-111;
138 case 112: return 255-112;
139 case 113: return 255-113;
140 case 114: return 255-114;
141 case 115: return 255-115;
142 case 116: return 255-116;
143 case 117: return 255-117;
144 case 118: return 255-118;
145 case 119: return 255-119;
146 case 120: return 255-120;
147 case 121: return 255-121;
148 case 122: return 255-122;
149 case 123: return 255-123;
150 case 124: return 255-124;
151 case 125: return 255-125;
152 case 126: return 255-126;
153 case 127: return 255-127;
154 case 128: return 255-128;
155 case 129: return 255-129;
156 case 130: return 255-130;
157 case 131: return 255-131;
158 case 132: return 255-132;
159 case 133: return 255-133;
160 case 134: return 255-134;
161 case 135: return 255-135;
162 case 136: return 255-136;
163 case 137: return 255-137;
164 case 138: return 255-138;
165 case 139: return 255-139;
166 case 140: return 255-140;
167 case 141: return 255-141;
168 case 142: return 255-142;
169 case 143: return 255-143;
170 case 144: return 255-144;
171 case 145: return 255-145;
172 case 146: return 255-146;
173 case 147: return 255-147;
174 case 148: return 255-148;
175 case 149: return 255-149;
176 case 150: return 255-150;
177 case 151: return 255-151;
178 case 152: return 255-152;
179 case 153: return 255-153;
180 case 154: return 255-154;
181 case 155: return 255-155;
182 case 156: return 255-156;
183 case 157: return 255-157;
184 case 158: return 255-158;
185 case 159: return 255-159;
186 case 160: return 255-160;
187 case 161: return 255-161;
188 case 162: return 255-162;
189 case 163: return 255-163;
190 case 164: return 255-164;
191 case 165: return 255-165;
192 case 166: return 255-166;
193 case 167: return 255-167;
194 case 168: return 255-168;
195 case 169: return 255-169;
196 case 170: return 255-170;
197 case 171: return 255-171;
198 case 172: return 255-172;
199 case 173: return 255-173;
200 case 174: return 255-174;
201 case 175: return 255-175;
202 case 176: return 255-176;
203 case 177: return 255-177;
204 case 178: return 255-178;
205 case 179: return 255-179;
206 case 180: return 255-180;
207 case 181: return 255-181;
208 case 182: return 255-182;
209 case 183: return 255-183;
210 case 184: return 255-184;
211 case 185: return 255-185;
212 case 186: return 255-186;
213 case 187: return 255-187;
214 case 188: return 255-188;
215 case 189: return 255-189;
216 case 190: return 255-190;
217 case 191: return 255-191;
218 case 192: return 255-192;
219 case 193: return 255-193;
220 case 194: return 255-194;
221 case 195: return 255-195;
222 case 196: return 255-196;
223 case 197: return 255-197;
224 case 198: return 255-198;
225 case 199: return 255-199;
226 case 200: return 255-200;
227 case 201: return 255-201;
228 case 202: return 255-202;
229 case 203: return 255-203;
230 case 204: return 255-204;
231 case 205: return 255-205;
232 case 206: return 255-206;
233 case 207: return 255-207;
234 case 208: return 255-208;
235 case 209: return 255-209;
236 case 210: return 255-210;
237 case 211: return 255-211;
238 case 212: return 255-212;
239 case 213: return 255-213;
240 case 214: return 255-214;
241 case 215: return 255-215;
242 case 216: return 255-216;
243 case 217: return 255-217;
244 case 218: return 255-218;
245 case 219: return 255-219;
246 case 220: return 255-220;
247 case 221: return 255-221;
248 case 222: return 255-222;
249 case 223: return 255-223;
250 case 224: return 255-224;
251 case 225: return 255-225;
252 case 226: return 255-226;
253 case 227: return 255-227;
254 case 228: return 255-228;
255 case 229: return 255-229;
256 case 230: return 255-230;
257 case 231: return 255-231;
258 case 232: return 255-232;
259 case 233: return 255-233;
260 case 234: return 255-234;
261 case 235: return 255-235;
262 case 236: return 255-236;
263 case 237: return 255-237;
264 case 238: return 255-238;
265 case 239: return 255-239;
266 case 240: return 255-240;
267 case 241: return 255-241;
268 case 242: return 255-242;
269 case 243: return 255-243;
270 case 244: return 255-244;
271 case 245: return 255-245;
272 case 246: return 255-246;
273 case 247: return 255-247;
274 case 248: return 255-248;
275 case 249: return 255-249;
276 case 250: return 255-250;
277 case 251: return 255-251;
278 case 252: return 255-252;
279 case 253: return 255-253;
280 case 254: return 255-254;
281 case 255: return 255-255;
284 return -1;
287 static int test (int v)
289 Console.WriteLine ("value: " + v);
290 switch (v){
291 case 1:
292 case 2:
293 return 1;
295 case 3:
296 return 3;
298 case 4:
299 return 5;
301 default:
302 Console.WriteLine ("default");
303 return 6;
306 return 7;
309 static int tests (string s)
311 switch (s){
312 case "one":
313 case "two":
314 return 1;
315 case "three":
316 return 3;
317 case "four":
318 return 5;
319 case null:
320 return 9;
321 case "new":
322 goto case null;
323 default:
324 return 6;
327 return 1;
330 static int tests2 (string s)
332 switch (s){
333 case "one":
334 goto case null;
335 case "two":
336 goto default;
337 case null:
338 default:
339 return 3;
343 static int testn (string s)
345 switch (s){
346 case "one":
347 return 1;
349 default:
350 return 0;
352 return -1;
355 static int testm (string s)
357 switch (s){
358 case "one":
359 return 1;
361 return 100;
364 static int testo (string s)
366 switch (s){
367 case "one":
368 return 1;
369 case null:
370 return 100;
372 return 2;
375 static int testp (string s)
377 switch (s){
378 case "one":
379 case null:
380 case "two":
381 return 1;
382 case "three":
383 return 3;
385 return 4;
388 static int test_def (string s)
390 switch (s){
391 case "one":
392 goto default;
393 case "two":
394 return 1;
395 case "three":
396 return 2;
397 default:
398 return 3;
400 return 4;
403 static int test_coverage (int x)
405 switch (x){
406 case 0:
407 return 1;
408 default:
409 return 10;
413 static int test_goto (int a)
415 switch (a){
416 case 0:
417 goto case 2;
418 case 1:
419 return 10;
420 case 2:
421 return 20;
422 default:
423 return 100;
427 static int test_memberaccess (string s)
429 switch (s){
430 case X.One:
431 return 3;
432 default:
433 return 4;
437 static int test_string_multiple_targets (string s)
439 switch (s){
440 case "A":
441 return 1;
442 case "B":
443 return 2;
444 case "C":
445 case "D":
446 return 3;
448 return 0;
451 enum My : byte {
455 static int test_casts (int n)
457 switch (n) {
458 case (int) (char) (int) My.A:
459 return 1;
461 default:
462 return 2;
466 public enum TestEnum : long {
467 a, b, c
470 public static int testSwitchEnumLong (TestEnum c)
473 switch (c) {
474 case TestEnum.a:
475 return 10;
477 case TestEnum.b:
478 return 20;
480 case TestEnum.c:
481 goto case TestEnum.b;
483 default:
484 return 40;
489 static int test_long_enum_switch ()
491 if (testSwitchEnumLong (TestEnum.a) != 10)
492 return 1;
493 if (testSwitchEnumLong (TestEnum.b) != 20)
494 return 2;
495 if (testSwitchEnumLong (TestEnum.c) != 20)
496 return 3;
497 if (testSwitchEnumLong ((TestEnum)5) != 40)
498 return 4;
499 return 0;
502 static int tests_default (string s)
504 // tests default in the middle of the switch
506 switch (s){
507 default:
508 case "hello":
509 case "world":
510 return 1;
511 case "how":
512 return 2;
516 // Bug #74655
517 static int tests_default_2 (string foo)
519 switch (foo) {
520 case "Hello":
521 break;
522 default:
523 return 1;
524 case "foo":
525 return 2;
526 case "Monkey":
527 break;
529 return 3;
532 static void test_76590 (string s)
534 switch (s) {
535 case "null":
536 case (string)null:
537 break;
539 case "#":
540 break;
542 default:
543 break;
547 static void test_77964()
549 char c = 'c';
550 switch (c)
552 case 'A':
553 break;
555 case 'a':
556 goto case 65;
560 static bool bug_78860()
562 string model = "TSP100";
564 System.Console.WriteLine("switch on '{0}'", model);
566 switch(model) {
567 case "wibble":
568 case null:
569 return false;
570 case "TSP100":
571 return true;
573 return false;
576 static void test_1597 ()
578 var a = "";
579 switch (a) {
583 static int LongStringSwitch (string s)
585 switch (s)
587 case "System":
588 case "System.Core":
589 case "System.Data":
590 case "System.Data.DataSetExtensions":
591 case "System.Data.Linq":
592 case "System.Data.OracleClient":
593 case "System.Data.Services":
594 case "System.Data.Services.Client":
595 case "System.IdentityModel":
596 case "System.IdentityModel.Selectors":
597 case "System.Runtime.Remoting":
598 case "System.Runtime.Serialization":
599 case "System.ServiceModel":
600 case "System.Transactions":
601 case "System.Windows.Forms":
602 case "System.Xml":
603 case "System.Xml.Linq":
604 return 1;
606 case "System.Configuration":
607 case "System.Configuration.Install":
608 case "System.Design":
609 case "System.DirectoryServices":
610 case "System.Drawing":
611 case "System.Drawing.Design":
612 case "System.EnterpriseServices":
613 case "System.Management":
614 case "System.Messaging":
615 case "System.Runtime.Serialization.Formatters.Soap":
616 case "System.Security":
617 case "System.ServiceProcess":
618 case "System.Web":
619 case "System.Web.Mobile":
620 case "System.Web.Services":
621 return 2;
623 case "System.ComponentModel.DataAnnotations":
624 case "System.ServiceModel.Web":
625 case "System.Web.Abstractions":
626 case "System.Web.Extensions":
627 case "System.Web.Extensions.Design":
628 case "System.Web.DynamicData":
629 case "System.Web.Routing":
630 return 3;
633 return 10;
636 static bool SwitchSingleSection (string scheme)
638 switch (scheme) {
639 case "http":
640 case "https":
641 case "file":
642 case "ftp":
643 case "nntp":
644 case "gopher":
645 case "mailto":
646 case "news":
647 return true;
648 default:
649 return false;
653 public static int Main ()
655 byte b;
657 for (b = 0; b < 255; b++){
658 if (s (b) != 255 - b){
659 Console.WriteLine ("Failed with: " + b + " [" + s (b) + "]");
660 return 1;
664 Console.WriteLine ("Batch 2");
665 if (test (1) != 1)
666 return 1;
667 if (test (2) != 1)
668 return 2;
669 if (test (3) != 3)
670 return 3;
671 if (test (4) != 5)
672 return 4;
673 if (test (100) != 6)
674 return 5;
676 if (tests ("one") != 1)
677 return 6;
678 if (tests ("two") != 1)
679 return 7;
680 if (tests ("three") != 3)
681 return 8;
682 if (tests ("four") != 5)
683 return 9;
684 if (tests (null) != 9)
685 return 10;
686 if (tests ("blah") != 6)
687 return 11;
688 if (tests ("new") != 9)
689 return 110;
692 if (testn ("one") != 1)
693 return 12;
694 if (testn ("hello") != 0)
695 return 13;
696 if (testn (null) != 0)
697 return 14;
699 if (testm ("one") != 1)
700 return 15;
701 if (testm ("two") != 100)
702 return 16;
703 if (testm (null) != 100)
704 return 17;
706 if (testo ("one") != 1)
707 return 18;
708 if (testo ("two") != 2)
709 return 19;
710 if (testo (null) != 100)
711 return 20;
713 if (testp ("one") != 1)
714 return 21;
715 if (testp (null) != 1)
716 return 22;
717 if (testp ("two") != 1)
718 return 23;
719 if (testp ("three") != 3)
720 return 24;
721 if (testp ("blah") != 4)
722 return 25;
724 if (test_def ("one") != 3)
725 return 26;
726 if (test_def ("two") != 1)
727 return 27;
728 if (test_def ("three") != 2)
729 return 28;
730 if (test_def (null) != 3)
731 return 29;
733 if (test_coverage (100) != 10)
734 return 30;
736 if (test_goto (0) != 20)
737 return 31;
738 if (test_goto (1) != 10)
739 return 32;
740 if (test_goto (2) != 20)
741 return 33;
742 if (test_goto (200) != 100)
743 return 34;
745 if (test_memberaccess ("one") != 3)
746 return 35;
748 if (test_string_multiple_targets ("A") != 1)
749 return 36;
750 if (test_string_multiple_targets ("B") != 2)
751 return 37;
752 if (test_string_multiple_targets ("C") != 3)
753 return 38;
754 if (test_string_multiple_targets ("D") != 3)
755 return 39;
756 if (test_string_multiple_targets ("E") != 0)
757 return 40;
759 if (test_casts (0) != 1)
760 return 41;
762 if (test_long_enum_switch () != 0)
763 return 42;
765 if (tests_default (null) != 1)
766 return 43;
767 if (tests_default ("hello") != 1)
768 return 44;
769 if (tests_default ("world") != 1)
770 return 45;
771 if (tests_default ("how") != 2)
772 return 46;
774 if (tests_default_2 ("Test") != 1)
775 return 47;
776 if (tests_default_2 ("foo") != 2)
777 return 48;
778 if (tests_default_2 ("Hello") != 3)
779 return 49;
780 if (tests_default_2 ("Monkey") != 3)
781 return 50;
783 if (!bug_78860 ())
784 return 60;
786 if (tests2 ("a") != 3)
787 return 71;
788 if (tests2 ("one") != 3)
789 return 72;
790 if (tests2 ("two") != 3)
791 return 73;
793 if (LongStringSwitch ("System.Management") != 2)
794 return 80;
795 if (LongStringSwitch (null) != 10)
796 return 81;
797 if (LongStringSwitch (".") != 10)
798 return 82;
800 if (!SwitchSingleSection ("file"))
801 return 90;
802 if (SwitchSingleSection (null))
803 return 91;
804 if (SwitchSingleSection ("-=-"))
805 return 92;
807 test_1597 ();
809 Console.WriteLine ("All tests pass");
810 return 0;