diff options
Diffstat (limited to 'mcs/tests')
214 files changed, 12029 insertions, 1 deletions
diff --git a/mcs/tests/ChangeLog b/mcs/tests/ChangeLog new file mode 100755 index 00000000000..587ae2b4ebe --- /dev/null +++ b/mcs/tests/ChangeLog @@ -0,0 +1,677 @@ +2002-12-21 Ravi Pratap <ravi@ximian.com> + + * test-171.cs : Fix up since it wasn't working because of some + array code bug. That is a separate problem ;-) + +2002-12-21 Ravi Pratap <ravi@ximain.com> + + * test-171.cs : This was mysteriously absent. Add new test in its + place. + +2002-12-18 Ravi Pratap <ravi@ximian.com> + + * test-177.cs : Add. This doesn't pass yet because we don't have + ReturnTypeCustomAttributes working. + +2002-12-10 Ravi Pratap <ravi@ximian.com> + + * test-102.cs : Improve to catch the case when an attribute + can be emitted twice for the same program element but with + different targets. + +2002-11-24 Martin Baulig <martin@ximian.com> + + * test-130.cs: This test did not compile with csc and + mcs now reports the error as well. Removed the offending + line from the test. + +2002-11-24 Martin Baulig <martin@ximian.com> + + * verify-6.cs: New test for bug #32269. + +2002-11-24 Martin Baulig <martin@ximian.com> + + * test-175.cs: New test for bug #30443. + +2002-11-17 Martin Baulig <martin@ximian.com> + + * README.tests: Whoever added test-167 to test-172 + while I was away, you forgot to add them here. + +2002-11-17 Martin Baulig <martin@ximian.com> + + * test-173.cs: New test for bug #34165. + +2002-11-14 Martin Baulig <martin@gnome.org> + + * test-148.cs: Added some tests from bug #33089. + +2002-10-10 Martin Baulig <martin@gnome.org> + + * verify-1.cs: Added testcase from bug #31470. + +2002-10-10 Martin Baulig <martin@gnome.org> + + * verify-5.cs: Added testcase from bug #31541. + +2002-10-06 Martin Baulig <martin@gnome.org> + + * test-164.cs: Added a few more testcases here. + +2002-10-04 Martin Baulig <martin@gnome.org> + + * test-154.cs: Added testcase from bug #31546. + +2002-09-19 Martin Baulig <martin@gnome.org> + + * test-154.cs: Added testcase from bug #30487. + +2002-09-17 Martin Baulig <martin@gnome.org> + + * test-148.cs: Added testcase for base indexers. + +2002-09-14 Martin Baulig <martin@gnome.org> + + * test-166.cs: New test. + +2002-09-14 Martin Baulig <martin@gnome.org> + + * verify-4.cs: Added testcase from bug #29857. + +2002-09-12 Martin Baulig <martin@gnome.org> + + * test-40.cs: Removed the syntax errors from this test. + +2002-09-09 Martin Baulig <martin@gnome.org> + + * makefile: Reverted Ravi's `Update'. When moving tests from + TESTS_NOPASS to TEST_SOURCES, please make sure that they actually + pass on both platforms and don't do it without a ChangeLog entry. + +2002-09-09 Martin Baulig <martin@gnome.org> + + * test-165.cs: Added testcase for bug #30040. + +2002-09-09 Martin Baulig <martin@gnome.org> + + * test-164.cs: Added testcase for virtual functions in delegate + creating expressions (Bug #30043). + +2002-09-06 Ravi Pratap <ravi@ximian.com> + + * test-163.cs : Add test to check we select string + over object when we have a Null literal as the argument. + + * makefile : Update. + +2002-08-11 Martin Baulig <martin@gnome.org> + + * test-162.cs: New test. + +2002-08-08 Martin Baulig <martin@gnome.org> + + * test-154.cs (test16): Added test for bug #28717. + +2002-08-08 Martin Baulig <martin@gnome.org> + + * test-161.cs: New test. + +2002-08-07 Martin Baulig <martin@gnome.org> + + * test-160.cs: New test for bug #28176. + +2002-08-07 Martin Baulig <martin@gnome.org> + + * test-158.cs: New test for bug #22119. + +2002-08-05 Martin Baulig <martin@gnome.org> + + * test-157.cs: Formerly known as ../errors/cs-20.cs + +2002-08-05 Martin Baulig <martin@gnome.org> + + * error-1.cs, error-2.cs: Moved to ../errors. + +2002-08-03 Martin Baulig <martin@gnome.org> + + * test-156.cs, error-2.cs: New tests. + +2002-08-02 Martin Baulig <martin@gnome.org> + + * makefile: Moved test-66.cs to TEST_NOPASS since there's currently + a bug in the runtime which makes this crash. + + * test-155.cs: New test. + +2002-08-01 Martin Baulig <martin@gnome.org> + + * verify-3.cs: New test. + +2002-07-31 Martin Baulig <martin@gnome.org> + + * test-154.cs: New test for the flow analysis code. + + * error-1.cs: Each method in this test must produce a compiler + error message. + + * makefile (test-unsafe-mono): New target to compile and run all + the --unsafe tests wich MCS and the Mono runtime. + +2002-07-29 Martin Baulig <martin@gnome.org> + + * makefile: Put back test-152.cs. + + * test-143.cs: Fixed a compilation error in this test. + +2002-07-27 Martin Baulig <martin@gnome.org> + + * test-153.cs: New test. + +2002-07-27 Martin Baulig <martin@gnome.org> + + * test-113.cs: Made this test actually work. + +2002-07-26 Martin Baulig <martin@gnome.org> + + * test-152.cs: New test for bug #24007. + + * makefile: Disabled test-151.cs since it isn't fixed yet. + +2002-07-24 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * test-151.cs: New test. See bug #22119. + * makefile: added new test. + +2002-07-24 Martin Baulig <martin@gnome.org> + + * test-150.cs: New test. + + * test-149.cs: New test. + + * test-95.cs: .... and finally, another bug in MCS is fixed and + the syntax error in this test is caught. + +2002-07-23 Martin Baulig <martin@gnome.org> + + * test-148.cs: New test. + +2002-07-22 Martin Baulig <martin@gnome.org> + + * verify-2.cs: New test. + +2002-07-22 Martin Baulig <martin@gnome.org> + + * verify-1.cs: New test. The verify-XXX.cs tests must be + compiled and then verified - either with `pedump --verify code' + or with PEverify. + +2002-07-22 Martin Baulig <martin@gnome.org> + + * makefile: test-29 now passes. + +2002-07-22 Martin Baulig <martin@gnome.org> + + * test.147.cs: New test for the `new' modifier. + +2002-07-21 Martin Baulig <martin@gnome.org> + + * test-38.cs: Added a few more test cases to this test. + +2002-07-20 Martin Baulig <martin@gnome.org> + + * test-38.cs: This test now passes with MCS. Added a few more + test cases to it. + + * test-52.cs: The order of the elements returned by + `IDictionary.Keys' is unspecified. + + * makefile: The following tests fail under linux and have been + moved to TEST_NOPASS: 45, 53, 91, 106, 107, 122, 132, 133. + (test-compiler-mono): Compile all the TEST_NOPASS tests, but + don't run them. + +2002-07-20 Martin Baulig <martin@gnome.org> + + * README.tests: Added (empty) list of all the test cases. + When you add any test cases, please add them to this file. + + * test-146.cs: Added test for bug #27977 which is now fixed. + +2002-07-19 Martin Baulig <martin@gnome.org> + + * test-145.cs: Added test for bug #25318 which is now fixed. + +2002-07-17 Martin Baulig <martin@gnome.org> + + * test-144.cs: Added test for constant `unchecked' and `checked' + expressions in a constant assignment. + +2002-07-10 Ravi Pratap <ravi@ximian.com> + + * test-142.cs : Add. This ensures events can be accessed + correctly from subclasses etc. + +2002-07-06 Andrew Birkett <adb@tardis.ed.ac.uk> + + * test-74.cs: Added test for \n in verbatim string. + +2002-06-27 Martin Baulig <martin@gnome.org> + + * makefile (test-compiler-mono): New target to compile and run + the tests with mcs and the mono jit. + +2002-06-25 Andrew Birkett <adb@tardis.ed.ac.uk> + + * makefile: The following tests fail under linux and have been + moved to TEST_NOPASS: 40, 45, 52, 53, 91, 106, 107, 122, 132, 133 + + Windows-specific tests have been extracted, and are now run by the + test-windows rule (it'll be run under linux but fail) + + The output format has been made less noisy, and is basically the + same as the tests in mcs/errors - like "Running test-1 ... OK". + +2002-06-13 Ravi Pratap <ravi@ximian.com> + + * test-131.cs : Add to test enum member attribute application. + +2002-06-10 Rachel Hestilow <hestilow@ximian.com> + + * unsafe-3.cs: New test for address-of-pointer. + +2002-06-09 Martin Baulig <martin@gnome.org> + + * test-130.cs: New test for constants and casts. + +2002-06-09 Martin Baulig <martin@gnome.org> + + * test-129.cs: New test for unary minus. + +2002-06-08 Ravi Pratap <ravi@ximian.com> + + * test-128.cs : Add. This ensures we apply attributes to accessors + of events and properties. + +2002-06-08 Martin Baulig <martin@gnome.org> + + * test-127.cs: New test for Enum.IsDefined(). + +2002-05-24 Ravi Pratap <ravi@ximian.com> + + * test-124.cs, test-125.cs : Add. + + * makefile : update. + +2002-05-11 Miguel de Icaza <miguel@ximian.com> + + * test-49.cs: Improve test. + +Wed May 8 16:48:11 CEST 2002 Paolo Molaro <lupus@ximian.com> + + * test-118.cs: test alternate type lookup for attributes. + +2002-05-07 Ravi Pratap <ravi@ximian.com> + + * test-117.cs : Add. + +2002-05-05 Miguel de Icaza <miguel@ximian.com> + + * test-28.cs: Improved test: before we were failing on abstract + indexers invoked in the same class (as the accessor would have no + body). + +2002-05-02 Ravi Pratap <ravi@ximian.com> + + * test-113.cs : Another test for overload resolution ;-) + + * test-114.cs : Add. + +2002-04-28 Miguel de Icaza <miguel@ximian.com> + + * test-108.cs: Improve test + +2002-04-26 Ravi Pratap <ravi@ximian.com> + + * test-105.cs, test-106.cs, test-107.cs : Add. + +2002-04-22 Ravi Pratap <ravi@ximian.com> + + * test-104.cs : Another overload resolution test ! + +2002-04-05 Ravi Pratap <ravi@ximian.com> + + * test-101.cs : Add test from Paolo. + + * test-102.cs : Another test for attribute emission. + +2002-04-05 Ravi Pratap <ravi@ximian.com> + + * test-90.cs : Fix bug where we had no class ! + + * test-96.cs : Here too ! + + * test-98.cs : Supply a missing Main. + +2002-03-27 Miguel de Icaza <miguel@ximian.com> + + * test-18.cs: Augment test with the multi-flow try/catch. + +2002-03-21 Miguel de Icaza <miguel@ximian.com> + + * test-49.cs: Improved test to excerise the coverage. + +2002-03-13 Ravi Pratap <ravi@ximian.com> + + * test-86.cs : Add. This is to check for correct overload resolution + with a null literal. + +2002-03-07 Ravi Pratap <ravi@ximian.com> + + * test-82.cs : Add. + +2002-03-07 Miguel de Icaza <miguel@ximian.com> + + * test-52.cs: Expanded test to cover more cases of foreach. + +2002-03-05 Ravi Pratap <ravi@ximian.com> + + * test-81.cs : Add. + + * makefile : Update accordingly as this test passes. + +2002-02-20 Miguel de Icaza <miguel@ximian.com> + + * unsafe-1.cs: Extend test. + +2002-01-18 Miguel de Icaza <miguel@ximian.com> + + * test-7.cs: Fix test (i.i wsa invalid) + +2002-01-18 Nick Drochak <ndrochak@gol.com> + + * makefile: remove path to beta2 csc.exe. path to csc.exe must be in PATH instead. + +2002-01-13 Ravi Pratap <ravi@ximian.com> + + * test-58.cs : Since it was a duplicate, replace with unsafe + code testing. + +2002-01-08 Miguel de Icaza <miguel@ximian.com> + + * test-34.cs: Improve this test to check ref/ref cases. + +2002-01-02 Ravi Pratap <ravi@ximian.com> + + * test-45.cs : Augment to exercise support for array initialization + for various other types. + +2001-12-30 Miguel de Icaza <miguel@ximian.com> + + * test-67.cs: Improve this test. + +2001-12-29 Ravi Pratap <ravi@ximian.com> + + * test-69.cs : Add. This tests support for methods which are + internal calls. + +2001-12-28 Ravi Pratap <ravi@ximian.com> + + * test-34.cs : Update to exercise the new overload resolution + code. + +2001-12-26 Ravi Pratap <ravi@ximian.com> + + * test-67.cs : Add. These are tests for explicit layout + of structs and classes. + + * makefile : Update accordingly. + +2001-12-25 Ravi Pratap <ravi@ximian.com> + + * test-57.cs : Update to exercise more of the code base for + events. + +2001-12-24 Ravi Pratap <ravi@ximian.com> + + * test-19.cs : Augment to exercise tests on delegates + defined in mscorlib. + + * test-57.cs : Update to exercise the -= operator + as well. + +2001-12-23 Ravi Pratap <ravi@ximian.com> + + * test-57.cs : Update. + + * makefile : Update to include the above as it passes nicely. + +2001-12-21 Ravi Pratap <ravi@ximian.com> + + * test-19.cs : Augment to exercise code which fixed the bug + where we were not generating a This for the delegate's + instance expression - for the non-static methods ie. + +2001-12-15 Miguel de Icaza <miguel@ximian.com> + + * test-45.cs: Make test also use variables as arguments to new; + We used to have a bug in the compiler that did not resolve some of + the arguments. + +2001-12-15 Ravi Pratap <ravi@ximian.com> + + * makefile : Include test-52.cs in the suite, it works fine! + + (NO_PASS): It's test-51 which doesn't seem to pass. + + * test-50.cs : Augment some more to set named arguments on + the DllImport attribute. + + * test-57.cs : Add. This tests support for Events and does not + pass yet. + +2001-12-14 Ravi Pratap <ravi@ximian.com> + + * test-45.cs : Update for float and double initialization. + +2001-12-13 Miguel de Icaza <miguel@ximian.com> + + * makefile (test-30): Another test moved to the `pass' section. + This is explicit interface implementation. + + (test-54): returning from catch exceptions has been working for + some time now. + +2001-12-09 Radek Doulik <rodo@ximian.com> + + * makefile (TEST_SOURCES): added test-55 for using alias directive + +2001-12-06 Dietmar Maurer <dietmar@ximian.com> + + * makefile: added new target test-jit + +2001-12-04 Ravi Pratap <ravi@ximian.com> + + * makefile : Update to include test 50 as it now passes. + +2001-12-04 Ravi Pratap <ravi@ximian.com> + + * test-45.cs : Update for string initialization tests. + +2001-12-03 Miguel de Icaza <miguel@ximian.com> + + * test-49.cs: Updated to test `goto default' + + * test-43.cs: Test break and continue here. + + * gen-cast-test.cs: Improved cast test generator. + +2001-12-03 Ravi Pratap <ravi@ximian.com> + + * test-50.cs : Add. This does not pass yet. + +2001-12-02 Ravi Pratap <ravi@ximian.com> + + * test-40.cs : Update to now test recursive definitions with + constants hooked up. + +2001-12-01 Ravi Pratap <ravi@ximian.com> + + * test-40.cs : Update to do recursive enumeration definition. + +2001-11-28 Ravi Pratap <ravi@ximian.com> + + * test-48.cs : Add for constant emission tests. + + * makefile : Update for the above as it passes nicely :-) + +2001-11-22 Ravi Pratap <ravi@ximian.com> + + * test-45.cs : Augment some more to test shorthand declaration + of variables/fields that are array types. + +2001-11-20 Ravi Pratap <ravi@ximian.com> + + * test-45.cs : Add for array initialization testing. + +2001-11-16 Miguel de Icaza <miguel@ximian.com> + + * test-34.cs: Improve this test to check if we are actually + walking over the arguments in foreach. + +2001-11-15 Ravi Pratap <ravi@ximian.com> + + * makefile : Update to include test-33 again. All tests + pass again ! + +2001-11-13 Ravi Pratap <ravi@ximian.com> + + * test-7.cs : Re-write to make the tests more robust. + +2001-11-12 Ravi Pratap <ravi@ximian.com> + + * test-39.cs : Update to test named arguments too. + +2001-11-11 Ravi Pratap <ravi@ximian.com> + + * test-40.cs : Update to be a little more useful. + +2001-11-08 Ravi Pratap <ravi@ximian.com> + + * test-39.cs : Add + + * test-40.cs : Add + + * makefile : Modify to include the above as they pass all tests. + +2001-10-31 Ravi Pratap <ravi@ximian.com> + + * test-34.cs : Add + +2001-10-28 Ravi Pratap <ravi@ximian.com> + + * test-32.cs : Added to test array definition and creation. + + * makefile : Updated accordingly. + +2001-10-22 Ravi Pratap <ravi@ximian.com> + + * makefile : New target 'verify' which uses the verifier to check + that executables produced by us are identical to the MSC produced ones. + + * test-7.cs : Update to exercise more overloadable operators. + +2001-10-21 Ravi Pratap <ravi@ximian.com> + + * test-27.cs : Add to do various implicit and explicit + reference conversions. + + * makefile : Update accordingly. + +2001-10-18 Ravi Pratap <ravi@ximian.com> + + * test-26.cs : Update to test delegate creation from another + delegate. + +2001-10-17 Ravi Pratap <ravi@ximian.com> + + * test-26.cs : Added to demonstrate delegate support. + +2001-10-16 Miguel de Icaza <miguel@ximian.com> + + * test-25.cs: Added new test to excercise break/continue on + various loop constructs. + + * test-24.cs: Test property use in expression and statement + contexts. + +2001-10-14 Miguel de Icaza <miguel@ximian.com> + + * test-23.cs: Added new test for properties. + +2001-10-12 Ravi Pratap <ravi@ximian.com> + + * test-21.cs : Update to actually do some checking and return + an appropriate value. + +2001-10-11 Ravi Pratap <ravi@ximian.com> + + * test-21.cs : Add. This is a test for testing our support + for nested types + +2001-10-05 Ravi Pratap <ravi@ximian.com> + + * test-16.cs : Update to exercise the code which selects the best + conversion operator based on "most encompassing/encompassed type" + + * test-7.cs : Update here too. + +2001-10-05 Ravi Pratap <ravi@ximian.com> + + * test-7.cs : Update to do explicit conversion tests. + + * makefile : small fix. + +2001-10-03 Ravi Pratap <ravi@ximian.com> + + * test-16.cs : Update to make the test more correct. + +2001-10-03 Ravi Pratap <ravi@ximian.com> + + * test-16.cs : Add. + + * makefile : update accordingly. + +2001-10-02 Miguel de Icaza <miguel@ximian.com> + + * makefile (test-compiler): Add rm *.exe before launching tests. + +2001-10-02 Ravi Pratap <ravi@ximian.com> + + * test-13.cs : Added. + + * makefile : update accordingly. + +2001-09-27 Ravi Pratap <ravi@ximian.com> + + * test-7.cs : Revamp and add more operator tests. Still in progress. + + * test-9,10.cs : Added by Miguel earlier. + +2001-09-26 Ravi Pratap <ravi@ximian.com> + + * test-7.cs : Update to return an exit code + + * test-8.cs : Added by Miguel. + +2001-09-25 Ravi Pratap <ravi@ximian.com> + + * test-7.cs : Update to include implicit conversion tests. + +2001-09-21 Ravi Pratap <ravi@ximian.com> + + * test-7.cs : Add. + +2001-09-21 Miguel de Icaza <miguel@ximian.com> + + * makefile (test-compiler): Abort tests on failure. + diff --git a/mcs/tests/README.tests b/mcs/tests/README.tests new file mode 100644 index 00000000000..27c11d806c8 --- /dev/null +++ b/mcs/tests/README.tests @@ -0,0 +1,194 @@ +Test cases listed by Category: +============================== + +* Binary operators + + test-146.cs test-175.cs + +* Overloading + + test-147.cs test-173.cs + +* Try/Catch blocks + + verify-1.cs verify-2.cs + +* Indexers and Properties + + test-148.cs test-166.cs + +* Events and Delegates + + test-149.cs test-164.cs verify-3.cs + +* Constant Folding + + test-150.cs + +* Switch blocks + + test-152.cs verify-4.cs + +* Member Access & Simple Names + + test-151.cs test-159.cs test-160.cs test-161.cs + +* Invocation + + test-153.cs test-163.c + +* Flow Analysis + + test-154.cs test-162.cs + +* Type Containers + + test-155.cs test-156.cs + +* Attributes + + test-157.cs test-158.cs + +* Arrays and array creation + + test-165.cs, test-167.cs + +* Labels and goto + + verify-5.cs + +* Enums + + verify-6.cs + +Test cases listed by Number: +============================ + +test-146.cs +----------- +Test for Binary.EmitBrancheable() to ensure we're emitting correct +unsinged branch targets. + +test-147.cs +----------- +Testing `new' modifier. + +test-148.cs +----------- +Testing the `IndexerName' attribute in interface indexers. + +test-149.cs +----------- +Testing interface events. + +test-150.cs +----------- +Test for folding of UIntConstants. See bug #28106. +FIXME: We should all all possible test cases to this test. + +test-151.cs +----------- + + A.Iface b; + void doit (Object A) { + b = (A.Iface)A; + } + +test-152.cs +----------- +Scope of variables declared inside a switch case. + +test-153.cs +----------- +Testing invocation of varargs function. + +test-154.cs +----------- +Flow analysis: This test contains all situations which are "allowed". + +test-155.cs +----------- +Nested interfaces. + +test-156.cs +----------- +Check whether base types are at least as accessible than the current type. + +test-157.cs +----------- +Attributes. + +test-158.cs +----------- +Attributes. + +test-159.cs +----------- +SimpleNameLookup: Cast to `A.Iface' type when there's a parameter called `A'. + +test-160.cs +----------- +ResolveMemberLookup: `B look; return look.s.a' must work in static context. + +test-161.cs +----------- +ResolveMemberLookup: Field initializer references `DateTime.Now' when there's +an instance property/field `DateTime'. + +test-162.cs +----------- +Control Flow Analysis wrt. structs. + +test-163.cs +----------- +Test to check we select string over object when we have a Null literal as the argument. + +test-164.cs +----------- +Virtual functions in delegate creation expressions. + +test-165.cs +----------- +Enums in array creation expression. + +test-166.cs +----------- +Using property from interface which is inherited multiple times. + +test-173.cs +----------- +Check whether we select the correct function, don't report CS0121 +for integer literals. + +test-174.cs +----------- +Checks access to protected properties on base classes, and access to +private properties on container classes. + +test-175.cs +----------- +Check for user-defined implicit conversions if both arguments of a +binary operator are of a user-defined type. Bug #30443. + +verify-1.cs +----------- +Test whether we do not jump out of the method in a Try/Finally block. + +verify-2.cs +----------- +Test whether `return' in a Try/Catch block actually returns. Test +whether continue uses Leave when the branch is across Try/Catch +boundaries. + +verify-3.cs +----------- +Checks default add/remove method of static events. + +verify-4.cs +----------- +When there's an unreachable break in a switch section, it must not emit a jump out of +the method. + +verify-6.cs +----------- +Casts from/to System.Enum. diff --git a/mcs/tests/c1.cs b/mcs/tests/c1.cs new file mode 100755 index 00000000000..8b81c046864 --- /dev/null +++ b/mcs/tests/c1.cs @@ -0,0 +1,7 @@ +// cs0146.cs: circular class definition +// Line: 6 +class A : B { +} + +class B : A { +} diff --git a/mcs/tests/c2.cs b/mcs/tests/c2.cs new file mode 100755 index 00000000000..eeeb6f19e74 --- /dev/null +++ b/mcs/tests/c2.cs @@ -0,0 +1,2 @@ +class X { +} diff --git a/mcs/tests/casts.cs b/mcs/tests/casts.cs new file mode 100755 index 00000000000..8934e4eee7e --- /dev/null +++ b/mcs/tests/casts.cs @@ -0,0 +1,566 @@ +using System; +class Test { +
+ static void receive_int (int a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_uint (uint a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_short (short a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_ushort (ushort a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_long (long a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_ulong (ulong a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_sbyte (sbyte a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_byte (byte a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void receive_char (char a) + { + Console.Write (" "); + Console.WriteLine (a); + } + + static void probe_int() + { + int zero = (int) 0; + int min = (int) int.MinValue; + int max = (int) int.MaxValue; +
+ Console.WriteLine ("Testing: int"); +
+ Console.WriteLine (" arg: int (int)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (int)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (int)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (int)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (int)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (int)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (int)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (int)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (int)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_uint() + { + uint zero = (uint) 0; + uint min = (uint) uint.MinValue; + uint max = (uint) uint.MaxValue; +
+ Console.WriteLine ("Testing: uint"); +
+ Console.WriteLine (" arg: int (uint)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (uint)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (uint)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (uint)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (uint)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (uint)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (uint)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (uint)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (uint)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_short() + { + short zero = (short) 0; + short min = (short) short.MinValue; + short max = (short) short.MaxValue; +
+ Console.WriteLine ("Testing: short"); +
+ Console.WriteLine (" arg: int (short)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (short)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (short)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (short)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (short)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (short)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (short)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (short)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (short)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_ushort() + { + ushort zero = (ushort) 0; + ushort min = (ushort) ushort.MinValue; + ushort max = (ushort) ushort.MaxValue; +
+ Console.WriteLine ("Testing: ushort"); +
+ Console.WriteLine (" arg: int (ushort)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (ushort)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (ushort)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (ushort)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (ushort)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (ushort)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (ushort)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (ushort)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (ushort)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_long() + { + long zero = (long) 0; + long min = (long) long.MinValue; + long max = (long) long.MaxValue; +
+ Console.WriteLine ("Testing: long"); +
+ Console.WriteLine (" arg: int (long)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (long)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (long)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (long)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (long)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (long)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (long)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (long)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (long)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_ulong() + { + ulong zero = (ulong) 0; + ulong min = (ulong) ulong.MinValue; + ulong max = (ulong) ulong.MaxValue; +
+ Console.WriteLine ("Testing: ulong"); +
+ Console.WriteLine (" arg: int (ulong)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (ulong)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (ulong)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (ulong)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (ulong)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (ulong)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (ulong)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (ulong)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (ulong)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_sbyte() + { + sbyte zero = (sbyte) 0; + sbyte min = (sbyte) sbyte.MinValue; + sbyte max = (sbyte) sbyte.MaxValue; +
+ Console.WriteLine ("Testing: sbyte"); +
+ Console.WriteLine (" arg: int (sbyte)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (sbyte)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (sbyte)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (sbyte)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (sbyte)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (sbyte)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (sbyte)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (sbyte)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (sbyte)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_byte() + { + byte zero = (byte) 0; + byte min = (byte) byte.MinValue; + byte max = (byte) byte.MaxValue; +
+ Console.WriteLine ("Testing: byte"); +
+ Console.WriteLine (" arg: int (byte)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (byte)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (byte)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (byte)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (byte)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (byte)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (byte)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (byte)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (byte)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void probe_char() + { + char zero = (char) 0; + char min = (char) char.MinValue; + char max = (char) char.MaxValue; +
+ Console.WriteLine ("Testing: char"); +
+ Console.WriteLine (" arg: int (char)"); +
+ receive_int (unchecked ((int) zero)); + receive_int (unchecked ((int) min)); + receive_int (unchecked ((int) max)); + Console.WriteLine (" arg: uint (char)"); +
+ receive_uint (unchecked ((uint) zero)); + receive_uint (unchecked ((uint) min)); + receive_uint (unchecked ((uint) max)); + Console.WriteLine (" arg: short (char)"); +
+ receive_short (unchecked ((short) zero)); + receive_short (unchecked ((short) min)); + receive_short (unchecked ((short) max)); + Console.WriteLine (" arg: ushort (char)"); +
+ receive_ushort (unchecked ((ushort) zero)); + receive_ushort (unchecked ((ushort) min)); + receive_ushort (unchecked ((ushort) max)); + Console.WriteLine (" arg: long (char)"); +
+ receive_long (unchecked ((long) zero)); + receive_long (unchecked ((long) min)); + receive_long (unchecked ((long) max)); + Console.WriteLine (" arg: ulong (char)"); +
+ receive_ulong (unchecked ((ulong) zero)); + receive_ulong (unchecked ((ulong) min)); + receive_ulong (unchecked ((ulong) max)); + Console.WriteLine (" arg: sbyte (char)"); +
+ receive_sbyte (unchecked ((sbyte) zero)); + receive_sbyte (unchecked ((sbyte) min)); + receive_sbyte (unchecked ((sbyte) max)); + Console.WriteLine (" arg: byte (char)"); +
+ receive_byte (unchecked ((byte) zero)); + receive_byte (unchecked ((byte) min)); + receive_byte (unchecked ((byte) max)); + Console.WriteLine (" arg: char (char)"); +
+ receive_char (unchecked ((char) zero)); + receive_char (unchecked ((char) min)); + receive_char (unchecked ((char) max)); + } + + static void Main () + {
+ probe_int (); + probe_uint (); + probe_short (); + probe_ushort (); + probe_long (); + probe_ulong (); + probe_sbyte (); + probe_byte (); + probe_char (); + }
+} +
diff --git a/mcs/tests/co1.cs b/mcs/tests/co1.cs new file mode 100755 index 00000000000..da1bdaab246 --- /dev/null +++ b/mcs/tests/co1.cs @@ -0,0 +1,4 @@ +class X {
+ const int x = 1;
+ const string s = "Hello";
+}
diff --git a/mcs/tests/cs1.cs b/mcs/tests/cs1.cs new file mode 100755 index 00000000000..bfb3c74b3c8 --- /dev/null +++ b/mcs/tests/cs1.cs @@ -0,0 +1,5 @@ +class X {
+}
+
+struct Y {
+}
diff --git a/mcs/tests/csc-casts.out b/mcs/tests/csc-casts.out Binary files differnew file mode 100755 index 00000000000..70ce7135da8 --- /dev/null +++ b/mcs/tests/csc-casts.out diff --git a/mcs/tests/gen-cast-test.cs b/mcs/tests/gen-cast-test.cs new file mode 100755 index 00000000000..d1f9531d2f1 --- /dev/null +++ b/mcs/tests/gen-cast-test.cs @@ -0,0 +1,99 @@ +using System; + +class Stress { + + static string mode = "unchecked"; + + static string [] types = { + "int", "uint", + "short", "ushort", + "long", "ulong", + "sbyte", "byte", "char" + }; + + + static void w (string s) + { + Console.Write (s); + } + + static void wl (string s) + { + Console.WriteLine (s); + } + + static void generate_receptors () + { + foreach (string t in types){ + w ("\tstatic void receive_" + t + " (" + t + " a)\n\t{\n"); + w ("\t\tConsole.Write (\" \");\n"); + w ("\t\tConsole.WriteLine (a);\n"); + w ("\t}\n\n"); + } + + } + + static void var (string type, string name, string init) + { + w ("\t\t" + type + " " + name + " = (" + type + ") " + init + ";\n"); + } + + static void call (string type, string name) + { + w ("\t\treceive_" + type + " (" + mode + "((" + type + ") " + name + "));\n"); + } + + static void generate_emision () + { + foreach (string type in types){ + w ("\tstatic void probe_" + type + "()\n\t{\n"); + var (type, "zero", "0"); + var (type, "min", type + ".MinValue"); + var (type, "max", type + ".MaxValue"); + wl (""); + + wl ("\t\tConsole.WriteLine (\"Testing: " + type + "\");\n"); + foreach (string t in types){ + wl ("\t\tConsole.WriteLine (\" arg: " + t + " (" + type + ")\");\n"); + call (t, "zero"); + call (t, "min"); + call (t, "max"); + } + + w ("\t}\n\n"); + } + } + + static void generate_main () + { + wl ("\tstatic void Main ()\n\t{"); + + foreach (string t in types){ + w ("\t\tprobe_" + t + " ();\n"); + } + wl ("\t}"); + } + + static void Main (string [] args) + { + foreach (string arg in args){ + if (arg == "-h" || arg == "--help"){ + Console.WriteLine ("-h, --help Shows help"); + Console.WriteLine ("-c, --checked Generate checked contexts"); + return; + } + if (arg == "--checked" || arg == "-c"){ + mode = "checked"; + continue; + } + } + wl ("using System;\nclass Test {\n"); + + generate_receptors (); + generate_emision (); + + generate_main (); + + wl ("}\n"); + } +} diff --git a/mcs/tests/gen-check.cs b/mcs/tests/gen-check.cs new file mode 100755 index 00000000000..9077b141a74 --- /dev/null +++ b/mcs/tests/gen-check.cs @@ -0,0 +1,78 @@ +using System; + +class Stress { + + static string [] types = { + "int", "uint", + "short", "ushort", + "long", "ulong", + "sbyte", "byte", "char" + }; + + + static void w (string s) + { + Console.Write (s); + } + + static void wl (string s) + { + Console.WriteLine (s); + } + + static void generate_receptors () + { + foreach (string t in types){ + w ("\tstatic void receive_" + t + " (" + t + " a)\n\t{\n"); + w ("\t\tConsole.Write (\" \");\n"); + w ("\t\tConsole.WriteLine (a);\n"); + w ("\t}\n\n"); + } + + } + + static void call (string type, string name) + { + w ("\t\treceive_" + type + " (checked ((" + type + ") var ));\n"); + } + + static void generate_emision () + { + foreach (string type in types){ + w ("\tstatic void probe_" + type + "()\n\t{\n"); + if (type == "char") + w ("\t\t" + type + " var = (char) 0;"); + else + w ("\t\t" + type + " var = 0;"); + + wl (""); + + foreach (string t in types) + call (t, "var"); + + w ("\t}\n\n"); + } + } + + static void generate_main () + { + wl ("\tstatic void Main ()\n\t{"); + + foreach (string t in types){ + w ("\t\tprobe_" + t + " ();\n"); + } + wl ("\t}"); + } + + static void Main (string [] args) + { + wl ("using System;\nclass Test {\n"); + + generate_receptors (); + generate_emision (); + + generate_main (); + + wl ("}\n"); + } +} diff --git a/mcs/tests/i-recursive.cs b/mcs/tests/i-recursive.cs new file mode 100644 index 00000000000..9c22e5876cc --- /dev/null +++ b/mcs/tests/i-recursive.cs @@ -0,0 +1,5 @@ +interface A : B { +} + +interface B : A { +} diff --git a/mcs/tests/i-three.cs b/mcs/tests/i-three.cs new file mode 100755 index 00000000000..7c473f21657 --- /dev/null +++ b/mcs/tests/i-three.cs @@ -0,0 +1,11 @@ +interface A { +} + +interface B : A{ +} + +interface C : A { +} + +interface D : C { +} diff --git a/mcs/tests/i-undefined.cs b/mcs/tests/i-undefined.cs new file mode 100644 index 00000000000..496795cd6db --- /dev/null +++ b/mcs/tests/i-undefined.cs @@ -0,0 +1,2 @@ +interface A : B { +} diff --git a/mcs/tests/i1.cs b/mcs/tests/i1.cs new file mode 100755 index 00000000000..00141820820 --- /dev/null +++ b/mcs/tests/i1.cs @@ -0,0 +1,2 @@ +interface A {
+}
diff --git a/mcs/tests/i2.cs b/mcs/tests/i2.cs new file mode 100755 index 00000000000..9c22e5876cc --- /dev/null +++ b/mcs/tests/i2.cs @@ -0,0 +1,5 @@ +interface A : B { +} + +interface B : A { +} diff --git a/mcs/tests/i3.cs b/mcs/tests/i3.cs new file mode 100755 index 00000000000..dff6c54db9d --- /dev/null +++ b/mcs/tests/i3.cs @@ -0,0 +1,5 @@ +class X { +} + +interface A : X { +} diff --git a/mcs/tests/i4.cs b/mcs/tests/i4.cs new file mode 100755 index 00000000000..f89988f2cb3 --- /dev/null +++ b/mcs/tests/i4.cs @@ -0,0 +1,8 @@ +// cs0509.cs: base class is sealed +// Line: 7 +struct V { + int v; +} + +class X : V { +} diff --git a/mcs/tests/i5.cs b/mcs/tests/i5.cs new file mode 100755 index 00000000000..e312377061b --- /dev/null +++ b/mcs/tests/i5.cs @@ -0,0 +1,8 @@ +class A1 { +} + +class A2 { +} + +class B : A1, A2 { +} diff --git a/mcs/tests/i6.cs b/mcs/tests/i6.cs new file mode 100755 index 00000000000..fa20da0ada8 --- /dev/null +++ b/mcs/tests/i6.cs @@ -0,0 +1,4 @@ +// cs0246.cs: can not find type `B' +// Line: 4 +class X : D { +} diff --git a/mcs/tests/ix1.cs b/mcs/tests/ix1.cs new file mode 100755 index 00000000000..984391d2fda --- /dev/null +++ b/mcs/tests/ix1.cs @@ -0,0 +1,3 @@ +interface INTERFACE { + string PROPERTY { get; set; } +} diff --git a/mcs/tests/ix2.cs b/mcs/tests/ix2.cs new file mode 100755 index 00000000000..c36b52ea2ac --- /dev/null +++ b/mcs/tests/ix2.cs @@ -0,0 +1,15 @@ +using System; + +interface Blah { + string this [ int INDEX ] { get; set; } + string Item (int index); +} + +public class Foo { + + public static void Main () + { + Console.WriteLine ("foo"); + } +} + diff --git a/mcs/tests/makefile b/mcs/tests/makefile new file mode 100755 index 00000000000..ea9b7eff336 --- /dev/null +++ b/mcs/tests/makefile @@ -0,0 +1,182 @@ +# +# You can change "RUNTIME" to control what runtime to use +# ie, make vs make RUNTIME=mono +# +CSC=csc.exe + +MCS=../mcs/mcs.exe +MCS2=mono ../mcs/mcs.exe +VERIFY=../tools/verifier.exe + +TEST_SOURCES = \ + test-1 test-2 test-3 test-4 test-5 test-6 test-7 test-8 test-9 test-10 \ + test-11 test-12 test-13 test-14 test-15 test-16 test-17 test-18 test-19 test-20 \ + test-21 test-22 test-23 test-24 test-25 test-26 test-27 test-28 test-29 test-30 \ + test-31 test-32 test-33 test-34 test-35 test-36 test-37 test-38 test-39 test-40 \ + test-41 test-42 test-43 test-44 test-46 test-47 test-48 test-49 \ + test-51 test-52 test-54 test-55 test-56 test-57 test-59 test-60 \ + test-61 test-62 test-63 test-64 test-65 test-68 test-69 test-70 \ + test-71 test-72 test-73 test-74 test-75 test-76 test-77 test-78 test-79 test-80 \ + test-81 test-82 test-83 test-84 test-85 test-86 test-87 test-88 test-89 test-90 \ + test-92 test-93 test-94 test-95 test-96 test-97 test-98 test-99 test-100\ + test-101 test-102 test-103 test-104 test-105 test-108 test-109 test-110\ + test-111 test-112 test-113 test-114 test-115 test-116 test-117 test-118 test-119 \ + test-121 test-123 test-125 test-126 test-127 test-128 test-129 test-130 \ + test-131 test-134 test-135 test-136 test-137 test-138 test-139 test-140 \ + test-141 test-142 test-143 test-144 test-145 test-146 test-147 test-148 test-149 test-150 \ + test-153 test-154 test-155 test-156 test-157 test-158 test-159 test-160 \ + test-161 test-162 test-163 test-164 test-165 test-166 test-167 test-168 test-169 test-170 \ + test-172 test-173 test-174 test-175 test-176 + +UNSAFE_SOURCES = \ + unsafe-1 unsafe-2 unsafe-3 test-58.cs test-171.cs + +WINDOWS_SOURCES = \ + test-50 test-67 + +# A test is a 'no pass' if it fails on either windows or linux +# Test 120 does not pass because the MS.NET runtime is buggy. +TEST_NOPASS = \ + test-45 test-53 test-91 test-106 test-107 test-120 test-122 test-132 test-133 test-66 test-177 + +all: test-compiler test-unsafe test-windows + + +# Compile with mono, run with MS jit +test-compiler: + @rm -f *.exe; \ + for i in $(TEST_SOURCES); do \ + echo -n "Running $$i ... "; \ + if $(MCS) $$i.cs > /dev/null; then \ + if $(RUNTIME) ./$$i.exe > /dev/null; then \ + echo $$i: ok; \ + else \ + echo FAILED; exit 1; \ + fi; \ + else \ + echo FAILED TO COMPILE; exit 1; \ + fi \ + done + +# Compile with mono, run with MS jit +test-unsafe: + @for i in $(UNSAFE_SOURCES); do \ + echo -n "Running (unsafe) $$i ... "; \ + if $(MCS) --unsafe $$i.cs > /dev/null; then \ + if $(RUNTIME) ./$$i.exe > /dev/null; then \ + echo OK; \ + else \ + echo FAILED; exit 1; \ + fi; \ + else \ + echo FAILED WHILE COMPILING; exit 1; \ + fi \ + done + +# Compiled (previously) with mono, run with mono jit +test-jit: + @for i in $(TEST_SOURCES:.cs=.exe); do \ + echo -n "Running jit $$i ... "; \ + if mono ./$$i.exe > /dev/null; then \ + echo OK; \ + else \ + echo FAILED; exit 1; \ + fi \ + done + +# Compiled with mono, run with MS jit +test-windows: + @echo Running windows-only tests - these will fail on linux; \ + for i in $(WINDOWS_SOURCES); do \ + echo -n "Running $$i ... "; \ + if $(MCS) $$i.cs > /dev/null; then \ + if ./$$i.exe > /dev/null; then \ + echo OK; \ + else \ + echo FAILED; exit 1; \ + fi; \ + else \ + echo FAILED TO COMPILE; exit 1; \ + fi \ + done + +# Compile with mono, run with mono jit +test-compiler-mono: + @rm -f *.exe; \ + for i in $(TEST_SOURCES); do \ + echo -n "Running $$i ... "; \ + if $(MCS2) $$i.cs > /dev/null; then \ + if mono ./$$i.exe > /dev/null; then \ + echo OK; \ + else \ + echo FAILED; exit 1; \ + fi; \ + else \ + echo FAILED TO COMPILE; exit 1; \ + fi \ + done + echo "Running NO_PASS tests ..." + for i in $(TEST_NOPASS); do \ + echo -n "Running $$i ... "; \ + if $(MCS2) $$i.cs > /dev/null; then \ + echo OK; \ + else \ + echo FAILED TO COMPILE; exit 1; \ + fi \ + done + +# Compile with mono, run with mono jit +test-unsafe-mono: + @rm -f *.exe; \ + for i in $(UNSAFE_SOURCES); do \ + echo -n "Running $$i ... "; \ + if $(MCS2) --unsafe $$i.cs > /dev/null; then \ + if mono ./$$i.exe > /dev/null; then \ + echo OK; \ + else \ + echo FAILED; exit 1; \ + fi; \ + else \ + echo FAILED TO COMPILE; exit 1; \ + fi \ + done + +verify: + @for i in $(TEST_SOURCES); do \ + if $(MCS) -o mcs-gen-code.exe $$i.cs > /dev/null; then \ + if $(CSC) /out:csc-gen-code.exe $$i.cs > /dev/null; then \ + if $(VERIFY) mcs-gen-code.exe csc-gen-code.exe > /dev/null; then \ + echo $$i: identical assemblies; \ + else \ + echo $$i: unidentical assemblies; exit; \ + fi; \ + fi \ + fi \ + done; \ + echo Verification passed + + +casts.cs: gen-cast-test.cs + $(CSC) /out:csc-cast.exe gen-cast-test.cs + ./csc-cast > casts.cs + +casts-csc.exe: casts.cs + $(CSC) /out:casts-csc.exe casts.cs + +casts.exe: casts.cs + $(MCS) casts.cs + +csc-casts.out: casts-csc.exe + ./casts-csc.exe > csc-casts.out + +msc-casts.out: casts.exe + ./casts.exe > msc-casts.out + +test-casts: csc-casts.out msc-casts.out + cmp csc-casts.out msc-casts.out + +clean: + rm *.exe + rm *.out + rm casts.cs + diff --git a/mcs/tests/n1.cs b/mcs/tests/n1.cs new file mode 100755 index 00000000000..b47fd24b2ca --- /dev/null +++ b/mcs/tests/n1.cs @@ -0,0 +1,11 @@ +namespace A {
+ class X {
+ void Y () {}
+ }
+}
+
+namespace A {
+ class XX : X {
+ void YY () {}
+ }
+}
diff --git a/mcs/tests/n2.cs b/mcs/tests/n2.cs new file mode 100755 index 00000000000..34c210e1fe7 --- /dev/null +++ b/mcs/tests/n2.cs @@ -0,0 +1,4 @@ +using System.Collections; + +class X : Queue { +} diff --git a/mcs/tests/s1.cs b/mcs/tests/s1.cs new file mode 100755 index 00000000000..6c1191a86a0 --- /dev/null +++ b/mcs/tests/s1.cs @@ -0,0 +1,7 @@ +struct A {
+ int x;
+}
+
+struct B : A {
+ int y;
+}
diff --git a/mcs/tests/test-1.cs b/mcs/tests/test-1.cs new file mode 100755 index 00000000000..adb1dd88a92 --- /dev/null +++ b/mcs/tests/test-1.cs @@ -0,0 +1,9 @@ +using System; + +class X { + static int Main (string [] args) + { + Console.WriteLine ("Hello, World!"); + return 0; + } +} diff --git a/mcs/tests/test-10.cs b/mcs/tests/test-10.cs new file mode 100644 index 00000000000..20e1cc6ee81 --- /dev/null +++ b/mcs/tests/test-10.cs @@ -0,0 +1,150 @@ +/* + * Test explicit numeric conversions. + */ + +using System; + +class X { + + void asbyte (byte a, ushort b, uint c, ulong d, char e) + { + } + + void bsbyte () + { + sbyte s = 0; + + asbyte ((byte) s, (ushort) s, (uint) s, (ulong) s, (char) s); + asbyte (checked ((byte) s), checked ((ushort) s), checked ((uint) s), checked ((ulong) s), checked ((char) s)); + } + + void abyte (sbyte a, char b) + { + } + + void bbyte () + { + byte b = 0; + + abyte ((sbyte) b, (char) b); + abyte (checked ((sbyte) b), checked ((char) b)); + } + + void ashort (sbyte a, byte b, ushort c, uint d, ulong e, char f) + { + } + + void bshort () + { + short a = 1; + + ashort ((sbyte) a, (byte) a, (ushort) a, (uint) a, (ulong) a, (char) a); + ashort (checked ((sbyte) a), checked ((byte) a), checked ((ushort) a), checked ((uint) a), checked ((ulong) a), checked ((char) a)); + } + + void aushort (sbyte a, byte b, short c, char d) + { + } + + void bushort () + { + ushort a = 1; + aushort ((sbyte) a, (byte) a, (short) a, (char) a); + aushort (checked ((sbyte) a), checked ((byte) a), checked ((short) a), checked ((char) a)); + } + + void aint (sbyte a, byte b, short c, ushort d, uint e, ulong f, char g) + { + } + + void bint () + { + int a = 1; + + aint ((sbyte) a, (byte) a, (short) a, (ushort) a, (uint) a, (ulong) a, (char) a); + aint (checked ((sbyte) a), checked ((byte) a), checked ((short) a), checked ((ushort) a), checked ((uint) a), checked ((ulong) a), checked ((char) a)); + } + + void auint (sbyte a, byte b, short c, ushort d, int e, char f) + { + } + + void buint () + { + uint a = 1; + + auint ((sbyte) a, (byte) a, (short) a, (ushort) a, (int) a, (char) a); + auint (checked ((sbyte) a), checked ((byte) a), checked ((short) a), checked ((ushort) a), checked ((int) a), checked ((char) a)); + } + + void along (sbyte a, byte b, short c, ushort d, int e, uint f, ulong g, char h) + { + } + + void blong () + { + long a = 1; + + along ((sbyte) a, (byte) a, (short) a, (ushort) a, (int) a, (uint) a, (ulong) a, (char) a); + along (checked ((sbyte) a), checked ((byte) a), checked ((short) a), checked ((ushort) a), checked ((int) a), checked ((uint) a), checked ((ulong) a), checked ((char) a)); + } + + void aulong (sbyte a, byte b, short c, ushort d, int e, uint f, long g, char h) + { + } + + void bulong () + { + ulong a = 1; + + aulong ((sbyte) a, (byte) a, (short) a, (ushort) a, (int) a, (uint) a, (long) a, (char) a); + aulong (checked ((sbyte) a), checked ((byte) a), checked ((short) a), checked ((ushort) a), checked ((int) a), checked ((uint) a), checked ((long) a), checked ((char) a)); + } + + void achar (sbyte a, byte b, short c) + { + + } + + void bchar () + { + char a = (char) 1; + + achar ((sbyte) a, (byte) a, (short) a); + achar (checked ((sbyte) a), checked ((byte) a), checked ((short) a)); + } + + void afloat (sbyte a, byte b, short c, ushort d, int e, uint f, long ll, ulong g, char h, decimal dd) + { + } + + void bfloat () + { + float a = 1; + + afloat ((sbyte) a, (byte) a, (short) a, (ushort) a, (int) a, (uint) a, (long) a, + (ulong) a, (char) a, (decimal) a); + afloat (checked ((sbyte) a), checked ((byte) a), checked ((short) a), checked ((ushort) a), checked ((int) a), checked ((uint) a), checked ((long) a), +checked ( (ulong) a), checked ((char) a), checked ((decimal) a)); + } + + void adouble (sbyte a, byte b, short c, ushort d, int e, uint f, long ll, ulong g, char h, + float ff, decimal dd) + { + } + + void bdouble () + { + double a = 1; + + adouble ((sbyte) a, (byte) a, (short) a, (ushort) a, (int) a, (uint) a, (long) a, + (ulong) a, (char) a, (float) a, (decimal) a); + adouble (checked ((sbyte) a), checked ((byte) a), checked ((short) a), checked ((ushort) a), checked ((int) a), checked ((uint) a), checked ((long) a), +checked ( (ulong) a), checked ((char) a), checked ((float) a), (decimal) a); + } + + static void Main () + { + + } +} diff --git a/mcs/tests/test-100.cs b/mcs/tests/test-100.cs new file mode 100755 index 00000000000..da77cf3cdda --- /dev/null +++ b/mcs/tests/test-100.cs @@ -0,0 +1,31 @@ +namespace GLib { + + using System; + using System.Runtime.InteropServices; + + public class Object { + int v; + + protected int Raw { + get { + return 1; + } + set { + v = value; + } + } + + [DllImport("bah", CallingConvention=CallingConvention.Cdecl)] + static extern void g_object_get (int obj); + + public void GetProperty () + { + g_object_get (Raw); + } + + static int Main () + { + return 0; + } + } +} diff --git a/mcs/tests/test-101.cs b/mcs/tests/test-101.cs new file mode 100644 index 00000000000..5ed02f537e6 --- /dev/null +++ b/mcs/tests/test-101.cs @@ -0,0 +1,44 @@ +using System; +using System.Reflection; + +namespace Test { + + public class MyAttribute: Attribute { + public string val; + public MyAttribute (string stuff) { + System.Console.WriteLine (stuff); + val = stuff; + } + } + + public class My2Attribute: MyAttribute { + public int ival; + public My2Attribute (string stuff, int blah) : base (stuff) { + System.Console.WriteLine ("ctor with int val"+stuff); + ival = blah; + } + } + + [Flags, ] + enum X { + A, B + } + + [My("testclass")] + [My2("testclass", 22)] + public class Test { + static public int Main() { + System.Reflection.MemberInfo info = typeof (Test); + object[] attributes = info.GetCustomAttributes (false); + for (int i = 0; i < attributes.Length; i ++) { + System.Console.WriteLine(attributes[i]); + } + if (attributes.Length != 2) + return 1; + MyAttribute attr = (MyAttribute) attributes [0]; + if (attr.val != "testclass") + return 2; + return 0; + } + } +} diff --git a/mcs/tests/test-102.cs b/mcs/tests/test-102.cs new file mode 100644 index 00000000000..de79a8ea464 --- /dev/null +++ b/mcs/tests/test-102.cs @@ -0,0 +1,36 @@ +using System; +using System.Reflection; + +[assembly: AssemblyTitle ("Foo")] +[assembly: AssemblyVersion ("1.0.2")] + +namespace N1 { + + [AttributeUsage (AttributeTargets.All)] + public class MineAttribute : Attribute { + + string name; + + public MineAttribute (string s) + { + name = s; + } + } + + interface A { + [Mine ("hello")] + void Hello (); + } + + public class Foo { + + int i; + + [Mine ("Foo")] + [return: Mine ("Bar")] + public static int Main () + { + return 0; + } + } +} diff --git a/mcs/tests/test-103.cs b/mcs/tests/test-103.cs new file mode 100755 index 00000000000..09974f4cc29 --- /dev/null +++ b/mcs/tests/test-103.cs @@ -0,0 +1,28 @@ +// +// We should also allow overrides to work on protected methods. +// Only private is not considered part of the override process. +// +abstract class A { + protected abstract int Foo (); +} + +class B : A { + protected override int Foo () + { + return 0; + } + + public int M () + { + return Foo (); + } +} + +class Test { + public static int Main () + { + return new B ().M (); + } +} + + diff --git a/mcs/tests/test-104.cs b/mcs/tests/test-104.cs new file mode 100644 index 00000000000..82fcfac57fd --- /dev/null +++ b/mcs/tests/test-104.cs @@ -0,0 +1,14 @@ +// +// Test to ensure we do correct overload resolution +// +using System; + +class Test { + public static int Main(String[] args) { + int iTest = 1; + + System.Threading.Interlocked.Increment(ref iTest); + + return 0; + } +} diff --git a/mcs/tests/test-105.cs b/mcs/tests/test-105.cs new file mode 100644 index 00000000000..ddfc2dbc05b --- /dev/null +++ b/mcs/tests/test-105.cs @@ -0,0 +1,61 @@ +using System; +using System.Threading; +using System.Runtime.InteropServices; + +class Test { + delegate int SimpleDelegate (int a); + + static int F (int a) { + Console.WriteLine ("Test.F from delegate: " + a); + Thread.Sleep (200); + return a; + } + + static void async_callback (IAsyncResult ar) + { + Console.WriteLine ("Async Callback " + ar.AsyncState); + } + + static int Main () { + SimpleDelegate d = new SimpleDelegate (F); + AsyncCallback ac = new AsyncCallback (async_callback); + string state1 = "STATE1"; + string state2 = "STATE2"; + string state3 = "STATE3"; + string state4 = "STATE4"; + int fin = 0; + + IAsyncResult ar1 = d.BeginInvoke (1, ac, state1); + IAsyncResult ar2 = d.BeginInvoke (2, ac, state2); + IAsyncResult ar3 = d.BeginInvoke (3, ac, state3); + IAsyncResult ar4 = d.BeginInvoke (4, ac, state4); + + int res = d.EndInvoke (ar1); + + Console.WriteLine ("Result = " + res); + + try { + d.EndInvoke (ar1); + } catch (InvalidOperationException) { + Console.WriteLine ("cant execute EndInvoke twice ... OK"); + } + + ar1.AsyncWaitHandle.WaitOne (); + if (ar1.IsCompleted) fin++; + Console.WriteLine ("completed1: " + ar1.IsCompleted); + ar2.AsyncWaitHandle.WaitOne (); + if (ar2.IsCompleted) fin++; + Console.WriteLine ("completed2: " + ar2.IsCompleted); + ar3.AsyncWaitHandle.WaitOne (); + if (ar3.IsCompleted) fin++; + Console.WriteLine ("completed3: " + ar3.IsCompleted); + ar4.AsyncWaitHandle.WaitOne (); + if (ar4.IsCompleted) fin++; + Console.WriteLine ("completed4: " + ar4.IsCompleted); + + if (fin != 4) + return 1; + + return 0; + } +} diff --git a/mcs/tests/test-106.cs b/mcs/tests/test-106.cs new file mode 100644 index 00000000000..52b5f61d9f1 --- /dev/null +++ b/mcs/tests/test-106.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading; +using System.Runtime.InteropServices; + +class Test { + delegate int SimpleDelegate (int a); + + static int cb_state = 0; + + static int F (int a) { + Console.WriteLine ("Test.F from delegate: " + a); + throw new NotImplementedException (); + } + + static void async_callback (IAsyncResult ar) + { + Console.WriteLine ("Async Callback " + ar.AsyncState); + cb_state = 1; + throw new NotImplementedException (); + } + + static int Main () { + SimpleDelegate d = new SimpleDelegate (F); + AsyncCallback ac = new AsyncCallback (async_callback); + string state1 = "STATE1"; + int res = 0; + + IAsyncResult ar1 = d.BeginInvoke (1, ac, state1); + + ar1.AsyncWaitHandle.WaitOne (); + + try { + res = d.EndInvoke (ar1); + } catch (NotImplementedException) { + res = 1; + Console.WriteLine ("received exception ... OK"); + } + + while (cb_state == 0) + Thread.Sleep (0); + + if (cb_state != 1) + return 1; + + if (res != 1) + return 2; + + return 0; + } +} diff --git a/mcs/tests/test-107.cs b/mcs/tests/test-107.cs new file mode 100644 index 00000000000..a5639efa8f0 --- /dev/null +++ b/mcs/tests/test-107.cs @@ -0,0 +1,45 @@ +using System; +using System.Threading; +using System.Runtime.InteropServices; +using System.Runtime.Remoting.Messaging; + +class Test { + delegate int SimpleDelegate (int a); + + static int cb_state = 0; + + static int F (int a) { + Console.WriteLine ("Test.F from delegate: " + a); + throw new NotImplementedException (); + } + + static void async_callback (IAsyncResult ar) + { + AsyncResult ares = (AsyncResult)ar; + AsyncCallback ac = new AsyncCallback (async_callback); + + Console.WriteLine ("Async Callback " + ar.AsyncState); + cb_state++; + SimpleDelegate d = (SimpleDelegate)ares.AsyncDelegate; + + if (cb_state < 5) + d.BeginInvoke (cb_state, ac, cb_state); + + //throw new NotImplementedException (); + } + + static int Main () { + SimpleDelegate d = new SimpleDelegate (F); + AsyncCallback ac = new AsyncCallback (async_callback); + + IAsyncResult ar1 = d.BeginInvoke (cb_state, ac, cb_state); + + ar1.AsyncWaitHandle.WaitOne (); + + + while (cb_state < 5) + Thread.Sleep (200); + + return 0; + } +} diff --git a/mcs/tests/test-108.cs b/mcs/tests/test-108.cs new file mode 100755 index 00000000000..2edc56d9457 --- /dev/null +++ b/mcs/tests/test-108.cs @@ -0,0 +1,44 @@ +class X { + + static int Main () + { + int i = 0; + + if (false){ + i = 1; + return 1; + } + + if (true) + i = 2; + else + i = 3; + + if (i != 2) + return 5; + + while (true){ + i++; + if (i == 10) + break; + } + + while (false){ + i--; + return 3; + } + + if (i != 10) + return 2; + + do { + if (i++ == 20) + break; + } while (true); + + if (i != 21) + return 4; + + return 0; + } +} diff --git a/mcs/tests/test-109.cs b/mcs/tests/test-109.cs new file mode 100755 index 00000000000..740155886cd --- /dev/null +++ b/mcs/tests/test-109.cs @@ -0,0 +1,13 @@ +using System; + +class T { + static int Main () + { + // + // Just a test to compile the following: + // + string a = "Time is: " + DateTime.Now; + + return 0; + } +} diff --git a/mcs/tests/test-11.cs b/mcs/tests/test-11.cs new file mode 100644 index 00000000000..c122201d472 --- /dev/null +++ b/mcs/tests/test-11.cs @@ -0,0 +1,27 @@ +using System; +using System.IO; + +public class Test { + + public static int boxtest () + { + int i = 123; + object o = i; +// int j = (int) o; + +// if (i != j) +// return 1; + + return 0; + } + + public static int Main () { + if (boxtest () != 0) + return 1; + + + return 0; + } +} + + diff --git a/mcs/tests/test-110.cs b/mcs/tests/test-110.cs new file mode 100755 index 00000000000..b8900991ed3 --- /dev/null +++ b/mcs/tests/test-110.cs @@ -0,0 +1,32 @@ +// +// Special test case for the Compound Assignment for the +// second case (not the obvious one, but the one with +// implicit casts) + +using System; + +namespace test +{ + public class test + { + static int test_method(int vv) + { + byte b = 45; + + // The cast below will force the expression into being + // a byte, and we basically make an explicit cast from + // the return of "<<" from int to byte (the right-side type + // of the compound assignemtn) + b |= (byte)(vv << 1); + + return b; + } + + public static int Main () + { + if (test_method (1) != 47) + return 1; + return 0; + } + } +} diff --git a/mcs/tests/test-111.cs b/mcs/tests/test-111.cs new file mode 100755 index 00000000000..4af5997bef9 --- /dev/null +++ b/mcs/tests/test-111.cs @@ -0,0 +1,11 @@ +class T { + static object get_obj() { + return new object (); + } + static int Main() { + object o = get_obj (); + if (o == "string") + return 1; + return 0; + } +} diff --git a/mcs/tests/test-112.cs b/mcs/tests/test-112.cs new file mode 100755 index 00000000000..c1c28547991 --- /dev/null +++ b/mcs/tests/test-112.cs @@ -0,0 +1,19 @@ +// +// This tests the use of an array indexer on value exprclasses +// and not only variables +// +class X { + static int [] g () + { + int [] x = new int [5]; + x [1] = 10; + return x; + } + + static int Main () + { + if (g () [1] == 10) + return 0; + return 1; + } +} diff --git a/mcs/tests/test-113.cs b/mcs/tests/test-113.cs new file mode 100644 index 00000000000..c26268c1432 --- /dev/null +++ b/mcs/tests/test-113.cs @@ -0,0 +1,32 @@ +using System; + +class X { + + IntPtr Raw; + + void g_object_get (IntPtr obj, string name, out string val, IntPtr term) + { + val = null; + } + + public void GetProperty (String name, out String val) + { + g_object_get (Raw, name, out val, new IntPtr (0)); + } + + void g_object_get (IntPtr obj, string name, out bool val, IntPtr term) + { + val = true; + } + + public void GetProperty (String name, out bool val) + { + g_object_get (Raw, name, out val, new IntPtr (0)); + } + + public static int Main () + { + return 0; + } + +} diff --git a/mcs/tests/test-114.cs b/mcs/tests/test-114.cs new file mode 100644 index 00000000000..36925d310be --- /dev/null +++ b/mcs/tests/test-114.cs @@ -0,0 +1,13 @@ +using System; + +class MyClass { + + delegate bool IsAnything (Char c); + + public static int Main () { + IsAnything validDigit; + validDigit = new IsAnything (Char.IsDigit); + + return 0; + } +} diff --git a/mcs/tests/test-115.cs b/mcs/tests/test-115.cs new file mode 100755 index 00000000000..02b630e0225 --- /dev/null +++ b/mcs/tests/test-115.cs @@ -0,0 +1,42 @@ +// +// This is a compile test, submitted by Joe. We really need +// a more thorough set of tests for the user defined explicit +// conversions +// +using System; + +class A { + public static explicit operator X (A foo) + { + X myX = new X(); + + return myX; + } +} + +class X { +} + +class Y : X { +} + +class blah { + public static int Main () + { + A testA = new A(); + + X testX = (X) testA; + + try { + Y testY = (Y) testA; + } catch (InvalidCastException){ + return 0; + } + + // + // We should have thrown the exception above + // + return 1; + } +} + diff --git a/mcs/tests/test-116.cs b/mcs/tests/test-116.cs new file mode 100755 index 00000000000..c5690ba62f1 --- /dev/null +++ b/mcs/tests/test-116.cs @@ -0,0 +1,12 @@ +// +// Parsing tests +// + +class X { + static int Main () + { + double d = 1.4e-4; + // add more ;-) + return 0; + } +} diff --git a/mcs/tests/test-117.cs b/mcs/tests/test-117.cs new file mode 100644 index 00000000000..d6745124677 --- /dev/null +++ b/mcs/tests/test-117.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections; + +public interface IFoo { + +} + +public class Blah : IFoo { + + Hashtable table; + + public Blah () + { + table = new Hashtable (); + } + + public static int Main () + { + Blah b = new Blah (); + + b.table.Add ("Ravi", (IFoo) b); + + return 0; + } + + + +} diff --git a/mcs/tests/test-118.cs b/mcs/tests/test-118.cs new file mode 100755 index 00000000000..7e814876687 --- /dev/null +++ b/mcs/tests/test-118.cs @@ -0,0 +1,14 @@ +using System; +using System.Security.Policy; +using System.Threading; + +class Container { + + // LoaderOptimization exists as an enum + // and LoaderOptimization is also the abbreviation for + // LoaderOptimizationAttribute + [LoaderOptimization (LoaderOptimization.SingleDomain)] + static int Main (string[] args) { + return 0; + } +} diff --git a/mcs/tests/test-119.cs b/mcs/tests/test-119.cs new file mode 100644 index 00000000000..be7d7695a22 --- /dev/null +++ b/mcs/tests/test-119.cs @@ -0,0 +1,50 @@ +class Value { + public static explicit operator int (Value val) + { + return 1; + } + + public static explicit operator MyObject (Value val) + { + return new MyObject (1); + } + + public static explicit operator uint (Value val) + { + return 1; + } +} + +class MyObject { + public MyObject (int i) {} +} + +class Derived : MyObject { + public Derived (int i) : base (i) { } + + Derived Blah () + { + Value val = new Value (); + + return (Derived) val; + } +} + +class Test { + static int Main () + { + Value v = new Value (); + + v = null; + + try { + // This will throw an exception. + // This test is more of a compile test, we need a real + // good test that does not require this lame catch. + Derived d = (Derived) v; + } catch { + } + + return 0; + } +} diff --git a/mcs/tests/test-12.cs b/mcs/tests/test-12.cs new file mode 100644 index 00000000000..b788eb89dd1 --- /dev/null +++ b/mcs/tests/test-12.cs @@ -0,0 +1,44 @@ +/* + * Tests the ?: operator and the string concatenation + */ + +using System; +class X { + static int Main (string [] args) + { + string a = "hello"; + string b = "1"; + string c = a + b; + string d = a + 1; + string y; + + if (c != d) + return 1; + if (d != (a + b)) + return 2; + if (d != x (a, b)) + return 3; + if (d != x (a, 1)) + return 4; + + y = c == d ? "equal" : "not-equal"; + if (y != "equal") + return 5; + y = b == a ? "oops" : "nice"; + if (y != "nice") + return 6; + + Console.WriteLine (c); + return 0; + } + + static string s (string a, int o) + { + return a + o; + } + static string x (string s, object o) + { + return s + o; + } + +} diff --git a/mcs/tests/test-120.cs b/mcs/tests/test-120.cs new file mode 100755 index 00000000000..5d4f5180a34 --- /dev/null +++ b/mcs/tests/test-120.cs @@ -0,0 +1,56 @@ +// +// This tests checks that the compiler catches the special attributes +// for in a struct for CharSet, and turns the right bit on the TypeAttribute +// +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +[StructLayout(LayoutKind.Explicit, Size=32,CharSet=CharSet.Unicode)] +struct MyUnicode +{ + [FieldOffset(0)] public float fh_float; + [FieldOffset(0)] public int fh_int; +} + +[StructLayout(LayoutKind.Explicit, Size=32,CharSet=CharSet.Ansi)] +struct MyAnsi +{ + [FieldOffset(0)] public float fh_float; + [FieldOffset(0)] public int fh_int; +} +[StructLayout(LayoutKind.Explicit, Size=32,CharSet=CharSet.Auto)] +struct MyAuto +{ + [FieldOffset(0)] public float fh_float; + [FieldOffset(0)] public int fh_int; +} + +class test +{ + + static int Main () + { + Type t = typeof (MyUnicode); + + if ((t.Attributes & TypeAttributes.UnicodeClass) != TypeAttributes.UnicodeClass){ + Console.WriteLine ("Class MyUnicode does not have Unicode bit set"); + return 1; + } + + t = typeof (MyAuto); + if ((t.Attributes & TypeAttributes.AutoClass) != TypeAttributes.AutoClass){ + Console.WriteLine ("Class MyAuto does not have Auto bit set"); + return 2; + } + + t = typeof (MyAnsi); + + if ((t.Attributes & TypeAttributes.AnsiClass) != TypeAttributes.AnsiClass){ + Console.WriteLine ("Class MyUnicode does not have Ansi bit set"); + return 3; + } + + return 0; + } +} diff --git a/mcs/tests/test-121.cs b/mcs/tests/test-121.cs new file mode 100755 index 00000000000..21e96bc967f --- /dev/null +++ b/mcs/tests/test-121.cs @@ -0,0 +1,35 @@ +// +// This test excercises the fact that array evaluation in UnaryMutator and +// CompoundAssign expressions should never mutate data more than once +// +class X { + static int g_calls; + + static int g () + { + g_calls++; + return 0; + } + + + static int Main () + { + int [] a = new int [10]; + int i = 0; + + a [0] = 1; + + a [i++] += 3; + + if (i != 1) + return 1; + if (a [0] != 4) + return 2; + + a [g ()]++ ; + + if (g_calls != 1) + return 3; + return 0; + } +} diff --git a/mcs/tests/test-122.cs b/mcs/tests/test-122.cs new file mode 100755 index 00000000000..27a08e8adde --- /dev/null +++ b/mcs/tests/test-122.cs @@ -0,0 +1,21 @@ +// +// Tests that a nested class has full access to its container members +// +// A compile-only test. +// + +class A { + private static int X = 0; + + class B { + void Foo () + { + ++ X; + } + } + + public static int Main () + { + return 0; + } +} diff --git a/mcs/tests/test-123.cs b/mcs/tests/test-123.cs new file mode 100755 index 00000000000..87f7dbbfe01 --- /dev/null +++ b/mcs/tests/test-123.cs @@ -0,0 +1,47 @@ +class X { + + static object get_non_null () + { + return new X (); + } + + static object get_null () + { + return null; + } + + static int Main () + { + int a = 5; + object o; + decimal d = 0M; + + // + // compile time + // + if (!(get_non_null () is object)) + return 1; + + if (get_null () is object) + return 2; + + if (!(a is object)) + return 3; + + // + // explicit reference + // + if (null is object) + return 4; + + o = a; + if (!(o is int)) + return 5; + + if (d is int) + return 6; + + System.Console.WriteLine ("Is tests pass"); + return 0; + } +} diff --git a/mcs/tests/test-124.cs b/mcs/tests/test-124.cs new file mode 100644 index 00000000000..c28d9899d65 --- /dev/null +++ b/mcs/tests/test-124.cs @@ -0,0 +1,24 @@ +using System.Drawing; + +namespace N1 +{ + public class D + { + public static int Main () + { + Rectangle rect = new Rectangle (); + N (rect); + + return 0; + } + + public static bool N (RectangleF rect) + { + if (rect.X > rect.Y) + return true; + + return false; + } + } +} + diff --git a/mcs/tests/test-125.cs b/mcs/tests/test-125.cs new file mode 100644 index 00000000000..51217ef2697 --- /dev/null +++ b/mcs/tests/test-125.cs @@ -0,0 +1,100 @@ +using System; + +public class Fraction { + + public Fraction(int numerator, int denominator) { + Console.WriteLine("In Fraction Constructor(int, int)"); + this.numerator = numerator; + this.denominator = denominator; + } + + public Fraction(int wholeNumber) { + Console.WriteLine("In Fraction Constructor(int)"); + numerator = wholeNumber; + denominator = 1; + } + + // this function is not recognised by mcs further down + public static implicit operator Fraction(int theInt) { + Console.WriteLine("In implicit conversion to Fraction"); + return new Fraction(theInt); + } + + public static explicit operator int(Fraction theFraction) { + Console.WriteLine("In explicit conversion to int"); + return theFraction.numerator / + theFraction.denominator; + } + + public static bool operator==(Fraction lhs, Fraction rhs) { + Console.WriteLine("In operator =="); + if (lhs.denominator == rhs.denominator && + lhs.numerator == rhs.numerator) { + return true; + } + // code here to handle unlike fraction + return false; + } + + public static bool operator!=(Fraction lhs, Fraction rhs) { + Console.WriteLine("In operator !="); + return !(lhs == rhs); + } + + public override bool Equals(object o) { + Console.WriteLine("In method Equals"); + if (! (o is Fraction)) { + return false; + } + return this == (Fraction) o; + } + + public static Fraction operator+(Fraction lhs, Fraction rhs) { + Console.WriteLine("In operator +"); + if (lhs.denominator == rhs.denominator) { + return new Fraction(lhs.numerator + rhs.numerator, + lhs.denominator); + } + + // simplistic solution for unlike fractions + // 1/2 + 3/4 == (1*4) + (3*2) / (2*4) == 10/8 + int firstProduct = lhs.numerator * rhs.denominator; + int secondProduct = lhs.denominator * rhs.numerator; + return new Fraction( + firstProduct + secondProduct, + lhs.denominator * rhs.denominator); + } + + public override string ToString() { + String s = numerator.ToString() + "/" + + denominator.ToString(); + return s; + } + + private int numerator; + private int denominator; +} + +public class Tester { + public static int Main() { + + Fraction f1 = new Fraction(3,4); + Console.WriteLine("f1: {0}", f1.ToString()); + + Fraction f2 = new Fraction(2,4); + Console.WriteLine("f2: {0}", f2.ToString()); + + Fraction f3 = f1 + f2; + Console.WriteLine("f1 + f2 = f3: {0}", f3.ToString()); + + Fraction f4 = f3 + 5; + Console.WriteLine("f3 + 5 = f4: {0}", f4.ToString()); + + Fraction f5 = new Fraction(2, 4); + if (f5 == f2) + Console.WriteLine("f5: {0} == f2: {1}", f5.ToString(), f2.ToString()); + + + return 0; + } +} diff --git a/mcs/tests/test-126.cs b/mcs/tests/test-126.cs new file mode 100755 index 00000000000..26ed4190a20 --- /dev/null +++ b/mcs/tests/test-126.cs @@ -0,0 +1,24 @@ +// +// It is possible to invoke object methods in an interface. +// +using System; + +interface Iface { + void Method (); +} + +class X : Iface { + + void Iface.Method () {} + + static int Main () + { + X x = new X (); + Iface f = x; + + if (f.ToString () != "X") + return 1; + + return 0; + } +} diff --git a/mcs/tests/test-127.cs b/mcs/tests/test-127.cs new file mode 100755 index 00000000000..1ca2bed7449 --- /dev/null +++ b/mcs/tests/test-127.cs @@ -0,0 +1,23 @@ +// +// It is possible to invoke Enum methods on an enum type. +// +using System; + +enum Test { + A, + B, + C +} + +class X { + + static int Main () + { + Test test = Test.A; + + if (!Test.IsDefined (typeof (Test), test)) + return 1; + + return 0; + } +} diff --git a/mcs/tests/test-128.cs b/mcs/tests/test-128.cs new file mode 100644 index 00000000000..21e5ec7b05b --- /dev/null +++ b/mcs/tests/test-128.cs @@ -0,0 +1,41 @@ +using System; + +public class SimpleAttribute : Attribute { + + string n; + + public SimpleAttribute (string name) + { + n = name; + } +} + +public class Blah { + + int i; + + public int Value { + + [Simple ("Foo!")] + get { + return i; + } + + [Simple ("Bar !")] + set { + i = value; + } + + } + + public static int Main () + { + // + // We need a better test which does reflection to check if the + // attributes have actually been applied etc. + // + + return 0; + } + +} diff --git a/mcs/tests/test-129.cs b/mcs/tests/test-129.cs new file mode 100755 index 00000000000..11cf4b70e2c --- /dev/null +++ b/mcs/tests/test-129.cs @@ -0,0 +1,17 @@ +// +// Check unary minus. +// +using System; + +class X { + + static int Main () + { + short a = -32768; + int b = -2147483648; + long c = -9223372036854775808; + sbyte d = -128; + + return 0; + } +} diff --git a/mcs/tests/test-13.cs b/mcs/tests/test-13.cs new file mode 100644 index 00000000000..f921ae55728 --- /dev/null +++ b/mcs/tests/test-13.cs @@ -0,0 +1,31 @@ +using System; + +class Foo { + + public bool MyMethod () + { + Console.WriteLine ("Base class method !"); + return true; + } +} + +class Blah : Foo { + + public static int Main () + { + Blah k = new Blah (); + + Foo i = k; + + if (i.MyMethod ()) + return 0; + else + return 1; + + + } + +} + + + diff --git a/mcs/tests/test-130.cs b/mcs/tests/test-130.cs new file mode 100755 index 00000000000..6ec174a8d5f --- /dev/null +++ b/mcs/tests/test-130.cs @@ -0,0 +1,29 @@ +// +// Check casts. +// +using System; + +class X { + + public const short a = 128; + public const int b = 0xffff; + public const double c = 123.4; + + public const long d = 5; + // public const int e = 2147483648; + + public const byte f = 127; + + public const char c1 = (char) 0xffff; + public const char c2 = (char) 123.4; + public const char c3 = (char) a; + public const char c4 = (char) b; + public const char c5 = (char) c; + + public const short s2 = (short) c; + + static int Main () + { + return 0; + } +} diff --git a/mcs/tests/test-131.cs b/mcs/tests/test-131.cs new file mode 100644 index 00000000000..568576c96fa --- /dev/null +++ b/mcs/tests/test-131.cs @@ -0,0 +1,35 @@ +using System; + +public class SimpleAttribute : Attribute { + + string n; + + public SimpleAttribute (string name) + { + n = name; + } +} + +public class Blah { + + public enum Foo { + + A, + + [Simple ("second")] + B, + + C + } + + public static int Main () + { + // + // We need a better test which does reflection to check if the + // attributes have actually been applied etc. + // + + return 0; + } + +} diff --git a/mcs/tests/test-132.cs b/mcs/tests/test-132.cs new file mode 100755 index 00000000000..0ac9a986ce4 --- /dev/null +++ b/mcs/tests/test-132.cs @@ -0,0 +1,14 @@ +using System.Reflection; + +class T { + protected internal string s; + static int Main() { + FieldInfo f = typeof(T).GetField ("s", BindingFlags.NonPublic|BindingFlags.Instance); + if (f == null) + return 2; + FieldAttributes attrs = f.Attributes; + if ((attrs & FieldAttributes.FieldAccessMask) != FieldAttributes.FamORAssem) + return 1; + return 0; + } +} diff --git a/mcs/tests/test-133.cs b/mcs/tests/test-133.cs new file mode 100755 index 00000000000..1e27fc40631 --- /dev/null +++ b/mcs/tests/test-133.cs @@ -0,0 +1,36 @@ +using System; + +public struct S { + public int a, b; +} + +class T { + enum OpCode : ushort { False } + enum OpFlags : ushort { None } + static void DecodeOp (ushort word, out OpCode op, out OpFlags flags) { + op = (OpCode)(word & 0x00ff); + flags = (OpFlags)(word & 0xff00); + } + static void get_struct (out S s) { + S ss; + ss.a = 1; + ss.b = 2; + s = ss; + } + static int Main() { + OpCode op; + OpFlags flags; + S s; + DecodeOp ((ushort)0x0203, out op, out flags); + if (op != (OpCode)0x3) + return 1; + if (flags != (OpFlags)0x200) + return 2; + get_struct (out s); + if (s.a != 1) + return 3; + if (s.b != 2) + return 4; + return 0; + } +} diff --git a/mcs/tests/test-134.cs b/mcs/tests/test-134.cs new file mode 100755 index 00000000000..35cb5c0c15b --- /dev/null +++ b/mcs/tests/test-134.cs @@ -0,0 +1,69 @@ +// +// This test checks if we implement all the interfaces inherited +// + +interface IA { + void A (); +} + +interface IB : IA { + void B (); +} + +interface IC : IA, IB { + void C (); +} + +interface ID : IC { +} + +class AA : IC { + bool a, b, c; + public void A () { a = true; } + public void B () { b = true; } + public void C () { c = true; } + + public bool OK { + get { + return a && b && c; + } + } +} + +class BB : ID{ + bool a, b, c; + public void A () { a = true; System.Console.WriteLine ("A"); } + public void B () { b = true; } + public void C () { c = true; } + + public bool OK { + get { + return a && b && c; + } + } +} + +class T: IB { + public void A () {} + public void B () {} + + static int Main() { + + BB bb = new BB (); + bb.A (); + bb.B (); + bb.C (); + + if (!bb.OK) + return 1; + + AA aa = new AA (); + aa.A (); + aa.B (); + aa.C (); + if (!aa.OK) + return 2; + + return 0; + } +} diff --git a/mcs/tests/test-135.cs b/mcs/tests/test-135.cs new file mode 100755 index 00000000000..c7372e1755b --- /dev/null +++ b/mcs/tests/test-135.cs @@ -0,0 +1,29 @@ +using System; +using System.Reflection; +// test bug bug#26264 + +interface IA { + void doh(); +} +interface IB { + + IA Prop {get;} +} +class A : IA { + public void doh() {} +} +class T : IB { + IA IB.Prop { + get { return new A(); } + } + public A Prop { + get { return new A(); } + } + static int Main() { + PropertyInfo[] p = typeof (T).GetProperties (BindingFlags.Public| BindingFlags.NonPublic|BindingFlags.Instance); + if (p == null || p.Length != 1) + return 1; + return 0; + } +} + diff --git a/mcs/tests/test-136.cs b/mcs/tests/test-136.cs new file mode 100755 index 00000000000..562cdbee956 --- /dev/null +++ b/mcs/tests/test-136.cs @@ -0,0 +1,60 @@ +// +// Tests that explicit and normal implementations of methods are handled +// properly. Before we used to have the normal method implementation +// "implement" the classes, so that it would go into an infinite loop. +// (bug #26334) +// +// Now explicit implementations are defined first. +// +using System; + +public interface IDiagnostic +{ + void Stop(); +} +public interface IAutomobile +{ + void Stop(); +} + +public class MyCar: IAutomobile, IDiagnostic { + public bool diag_stop, car_stop, auto_stop; + + void IDiagnostic.Stop() { + diag_stop = true; + } + + public void Stop() { + car_stop = true; + IAutomobile self = (IAutomobile)this; // cast this + self.Stop(); // forwarding call + } + + void IAutomobile.Stop() + { + auto_stop = true; + } +} + +class TestConflict { + static int Main () + { + MyCar car1 = new MyCar(); + car1.Stop(); // calls the IAutomobile.Stop implementation + + IDiagnostic car2 = new MyCar(); + car2.Stop(); + + IAutomobile car3 = new MyCar(); + car3.Stop(); + + if (!car1.car_stop) + return 1; + + if (car1.diag_stop) + return 2; + + Console.WriteLine ("ok"); + return 0; + } +} diff --git a/mcs/tests/test-137.cs b/mcs/tests/test-137.cs new file mode 100755 index 00000000000..ba11bb7fc39 --- /dev/null +++ b/mcs/tests/test-137.cs @@ -0,0 +1,45 @@ +// +// Explicitly implement all the interface methods pending with the same name. +// +using System; + +interface A { + void X (); +} + +interface B { + void X (); +} + +class C : A, B { + int var; + + public void X () + { + var++; + } + + static int Main () + { + C c = new C (); + + A a = c; + B b = c; + + if (c.var != 0) + return 1; + + a.X (); + if (c.var != 1) + return 2; + b.X (); + if (c.var != 2) + return 3; + c.X (); + if (c.var != 3) + return 4; + + Console.WriteLine ("Test passes"); + return 0; + } +} diff --git a/mcs/tests/test-138.cs b/mcs/tests/test-138.cs new file mode 100755 index 00000000000..1581d2f99ec --- /dev/null +++ b/mcs/tests/test-138.cs @@ -0,0 +1,9 @@ +// ensure the argument to newarr is converted to int32 or native int +class T { + static int Main() { + char[] a; + long len = 10; + a = new char [len]; + return 0; + } +} diff --git a/mcs/tests/test-139.cs b/mcs/tests/test-139.cs new file mode 100755 index 00000000000..be84d94fc98 --- /dev/null +++ b/mcs/tests/test-139.cs @@ -0,0 +1,48 @@ +// +// This tests two uses of the `This' expression on structs; being used as an argument +// and being used implicitly. +// + +struct T { + int val; + void one () { + + // + // First test: Pass this as an argument. + // + two (this); + } + + void two (T t) { + this = t; + } + + void three (ref T t) { + two (t); + } + + + public override int GetHashCode () { + // + // Second test: do we correctly load this? + // + return val.GetHashCode(); + } + + static int Main() + { + T t = new T (); + + t.one (); + + t.GetHashCode (); + + return 0; + } +} + + + + + + diff --git a/mcs/tests/test-14.cs b/mcs/tests/test-14.cs new file mode 100644 index 00000000000..dac824b6028 --- /dev/null +++ b/mcs/tests/test-14.cs @@ -0,0 +1,43 @@ +using System; + +namespace Obj { + interface Bah { + int H (); + } + class A : Bah { + public int F () {return 1;} + public virtual int G () {return 2;} + public int H () {return 10;} + } + class B : A { + public new int F () {return 3;} + public override int G () {return 4;} + public new int H () {return 11;} + } + class Test { + static public int Main () { + int result = 0; + B b = new B (); + A a = b; + if (a.F () != 1) + result |= 1 << 0; + if (b.F () != 3) + result |= 1 << 1; + if (b.G () != 4) + result |= 1 << 2; + if (a.G () != 4){ + Console.WriteLine ("oops: " + a.G ()); + result |= 1 << 3; + } + if (a.H () != 10) + result |= 1 << 4; + if (b.H () != 11) + result |= 1 << 5; + if (((A)b).H () != 10) + result |= 1 << 6; + if (((B)a).H () != 11) + result |= 1 << 7; + return result; + } + }; +}; diff --git a/mcs/tests/test-140.cs b/mcs/tests/test-140.cs new file mode 100755 index 00000000000..03c9757b16b --- /dev/null +++ b/mcs/tests/test-140.cs @@ -0,0 +1,28 @@ +// +// We used to generate incorrect code for breaks in infinite while loops +// +using System; + +public class BreakTest +{ + static int ok = 0; + + public static void B () + { + ok++; + while (true) + { + ok++; + break; + } + ok++; + } + + public static int Main() + { + B (); + if (ok != 3) + return 1; + return 0; + } +} diff --git a/mcs/tests/test-141.cs b/mcs/tests/test-141.cs new file mode 100755 index 00000000000..a540037bdeb --- /dev/null +++ b/mcs/tests/test-141.cs @@ -0,0 +1,25 @@ +using System; + +class X { + public static int Main() + { + byte num1 = 105; + byte num2 = 150; + byte sum; + + bool ok = false; + + // should generate OverflowException + try { + checked { + sum = (byte) (num1 - num2); + } + } catch (OverflowException){ + ok = true; + } + + if (ok) + return 0; + return 1; + } +} diff --git a/mcs/tests/test-142.cs b/mcs/tests/test-142.cs new file mode 100644 index 00000000000..686283b0aaf --- /dev/null +++ b/mcs/tests/test-142.cs @@ -0,0 +1,20 @@ +using System; + +public class TestClass : TestBaseClass { + + public TestClass (EventHandler hndlr) : base () + { + Blah += hndlr; + } + + public static int Main () + { + return 0; + } +} + +public class TestBaseClass { + + public event EventHandler Blah; + +} diff --git a/mcs/tests/test-143.cs b/mcs/tests/test-143.cs new file mode 100755 index 00000000000..3fb5ec2db83 --- /dev/null +++ b/mcs/tests/test-143.cs @@ -0,0 +1,27 @@ +using System; + +struct MonoEnumInfo { + int val; + + void stuff() { val = 1; } + + static int GetInfo (out MonoEnumInfo info) { + info = new MonoEnumInfo (); + info.stuff(); + return info.val; + } + + static int Main() + { + MonoEnumInfo m; + + if (GetInfo (out m) != 1) + return 1; + + if (m.val != 1) + return 2; + + return 0; + } +}; + diff --git a/mcs/tests/test-144.cs b/mcs/tests/test-144.cs new file mode 100644 index 00000000000..3e1929415de --- /dev/null +++ b/mcs/tests/test-144.cs @@ -0,0 +1,11 @@ +using System; + +public class Test +{ + const int A = unchecked ((int)0x80000000); + const int B = checked ((int)0x08000000); + + public static void Main () + { + } +} diff --git a/mcs/tests/test-145.cs b/mcs/tests/test-145.cs new file mode 100644 index 00000000000..78cb9a6811d --- /dev/null +++ b/mcs/tests/test-145.cs @@ -0,0 +1,11 @@ +using System; + +class JagArrayTest +{ + private static int [][] array = { new int [] { 1 }}; + + public static void Main() { + Console.WriteLine(array[0][0]); + } +} + diff --git a/mcs/tests/test-146.cs b/mcs/tests/test-146.cs new file mode 100644 index 00000000000..e45fb40f95a --- /dev/null +++ b/mcs/tests/test-146.cs @@ -0,0 +1,58 @@ +using System; + +public class Test +{ + public static int Main () + { + ulong a = 0; + bool[] r = new bool [16]; + + for (int i = 1; i < 16; i++) + r [i] = false; + + if (a < System.UInt64.MaxValue) + r [0] = true; + if (a <= System.UInt64.MaxValue) + r [1] = true; + if (System.UInt64.MaxValue > a) + r [2] = true; + if (System.UInt64.MaxValue >= a) + r [3] = true; + + float b = 0F; + if (b < System.UInt64.MaxValue) + r [4] = true; + if (b <= System.UInt64.MaxValue) + r [5] = true; + if (System.UInt64.MaxValue > b) + r [6] = true; + if (System.UInt64.MaxValue >= b) + r [7] = true; + + ushort c = 0; + if (c < System.UInt16.MaxValue) + r [8] = true; + if (c <= System.UInt16.MaxValue) + r [9] = true; + if (System.UInt16.MaxValue > c) + r [10] = true; + if (System.UInt16.MaxValue >= c) + r [11] = true; + + byte d = 0; + if (d < System.Byte.MaxValue) + r [12] = true; + if (d <= System.Byte.MaxValue) + r [13] = true; + if (System.Byte.MaxValue > d) + r [14] = true; + if (System.Byte.MaxValue >= d) + r [15] = true; + + foreach (bool check in r) + if (!check) + return 1; + + return 0; + } +} diff --git a/mcs/tests/test-147.cs b/mcs/tests/test-147.cs new file mode 100644 index 00000000000..8d7866cfd26 --- /dev/null +++ b/mcs/tests/test-147.cs @@ -0,0 +1,163 @@ +using System; + +public class X +{ + public long Value = 5; + public static long StaticValue = 6; + + public static X Foo () + { + return new X (); + } + + public static X Bar () + { + return Foo (); + } + + public X Baz () + { + return Bar (); + } + + public uint Property { + get { + return 3; + } + } + + public static uint StaticProperty { + get { + return 20; + } + } + + public int this [int index] { + get { + return 1; + } + } +} + +public class Y : X +{ + new public long Value = 8; + new public static long StaticValue = 9; + + public static new Y Foo () + { + return new Y (); + } + + public static new Y Bar () + { + return Foo (); + } + + public new Y Baz () + { + return Bar (); + } + + public new uint Property { + get { + return 4; + } + } + + public new static uint StaticProperty { + get { + return 21; + } + } + + public new int this [int index] { + get { + return 2; + } + } +} + +public class Z : Y +{ + public int Test () { + if (Property != 4) + return 20; + + if (StaticProperty != 21) + return 21; + + if (((X) this).Property != 3) + return 22; + + if (X.StaticProperty != 20) + return 23; + + if (this [5] != 2) + return 24; + + if (((X) this) [6] != 1) + return 25; + + return 0; + } +} + +public class Test +{ + public static int Main () + { + Y y = new Y (); + X a,b,c,d; + + a = Y.Bar (); + if (!(a is Y)) + return 1; + + b = y.Baz (); + if (!(b is Y)) + return 2; + + c = X.Bar (); + if (c is Y) + return 3; + + d = ((X) y).Baz (); + if (d is Y) + return 4; + + if (y.Value != 8) + return 5; + + if (((X) y).Value != 5) + return 6; + + if (Y.StaticValue != 9) + return 7; + + if (X.StaticValue != 6) + return 8; + + if (y.Property != 4) + return 9; + + if (((X) y).Property != 3) + return 10; + + if (y [5] != 2) + return 11; + + if (((X) y) [7] != 1) + return 10; + + if (X.StaticProperty != 20) + return 11; + + if (Y.StaticProperty != 21) + return 12; + + Z z = new Z (); + + return z.Test (); + } +} diff --git a/mcs/tests/test-148.cs b/mcs/tests/test-148.cs new file mode 100644 index 00000000000..c4afdec50fc --- /dev/null +++ b/mcs/tests/test-148.cs @@ -0,0 +1,172 @@ +using System; +using System.Runtime.CompilerServices; + +public interface X +{ + [IndexerName ("Foo")] + int this [int a] { + get; + } +} + +public class Y : X +{ + int X.this [int a] { + get { + return 1; + } + } + + [IndexerName ("Bar")] + public int this [int a] { + get { + return 2; + } + } + + [IndexerName ("Bar")] + public long this [double a] { + get { + return 3; + } + } +} + +public class Z : Y +{ + [IndexerName ("Whatever")] + new public long this [double a] { + get { + return 4; + } + } + + [IndexerName ("Whatever")] + public float this [long a, int b] { + get { + return a / b; + } + } + + public int InstanceTest () + { + double index = 5; + + Console.WriteLine ("INSTANCE TEST"); + + if (this [index] != 4) + return 6; + if (base [index] != 3) + return 7; + + return 0; + } + + public static int Test () + { + Z z = new Z (); + X x = (X) z; + Y y = (Y) z; + + Console.WriteLine (z [1]); + Console.WriteLine (y [2]); + Console.WriteLine (x [3]); + + if (z [1] != 4) + return 1; + if (y [1] != 2) + return 2; + if (x [1] != 1) + return 3; + + double index = 5; + + Console.WriteLine (z [index]); + Console.WriteLine (y [index]); + + if (z [index] != 4) + return 4; + if (y [index] != 3) + return 5; + + int retval = z.InstanceTest (); + if (retval != 0) + return retval; + + B b = new B (); + if (b [4] != 16) + return 8; + if (b [3,5] != 15) + return 9; + + D d = new D (); + if (d [4] != 16) + return 10; + if (d [3,5] != 15) + return 11; + + return 0; + } + + public static int Main () + { + int result = Test (); + + Console.WriteLine ("RESULT: " + result); + + E e = new E (); + e.g = "monkey"; + + return result; + } +} + +public class A +{ + [IndexerName("Monkey")] + public int this [int value] { + get { + return value * 4; + } + } +} + +public class B : A +{ + public long this [long a, int value] { + get { + return a * value; + } + } +} + +public class C +{ + public int this [int value] { + get { + return value * 4; + } + } +} + +public class D : C +{ + public long this [long a, int value] { + get { + return a * value; + } + } +} + +public class E { + public virtual string g { + get { return "g"; } + set { } + } +} + +public class F : E { + public override string g { + get { return "h"; } + } +} diff --git a/mcs/tests/test-149.cs b/mcs/tests/test-149.cs new file mode 100644 index 00000000000..a3d49b35dda --- /dev/null +++ b/mcs/tests/test-149.cs @@ -0,0 +1,98 @@ +using System; + +public delegate long MyDelegate (int a); + +public interface X +{ + event EventHandler Foo; + + event MyDelegate TestEvent; +} + +public class Y : X +{ + static int a = 0; + + event EventHandler X.Foo { + add { + } + + remove { + } + } + + public event EventHandler Foo; + + public event MyDelegate TestEvent; + + public int Test () + { + X x = this; + + Foo += new EventHandler (callback1); + TestEvent += new MyDelegate (callback2); + + x.Foo += new EventHandler (callback3); + + if (a != 0) + return 1; + + Foo (this, new EventArgs ()); + if (a != 1) + return 2; + + if (TestEvent (2) != 4) + return 3; + + if (a != 2) + return 4; + + return 0; + } + + + private static void callback1 (object sender, EventArgs e) + { + a = 1; + } + + private static long callback2 (int b) + { + a = b; + return a * a; + } + + private static void callback3 (object sender, EventArgs e) + { + a = 3; + } +} + +public class Z : Y +{ + public delegate int SomeEventHandler(); + public static event SomeEventHandler BuildStarted; + + static int a () + { + return 1; + } + public static int Main () + { + Z z = new Z (); + + int result = z.Test (); + + if (result != 0) + return result; + + if (BuildStarted != null) { + BuildStarted(); + } + BuildStarted = new SomeEventHandler (a); + if (BuildStarted () != 1) + return 50; + + return 0; + } +} diff --git a/mcs/tests/test-15.cs b/mcs/tests/test-15.cs new file mode 100755 index 00000000000..c199bc13bcb --- /dev/null +++ b/mcs/tests/test-15.cs @@ -0,0 +1,22 @@ +using System; + +interface Iface { + void A (); +} + +class Implementor : Iface { + public void A () {} +} + +class Run { + + static int Main () + { + Iface iface; + Implementor i = new Implementor (); + + iface = i; + + return 0; + } +} diff --git a/mcs/tests/test-150.cs b/mcs/tests/test-150.cs new file mode 100644 index 00000000000..544d297fa7e --- /dev/null +++ b/mcs/tests/test-150.cs @@ -0,0 +1,8 @@ +using System; +class T { + public static int Main() { + if (Int32.MinValue == 0x80000000) + return 1; + return 0; + } +} diff --git a/mcs/tests/test-151.cs b/mcs/tests/test-151.cs new file mode 100644 index 00000000000..ab523eed154 --- /dev/null +++ b/mcs/tests/test-151.cs @@ -0,0 +1,16 @@ +using System; +namespace A { + public class Iface { + void bah() {} + } + class my { + A.Iface b; + void doit (Object A) { + b = (A.Iface)A; + } + public static int Main () { + return 0; + } + } +} + diff --git a/mcs/tests/test-152.cs b/mcs/tests/test-152.cs new file mode 100644 index 00000000000..357c7699bc1 --- /dev/null +++ b/mcs/tests/test-152.cs @@ -0,0 +1,39 @@ +using System; + +public class X +{ + public static int Main () + { + int v = 10; + int a; + + switch (v) { + case 0: + int i = v + 1; + a = i; + break; + default: + i = 5; + a = i; + break; + } + if (a != 5) + return 1; + + + v = 20; + int r = 0; + + switch (v){ + case 20: + r++; + int j = 10; + r += j; + break; + } + if (r != 11) + return 5; + + return 0; + } +} diff --git a/mcs/tests/test-153.cs b/mcs/tests/test-153.cs new file mode 100644 index 00000000000..29419075afb --- /dev/null +++ b/mcs/tests/test-153.cs @@ -0,0 +1,24 @@ +#define DEBUG +using System; +using System.Text; +using System.Diagnostics; + +class Z +{ + static public void Test2 (string message, params object[] args) + { + } + + static public void Test (string message, params object[] args) + { + Test2 (message, args); + } + + static int Main () + { + Test ("TEST"); + Test ("Foo", 8); + Test ("Foo", 8, 9, "Hello"); + return 0; + } +} diff --git a/mcs/tests/test-154.cs b/mcs/tests/test-154.cs new file mode 100644 index 00000000000..f73b25dacaf --- /dev/null +++ b/mcs/tests/test-154.cs @@ -0,0 +1,393 @@ +using System; +using System.Collections; + +public class X +{ + public static int Main () + { + // This is a compilation-only test. + return 0; + } + + // All code paths throw an exception, no need to set out parameters. + public static void test1 (out float f) + { + throw new NotSupportedException (); + } + + // The while loop breaks but does not return, so this is ok. + public static void test2 (int a, out float f) + { + while (a > 0) { + if (a == 5) + continue; + + Console.WriteLine (a); + } + + f = 8.53F; + } + + // a has been assigned in all code paths which do not return. + public static void test3 (long[] b, int c) + { + ICollection a; + if (b == null) + throw new ArgumentException (); + else + a = (ICollection) b; + + Console.WriteLine (a); + } + + // Forward goto, it's ok to set f after the target label. + public static int test4 (int b, out float f) + { + long a; + + Console.WriteLine ("Hello World"); + + a = 5; + + goto World; + + World: + Console.WriteLine (a); + + f = 8.53F; + + return 0; + } + + // try { ... } catch { ... } finally { ... } block + static public int test5 (out float f, long d) + { + int a; + long b = 8; + + try { + f = 8.53F; + + if (d == 500) + return 9; + + a = 5; + } catch (NotSupportedException e) { + a = 9; + } catch (Exception e) { + return 9; + } finally { + f = 9.234F; + } + + return a; + } + + // Passing out parameter to method invocation + static public int test6 (out float f) + { + return test5 (out f, 50); + } + + // Loop-variable of foreach() and for() loop. + static public long test7 (int[] a, int stop) + { + long b = 0; + foreach (int i in a) + b += i; + + for (int i = 1; i < stop; i++) + b *= i; + + return b; + } + + // Initializing locals in initialize or test of for block + static public long test8 (int stop) + { + int i; + long b; + for (i = 1; (b = stop) > 3; i++) { + stop--; + b += i; + } + return b; + } + + // Initializing locals in test of while block + static public long test9 (int stop) + { + long b; + while ((b = stop) > 3) { + stop--; + b += stop; + } + return b; + } + + // Return in subblock + public static void test10 (int a, out float f) + { + if (a == 5) { + f = 8.53F; + return; + } + + f = 9.0F; + } + + // Switch block + public static long test11 (int a) + { + long b; + + switch (a) { + case 5: + b = 1; + break; + + case 9: + b = 3; + break; + + default: + return 9; + } + + return b; + } + + // Try block which rethrows exception. + public static void test12 (out float f) + { + try { + f = 9.0F; + } catch { + throw new NotSupportedException (); + } + } + + // Return in subblock. + public static void test13 (int a, out float f) + { + do { + if (a == 8) { + f = 8.5F; + return; + } + } while (false); + + f = 1.3F; + return; + } + + // Switch block with goto case / goto default. + public static long test14 (int a, out float f) + { + long b; + + switch (a) { + case 1: + goto case 2; + + case 2: + f = 9.53F; + return 9; + + case 3: + goto default; + + default: + b = 10; + break; + } + + f = 10.0F; + + return b; + } + + // Forward goto, it's ok to set f before the jump. + public static int test15 (int b, out float f) + { + long a; + + Console.WriteLine ("Hello World"); + + a = 5; + f = 8.53F; + + goto World; + + World: + Console.WriteLine (a); + + return 0; + } + + // `continue' breaks unless we're a loop block. + public static void test16 () + { + int value; + + for (int i = 0; i < 5; ++i) { + if (i == 0) { + continue; + } else if (i == 1) { + value = 2; + } else { + value = 0; + } + if (value > 0) + return; + } + } + + // `continue' in a nested if. + public static void test17 () + { + int value; + long charCount = 9; + long testit = 5; + + while (charCount > 0) { + --charCount; + + if (testit == 8) { + if (testit == 9) + throw new Exception (); + + continue; + } else { + value = 0; + } + + Console.WriteLine (value); + } + } + + // `out' parameter assigned after conditional exception. + static void test18 (int a, out int f) + { + try { + if (a == 5) + throw new Exception (); + + f = 9; + } catch (IndexOutOfRangeException) { + throw new FormatException (); + } + } + + // code after try/catch block is unreachable. always returns. + static int test19 () { + int res; + int a = Environment.NewLine.Length; + int fin = 0; + + try { + res = 10/a; + throw new NotImplementedException (); + } catch (NotImplementedException e) { + fin = 2; + throw new NotImplementedException (); + } finally { + fin = 1; + } + return res; + } + + // from bug #30487. + static int test20 () { + try { + return 0; + } + catch (Exception) { + throw; + } + } + + // from bug #31546 + static int test21 () { + int res; + + try { + res = 4; + return 3; + } catch (DivideByZeroException) { + res = 33; + } finally { + // Do nothing + } + + return res; + } + + // the same, but without the finally block. + static int test22 () { + int res; + + try { + res = 4; + return 3; + } catch (DivideByZeroException) { + res = 33; + } + + return res; + } + + static int test23 (object obj, int a, out bool test) { + if (obj == null) + throw new ArgumentNullException (); + + if (a == 5) { + test = false; + return 4; + } else { + test = true; + return 5; + } + } + + static long test24 (int a) { + long b; + + switch (a) { + case 0: + return 4; + } + + if (a > 2) { + if (a == 5) + b = 4; + else if (a == 6) + b = 5; + else + return 7; + + Console.WriteLine (b); + return b; + } + + return 4; + } + + static long test25 (int a) { + long b, c; + + try { + b = 5; + } catch (NotSupportedException) { + throw new InvalidOperationException (); + } + + try { + c = 5; + } catch { + throw new InvalidOperationException (); + } + + return b + c; + } +} diff --git a/mcs/tests/test-155.cs b/mcs/tests/test-155.cs new file mode 100644 index 00000000000..6a0f083c2c1 --- /dev/null +++ b/mcs/tests/test-155.cs @@ -0,0 +1,23 @@ +using System; + +class Test { + public static int Main() { + Console.WriteLine("test"); + TestClass tst = new TestClass(); + tst.test("test"); + TestInterface ti = (TestInterface)tst; + ti.test("test"); + return 0; + } + + public interface TestInterface { + string test(string name); + } + + public class TestClass: TestInterface { + public string test(string name) { + Console.WriteLine("test2"); + return name + " testar"; + } + } +} diff --git a/mcs/tests/test-156.cs b/mcs/tests/test-156.cs new file mode 100644 index 00000000000..43545820720 --- /dev/null +++ b/mcs/tests/test-156.cs @@ -0,0 +1,107 @@ +class Internal { } + +public class Public { } + +class X +{ + public class NestedPublic { } + + internal class NestedAssembly { } + + protected internal class NestedFamilyAndAssembly { } + + protected class NestedFamily { } + + private class NestedPrivate { } + + static void Main () { } +} + +public class A : Public { } + +class B : Public { } +class C : Internal { } + +class D : X.NestedPublic { } +class E : X.NestedAssembly { } +class F : X.NestedFamilyAndAssembly { } + +public class Y +{ + public class YA : Public { } + + class YB : Internal { } + + class YC : X.NestedPublic { } + class YD : X.NestedAssembly { } + class YE : X.NestedFamilyAndAssembly { } + + internal class YF : Internal { } + + internal class YG : X.NestedAssembly { } + internal class YH : X.NestedFamilyAndAssembly { } + + internal enum YI { A, B } + + internal void Test (YI yi) { } +} + +public class Z +{ + public class P : Y.YA { } +} + +class W : X +{ + public class WA : NestedPublic { } + public class WB : NestedAssembly { } + public class WC : NestedFamilyAndAssembly { } + internal class WD : NestedPublic { } + internal class WE : NestedFamilyAndAssembly { } + + private class WCA + { + } + + private class WCB + { + public class WCD + { + public class WCE : WCA + { + } + } + } +} + +class G +{ + public void Test (X x) { } + + private enum Foo { A, B }; + + enum Bar { C, D }; + + private class I + { + public class J + { + public void Test (Foo foo) { } + } + } +} + +public class H +{ + public void Test (int[] a) { } +} + +internal interface L +{ + void Hello (string hello); +} + +public class M : L +{ + public void Hello (string hello) { } +} diff --git a/mcs/tests/test-157.cs b/mcs/tests/test-157.cs new file mode 100644 index 00000000000..a01ffc79c1c --- /dev/null +++ b/mcs/tests/test-157.cs @@ -0,0 +1,31 @@ +using System; +using System.Reflection; + +namespace Test { + + //[AttributeUsage (AttributeTargets.All)] + public class MyAttribute: Attribute { + public string val; + public MyAttribute (string stuff) { + System.Console.WriteLine (stuff); + val = stuff; + } + } + + [My("testclass")] + public class Test { + static public int Main() { + System.Reflection.MemberInfo info = typeof (Test); + object[] attributes = info.GetCustomAttributes (false); + for (int i = 0; i < attributes.Length; i ++) { + System.Console.WriteLine(attributes[i]); + } + if (attributes.Length != 1) + return 1; + MyAttribute attr = (MyAttribute) attributes [0]; + if (attr.val != "testclass") + return 2; + return 0; + } + } +} diff --git a/mcs/tests/test-158.cs b/mcs/tests/test-158.cs new file mode 100644 index 00000000000..80b26d88ed0 --- /dev/null +++ b/mcs/tests/test-158.cs @@ -0,0 +1,28 @@ +using System; +using System.Reflection; + +[AttributeUsage (AttributeTargets.All)] +public class My : Attribute { + public object o; + + public My (object o) { + this.o = o; + } + + [My(TypeCode.Empty)] + public class Test { + static public int Main() { + System.Reflection.MemberInfo info = typeof (Test); + object[] attributes = info.GetCustomAttributes (false); + for (int i = 0; i < attributes.Length; i ++) { + System.Console.WriteLine(attributes[i]); + } + if (attributes.Length != 1) + return 1; + My attr = (My) attributes [0]; + if ((TypeCode) attr.o != TypeCode.Empty) + return 2; + return 0; + } + } +} diff --git a/mcs/tests/test-159.cs b/mcs/tests/test-159.cs new file mode 100644 index 00000000000..d3d9f101014 --- /dev/null +++ b/mcs/tests/test-159.cs @@ -0,0 +1,15 @@ +using System; +namespace A { + public class Iface { + void bah() {} + } + class my { + A.Iface b; + void doit (Object A) { + b = (A.Iface)A; + } + public static int Main () { + return 0; + } + } +} diff --git a/mcs/tests/test-16.cs b/mcs/tests/test-16.cs new file mode 100644 index 00000000000..3c59e917e19 --- /dev/null +++ b/mcs/tests/test-16.cs @@ -0,0 +1,61 @@ +using System; + +namespace Mine { + + public class Blah { + + public static int operator + (Blah i, Blah j) + { + Console.WriteLine ("Base class binary + operator"); + return 2; + } + + public static implicit operator int (Blah i) + { + Console.WriteLine ("Blah->int"); + return 3; + } + + public static implicit operator byte (Blah i) + { + Console.WriteLine ("Blah->byte"); + return 0; + } + + public static implicit operator short (Blah i) + { + Console.WriteLine ("Blah->short"); + return 1; + } + + } + + public class Foo : Blah { + + public static int Main () + { + int number = new Foo () + new Foo () ; + Console.WriteLine (number); + + Foo tmp = new Foo (); + + int k = tmp; + + Console.WriteLine ("Convert from Foo to float"); + float f = tmp; + Console.WriteLine ("Converted"); + + // The following will not work till we fix our UserCast::Emit + // to convert the return value on the stack. + if (f == 3) + Console.WriteLine ("Best implicit conversion selected correctly."); + + Console.WriteLine ("F is {0}", f); + + if (number == 2 && k == 3) + return 0; + else + return 1; + } + } +} diff --git a/mcs/tests/test-160.cs b/mcs/tests/test-160.cs new file mode 100644 index 00000000000..c2083dd68c8 --- /dev/null +++ b/mcs/tests/test-160.cs @@ -0,0 +1,21 @@ +class B { + public S s; +} +class S { + public int a; +} +class T { + static B foo; + + static int blah (object arg) { + B look = (B)arg; + foo.s.a = 9; + look.s.a = foo.s.a; + return look.s.a; + } + + static int Main() { + // Compilation only test; + return 0; + } +} diff --git a/mcs/tests/test-161.cs b/mcs/tests/test-161.cs new file mode 100644 index 00000000000..9c4e7ade77e --- /dev/null +++ b/mcs/tests/test-161.cs @@ -0,0 +1,25 @@ +using System; + +public class ZipEntry +{ + DateTime cal = DateTime.Now; + + public ZipEntry(string name) + { + } + + public ZipEntry(ZipEntry e) + { + } + + public DateTime DateTime { + get { + return cal; + } + } + + static int Main () { + // Compilation only test. + return 0; + } +} diff --git a/mcs/tests/test-162.cs b/mcs/tests/test-162.cs new file mode 100644 index 00000000000..284a423d0fb --- /dev/null +++ b/mcs/tests/test-162.cs @@ -0,0 +1,91 @@ +using System; + +struct A +{ + public int a; + private long b; + private float c; + + public A (int foo) + { + a = foo; + b = 8; + c = 9.0F; + } +} + +struct B +{ + public int a; +} + +struct C +{ + public long b; + + public C (long foo) + { + b = foo; + } + + // has `this' initializer, no need to initialize fields. + public C (string foo) + : this (500) + { } +} + +class X +{ + static void test_output (A x) + { + } + + static void test_output (B y) + { + } + + static void test1 () + { + A x; + + x.a = 5; + Console.WriteLine (x.a); + } + + static void test2 () + { + B y; + + y.a = 5; + Console.WriteLine (y.a); + Console.WriteLine (y); + } + + static void test3 () + { + A x = new A (85); + + Console.WriteLine (x); + } + + static void test4 (A x) + { + x.a = 5; + } + + static void test5 (out A x) + { + x = new A (85); + } + + static void test6 (out B y) + { + y.a = 1; + } + + public static int Main () + { + // Compilation-only test. + return 0; + } +} diff --git a/mcs/tests/test-163.cs b/mcs/tests/test-163.cs new file mode 100644 index 00000000000..67674b9505c --- /dev/null +++ b/mcs/tests/test-163.cs @@ -0,0 +1,30 @@ +using System; + +public class Blah { + + static int Foo (string s) + { + return 2; + } + + static int Foo (object o) + { + return 1; + } + + public static int Main () + { + int i = Foo (null); + + if (i == 1) { + Console.WriteLine ("Wrong method "); + return 1; + } + + return 0; + } + +} + + + diff --git a/mcs/tests/test-164.cs b/mcs/tests/test-164.cs new file mode 100644 index 00000000000..24b4ec924e9 --- /dev/null +++ b/mcs/tests/test-164.cs @@ -0,0 +1,45 @@ +using System; + +class X +{ + protected virtual int Foo () + { + return 1; + } + + protected delegate int FooDelegate (); + protected FooDelegate foo; + + protected X () + { + foo = new FooDelegate (Foo); + } +} + +class Y : X +{ + protected Y () + : base () + { } + + protected override int Foo () + { + return 2; + } + + int Hello () + { + return foo (); + } + + static void Main () + { + Y y = new Y (); + int result = y.Hello (); + + if (result == 2) + Console.WriteLine ("OK"); + else + Console.WriteLine ("NOT OK"); + } +} diff --git a/mcs/tests/test-165.cs b/mcs/tests/test-165.cs new file mode 100644 index 00000000000..f6a2f48204c --- /dev/null +++ b/mcs/tests/test-165.cs @@ -0,0 +1,20 @@ +using System; + +public class Testing +{ + enum Fruit { Apple, Banana, Cherry }; + + public static int Main() + { + Fruit[] pieFillings = { Fruit.Apple, Fruit.Banana, Fruit.Cherry }; + + if (pieFillings [0] != Fruit.Apple) + return 1; + if (pieFillings [1] != Fruit.Banana) + return 2; + if (pieFillings [2] != Fruit.Cherry) + return 3; + + return 0; + } +} diff --git a/mcs/tests/test-166.cs b/mcs/tests/test-166.cs new file mode 100644 index 00000000000..aac60257e52 --- /dev/null +++ b/mcs/tests/test-166.cs @@ -0,0 +1,38 @@ +using System; + +interface ITargetInfo +{ + int TargetIntegerSize { + get; + } +} + +interface ITargetMemoryAccess : ITargetInfo +{ +} + +interface IInferior : ITargetMemoryAccess +{ +} + +class D : IInferior +{ + public int TargetIntegerSize { + get { return 5; } + } + + int Hello (IInferior inferior) + { + return inferior.TargetIntegerSize; + } + + static int Main () + { + D d = new D (); + + if (d.Hello (d) != 5) + return 1; + + return 0; + } +} diff --git a/mcs/tests/test-167.cs b/mcs/tests/test-167.cs new file mode 100644 index 00000000000..b86e49df668 --- /dev/null +++ b/mcs/tests/test-167.cs @@ -0,0 +1,39 @@ +// +// See bug 31834 for details about this bug +// + +using System; + +class X +{ + static int Test (params Foo[] foo) + { + if (foo.Length != 1) + return 1; + + if (foo [0] != Foo.A) + return 2; + + return 0; + } + + enum Foo { + A, B + } + + static int Main () + { + int v = Test (Foo.A); + if (v != 0) + return v; + + MyEnum [] arr = new MyEnum [2]; + arr [0] = MyEnum.c; + + if (arr [0] != MyEnum.c) + return 3; + return 0; + } + + enum MyEnum {a,b,c}; +} diff --git a/mcs/tests/test-168.cs b/mcs/tests/test-168.cs new file mode 100644 index 00000000000..328e299bf82 --- /dev/null +++ b/mcs/tests/test-168.cs @@ -0,0 +1,21 @@ +using System; + +struct X { + static public implicit operator string (X x) + { + return "x"; + } + +} + +class Test { + + static public int Main () + { + X x = new X (); + Console.WriteLine (x); + + return 0; + } +} + diff --git a/mcs/tests/test-169.cs b/mcs/tests/test-169.cs new file mode 100644 index 00000000000..703c3148085 --- /dev/null +++ b/mcs/tests/test-169.cs @@ -0,0 +1,65 @@ +// +// Test for overloaded properties. +// +using System; + +public class basec { + public virtual string Message { + get { + return "base"; + } + } +} + +public class der : basec { + public override string Message { + get { + return "der"; + } + } +} + +class Base { + int thingy = 0; + public virtual int Thingy { + get { return thingy; } + set { thingy = value; } + } +} + +class Derived : Base { + public int BaseThingy { + get { return Thingy; } + } + + public override int Thingy { + // override the set constructor + set { } + } +} + +class D { + + static int Main () + { + // + // These tests just are compilation tests, the new property code + // will excercise these + // + der d = new der (); + if (d.Message != "der") + return 1; + + basec b = new basec (); + if (b.Message != "base") + return 2; + + Derived dd = new Derived (); + dd.Thingy = 10; + if (dd.BaseThingy != 0) + return 3; + + Console.WriteLine ("Test ok"); + return 0; + } +} diff --git a/mcs/tests/test-17.cs b/mcs/tests/test-17.cs new file mode 100755 index 00000000000..c6e2a95745c --- /dev/null +++ b/mcs/tests/test-17.cs @@ -0,0 +1,45 @@ +// +// This test excercises user defined conversions and an implicit +// conversion to a type afterwards. +// +// +using System; + +class Blah { + + public static int Main () + { + Blah k = new Blah (); + + float f = k; + + if (f == 2){ + Console.WriteLine ("Best implicit operator selected correctly"); + return 0; + } + return 1; + + } + + public static implicit operator byte (Blah i) + { + Console.WriteLine ("Blah->byte"); + return 0; + } + + + public static implicit operator short (Blah i) + { + Console.WriteLine ("Blah->short"); + return 1; + } + + public static implicit operator int (Blah i) + { + Console.WriteLine ("Blah->int"); + return 2; + } + + +} + diff --git a/mcs/tests/test-170.cs b/mcs/tests/test-170.cs new file mode 100644 index 00000000000..8413f5c97a8 --- /dev/null +++ b/mcs/tests/test-170.cs @@ -0,0 +1,56 @@ +// +// base and properties test +// +using System; + +class X { + int val; + + public virtual int prop { + get { + return val; + } + + set { + val = value; + } + } + + public int AAA { + set { } + } +} + +class Y : X { + int val2 = 1; + + public override int prop { + get { + return val2; + } + + set { + val2 = value; + } + } + + int A () { + if (base.prop != 0) + return 3; + base.prop = 10; + + if (base.prop != 10) + return 2; + + return 0; + } + + + static int Main () + { + Y y = new Y (); + + return y.A (); + } + +} diff --git a/mcs/tests/test-171.cs b/mcs/tests/test-171.cs new file mode 100644 index 00000000000..2aaee4b8a25 --- /dev/null +++ b/mcs/tests/test-171.cs @@ -0,0 +1,28 @@ +//
+// Checks for an implicit void * conversion during an
+// explicit conversion
+//
+
+using System;
+
+namespace IntPtr_Conv
+{
+ struct FooStruct {
+ int x;
+ }
+
+ class Class1 {
+
+ static int Main(string[] args)
+ {
+ IntPtr p = IntPtr.Zero;
+
+ unsafe {
+ FooStruct* s = (FooStruct*) (p);
+ }
+
+ return 0;
+ }
+ }
+}
+
diff --git a/mcs/tests/test-172.cs b/mcs/tests/test-172.cs new file mode 100644 index 00000000000..091b2d44cdc --- /dev/null +++ b/mcs/tests/test-172.cs @@ -0,0 +1,228 @@ +// +// This test excercises a few new optimizations that were entered in the context +// of Binary operators and EmitBranchable. +// +// There are a number of cases: +// +// EmitBranchable can be called with an `onTrue' (false for if, true for loops). +// +// The == and != operators handle the Null compares specially +using System; + +class X { + static int one = 1; + static int two = 2; + static int three = 3; + static int four = 4; + static bool t = true; + static bool f = false; + + static int fcalls = 0; + static int tcalls = 0; + + static bool ff () + { + fcalls++; + return false; + } + + static bool tt () + { + tcalls++; + return true; + } + + static int test_if () + { + // + // Ands in the if context + // + if (f && f) + return 1; + if (t && f) + return 2; + if (f && t) + return 3; + + if (one < two && f) + return 4; + if (one > two && t) + return 5; + if (one < two && t) + Console.WriteLine (""); + + if (ff () && ff ()) + return 6; + if (fcalls != 1) + return 10; + + if (tt () && tt ()){ + if (tcalls != 2) + return 11; + + if (tt () && ff ()) + return 8; + if (tcalls != 3) + return 12; + if (fcalls != 2) + return 13; + if (ff () && tt ()) + return 9; + if (fcalls != 3) + return 14; + if (tcalls != 3) + return 15; + } else + return 7; + + if (one < two && four > three){ + if (one == one && two != three){ + + } else + return 20; + } else + return 21; + + if (one == two || two != two) + return 22; + + object o = null; + + if (o == null || false){ + o = 1; + + if (o != null || false) + o = null; + else + return 23; + + if (true || o == null){ + if (o != null || o == null){ + if (o == null && o != null) + return 25; + if (o == null && one == two) + return 26; + if (one == one && o != null) + return 27; + o = 1; + if (two == two && o == null) + return 28; + return 0; + } + return 25; + } + return 26; + } + return 27; + } + + // + // This tests emitbranchable with an `onTrue' set to tru + // + static int test_while () + { + int count = 0; + + while (t && t){ + count++; + break; + } + + if (count != 1) + return 1; + + while (f || t){ + count++; break; + } + if (count != 2) + return 2; + while (f || f){ + count++; break; + } + if (count != 2) + return 3; + + while (one < two && two > one){ + count++; + break; + } + if (count != 3) + return 4; + + while (one < one || two > one){ + count++; + break; + } + if (count != 4) + return 5; + + while (one < one || two > two){ + count++; + break; + } + if (count != 4) + return 6; + + while (one < two && t){ + count++; + break; + } + if (count != 5) + return 7; + + while (one < one || t){ + count++; + break; + } + if (count != 6) + return 8; + + while (one < one || f){ + count++; + break; + } + + if (count != 6) + return 9; + + return 0; + } + + static int test_inline () + { + bool lt = t || f; + + if (!lt) + return 1; + + return 0; + } + + static int Main () + { + int v; + object o = null; + + if (o == null || false) + o = 1; + else + o = 2; + + Console.WriteLine ("V: "+ o); + + v = test_if (); + if (v != 0) + return v; + v = test_inline (); + if (v != 0) + return 30 + v; + + v = test_while (); + if (v != 0) + return 90 + v; + + Console.WriteLine ("test ok"); + return 0; + } +} + diff --git a/mcs/tests/test-173.cs b/mcs/tests/test-173.cs new file mode 100644 index 00000000000..0484578d1dc --- /dev/null +++ b/mcs/tests/test-173.cs @@ -0,0 +1,176 @@ +using System; + +class Base +{ + int value; + + public int Value { + get { return value; } + } + + protected Base (int value) + { + this.value = value; + } +} + +class A : Base +{ + public A (int value) + : base (1) + { + Console.WriteLine ("Int"); + } + + public A (uint value) + : base (2) + { + Console.WriteLine ("UInt"); + } +} + +class B : Base +{ + public B (long value) + : base (3) + { + Console.WriteLine ("Long"); + } + + public B (ulong value) + : base (4) + { + Console.WriteLine ("ULong"); + } +} + +class C : Base +{ + public C (short value) + : base (5) + { + Console.WriteLine ("Short"); + } + + public C (ushort value) + : base (6) + { + Console.WriteLine ("UShort"); + } +} + +class D : Base +{ + public D (sbyte value) + : base (7) + { + Console.WriteLine ("SByte"); + } + + public D (byte value) + : base (8) + { + Console.WriteLine ("Byte"); + } +} + +class E : Base +{ + public E (long value) + : base (9) + { + Console.WriteLine ("Long"); + } + + public E (E e) + : base (10) + { + Console.WriteLine ("E"); + } + + public static implicit operator E (long value) + { + return (new E (value)); + } +} + +class F : Base +{ + public F (int value) + : base (11) + { + Console.WriteLine ("Int"); + } + + public F (F f) + : base (12) + { + Console.WriteLine ("F"); + } + + public static implicit operator F (int value) + { + return (new F (value)); + } +} + +class X +{ + static int Test () + { + { + A a = new A (4); + if (a.Value != 1) + return 1; + + B b = new B (4); + if (b.Value != 3) + return 2; + + C c = new C (4); + if (c.Value != 5) + return 3; + + D d = new D (4); + if (d.Value != 7) + return 4; + } + + { + A a = new A (4u); + if (a.Value != 2) + return 5; + + B b = new B (4u); + if (b.Value != 3) + return 6; + + C c = new C (4); + if (c.Value != 5) + return 7; + + D d = new D (4); + if (d.Value != 7) + return 8; + } + + { + E e = new E (4); + if (e.Value != 9) + return 9; + + F f = new F (4); + if (f.Value != 11) + return 10; + } + + return 0; + } + + static int Main () + { + int result = Test (); + Console.WriteLine ("RESULT: {0}", result); + return result; + } +} diff --git a/mcs/tests/test-174.cs b/mcs/tests/test-174.cs new file mode 100644 index 00000000000..55323c772de --- /dev/null +++ b/mcs/tests/test-174.cs @@ -0,0 +1,110 @@ +// +// This tests only checks if we can compile the program. +// +// The trick is that we are accessing a protected property, with the way +// mcs deals with properties in two steps (property first, method next) +// this text excercises some eager optimizations in the TypeManager.FilterWithClosure. +// +// +// The second class excercises accessing private members from a container class +// +// The third class excercises accessing a private/protected value on an instance of +// a child + +using System; +using System.Collections; + +class ProtectedAccessToPropertyOnChild : Hashtable { + + ProtectedAccessToPropertyOnChild () + { + comparer = null; + } + + static int Main () + { + TestAccessToProtectedOnChildInstanceFromParent t = new TestAccessToProtectedOnChildInstanceFromParent (); + + if (t.Test () != 0) + return 1; + + return 0; + + } +} + +// +// Again, only for compiling reasons +// +public class TestAccessToPrivateMemberInParentClass +{ + double[][] data; + int rows; + int columns; + + public TestAccessToPrivateMemberInParentClass() + { + } + + double[][] Array + { + get { return data; } + } + + class CholeskyDecomposition + { + TestAccessToPrivateMemberInParentClass L; + bool isSymmetric; + bool isPositiveDefinite; + + public CholeskyDecomposition(TestAccessToPrivateMemberInParentClass A) + { + L = new TestAccessToPrivateMemberInParentClass(); + + double[][] a = A.Array; + double[][] l = L.Array; + } + } +} + +public class TestAccessToProtectedOnChildInstanceFromParent { + + class Parent { + protected int a; + + static int x; + + Parent () + { + a = x++; + } + + public int TestAccessToProtected (Child c) + { + if (c.a == 0) + return 1; + else + return 2; + } + } + + class Child : Parent { + + } + + Child c, d; + + public TestAccessToProtectedOnChildInstanceFromParent () + { + c = new Child (); + d = new Child (); + } + + public int Test () + { + if (d.TestAccessToProtected (c) == 1) + return 0; + return 1; + } + +} diff --git a/mcs/tests/test-175.cs b/mcs/tests/test-175.cs new file mode 100644 index 00000000000..2a2ea42ad10 --- /dev/null +++ b/mcs/tests/test-175.cs @@ -0,0 +1,37 @@ +using System; + +struct RVA { + public uint value; + + public RVA (uint val) + { + value = val; + } + + public static implicit operator RVA (uint val) + { + return new RVA (val); + } + + public static implicit operator uint (RVA rva) + { + return rva.value; + } +} + +class X +{ + static int Main () + { + RVA a = 10; + RVA b = 20; + + if (a > b) + return 1; + + if (a + b != 30) + return 2; + + return 0; + } +} diff --git a/mcs/tests/test-176.cs b/mcs/tests/test-176.cs new file mode 100644 index 00000000000..de83474486e --- /dev/null +++ b/mcs/tests/test-176.cs @@ -0,0 +1,20 @@ +using System; + +// +// ~ constant folding +// +class X { + const byte b = 0x0f; + + static int Main () + { + int x = ~b; + byte bb = 0xf; + + if (~bb != x){ + Console.WriteLine ("{0:x}", x); + return 1; + } + return 0; + } +} diff --git a/mcs/tests/test-177.cs b/mcs/tests/test-177.cs new file mode 100644 index 00000000000..96579a8b5af --- /dev/null +++ b/mcs/tests/test-177.cs @@ -0,0 +1,24 @@ +using System; +using System.Reflection; + +public class MethodAttribute : Attribute {} +public class ReturnAttribute : Attribute {} + +public class Test { + [Method] + [return: Return] + public void Method () {} + + public static int Main () { + + Type t = typeof(Test); + MethodInfo mi = t.GetMethod ("Method"); + ICustomAttributeProvider cap = mi.ReturnTypeCustomAttributes; + + if (cap != null) + return 0; + else + return 1; + } +} + diff --git a/mcs/tests/test-178.cs b/mcs/tests/test-178.cs new file mode 100644 index 00000000000..a8fd25ee946 --- /dev/null +++ b/mcs/tests/test-178.cs @@ -0,0 +1,26 @@ +using System; + +namespace testapp{ + public unsafe class LibTestAPI{ + + struct LibTestStruct{ + void* pData; + void* pTest1; + } + + LibTestStruct* the_struct; + + public void Create(){ + IntPtr MyPtr = new IntPtr(0); // Usually created elsewhere + the_struct = (LibTestStruct *) 0; // error CS1002 + } + } + + class TestApp{ + static void Main(string[] args){ + LibTestAPI myapi = new LibTestAPI(); + myapi.Create(); + } + } +} + diff --git a/mcs/tests/test-18.cs b/mcs/tests/test-18.cs new file mode 100644 index 00000000000..eb2a02c0033 --- /dev/null +++ b/mcs/tests/test-18.cs @@ -0,0 +1,52 @@ +using System; + +class X { + static int i; + static int j; + + static void m () + { + i = 0; + j = 0; + + try { + throw new ArgumentException ("Blah"); + } catch (ArgumentException){ + i = 1; + } catch (Exception){ + i = 2; + } finally { + j = 1; + } + } + + static int ret (int a) + { + try { + if (a == 1) + throw new Exception (); + + return 1; + } catch { + return 2; + } + } + + static int Main () + { + m (); + if (i != 1) + return 1; + if (j != 1) + return 2; + + if (ret (1) != 2) + return 3; + + if (ret (10) != 1) + return 4; + + return 0; + } +} + diff --git a/mcs/tests/test-19.cs b/mcs/tests/test-19.cs new file mode 100755 index 00000000000..f63dff52958 --- /dev/null +++ b/mcs/tests/test-19.cs @@ -0,0 +1,114 @@ +using System; +using System.Threading; +using System.Reflection; + +class I { + + public delegate string GetTextFn (string a); + + static public GetTextFn GetText; + + static string fn (string s) + { + return "(" + s + ")"; + } + + static I () + { + GetText = new GetTextFn (fn); + } +} + +class X { + + public delegate int Foo (int i, int j); + + private void Thread_func () { + Console.WriteLine ("Inside the thread !"); + } + + public int Func (int i, int j) + { + return i+j; + } + + public void Bar () + { + Foo my_func = new Foo (Func); + + int result = my_func (2, 4); + + Console.WriteLine ("Answer is : " + result); + } + + static bool MyFilter (MemberInfo mi, object criteria) + { + Console.WriteLine ("You passed in : " + criteria); + return true; + } + + public static int Main () + { + I.GetTextFn _ = I.GetText; + + Console.WriteLine ("Value: " + I.GetText); + X x = new X (); + + Thread thr = new Thread (new ThreadStart (x.Thread_func)); + + thr.Start (); + Console.WriteLine ("Inside main "); + thr.Join (); + + Console.WriteLine (_("Hello")); + + x.Bar (); + + MemberFilter filter = new MemberFilter (MyFilter); + + Type t = x.GetType (); + + MemberInfo [] mi = t.FindMembers (MemberTypes.Method, BindingFlags.Static | BindingFlags.NonPublic, + Type.FilterName, "MyFilter"); + + Console.WriteLine ("FindMembers called, mi = " + mi); + Console.WriteLine (" Count: " + mi.Length); + if (!filter (mi [0], "MyFilter")) + return 1; + + // + // This test is used to call into a delegate defined in a separate + // namespace, but which is still not a nested delegate inside a class + // + NameSpace.TestDelegate td = new NameSpace.TestDelegate (multiply_by_three); + + if (td (8) != 24) + return 30; + + // + // Check the names that were used to define the delegates + // + if (td.GetType ().FullName != "NameSpace.TestDelegate") + return 31; + + if (_.GetType ().FullName != "I+GetTextFn") + return 32; + + Console.WriteLine ("Test passes"); + + return 0; + } + + static int multiply_by_three (int v) + { + return v * 3; + } + +} + +namespace NameSpace { + + public delegate int TestDelegate (int a); + +} + diff --git a/mcs/tests/test-2.cs b/mcs/tests/test-2.cs new file mode 100755 index 00000000000..0a18d50767b --- /dev/null +++ b/mcs/tests/test-2.cs @@ -0,0 +1,7 @@ +class X { + static int Main (string [] args) + { + System.Console.WriteLine ("Hello, World"); + return 0; + } +} diff --git a/mcs/tests/test-20.cs b/mcs/tests/test-20.cs new file mode 100755 index 00000000000..006bd45075e --- /dev/null +++ b/mcs/tests/test-20.cs @@ -0,0 +1,70 @@ +// +// This generates a warning +// +using System; + +class A { + public int a; + + public void X () + { + a = 1; + } +} + +class B : A { + void X () + { + a = 2; + } + + public void TestB () + { + X (); + } +} + +class Ax { + public int a; + + public virtual void A () + { + a = 1; + } + + public virtual void B () + { + a = 3; + } +} + +class Bx : Ax { + public override void A () + { + a = 2; + } + public new void B () + { + a = 4; + } +} +class Test { + static int Main () + { + B b = new B (); + + b.TestB (); + if (b.a != 2) + return 1; + + Bx bx = new Bx (); + bx.A (); + if (b.a != 2) + return 2; + bx.B (); + Console.WriteLine ("a="+bx.a); + if (bx.a != 4) + return 3; + return 0; + } +} diff --git a/mcs/tests/test-21.cs b/mcs/tests/test-21.cs new file mode 100644 index 00000000000..cd125497bbb --- /dev/null +++ b/mcs/tests/test-21.cs @@ -0,0 +1,35 @@ +using System; + +public class Blah { + + public class Foo { + + public Foo () + { + Console.WriteLine ("Inside the Foo constructor now"); + } + + public int Bar (int i, int j) + { + Console.WriteLine ("The Bar method"); + return i+j; + } + + + } + + public static int Main () + { + Foo f = new Foo (); + + int j = f.Bar (2, 3); + Console.WriteLine ("Blah.Foo.Bar returned " + j); + + if (j == 5) + return 0; + else + return 1; + + } + +} diff --git a/mcs/tests/test-22.cs b/mcs/tests/test-22.cs new file mode 100644 index 00000000000..2e662494ddd --- /dev/null +++ b/mcs/tests/test-22.cs @@ -0,0 +1,46 @@ +// +// This test excercises invocations of methods in structures. +// +// Unlike classes, we can not just leave the result of a computed +// structure in the IL stack as a result. The reason is that the +// result is the whole structure, not a pointer to it. +// +// This program excercises invocations to methods on structures +// + +struct T { + public int a, b; +} + +struct S { + T t; + + public T GetT () + { + return t; + } + + public void Init () + { + t.a = 1; + t.b = 2; + } +} + +class M { + static int Main () + { + S s = new S (); + + s.Init (); + + if (s.GetT ().a != 1) + return 1; + + if (s.GetT ().b != 2) + return 2; + + return 0; + } +} + diff --git a/mcs/tests/test-23.cs b/mcs/tests/test-23.cs new file mode 100644 index 00000000000..0723c667d95 --- /dev/null +++ b/mcs/tests/test-23.cs @@ -0,0 +1,106 @@ +// +// Tests properties +// +using System; + +class X { + static int v; + + static X () + { + v = 10; + } + + public static int Value { + get { + return v; + } + + set { + v = value; + } + } + + static int Main () + { + if (Value != 10) + return 1; + + Value = 4; + + if (Value != 4) + return 2; + + Y y = new Y ("hello"); + + if (y.Value != "hello") + return 3; + + y.Value = "goodbye"; + if (y.Value != "goodbye") + return 4; + + Z z = new Z (); + + if (Z.IVal != 4) + return 5; + Z.IVal = 10; + if (Z.IVal != 10) + return 6; + + z.XVal = 23; + if (z.XVal != 23) + return 7; + + return 0; + } +} + +class Y { + string init; + + public Y (string s) + { + init = s; + } + + public string Value { + get { + return init; + } + + set { + init = value; + } + } +} + +struct Z { + static int val; + int xval; + + static Z () + { + val = 4; + } + + static public int IVal { + get { + return val; + } + + set { + val= value; + } + } + + public int XVal { + get { + return xval; + } + + set { + xval = value; + } + } +} diff --git a/mcs/tests/test-24.cs b/mcs/tests/test-24.cs new file mode 100644 index 00000000000..e69a844c93d --- /dev/null +++ b/mcs/tests/test-24.cs @@ -0,0 +1,35 @@ +// +// Properties intermixed in assignments +// + +using System; + +class X { + + static string v; + + static string S { + get { + return v; + } + set { + v = value; + } + } + + static string x, b; + + static int Main () + { + + x = S = b = "hlo"; + if (x != "hlo") + return 1; + if (S != "hlo") + return 2; + if (b != "hlo") + return 3; + return 0; + } +} + diff --git a/mcs/tests/test-25.cs b/mcs/tests/test-25.cs new file mode 100644 index 00000000000..a01a8daa4f1 --- /dev/null +++ b/mcs/tests/test-25.cs @@ -0,0 +1,65 @@ +// +// Test the various iteration constructs, breaks and continues +// +// FIXME: Add foreach and more tests. +// +using System; + +class X { + + static int Main () + { + int i, j, t, k; + + for (i = 0; i < 10; i++){ + if (i == 5) + break; + } + + if (i != 5) + return 1; + + t = 0; + k = 0; + for (i = 0; i < 10; i++){ + for (j = 0; j < 10; j++){ + if (j > 3) + break; + t++; + + if (j >= 1) + continue; + + k++; + } + } + + if (t != 40) + return 2; + if (k != 10) + return 3; + + + t = 0; + do { + if (k == 5) + continue; + t++; + } while (--k > 0); + + if (t != 9) + return 4; + + t = 0; + do { + t++; + if (t == 5) + break; + } while (k++ < 10); + + if (t != 5) + return 5; + + return 0; + } +} diff --git a/mcs/tests/test-26.cs b/mcs/tests/test-26.cs new file mode 100644 index 00000000000..38b173ca3bd --- /dev/null +++ b/mcs/tests/test-26.cs @@ -0,0 +1,72 @@ +using System; + +public class Blah { + + public delegate int MyDelegate (int i, int j); + + public int Foo (int i, int j) + { + return i+j; + } + + public static int Test1 () + { + Blah f = new Blah (); + + MyDelegate del = new MyDelegate (f.Foo); + + MyDelegate another = new MyDelegate (del); + + int number = del (2, 3); + + int i = another (4, 6); + + Console.WriteLine ("Delegate invocation of one returned : " + number); + + Console.WriteLine ("Delegate invocation of the other returned : " + i); + + if (number == 5 && i == 10) + return 0; + else + return 1; + } + + public delegate int List (params int [] args); + + public static int Adder (params int [] args) + { + int total = 0; + + foreach (int i in args) + total += i; + + return total; + } + + public static int Test2 () + { + List my_adder = new List (Adder); + + if (my_adder (1, 2, 3) != 6) + return 2; + + return 0; + } + + public static int Main () + { + int v; + + v = Test1 (); + if (v != 0) + return v; + + v = Test2 (); + if (v != 0) + return v; + + Console.WriteLine ("All tests pass"); + return 0; + } + +} diff --git a/mcs/tests/test-27.cs b/mcs/tests/test-27.cs new file mode 100644 index 00000000000..f1bd59b102a --- /dev/null +++ b/mcs/tests/test-27.cs @@ -0,0 +1,97 @@ +using System; + +public interface Hello { + + bool MyMethod (int i); +} + +public interface Another : Hello { + + int AnotherMethod (int i); +} + +public class Foo : Hello, Another { + + public bool MyMethod (int i) + { + if (i == 22) + return true; + else + return false; + } + + public int AnotherMethod (int i) + { + return i * 10; + } + +} + +public interface ITest { + + bool TestMethod (int i, float j); +} + +public class Blah : Foo { + + public delegate void MyDelegate (int i, int j); + + void Bar (int i, int j) + { + Console.WriteLine (i+j); + } + + public static int Main () + { + Blah k = new Blah (); + + Foo f = k; + + object o = k; + + if (f is Foo) + Console.WriteLine ("I am a Foo!"); + + Hello ihello = f; + + Another ianother = f; + + ihello = ianother; + + bool b = f.MyMethod (22); + + MyDelegate del = new MyDelegate (k.Bar); + + del (2, 3); + + Delegate tmp = del; + + // Explicit reference conversions + + MyDelegate adel = (MyDelegate) tmp; + + adel (4, 7); + + Blah l = (Blah) o; + + l.Bar (20, 30); + + l = (Blah) f; + + l.Bar (2, 5); + + f = (Foo) ihello; + + // The following cause exceptions even though they are supposed to work + // according to the spec + + // This one sounds ridiculous ! + // ITest t = (ITest) l; + + // ITest u = (ITest) ihello; + + return 0; + + } +} + diff --git a/mcs/tests/test-28.cs b/mcs/tests/test-28.cs new file mode 100644 index 00000000000..50f7dbb02bf --- /dev/null +++ b/mcs/tests/test-28.cs @@ -0,0 +1,56 @@ +abstract class A { + protected abstract int this [int a] { get; } + + public int EmulateIndexer (int a) + { + return this [a]; + } +} + +class B : A { + protected override int this [int a] { get { return a;} } + + public int M () + { + return this [0]; + } + +} +class X { + int v1, v2; + + int this [int a] { + get { + if (a == 0) + return v1; + else + return v2; + } + + set { + if (a == 0) + v1 = value; + else + v2 = value; + } + } + + static int Main () + { + X x = new X (); + + x [0] = 1; + if (x.v1 != 1) + return 1; + + if (x [0] != 1) + return 2; + + B bb = new B (); + + if (bb.EmulateIndexer (10) != 10) + return 3; + + return new B ().M (); + } +} diff --git a/mcs/tests/test-29.cs b/mcs/tests/test-29.cs new file mode 100644 index 00000000000..6183126d277 --- /dev/null +++ b/mcs/tests/test-29.cs @@ -0,0 +1,40 @@ +// +// Versioning, should choose Derived.Add (1) +// +using System; + +class Base { + public int val; + + public void Add (int x) + { + Console.WriteLine ("Incorrect method called"); + + val = 1; + } +} + +class Derived : Base { + public void Add (double x) + { + Console.WriteLine ("Calling the derived class with double! Excellent!"); + val = 2; + } +} + +class Demo { + + static int Main () + { + Derived d = new Derived (); + + d.Add (1); + if (d.val == 1) + return 1; + + if (d.val == 2) + return 0; + return 2; + + } +} diff --git a/mcs/tests/test-3.cs b/mcs/tests/test-3.cs new file mode 100755 index 00000000000..5e7d4e1fab2 --- /dev/null +++ b/mcs/tests/test-3.cs @@ -0,0 +1,62 @@ + +public class TestIntOps { + + public static sbyte sbyte_add (sbyte a, sbyte b) { + return (sbyte)(a+b); + } + + public static short short_add (short a, short b) { + return (short)(a+b); + } + + public static double double_add (double a, double b) { + return a+b; + } + + public static int int_add (int a, int b) { + return a+b; + } + + public static int int_sub (int a, int b) { + return a-b; + } + + public static int int_mul (int a, int b) { + return a*b; + } + + public static int Main() { + int num = 1; + + if (int_add (1, 1) != 2) return num; + num++; + + if (int_add (31, -1) != 30) return num; + num++; + + if (int_sub (31, -1) != 32) return num; + num++; + + if (int_mul (12, 12) != 144) return num; + num++; + + if (sbyte_add (1, 1) != 2) return num; + num++; + + if (sbyte_add (31, -1) != 30) return num; + num++; + + if (short_add (1, 1) != 2) return num; + num++; + + if (short_add (31, -1) != 30) return num; + num++; + + if (double_add (1.5, 1.5) != 3) return num; + num++; + + // add more meaningful tests + + return 0; + } +} diff --git a/mcs/tests/test-30.cs b/mcs/tests/test-30.cs new file mode 100644 index 00000000000..56c8308c02b --- /dev/null +++ b/mcs/tests/test-30.cs @@ -0,0 +1,60 @@ +// +// Tests whether we implement the correct methods from interfaces +// + +using System; + +interface IA { + void Draw (); +} + +interface IB { + void Draw (); +} + +class X : IA, IB { + public bool ia_called; + public bool ib_called; + + void IA.Draw () + { + ia_called = true; + } + + void IB.Draw () + { + ib_called = true; + } +} + +class test { + + static int Main () + { + X x = new X (); + + ((IA) x).Draw (); + Console.WriteLine ("IA: " + x.ia_called); + Console.WriteLine ("IB: " + x.ib_called); + + if (x.ib_called) + return 1; + if (!x.ia_called) + return 2; + + X y = new X (); + ((IB) y).Draw (); + Console.WriteLine ("IA: " + x.ia_called); + Console.WriteLine ("IB: " + x.ib_called); + + if (!y.ib_called) + return 3; + if (y.ia_called) + return 4; + + Console.WriteLine ("All tests pass"); + return 0; + } +} + + diff --git a/mcs/tests/test-31.cs b/mcs/tests/test-31.cs new file mode 100644 index 00000000000..c7c31fed25e --- /dev/null +++ b/mcs/tests/test-31.cs @@ -0,0 +1,41 @@ +// +// Versioning test: make sure that we output a warning, but still call the derived +// method +// +using System; + +class Base { + public int which; + + public virtual void A () + { + which = 1; + } +} + +class Derived :Base { + public virtual void A () + { + which = 2; + } +} + +class Test { + static int Main () + { + Derived d = new Derived (); + + // + // This should call Derived.A and output a warning. + // + d.A (); + + + if (d.which == 1) + return 1; + + Console.WriteLine ("Test passes"); + + return 0; + } +} diff --git a/mcs/tests/test-32.cs b/mcs/tests/test-32.cs new file mode 100644 index 00000000000..94399b230e2 --- /dev/null +++ b/mcs/tests/test-32.cs @@ -0,0 +1,21 @@ +using System; + +public class Blah { + + public static int Main () + { + int [][] i = new int [2][]; + + int [,][] j = new int [3,6][]; + + Blah [] k = new Blah [2]; + + Blah [,][] l = new Blah [3,4][]; + + Uri [] uri = new Uri [4]; + + Console.WriteLine ("All arrays successfully created"); + + return 0; + } +} diff --git a/mcs/tests/test-33.cs b/mcs/tests/test-33.cs new file mode 100644 index 00000000000..3e908b2ef35 --- /dev/null +++ b/mcs/tests/test-33.cs @@ -0,0 +1,51 @@ +using System;
+
+namespace FirstOuter
+{
+ namespace FirstInner
+ {
+ public class First
+ {
+ public string MyIdentity {
+ get {
+ return this.GetType().FullName;
+ }
+ }
+ }
+ }
+
+ public class Second : FirstInner.First {}
+
+ namespace SecondInner
+ {
+ public class Third : FirstOuter.FirstInner.First {}
+ }
+
+ namespace FirstInner // purposefully again
+ {
+ public class Fourth : First {} // must understand First in the nom qualified form
+ }
+}
+
+public class Fifth : FirstOuter.FirstInner.First {}
+
+class Application
+{
+ static int Main(string[] args)
+ {
+ FirstOuter.FirstInner.First V1 = new FirstOuter.FirstInner.First();
+ FirstOuter.Second V2 = new FirstOuter.Second();
+ FirstOuter.SecondInner.Third V3 = new FirstOuter.SecondInner.Third();
+ FirstOuter.FirstInner.Fourth V4 = new FirstOuter.FirstInner.Fourth();
+ Fifth V5 = new Fifth();
+
+ Console.WriteLine("V1 is " + V1.MyIdentity);
+ Console.WriteLine("V2 is " + V2.MyIdentity);
+ Console.WriteLine("V3 is " + V3.MyIdentity);
+ Console.WriteLine("V4 is " + V4.MyIdentity);
+ Console.WriteLine("V5 is " + V5.MyIdentity);
+
+ return 0;
+ }
+}
+
diff --git a/mcs/tests/test-34.cs b/mcs/tests/test-34.cs new file mode 100644 index 00000000000..60399d53be4 --- /dev/null +++ b/mcs/tests/test-34.cs @@ -0,0 +1,121 @@ +// +// This test tests both how arguments are selected in the presence +// of ref/out modifiers and the params arguments. +// +using System; + +public struct FancyInt { + public int value; + + public FancyInt (int v) + { + value = v; + } + +} + +public class Blah { + static int got; + + public static void Foo (ref int i, ref int j) + { + got = 1; + } + + public static int Bar (int j, params int [] args) + { + got = 2; + int total = 0; + + foreach (int i in args){ + Console.WriteLine ("My argument: " + i); + total += i; + } + + return total; + } + + public static void Foo (int i, int j) + { + got = 3; + } + + static void In (ref int a) + { + a++; + } + + static void Out (ref int a) + { + In (ref a); + } + + static int AddArray (params int [] valores) + { + int total = 0; + + for (int i = 0; i < valores.Length; i++) + total += valores [i]; + + return total; + } + + static int AddFancy (params FancyInt [] vals) + { + int total = 0; + + for (int i = 0; i < vals.Length; i++) + total += vals [i].value; + + return total; + } + + + public static int Main () + { + int i = 1; + int j = 2; + + int [] arr = new int [2] { 0, 1 }; + + Foo (i, j); + if (got != 3) + return 1; + + Foo (ref i, ref j); + if (got != 1) + return 2; + + if (Bar (i, j, 5, 4, 3, 3, 2) != 19) + return 4; + + //if (Bar (1, arr) != 1) + // return 5; + + if (got != 2) + return 3; + + int k = 10; + + Out (ref k); + if (k != 11) + return 10; + + int [] arr2 = new int [2] {1, 2}; + + if (AddArray (arr2) != 3) + return 11; + + FancyInt f_one = new FancyInt (1); + FancyInt f_two = new FancyInt (2); + + if (AddFancy (f_one) != 1) + return 12; + + if (AddFancy (f_one, f_two) != 3) + return 13; + + Console.WriteLine ("Test passes"); + return 0; + } +} diff --git a/mcs/tests/test-35.cs b/mcs/tests/test-35.cs new file mode 100755 index 00000000000..d9bc1d8338e --- /dev/null +++ b/mcs/tests/test-35.cs @@ -0,0 +1,71 @@ +// +// This test checks the !x optimization for if/while/for/do +// +class X { + + static bool t = true; + static bool f = false; + static int j = 0; + + static void a () + { + if (!t) + j = 1; + } + + static void w (int x) + { + System.Console.WriteLine (" " + x); + } + + static int Main () + { + int ok = 0, error = 0; + + if (!f) + ok = 1; + else + error++; + + w (1); + if (f) + error++; + else + ok |= 2; + + w(2); + if (t) + ok |= 4; + else + error++; + + if (!t) + error++; + else + ok |= 8; + + if (!(t && f == false)) + error++; + else + ok |= 16; + + int i = 0; + w(3); + do { + i++; + } while (!(i > 5)); + if (i != 6) + error ++; + else + ok |= 32; + + w(100); + System.Console.WriteLine ("Value: " + t); + do { + i++; + } while (!t); + + System.Console.WriteLine ("Ok=" + ok + " Errors=" + error); + return ((ok == 63) && (error == 0)) ? 0 : 1; + } +} diff --git a/mcs/tests/test-36.cs b/mcs/tests/test-36.cs new file mode 100755 index 00000000000..9f4897a82f4 --- /dev/null +++ b/mcs/tests/test-36.cs @@ -0,0 +1,46 @@ +// +// This program excercises invoking foreach on structures +// that implement GetEnumerator +// + +using System; +using System.Collections; +struct X { + int [] a; + + public IEnumerator GetEnumerator () + { + a = new int [3] { 1, 2, 3}; + return a.GetEnumerator (); + } + } + +class Y { + static X x; + + static int Main () + { + int total = 0; + x = new X (); + + foreach (object a in x){ + total += (int) a; + } + + if (total != 6) + return 1; + + total = 0; + + // + // implicit block + // + foreach (object a in x) + total += (int) a; + if (total != 6) + return 2; + + return 0; + } +} + diff --git a/mcs/tests/test-37.cs b/mcs/tests/test-37.cs new file mode 100755 index 00000000000..91f54f4d9a0 --- /dev/null +++ b/mcs/tests/test-37.cs @@ -0,0 +1,136 @@ +// +// This test excercises array access on single dimension, multi-dimension +// and jagged arrays. +// +using System; + +class X { + static void m (int [] a) + { + a [0] = 0xdead; + } + + static int test_int_single_dim () + { + int [] a = new int [10]; + int i; + + for (i = 0; i < 10; i++) + a [i] = i; + + m (a); + + if (a [0] != 0xdead) + return 1; + + a [0] = 0; + for (i = 9; i >= 0; i--){ + if (a [i] != i) + return 2; + } + return 0; + } + + static int simple_test_double_dim () + { + int [,] b = new int [10, 10]; + + b [0, 0] = 1; + b [4, 4] = 1; + + if (b [0, 0] != b [4, 4]) + return 20; + if (b [1, 1] != b [5, 5]) + return 21; + + return 0; + } + +// static void dd (int [,] b) +// { +// int i, j; +// +// for (i = 0; i < 10; i++) +// for (j = 0; j < 10; j++) +// b [i, j] = b [i, j] + 1; +// } +// +// static int test_int_double_dim () +// { +// int [,] b = new int [10,10]; +// int i, j; +// +// for (i = 0; i < 10; i++) +// for (j = 0; j < 10; j++) +// b [i,j] = i * 10 + j; +// +// dd (b); +// +// for (i = 0; i < 10; i++) +// for (j = 0; j < 10; j++) +// if (b [i,j] != i *10 + j + 1){ +// Console.WriteLine ("Expecting " + (i * 10 + j + 1) + "got: " + b [i,j]); +// return 10; +// } +// +// return 0; +// } + +// static int test_jagged () +// { +// int [][] a = new int [10][]; +// int i; +// +// for (i = 0; i < 10; i++){ +// if (a [i] != null) +// return 20; +// +// a [i] = new int [10]; +// +// for (int j = 0; j < 10; j++){ +// int q; +// a [i][j] = j * 10; +// q = a [i][j] = j * 10; +// +// a [i][j]++; +// +// if (a [i][j] != q + 1) +// return 21; +// } +// } +// +// return 0; +// } + + static int Main () + { + int v; + + Console.WriteLine ("hello"); + return 0; + + v = test_int_single_dim (); + + if (v != 0) + return v; + + // v = test_int_double_dim (); + // if (v != 0) + // return v; + // + // v = test_jagged (); + + v = simple_test_double_dim (); + if (v != 0) + return v; + + int [] a = new int [10]; + int i; + for (i = 0; i < 10; i++){ + a [i] = i; + // a [i]++; + // Console.WriteLine ("Should be: " + (i + 1) + " it is = " + a [i]); + } + return 0; + } +} diff --git a/mcs/tests/test-38.cs b/mcs/tests/test-38.cs new file mode 100755 index 00000000000..73a388353f2 --- /dev/null +++ b/mcs/tests/test-38.cs @@ -0,0 +1,118 @@ +class X { + public int v1, v2; + int y; + + public int this [int a] { + get { + if (a == 0) + return v1; + else + return v2; + } + + set { + if (a == 0) + v1 = value; + else + v2 = value; + } + } + + public int Foo () { + return 8; + } + + public int Bar { + get { + return y; + } + + set { + y = value; + } + } +} + +class Y { + public uint v1, v2; + uint y; + + public uint this [uint a] { + get { + if (a == 0) + return v1; + else + return v2; + } + + set { + if (a == 0) + v1 = value; + else + v2 = value; + } + } + + public uint Foo () { + return 8; + } + + public uint Bar { + get { + return y; + } + + set { + y = value; + } + } +} + +class Test { + + static int Main () + { + X x = new X (); + Y y = new Y (); + int b; + + x [0] = x [1] = 1; + x [0] = 1; + if (x.v1 != 1) + return 1; + + if (x [0] != 1) + return 2; + + double d; + long l; + + d = l = b = x [0] = x [1] = x.Bar = x [2] = x [3] = x [4] = x.Foo (); + + if (x.Bar != 8) + return 3; + + if (l != 8) + return 4; + + uint e, f; + e = 5; + e = f = 8; + + if (e != 8) + return 5; + + y [0] = y [1] = 9; + y [0] = y.Bar = 12; + + if (y.Bar != 12) + return 6; + + y.Bar = 15; + if (y.Bar != 15) + return 7; + + return 0; + + } +} diff --git a/mcs/tests/test-39.cs b/mcs/tests/test-39.cs new file mode 100644 index 00000000000..7366b1c0ce2 --- /dev/null +++ b/mcs/tests/test-39.cs @@ -0,0 +1,38 @@ +using System; +[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)] + public class SimpleAttribute : Attribute { + + string name = null; + + public string MyNamedArg; + + private string secret; + + public SimpleAttribute (string name) + { + this.name = name; + } + + public string AnotherArg { + get { + return secret; + } + set { + secret = value; + } + } + + } + +[Simple ("Dummy", MyNamedArg = "Dude!")] +[Simple ("Vids", MyNamedArg = "Raj", AnotherArg = "Foo")] + public class Blah { + + public static int Main () + { + Console.WriteLine ("A dummy app which tests attribute emission"); + return 0; + } + } + + diff --git a/mcs/tests/test-4.cs b/mcs/tests/test-4.cs new file mode 100755 index 00000000000..3023f6e9d1b --- /dev/null +++ b/mcs/tests/test-4.cs @@ -0,0 +1,40 @@ +using System; +class X { + bool sbyte_selected; + bool int_selected; + + void test (sbyte s) + { + sbyte_selected = true; + } + + void test (int i) + { + int_selected = true; + } + + static int Main () + { + X x = new X (); + + x.test (1); + if (x.sbyte_selected){ + Console.WriteLine ("FAILED: Sbyte selected on constant int argument"); + return 1; + } else { + Console.WriteLine ("OK: int selected for constant int"); + } + + X y = new X (); + sbyte s = 10; + + y.test (s); + if (y.sbyte_selected){ + Console.WriteLine ("OK: sbyte selected for sbyte argument"); + } else { + Console.WriteLine ("FAILED: sbyte not selected for sbyte argument"); + return 1; + } + return 0; + } +} diff --git a/mcs/tests/test-40.cs b/mcs/tests/test-40.cs new file mode 100644 index 00000000000..8bd84c4bbc5 --- /dev/null +++ b/mcs/tests/test-40.cs @@ -0,0 +1,97 @@ +using System; + +public class Blah { + + enum Bar { + a = MyEnum.Foo, + b = A.c, + c = MyEnum.Bar, + d = myconstant + } + + public enum MyEnum : byte { + Foo = 254, + Bar = (byte) B.y + } + + enum A { + a, b, c + } + + enum B { + x, y, z + } + + enum AA : byte { a, b } + enum BB : ulong { x, y } + + const int myconstant = 30; + + enum Compute { two = AA.b + B.y } + + public static int Main () + { + byte b = (byte) MyEnum.Foo; + + Console.WriteLine ("Foo has a value of " + b); + + if (b != 254) + return 1; + + int i = (int) A.a; + int j = (int) B.x; + int k = (int) A.c; + int l = (int) AA.b + 1; + + if ((int) Compute.two != 2) + return 10; + if (i != j) + return 1; + + if (k != l) + return 1; + + A var = A.b; + + i = (int) Bar.a; + + if (i != 254) + return 1; + + i = (int) Bar.b; + + if (i != 2) + return 1; + + j = (int) Bar.c; + + if (j != 1) + return 1; + + j = (int) Bar.d; + + if (j != 30) + return 1; + + Enum e = Bar.d; + if (e.ToString () != "d") + return 15; + + // + // Test "U operator (E x, E x)" + // + // Notice that the Microsoft C# compiler wont compile the following + // code, that is a bug in their compiler, see section 14.7.5 of the + // spec. + + if ((A.c - A.a) != 2) + return 16; + + if ((A.c - 1) != A.b) + return 17; + + Console.WriteLine ("Value: " + e.ToString ()); + Console.WriteLine ("Enum emission test okay"); + return 0; + } +} diff --git a/mcs/tests/test-41.cs b/mcs/tests/test-41.cs new file mode 100644 index 00000000000..cdf1fd45f89 --- /dev/null +++ b/mcs/tests/test-41.cs @@ -0,0 +1,93 @@ +// +// This tests the ref access to parameters +// +using System; + +class X { + + static void A (ref int a, ref uint b, ref sbyte c, ref byte d, ref long e, ref ulong f, + ref short g, ref ushort h, ref char i, ref X x, ref float j, ref double k) + { + if (a == 1) + a = 2; + + if (b == 1) + b = 2; + + if (c == 1) + c = 2; + + if (d == 1) + d = 2; + + if (e == 1) + e = 2; + + if (f == 1) + f = 2; + + if (g == 1) + g = 2; + + if (h == 1) + h = 2; + + if (i == 'a') + i = 'b'; + + if (x == null) + x = new X (); + + if (j == 1.0) + j = 2.0F; + if (k == 1.0) + k = 2.0; + } + + static int Main () + { + int a = 1; + uint b = 1; + sbyte c = 1; + byte d = 1; + long e = 1; + ulong f = 1; + short g = 1; + ushort h = 1; + char i = 'a'; + float j = 1.0F; + double k = 1.0; + X x = null; + + A (ref a, ref b, ref c, ref d, ref e, ref f, ref g, ref h, ref i, ref x, ref j, ref k); + + if (a != 2) + return 1; + if (b != 2) + return 2; + if (c != 2) + return 3; + if (d != 2) + return 4; + if (e != 2) + return 5; + if (f != 2) + return 6; + if (g != 2) + return 7; + if (h != 2) + return 8; + if (i != 'b') + return 9; + if (j != 2.0) + return 10; + if (k != 2.0) + return 11; + if (x == null) + return 12; + + Console.WriteLine ("Test passed"); + return 0; + } +} + diff --git a/mcs/tests/test-42.cs b/mcs/tests/test-42.cs new file mode 100755 index 00000000000..684324b8f93 --- /dev/null +++ b/mcs/tests/test-42.cs @@ -0,0 +1,184 @@ +// +// This test exercises the various ways in which mutator operators can be +// used in C# and the various different scenarios that the compiler would +// have to deal with +// +// variables, linear arrays, multi-dimensional arrays, jagged arrays, +// properties, indexers and overloaded ++ and -- +// + +class X { + + public int v, p; + public int idx; + + public int this [int n] { + get { + idx = n; + return v; + } + set { + idx = n; + v = value; + } + } + + public int P { + get { + return p; + } + + set { + p = value; + } + } + +} + +class Z { + int v; + + public Z P { + get { + return null; + } + + set { + } + } + + static public Z operator ++ (Z v) + { + v.v++; + return v; + } +} + +class Y { + + static int p_pre_increment (X x) + { + return ++x.P; + } + + static int p_post_increment (X x) + { + return x.P++; + } + + static int i_pre_increment (X x) + { + return ++x [100]; + } + + static int i_post_increment (X x) + { + return x [14]++; + } + + static Z overload_increment (Z z) + { + return z++; + } + + static Z overload_pre_increment (Z z) + { + return ++z; + } + + static Z ugly (Z z) + { + return z.P++; + } + + // + // Tests the ++ and -- operators on integers + // + static int simple (int i) + { + if (++i != 11) + return 1; + if (--i != 10) + return 2; + if (i++ != 10) + return 3; + if (i-- != 11) + return 4; + return 0; + } + + static int arrays () + { + int [] a = new int [10]; + int i, j; + + for (i = 0; i < 10; i++) + a [i]++; + + for (i = 0; i < 10; i++) + if (a [i] != 1) + return 100; + + int [,] b = new int [10,10]; + for (i = 0; i < 10; i++){ + for (j = 0; j < 10; j++){ + b [i,j] = i * 10 + j; + if (i < 5) + b [i,j]++; + else + ++b [i,j]; + } + } + + for (i = 0; i < 10; i++){ + for (j = 0; j < 10; j++){ + if (b [i,j] != i * 10 + (j + 1)) + return 101; + } + } + + return 0; + } + + static int Main () + { + X x = new X (); + int c; + + if ((c = simple (10)) != 0) + return c; + + if (i_pre_increment (x) != 1) + return 5; + + if (x.idx != 100) + return 6; + + if (i_post_increment (x) != 1) + return 7; + + if (x.idx != 14) + return 8; + + if (p_pre_increment (x) != 1) + return 9; + + if (x.p != 1) + return 10; + + if (p_post_increment (x) != 1) + return 10; + + if (x.p != 2) + return 11; + + Z z = new Z(); + + overload_increment (z); + + arrays (); + + return 0; + } + +} diff --git a/mcs/tests/test-43.cs b/mcs/tests/test-43.cs new file mode 100755 index 00000000000..7d8deffe812 --- /dev/null +++ b/mcs/tests/test-43.cs @@ -0,0 +1,78 @@ +// +// This test is used for testing the foreach array support +// +using System; + +class X { + + static int test_single (int [] a) + { + int total = 0; + + foreach (int i in a) + total += i; + + return total; + } + + static int test_continue (int [] a) + { + int total = 0; + int j = 0; + + foreach (int i in a){ + j++; + if (j == 5) + continue; + total += i; + } + + return total; + } + + static int test_break (int [] a) + { + int total = 0; + int j = 0; + + foreach (int i in a){ + j++; + if (j == 5) + break; + total += i; + } + + return total; + } + + static int Main () + { + int [] a = new int [10]; + int [] b = new int [2]; + + for (int i = 0; i < 10; i++) + a [i] = 10 + i; + + for (int j = 0; j < 2; j++) + b [j] = 50 + j; + + if (test_single (a) != 145) + return 1; + + if (test_single (b) != 101) + return 2; + + if (test_continue (a) != 131){ + Console.WriteLine ("Expecting: 131, got " + test_continue (a)); + return 3; + } + + if (test_break (a) != 46){ + Console.WriteLine ("Expecting: 46, got " + test_break (a)); + return 4; + } + + return 0; + } +} + diff --git a/mcs/tests/test-44.cs b/mcs/tests/test-44.cs new file mode 100755 index 00000000000..c1b896a5814 --- /dev/null +++ b/mcs/tests/test-44.cs @@ -0,0 +1,55 @@ +// +// This test shows that the current way in which we handle blocks +// and statements is broken. The b [q,w] code is only executed 10 +// times instead of a 100 +// +using System; + +class X { + + static int dob (int [,]b) + { + int total = 0; + + foreach (int i in b) + total += i; + + return total; + } + + // + // This tests typecasting from an object to an array of ints + // and then doing foreach + // + static int count (object o) + { + int total = 0; + + foreach (int i in (int []) o) + total += i; + + return total; + } + + static int Main () + { + int [,] b = new int [10,10]; + + for (int q = 0; q < 10; q++) + for (int w = 0; w < 10; w++) + b [q,w] = q * 10 + w; + + if (dob (b) != 4950) + return 1; + + int [] a = new int [10]; + for (int i = 0; i < 10; i++) + a [i] = 2; + + if (count (a) != 20) + return 2; + + return 0; + } +} + diff --git a/mcs/tests/test-45.cs b/mcs/tests/test-45.cs new file mode 100644 index 00000000000..9d50a9c9420 --- /dev/null +++ b/mcs/tests/test-45.cs @@ -0,0 +1,101 @@ +using System; + +public class Blah { + + private static int[] array = {0, 1, 2, 3}; + + private static int [,] bar = { {0,1}, {4,5}, {10,20} }; + + static string [] names = { + "Miguel", "Paolo", "Dietmar", "Dick", "Ravi" + }; + + public static int Main () + { + int [] i = new int [4] { 0, 1, 2, 3 }; + + short [,] j = new short [4,2] { {0,1}, {2,3}, {4,5}, {6,7} }; + + ushort [] a = { 4, 5, 6, 7 }; + + long [,,] m = new long [2,3,2] {{{0,1}, {2,3}, {4,5}}, {{6,7}, {8,9}, {10,11}}}; + + int foo = 1; + int [] k = new int [] { foo, foo+1, foo+4 }; + + int [,] boo = new int [,] {{foo, foo+10}, {foo+3, foo+10}}; + + float [] f_array = new float [] { 1.23F, 4.5F, 6.24F }; + + double [] double_arr = new double [] { 34.4567, 90.1226, 54.9823 }; + + char [] c_arr = { 'A', 'B', 'C', 'M', 'R' }; + + byte [] b_arr = { 0, 3, 8, 10, 21 }; + + sbyte [] s_arr = { 10, 15, 30, 123 }; + + if (a [2] != 6) + return 1; + + if (s_arr [3] != 123) + return 2; + + if (i [2] != 2) + return 1; + + if (j [1,1] != 3) + return 1; + + for (int t = 0; t < 4; ++t) { + if (array [t] != t) + return 1; + + if (a [t] != (t + 4)) + return 1; + } + + if (bar [2,1] != 20) + return 1; + + if (k [2] != 5) + return 1; + + if (m [1,1,1] != 9) + return 1; + + if (boo [0,1] != 11) + return 1; + + if (f_array [0] != 1.23F) + return 1; + + if (double_arr [1] != 90.1226) + return 1; + + foreach (string s in names) + Console.WriteLine ("Hello, " + s); + + if (names [0] != "Miguel") + return 1; + + if (c_arr [4] != 'R') + return 2; + + int count = 10; + + int [] x = new int [count]; + + for (int idx = 0; idx < count; idx++) + x [idx] = idx + 1; + + for (int idx = count; idx > 0; ){ + idx--; + if (x [idx] != idx + 1) + return 12; + } + Console.WriteLine ("Array initialization test okay."); + + return 0; + } +} diff --git a/mcs/tests/test-46.cs b/mcs/tests/test-46.cs new file mode 100755 index 00000000000..6a4aa000a0b --- /dev/null +++ b/mcs/tests/test-46.cs @@ -0,0 +1,127 @@ +// +// This test probes the various explicit unboxing casts +// +using System; + +class X { + static int cast_int (object o) { return (int) o; } + static uint cast_uint (object o) { return (uint) o; } + static short cast_short (object o) { return (short) o; } + static char cast_char (object o) { return (char) o; } + static ushort cast_ushort (object o) { return (ushort) o; } + static byte cast_byte (object o) { return (byte) o; } + static sbyte cast_sbyte (object o) { return (sbyte) o; } + static long cast_long (object o) { return (long) o; } + static ulong cast_ulong (object o) { return (ulong) o; } + static float cast_float (object o) { return (float) o; } + static double cast_double (object o) { return (double) o; } + static bool cast_bool (object o) { return (bool) o; } + + static int Main () + { + if (cast_int ((object) -1) != -1) + return 1; + if (cast_int ((object) 1) != 1) + return 2; + if (cast_int ((object) Int32.MaxValue) != Int32.MaxValue) + return 1; + if (cast_int ((object) Int32.MinValue) != Int32.MinValue) + return 2; + if (cast_int ((object) 0) != 0) + return 3; + + if (cast_uint ((object) (uint)0) != 0) + return 4; + if (cast_uint ((object) (uint) 1) != 1) + return 5; + if (cast_uint ((object) (uint) UInt32.MaxValue) != UInt32.MaxValue) + return 6; + if (cast_uint ((object) (uint) UInt32.MinValue) != UInt32.MinValue) + return 7; + + if (cast_ushort ((object) (ushort) 1) != 1) + return 8; + if (cast_ushort ((object) (ushort) UInt16.MaxValue) != UInt16.MaxValue) + return 9; + if (cast_ushort ((object) (ushort) UInt16.MinValue) != UInt16.MinValue) + return 10; + if (cast_ushort ((object) (ushort) 0) != 0) + return 11; + + if (cast_short ((object) (short)-1) != -1) + return 12; + if (cast_short ((object) (short) 1) != 1) + return 13; + if (cast_short ((object) (short) Int16.MaxValue) != Int16.MaxValue) + return 14; + if (cast_short ((object) (short) Int16.MinValue) != Int16.MinValue) + return 15; + if (cast_short ((object) (short) 0) != 0) + return 16; + + if (cast_byte ((object) (byte)1) != 1) + return 17; + if (cast_byte ((object) (byte) Byte.MaxValue) != Byte.MaxValue) + return 18; + if (cast_byte ((object) (byte) Byte.MinValue) != Byte.MinValue) + return 19; + if (cast_byte ((object) (byte) 0) != 0) + return 20; + + if (cast_sbyte ((object) (sbyte) -1) != -1) + return 21; + if (cast_sbyte ((object) (sbyte) 1) != 1) + return 22; + if (cast_sbyte ((object) (sbyte) SByte.MaxValue) != SByte.MaxValue) + return 23; + if (cast_sbyte ((object) (sbyte)SByte.MinValue) != SByte.MinValue) + return 24; + if (cast_sbyte ((object) (sbyte) 0) != 0) + return 25; + + + if (cast_long ((object) (long) -1) != -1) + return 26; + if (cast_long ((object) (long) 1) != 1) + return 27; + if (cast_long ((object) (long) Int64.MaxValue) != Int64.MaxValue) + return 28; + if (cast_long ((object) (long) Int64.MinValue) != Int64.MinValue) + return 29; + if (cast_long ((object) (long) 0) != 0) + return 30; + + if (cast_ulong ((object) (ulong) 0) != 0) + return 31; + if (cast_ulong ((object) (ulong) 1) != 1) + return 32; + if (cast_ulong ((object) (ulong) UInt64.MaxValue) != UInt64.MaxValue) + return 33; + if (cast_ulong ((object) (ulong) UInt64.MinValue) != UInt64.MinValue) + return 34; + + if (cast_double ((object) (double) -1) != -1) + return 35; + if (cast_double ((object) (double) 1) != 1) + return 36; + if (cast_double ((object) (double) Double.MaxValue) != Double.MaxValue) + return 37; + if (cast_double ((object) (double) Double.MinValue) != Double.MinValue) + return 38; + if (cast_double ((object) (double) 0) != 0) + return 39; + + if (cast_float ((object) (float) -1) != -1) + return 40; + if (cast_float ((object) (float) 1) != 1) + return 41; + if (cast_float ((object) (float)Single.MaxValue) != Single.MaxValue) + return 42; + if (cast_float ((object) (float) Single.MinValue) != Single.MinValue) + return 43; + if (cast_float ((object) (float) 0) != 0) + return 44; + + return 0; + } +} diff --git a/mcs/tests/test-47.cs b/mcs/tests/test-47.cs new file mode 100755 index 00000000000..c269d0b6c71 --- /dev/null +++ b/mcs/tests/test-47.cs @@ -0,0 +1,95 @@ +// +// Short-circuit evaluation tests +// +using System; + +class X { + + static int t_count = 0; + static int f_count = 0; + + static bool f () + { + Console.WriteLine ("f"); + f_count++; + return false; + } + + static bool t () + { + Console.WriteLine ("t"); + t_count++; + return true; + } + + static int Main () + { + if (t () && t ()){ + f_count--; + } + + if (t_count != 2) + return 1; + + if (f_count != -1) + return 3; + + f_count = 0; + + if (t () && f ()) + if (t_count != 3 && f_count == 1) + return 2; + + if (f () && f ()) + return 3; + + if (f_count != 2) + return 4; + + if (f () && t ()) + return 5; + + if (f_count != 3) + return 6; + + if (t_count != 3) + return 7; + + // + // reset + // + Console.WriteLine ("or"); + + t_count = f_count = 0; + + if (t () || t ()){ + if (t_count != 1) + return 8; + } else + return 9; + + if (t () || f ()){ + if (f_count != 0) + return 10; + if (t_count != 2) + return 16; + } else + return 11; + + if (f () || f ()){ + return 12; + } else + if (f_count != 2) + return 13; + + if (f () || t ()){ + if (f_count != 3) + return 15; + if (t_count != 3) + return 17; + } else + return 14; + + return 0; + } +} diff --git a/mcs/tests/test-48.cs b/mcs/tests/test-48.cs new file mode 100644 index 00000000000..21b6857ba6c --- /dev/null +++ b/mcs/tests/test-48.cs @@ -0,0 +1,30 @@ +using System; + +public class Blah { + + public const int i = 5; + + public static int Main () + { + const int foo = 10; + + int j = Blah.i; + + if (j != 5) + return 1; + + if (foo != 10) + return 1; + + for (int i = 0; i < 5; ++i){ + const int bar = 15; + + Console.WriteLine (bar); + Console.WriteLine (foo); + } + + Console.WriteLine ("Constant emission test okay"); + + return 0; + } +} diff --git a/mcs/tests/test-49.cs b/mcs/tests/test-49.cs new file mode 100755 index 00000000000..3cef3539c1d --- /dev/null +++ b/mcs/tests/test-49.cs @@ -0,0 +1,560 @@ +// +// This tests excercises a number of switch things: +// +// Code to test for multiple-labels is different that +// code for a single label. +// +// Code for switching on strings is different from the integer +// code. +// +// nulls (for strings) need to be handled specially since ceq will +// throw an exception if there. +// +// null as a case statement needs to be caught specially +// +using System; + +class X { + enum A { + a = 23333, + } + public const string One = "one"; + + static int s (byte b) + { + switch (b){ + case 0: return 255-0; + case 1: return 255-1; + case 2: return 255-2; + case 3: return 255-3; + case 4: return 255-4; + case 5: return 255-5; + case 6: return 255-6; + case 7: return 255-7; + case 8: return 255-8; + case 9: return 255-9; + case 10: return 255-10; + case 11: return 255-11; + case 12: return 255-12; + case 13: return 255-13; + case 14: return 255-14; + case 15: return 255-15; + case 16: return 255-16; + case 17: return 255-17; + case 18: return 255-18; + case 19: return 255-19; + case 20: return 255-20; + case 21: return 255-21; + case 22: return 255-22; + case 23: return 255-23; + case 24: return 255-24; + case 25: return 255-25; + case 26: return 255-26; + case 27: return 255-27; + case 28: return 255-28; + case 29: return 255-29; + case 30: return 255-30; + case 31: return 255-31; + case 32: return 255-32; + case 33: return 255-33; + case 34: return 255-34; + case 35: return 255-35; + case 36: return 255-36; + case 37: return 255-37; + case 38: return 255-38; + case 39: return 255-39; + case 40: return 255-40; + case 41: return 255-41; + case 42: return 255-42; + case 43: return 255-43; + case 44: return 255-44; + case 45: return 255-45; + case 46: return 255-46; + case 47: return 255-47; + case 48: return 255-48; + case 49: return 255-49; + case 50: return 255-50; + case 51: return 255-51; + case 52: return 255-52; + case 53: return 255-53; + case 54: return 255-54; + case 55: return 255-55; + case 56: return 255-56; + case 57: return 255-57; + case 58: return 255-58; + case 59: return 255-59; + case 60: return 255-60; + case 61: return 255-61; + case 62: return 255-62; + case 63: return 255-63; + case 64: return 255-64; + case 65: return 255-65; + case 66: return 255-66; + case 67: return 255-67; + case 68: return 255-68; + case 69: return 255-69; + case 70: return 255-70; + case 71: return 255-71; + case 72: return 255-72; + case 73: return 255-73; + case 74: return 255-74; + case 75: return 255-75; + case 76: return 255-76; + case 77: return 255-77; + case 78: return 255-78; + case 79: return 255-79; + case 80: return 255-80; + case 81: return 255-81; + case 82: return 255-82; + case 83: return 255-83; + case 84: return 255-84; + case 85: return 255-85; + case 86: return 255-86; + case 87: return 255-87; + case 88: return 255-88; + case 89: return 255-89; + case 90: return 255-90; + case 91: return 255-91; + case 92: return 255-92; + case 93: return 255-93; + case 94: return 255-94; + case 95: return 255-95; + case 96: return 255-96; + case 97: return 255-97; + case 98: return 255-98; + case 99: return 255-99; + case 100: return 255-100; + case 101: return 255-101; + case 102: return 255-102; + case 103: return 255-103; + case 104: return 255-104; + case 105: return 255-105; + case 106: return 255-106; + case 107: return 255-107; + case 108: return 255-108; + case 109: return 255-109; + case 110: return 255-110; + case 111: return 255-111; + case 112: return 255-112; + case 113: return 255-113; + case 114: return 255-114; + case 115: return 255-115; + case 116: return 255-116; + case 117: return 255-117; + case 118: return 255-118; + case 119: return 255-119; + case 120: return 255-120; + case 121: return 255-121; + case 122: return 255-122; + case 123: return 255-123; + case 124: return 255-124; + case 125: return 255-125; + case 126: return 255-126; + case 127: return 255-127; + case 128: return 255-128; + case 129: return 255-129; + case 130: return 255-130; + case 131: return 255-131; + case 132: return 255-132; + case 133: return 255-133; + case 134: return 255-134; + case 135: return 255-135; + case 136: return 255-136; + case 137: return 255-137; + case 138: return 255-138; + case 139: return 255-139; + case 140: return 255-140; + case 141: return 255-141; + case 142: return 255-142; + case 143: return 255-143; + case 144: return 255-144; + case 145: return 255-145; + case 146: return 255-146; + case 147: return 255-147; + case 148: return 255-148; + case 149: return 255-149; + case 150: return 255-150; + case 151: return 255-151; + case 152: return 255-152; + case 153: return 255-153; + case 154: return 255-154; + case 155: return 255-155; + case 156: return 255-156; + case 157: return 255-157; + case 158: return 255-158; + case 159: return 255-159; + case 160: return 255-160; + case 161: return 255-161; + case 162: return 255-162; + case 163: return 255-163; + case 164: return 255-164; + case 165: return 255-165; + case 166: return 255-166; + case 167: return 255-167; + case 168: return 255-168; + case 169: return 255-169; + case 170: return 255-170; + case 171: return 255-171; + case 172: return 255-172; + case 173: return 255-173; + case 174: return 255-174; + case 175: return 255-175; + case 176: return 255-176; + case 177: return 255-177; + case 178: return 255-178; + case 179: return 255-179; + case 180: return 255-180; + case 181: return 255-181; + case 182: return 255-182; + case 183: return 255-183; + case 184: return 255-184; + case 185: return 255-185; + case 186: return 255-186; + case 187: return 255-187; + case 188: return 255-188; + case 189: return 255-189; + case 190: return 255-190; + case 191: return 255-191; + case 192: return 255-192; + case 193: return 255-193; + case 194: return 255-194; + case 195: return 255-195; + case 196: return 255-196; + case 197: return 255-197; + case 198: return 255-198; + case 199: return 255-199; + case 200: return 255-200; + case 201: return 255-201; + case 202: return 255-202; + case 203: return 255-203; + case 204: return 255-204; + case 205: return 255-205; + case 206: return 255-206; + case 207: return 255-207; + case 208: return 255-208; + case 209: return 255-209; + case 210: return 255-210; + case 211: return 255-211; + case 212: return 255-212; + case 213: return 255-213; + case 214: return 255-214; + case 215: return 255-215; + case 216: return 255-216; + case 217: return 255-217; + case 218: return 255-218; + case 219: return 255-219; + case 220: return 255-220; + case 221: return 255-221; + case 222: return 255-222; + case 223: return 255-223; + case 224: return 255-224; + case 225: return 255-225; + case 226: return 255-226; + case 227: return 255-227; + case 228: return 255-228; + case 229: return 255-229; + case 230: return 255-230; + case 231: return 255-231; + case 232: return 255-232; + case 233: return 255-233; + case 234: return 255-234; + case 235: return 255-235; + case 236: return 255-236; + case 237: return 255-237; + case 238: return 255-238; + case 239: return 255-239; + case 240: return 255-240; + case 241: return 255-241; + case 242: return 255-242; + case 243: return 255-243; + case 244: return 255-244; + case 245: return 255-245; + case 246: return 255-246; + case 247: return 255-247; + case 248: return 255-248; + case 249: return 255-249; + case 250: return 255-250; + case 251: return 255-251; + case 252: return 255-252; + case 253: return 255-253; + case 254: return 255-254; + case 255: return 255-255; + } + + return -1; + } + + static int test (int v) + { + Console.WriteLine ("value: " + v); + switch (v){ + case 1: + case 2: + return 1; + + case 3: + return 3; + + case 4: + return 5; + + default: + Console.WriteLine ("default"); + return 6; + } + + return 7; + } + + static int tests (string s) + { + switch (s){ + case "one": + case "two": + return 1; + case "three": + return 3; + case "four": + return 5; + case null: + return 9; + default: + return 6; + } + + return 1; + } + + static int testn (string s) + { + switch (s){ + case "one": + return 1; + + default: + return 0; + } + return -1; + } + + static int testm (string s) + { + switch (s){ + case "one": + return 1; + } + return 100; + } + + static int testo (string s) + { + switch (s){ + case "one": + return 1; + case null: + return 100; + } + return 2; + } + + static int testp (string s) + { + switch (s){ + case "one": + case null: + case "two": + return 1; + case "three": + return 3; + } + return 4; + } + + static int test_def (string s) + { + switch (s){ + case "one": + goto default; + case "two": + return 1; + case "three": + return 2; + default: + return 3; + } + return 4; + } + + static int test_coverage (int x) + { + switch (x){ + case 0: + return 1; + default: + return 10; + } + } + + static int test_goto (int a) + { + switch (a){ + case 0: + goto case 2; + case 1: + return 10; + case 2: + return 20; + default: + return 100; + } + } + + static int test_memberaccess (string s) + { + switch (s){ + case X.One: + return 3; + default: + return 4; + } + } + + static int test_string_multiple_targets (string s) + { + switch (s){ + case "A": + return 1; + case "B": + return 2; + case "C": + case "D": + return 3; + } + return 0; + } + + enum My : byte { + A + } + + static int test_casts (int n) + { + switch (n) { + case (int) (char) (int) My.A: + return 1; + + default: + return 2; + } + } + + static int Main () + { + byte b; + + for (b = 0; b < 255; b++){ + if (s (b) != 255 - b){ + Console.WriteLine ("Failed with: " + b + " [" + s (b) + "]"); + return 1; + } + } + + Console.WriteLine ("Batch 2"); + if (test (1) != 1) + return 1; + if (test (2) != 1) + return 2; + if (test (3) != 3) + return 3; + if (test (4) != 5) + return 4; + if (test (100) != 6) + return 5; + + if (tests ("one") != 1) + return 6; + if (tests ("two") != 1) + return 7; + if (tests ("three") != 3) + return 8; + if (tests ("four") != 5) + return 9; + if (tests (null) != 9) + return 10; + if (tests ("blah") != 6) + return 11; + + if (testn ("one") != 1) + return 12; + if (testn ("hello") != 0) + return 13; + if (testn (null) != 0) + return 14; + + if (testm ("one") != 1) + return 15; + if (testm ("two") != 100) + return 16; + if (testm (null) != 100) + return 17; + + if (testo ("one") != 1) + return 18; + if (testo ("two") != 2) + return 19; + if (testo (null) != 100) + return 20; + + if (testp ("one") != 1) + return 21; + if (testp (null) != 1) + return 22; + if (testp ("two") != 1) + return 23; + if (testp ("three") != 3) + return 24; + if (testp ("blah") != 4) + return 25; + + if (test_def ("one") != 3) + return 26; + if (test_def ("two") != 1) + return 27; + if (test_def ("three") != 2) + return 28; + if (test_def (null) != 3) + return 29; + + if (test_coverage (100) != 10) + return 30; + + if (test_goto (0) != 20) + return 31; + if (test_goto (1) != 10) + return 32; + if (test_goto (2) != 20) + return 33; + if (test_goto (200) != 100) + return 34; + + if (test_memberaccess ("one") != 3) + return 35; + + if (test_string_multiple_targets ("A") != 1) + return 36; + if (test_string_multiple_targets ("B") != 2) + return 37; + if (test_string_multiple_targets ("C") != 3) + return 38; + if (test_string_multiple_targets ("D") != 3) + return 39; + if (test_string_multiple_targets ("E") != 0) + return 40; + + if (test_casts (0) != 1) + return 41; + + Console.WriteLine ("All tests pass"); + return 0; + } +} diff --git a/mcs/tests/test-5.cs b/mcs/tests/test-5.cs new file mode 100755 index 00000000000..7b3bdbc7924 --- /dev/null +++ b/mcs/tests/test-5.cs @@ -0,0 +1,14 @@ +using System; + +class X { + + static int Main () + { + Console.WriteLine ("From 0 to 9"); + + for (int i = 0; i < 10; i++) + Console.WriteLine (i); + + return 0; + } +} diff --git a/mcs/tests/test-50.cs b/mcs/tests/test-50.cs new file mode 100644 index 00000000000..84636e887ff --- /dev/null +++ b/mcs/tests/test-50.cs @@ -0,0 +1,15 @@ +using System;
+using System.Runtime.InteropServices;
+
+public class Blah {
+
+ [DllImport ("user32", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
+ public static extern int MessageBox (int hWnd, string pText, string pCaption, int uType);
+
+ public static int Main ()
+ {
+ MessageBox (0, "Hello from Mono !", "PInvoke Test", 0);
+
+ return 0;
+ }
+}
diff --git a/mcs/tests/test-51.cs b/mcs/tests/test-51.cs new file mode 100755 index 00000000000..3a6257747b6 --- /dev/null +++ b/mcs/tests/test-51.cs @@ -0,0 +1,89 @@ +// +// This test is used to test the `base' implementation +// +using System; + +class Base { + public int b_int_field; + public string b_string_field; + + public const int b_const_three = 3; + + public int b_int_property { + get { + return b_int_field; + } + + set { + b_int_field = value; + } + } + + public string b_get_id () + { + return "Base"; + } + + public Base () + { + b_int_field = 1; + b_string_field = "base"; + } +} + +class Derived : Base { + new int b_int_field; + new string b_string_field; + new const int b_const_three = 4; + + new int b_int_property { + get { + return b_int_field; + } + + + set { + b_int_field = value; + } + + } + + public Derived () + { + b_int_field = 10; + b_string_field = "derived"; + } + + public int Test () + { + if (b_int_field != 10) + return 1; + if (base.b_int_field != 1) + return 2; + if (base.b_string_field != "base") + return 3; + if (b_string_field != "derived") + return 4; + base.b_int_property = 4; + if (b_int_property != 10) + return 5; + if (b_int_property != 10) + return 6; + if (base.b_int_property != 4) + return 7; + if (b_const_three != 4) + return 8; + if (Base.b_const_three != 3) + return 9; + System.Console.WriteLine ("All tests pass"); + return 0; + } +} + +class boot { + static int Main () + { + Derived d = new Derived (); + return d.Test (); + } +} diff --git a/mcs/tests/test-52.cs b/mcs/tests/test-52.cs new file mode 100755 index 00000000000..fe5415c1ea7 --- /dev/null +++ b/mcs/tests/test-52.cs @@ -0,0 +1,98 @@ +// +// Tests the foreach on strings, and tests the implicit use of foreach +// to pull the enumerator from the class and identify the pattern to be called +// +using System; +using System.Collections; + +class Y { + int count = 0; + + public bool MoveNext () + { + count++; + return count != 10; + } + + public object Current { + get { + return count; + } + } +} + +class X { + + static string [] a = { + "one", "two", "three" + }; + + public Y GetEnumerator () + { + return new Y (); + } + + static int Main () + { + // + // String test + // + string total = ""; + + foreach (string s in a){ + total = total + s; + } + if (total != "onetwothree") + return 1; + + // + // Pattern test + // + X x = new X (); + + int t = 0; + foreach (object o in x){ + t += (int) o; + } + if (t != 45) + return 2; + + // + // Looking for GetEnumerator on interfaces test + // + Hashtable xx = new Hashtable (); + xx.Add ("A", 10); + xx.Add ("B", 20); + + IDictionary vars = xx; + string total2 = ""; + foreach (string name in vars.Keys){ + total2 = total2 + name; + } + + if ((total2 != "AB") && (total2 != "BA")) + return 3; + + ArrayList list = new ArrayList (); + list.Add ("one"); + list.Add ("two"); + list.Add ("three"); + int count = 0; + + // + // This test will make sure that `break' inside foreach will + // actually use a `leave' opcode instead of a `br' opcode + // + foreach (string s in list){ + if (s == "two"){ + break; + } + count++; + } + if (count != 1) + return 4; + + Console.WriteLine ("test passes"); + return 0; + } +} diff --git a/mcs/tests/test-53.cs b/mcs/tests/test-53.cs new file mode 100755 index 00000000000..34cdd0c2f94 --- /dev/null +++ b/mcs/tests/test-53.cs @@ -0,0 +1,119 @@ +// +// Tests the using statement implementation +// +using System; +using System.IO; + +class MyDispose : IDisposable { + public bool disposed; + + public void Dispose () + { + disposed = true; + } +} + +// +// This class does not implement IDiposable, but has an implicit conversion +// defined +// +class NoIDispose { + static public MyDispose x; + + public NoIDispose () + { + } + + static NoIDispose () + { + x = new MyDispose (); + } + + public static implicit operator MyDispose (NoIDispose a) + { + return x; + } +} + +class Y { + static void B () + { + using (NoIDispose a = new NoIDispose ()){ + } + } + +} + +class X { + static int Main () + { + MyDispose copy_a, copy_b, copy_c; + + // + // Test whether the two `a' and `b' get disposed + // + using (MyDispose a = new MyDispose (), b = new MyDispose ()){ + copy_a = a; + copy_b = b; + } + + if (!copy_a.disposed) + return 1; + if (!copy_b.disposed) + return 2; + + Console.WriteLine ("Nested using clause disposed"); + + // + // See if the variable `b' is disposed if there is + // an error thrown inside the using block. + // + copy_c = null; + try { + using (MyDispose c = new MyDispose ()){ + copy_c = c; + throw new Exception (); + } + } catch {} + + if (!copy_c.disposed) + return 3; + else + Console.WriteLine ("Disposal on finally block works"); + + // + // This should test if `a' is non-null before calling dispose + // implicitly + // + using (MyDispose d = null){ + } + + Console.WriteLine ("Null test passed"); + + // + // This tests that a variable is permitted here if there is + // an implicit conversion to a type that implement IDisposable + // + using (NoIDispose a = new NoIDispose ()){ + } + + // + // See if we dispose the object that can be implicitly converted + // to IDisposable + if (NoIDispose.x.disposed != true) + return 4; + else + Console.WriteLine ("Implicit conversion from type to IDisposable pass"); + + MyDispose bb = new MyDispose (); + using (bb){ + + } + if (bb.disposed == false) + return 6; + + Console.WriteLine ("All tests pass"); + return 0; + } +} + diff --git a/mcs/tests/test-54.cs b/mcs/tests/test-54.cs new file mode 100755 index 00000000000..0eb5b692204 --- /dev/null +++ b/mcs/tests/test-54.cs @@ -0,0 +1,23 @@ +// +// This test does not pass peverify because we dont return properly +// from catch blocks +// +using System; + +class X { + + bool v () + { + try { + throw new Exception (); + } catch { + return false; + } + return true; + } + + static int Main () + { + return 0; + } +} diff --git a/mcs/tests/test-55.cs b/mcs/tests/test-55.cs new file mode 100755 index 00000000000..6058ee2a1ba --- /dev/null +++ b/mcs/tests/test-55.cs @@ -0,0 +1,33 @@ +using c = System.Console; +using s = System; + +namespace A { + namespace B { + class C { + public static void Hola () { + c.WriteLine ("Hola!"); + } + } + } +} + +namespace X { + namespace Y { + namespace Z { + class W { + public static void Ahoj () { + s.Console.WriteLine ("Ahoj!"); + } + } + } + } +} + +class App { + public static int Main () { + A.B.C.Hola (); + X.Y.Z.W.Ahoj (); + + return 0; + } +} diff --git a/mcs/tests/test-56.cs b/mcs/tests/test-56.cs new file mode 100755 index 00000000000..286cb10dacd --- /dev/null +++ b/mcs/tests/test-56.cs @@ -0,0 +1,96 @@ +// +// Stress test properties and the various modes of +// declarations (virtual, overrides, abstract, new) +// +using System; + +interface I { + int P { + get; set; + } +} + +abstract class A : I { + public int p; + public int q; + + public int P { + get { return p; } + set { p = value; } + } + + public abstract int Q { get; set; } + + public int r; + public virtual int R { get { return r; } set { r = value; } } +} + +class B : A { + public int bp; + + public new int P + { + get { return bp; } + set { bp = value; } + } + + public override int Q { + get { return q; } + set { q = value; } + } +} + +class C : A { + public override int Q { + get { return q; } + set { q = value; } + } + + public int rr; + public override int R { get { return rr; } set { rr = value; } } +} + +class M { + + static int Main () + { + B b = new B (); + + b.P = 1; + b.R = 10; + b.Q = 20; + + if (b.P != 1) + return 1; + if (b.bp != 1) + return 2; + + if (b.R != 10) + return 3; + if (b.r != 10) + return 4; + + if (b.Q != 20) + return 5; + if (b.q != 20) + return 6; + + C c = new C (); + + c.R = 10; + c.Q = 20; + c.P = 30; + if (c.R != 10) + return 7; + if (c.rr != 10) + return 8; + if (c.P != 30) + return 9; + if (c.p != 30) + return 10; + + Console.WriteLine ("Test passes"); + return 0; + } +} + diff --git a/mcs/tests/test-57.cs b/mcs/tests/test-57.cs new file mode 100644 index 00000000000..2d23bdedb13 --- /dev/null +++ b/mcs/tests/test-57.cs @@ -0,0 +1,75 @@ +using System; + +public delegate void EventHandler (int i, int j); + +public class Button { + + private EventHandler click; + + public event EventHandler Click { + add { click += value; } + remove { click -= value; } + } + + public void OnClick (int i, int j) + { + if (click == null) { + Console.WriteLine ("Nothing to click!"); + return; + } + + click (i, j); + } + + public void Reset () + { + click = null; + } +} + +public class Blah { + + Button Button1 = new Button (); + + public void Connect () + { + Button1.Click += new EventHandler (Button1_Click); + Button1.Click += new EventHandler (Foo_Click); + } + + public void Button1_Click (int i, int j) + { + Console.WriteLine ("Button1 was clicked !"); + Console.WriteLine ("Answer : " + (i+j)); + } + + public void Foo_Click (int i, int j) + { + Console.WriteLine ("Foo was clicked !"); + Console.WriteLine ("Answer : " + (i+j)); + } + + public void Disconnect () + { + Console.WriteLine ("Disconnecting Button1's handler ..."); + Button1.Click -= new EventHandler (Button1_Click); + } + + public static int Main () + { + Blah b = new Blah (); + + b.Connect (); + + b.Button1.OnClick (2, 3); + + b.Disconnect (); + + Console.WriteLine ("Now calling OnClick again"); + b.Button1.OnClick (3, 7); + + Console.WriteLine ("Events test passes"); + return 0; + } + +} diff --git a/mcs/tests/test-58.cs b/mcs/tests/test-58.cs new file mode 100755 index 00000000000..d7230ee45df --- /dev/null +++ b/mcs/tests/test-58.cs @@ -0,0 +1,25 @@ +using System; +using System.Reflection; + +public class Blah { + + public static int Main () + { + unsafe { + int* i; + int foo = 10; + + void* bar; + + i = &foo; + + bar = i; + + Console.WriteLine ("Address : {0}", (int) i); + } + + return 0; + } +} + + diff --git a/mcs/tests/test-59.cs b/mcs/tests/test-59.cs new file mode 100755 index 00000000000..f857ed84d12 --- /dev/null +++ b/mcs/tests/test-59.cs @@ -0,0 +1,89 @@ +// +// Tests the varios type conversions. +// +using System; + +class X { + + static int test_explicit () + { + object x_int = 1; + object x_uint_1 = 1u; + object x_uint_2 = 1U; + object x_long_1 = 1l; + object x_long_2 = 1L; + object x_ulong_1 = 1ul; + object x_ulong_2 = 1UL; + object x_ulong_3 = 1lu; + object x_ulong_4 = 1Lu; + object x_ulong_5 = 1LU; + + if (!(x_int is int)) + return 1; + + if (!(x_uint_1 is uint)) + return 2; + + if (!(x_uint_2 is uint)) + return 3; + + if (!(x_long_1 is long)) + return 5; + + if (!(x_long_2 is long)) + return 6; + + if (!(x_ulong_1 is ulong)) + return 7; + + if (!(x_ulong_2 is ulong)) + return 8; + + if (!(x_ulong_3 is ulong)) + return 9; + + if (!(x_ulong_4 is ulong)) + return 10; + + if (!(x_ulong_5 is ulong)) + return 11; + + return 0; + + } + + static int test_implicit () + { + object i_int = 1; + object i_uint = 0x80000000; + object i_long = 0x100000000; + object i_ulong = 0x8000000000000000; + + if (!(i_int is int)) + return 1; + if (!(i_uint is uint)) + return 2; + if (!(i_long is long)) + return 3; + if (!(i_ulong is ulong)) + return 4; + + return 0; + } + + static int Main () + { + int v; + v = test_explicit (); + + if (v != 0) + return v; + + v = test_implicit (); + if (v != 0) + return 20 + v; + + Console.WriteLine ("Tests pass"); + return 0; + } +} diff --git a/mcs/tests/test-6.cs b/mcs/tests/test-6.cs new file mode 100755 index 00000000000..b95d891b7c4 --- /dev/null +++ b/mcs/tests/test-6.cs @@ -0,0 +1,15 @@ +using System; + +class X { + + static int Main () + { + Console.WriteLine ("From 0 to 9"); + int i; + + for (i = 0; i < 10; i++) + Console.WriteLine (i); + + return 0; + } +} diff --git a/mcs/tests/test-60.cs b/mcs/tests/test-60.cs new file mode 100755 index 00000000000..777160c5b46 --- /dev/null +++ b/mcs/tests/test-60.cs @@ -0,0 +1,53 @@ +// +// Really lame test, but it should be fine for now +// + +#if FLAG_FALSE + namespace ns1 +#else + #if FLAG_FALSE + #if FLAG_FALSE + namespace ns2 + #else + namespace ns3 + #endif + #else + #if FLAG_TRUE + namespace ns4 + #else + namespace ns5 + #endif + #endif +#endif +{ + public class Y + { + public Y() + { + } + + public void Run () {} + } +} + +#if (X) +#endif + +#if YY +#errro this should not be printed +#if X +#elif Y +#else +#endif +#else +class X { + static int Main () + { + ns5.Y y = new ns5.Y (); + + y.Run (); + return 0; + } +} +#endif + diff --git a/mcs/tests/test-61.cs b/mcs/tests/test-61.cs new file mode 100755 index 00000000000..9d8c8532b0f --- /dev/null +++ b/mcs/tests/test-61.cs @@ -0,0 +1,39 @@ +// +// This tests checks that we allow the `get' and `set' keywords inside +// the get and set blocks. It does the same for Events special remove +// and add keywords. +// +class X { + int Property { + get { + int get; + get = 1; + return get; + } + set { + int set; + set = value; + } + } + + int P2 { + get { return 0; } + } + + int P3 { + set { } + } + + public delegate void MyEvent (); + + public event MyEvent XX { + add { int add = 1; } + remove { int remove = 1; } + } + + static int Main () + { + return 0; + } +} + diff --git a/mcs/tests/test-62.cs b/mcs/tests/test-62.cs new file mode 100755 index 00000000000..550956009e0 --- /dev/null +++ b/mcs/tests/test-62.cs @@ -0,0 +1,28 @@ +// +// This test just makes sure that we can typecast to +// array types, as this was introduced later into the +// grammar. +// + +class X { + + X [] GetX () + { + return (X []) null; + } + + int [] getInt () + { + return (int []) null; + } + + int [,,] getMoreInt () + { + return (int [,,]) null; + } + + static int Main () + { + return 0; + } +} diff --git a/mcs/tests/test-63.cs b/mcs/tests/test-63.cs new file mode 100755 index 00000000000..268c607f783 --- /dev/null +++ b/mcs/tests/test-63.cs @@ -0,0 +1,31 @@ +// +// Tests rethrowing an exception +// +using System; + +class X { + static int Main () + { + bool one = false, two = false; + + try { + try { + throw new Exception (); + } catch (Exception e) { + one = true; + Console.WriteLine ("Caught"); + throw; + } + } catch { + two = true; + Console.WriteLine ("Again"); + } + + if (one && two){ + Console.WriteLine ("Ok"); + return 0; + } else + Console.WriteLine ("Failed"); + return 1; + } +} diff --git a/mcs/tests/test-64.cs b/mcs/tests/test-64.cs new file mode 100755 index 00000000000..43c31d7559e --- /dev/null +++ b/mcs/tests/test-64.cs @@ -0,0 +1,29 @@ +// +// This just test that we can compile this code. +// +// The challenge here is that LookupType needs to first look +// in classes defined in its class or parent classes before resorting +// to lookups in the namespace. +// + +class Operator { +} + +class Blah { + + public enum Operator { A, B }; + + public Blah (Operator x) + { + } +} + +class T { + static int Main () + { + Blah b = new Blah (Blah.Operator.A); + + return 0; + } +} + diff --git a/mcs/tests/test-65.cs b/mcs/tests/test-65.cs new file mode 100755 index 00000000000..b117ae309a4 --- /dev/null +++ b/mcs/tests/test-65.cs @@ -0,0 +1,51 @@ +// +// This exercises the various ways in which the new operator works +// with value types. +// + +using System; + +struct S { + int v; +} + +class X { + static bool receive, create, create_and_box; + + static void receiver (S x) + { + receive = true; + } + + static object BoxS () + { + create_and_box = true; + return new S (); + } + + static S Plain () + { + create = true; + return new S (); + } + + static int Main () + { + object a = new S (); + receiver (new S ()); + S s = Plain (); + object o = BoxS (); + + if (a == null) + return 1; + if (receive == false) + return 2; + if (create == false) + return 3; + if (create_and_box == false) + return 4; + + Console.WriteLine ("Test pass"); + return 0; + } +} diff --git a/mcs/tests/test-66.cs b/mcs/tests/test-66.cs new file mode 100755 index 00000000000..7691f6e7334 --- /dev/null +++ b/mcs/tests/test-66.cs @@ -0,0 +1,134 @@ +// +// This tests checks out field access to arrays +// +using System; + +struct A { + public int a; +} + +class Y { + public object a; +} + +class X { + static A [] a_single = new A [10]; + static A [,] a_double = new A [10,10]; + static Y [] o_single = new Y [10]; + static Y [,] o_double = new Y [10,10]; + + static void FillOne () + { + a_single [0].a = 1; + } + + static void FillSingle () + { + int i; + + for (i = 0; i < 10; i++){ + a_single [i].a = i + 1; + } + } + + static void FillDouble () + { + int i, j; + + for (i = 0; i < 10; i++) + for (j = 0; j < 10; j++) + a_double [i,j].a = i * j; + } + + static void FillObject () + { + int i; + + for (i = 0; i < 10; i++){ + o_single [i] = new Y (); + o_single [i].a = (i + 1); + } + } + + static void FillDoubleObject () + { + int i, j; + + for (i = 0; i < 10; i++) + for (j = 0; j < 10; j++){ + o_double [i,j] = new Y (); + o_double [i,j].a = i * j; + } + } + + static int TestSingle () + { + int i; + + for (i = 0; i < 10; i++){ + if (a_single [i].a != i + 1) + return 1; + } + return 0; + } + + static int TestDouble () + { + int i, j; + + for (i = 0; i < 10; i++){ + for (j = 0; j < 10; j++) + if (a_double [i,j].a != (i *j)) + return 2; + } + + return 0; + } + + static int TestObjectSingle () + { + int i; + + for (i = 0; i < 10; i++){ + if ((int)(o_single [i].a) != i + 1) + return 1; + } + return 0; + } + + static int TestObjectDouble () + { + int i, j; + + for (i = 0; i < 10; i++){ + for (j = 0; j < 10; j++) + if (((int)o_double [i,j].a) != (i *j)) + return 2; + } + + return 0; + } + + static int Main () + { + FillSingle (); + FillDouble (); + FillObject (); + FillDoubleObject (); + + if (TestSingle () != 0) + return 1; + + if (TestDouble () != 0) + return 2; + + if (TestObjectSingle () != 0) + return 3; + + if (TestObjectDouble () != 0) + return 4; + + Console.WriteLine ("test passes"); + return 0; + } +} diff --git a/mcs/tests/test-67.cs b/mcs/tests/test-67.cs new file mode 100644 index 00000000000..7eb792ae690 --- /dev/null +++ b/mcs/tests/test-67.cs @@ -0,0 +1,93 @@ +using System; +using System.Runtime.InteropServices; + +[StructLayout (LayoutKind.Sequential)] +public class MySystemTime { + public ushort Year; + public ushort Month; + public ushort DayOfWeek; + public ushort Day; + public ushort Hour; + public ushort Minute; + public ushort Second; + public ushort Milliseconds; +} + +[StructLayout (LayoutKind.Sequential)] +public struct Point { + public int x; + public int y; +} + +[StructLayout (LayoutKind.Explicit)] +public struct Rect { + [FieldOffset (0)] public int left; + [FieldOffset (4)] public int top; + [FieldOffset (8)] public int right; + [FieldOffset (12)] public int bottom; +} + +[StructLayout (LayoutKind.Explicit)] +struct A { + [FieldOffset (0)] + public int a; + [FieldOffset (0)] + public byte b1; + [FieldOffset (1)] + public byte b2; + [FieldOffset (2)] + public byte b3; + [FieldOffset (3)] + public byte b4; +} + +public class Blah { + + [DllImport ("Kernel32.dll")] + public static extern void GetSystemTime (MySystemTime st); + + [DllImport ("User32.dll")] + public static extern bool PtInRect (ref Rect r, Point p); + + public static int Main () { + + MySystemTime st = new MySystemTime (); + + GetSystemTime (st); + + Console.WriteLine ("Today's date is : {0:0000}-{1:00}-{2:00}", st.Year, st.Month, st.Day); + Console.WriteLine ("The time now is : {0:00}:{1:00}:{2:00}", st.Hour, st.Minute, st.Second); + + Rect r = new Rect (); + + r.left = 10; + r.top = 12; + r.right = 30; + r.bottom = 30; + + Point p = new Point (); + + p.x = 15; + p.y = 20; + + if (!PtInRect (ref r, p)) + return 1; + + A a = new A (); + + a.a = 0x12345678; + + if (a.b1 != 0x78) + return 2; + if (a.b2 != 0x56) + return 3; + if (a.b3 != 0x34) + return 4; + if (a.b4 != 0x12) + return 5; + + Console.WriteLine ("Point lies inside rect"); + Console.WriteLine ("Test passes"); + return 0; + } +} diff --git a/mcs/tests/test-68.cs b/mcs/tests/test-68.cs new file mode 100755 index 00000000000..ffe5031c079 --- /dev/null +++ b/mcs/tests/test-68.cs @@ -0,0 +1,35 @@ +// +// Tests invocation of reference type functions with value type arguments +// +using System; +enum A { + Hello +} + +class Y { + public Y () + { + value = 3; + } + public int value; +} + +class X { + + static int Main () + { + if ("Hello" != A.Hello.ToString ()) + return 1; + + Console.WriteLine ("value is: " + (5.ToString ())); + if (5.ToString () != "5") + return 2; + + Y y = new Y (); + if (y.value.ToString () != "3") + return 3; + Console.WriteLine ("Test ok"); + return 0; + } +} + diff --git a/mcs/tests/test-69.cs b/mcs/tests/test-69.cs new file mode 100644 index 00000000000..be58166c258 --- /dev/null +++ b/mcs/tests/test-69.cs @@ -0,0 +1,13 @@ +using System; +using System.Runtime.CompilerServices; + +public class Blah { + + [MethodImpl (MethodImplOptions.InternalCall)] + private extern void Start_internal(IntPtr handle); + + public static int Main () + { + return 0; + } +} diff --git a/mcs/tests/test-7.cs b/mcs/tests/test-7.cs new file mode 100644 index 00000000000..d3a9a9f34b1 --- /dev/null +++ b/mcs/tests/test-7.cs @@ -0,0 +1,176 @@ +using System; + +namespace Mine { + + public class Blah { + + public int i; + + public static int Main () + { + Blah k, l; + + k = new Blah (2) + new Blah (3); + if (k.i != 5) + return 1; + + k = ~ new Blah (5); + if (k.i != -6) + return 1; + + + k = + new Blah (4); + if (k.i != 4) + return 1; + + k = - new Blah (21); + if (k.i != -21) + return 1; + + k = new Blah (22) - new Blah (21); + if (k.i != 1) + return 1; + + if (!k) + Console.WriteLine ("! returned true"); + + int number = k; + if (number != 1) + return 1; + + k++; + ++k; + + if (k) + Console.WriteLine ("k is definitely true"); + + k = new Blah (30); + + double f = (double) k; + + if (f != 30.0) + return 1; + + int i = new Blah (5) * new Blah (10); + + if (i != 50) + return 1; + + k = new Blah (50); + l = new Blah (10); + + i = k / l; + + if (i != 5) + return 1; + + i = k % l; + + if (i != 0) + return 1; + + return 0; + } + + public Blah (int v) + { + i = v; + } + + public static Blah operator + (Blah i, Blah j) + { + Blah b = new Blah (i.i + j.i); + Console.WriteLine ("Overload binary + operator"); + return b; + } + + public static Blah operator + (Blah i) + { + Console.WriteLine ("Overload unary + operator"); + return new Blah (i.i); + } + + public static Blah operator - (Blah i) + { + Console.WriteLine ("Overloaded unary - operator"); + return new Blah (- i.i); + } + + public static Blah operator - (Blah i, Blah j) + { + Blah b = new Blah (i.i - j.i); + Console.WriteLine ("Overloaded binary - operator"); + return b; + } + + public static int operator * (Blah i, Blah j) + { + Console.WriteLine ("Overloaded binary * operator"); + return i.i * j.i; + } + + public static int operator / (Blah i, Blah j) + { + Console.WriteLine ("Overloaded binary / operator"); + return i.i / j.i; + } + + public static int operator % (Blah i, Blah j) + { + Console.WriteLine ("Overloaded binary % operator"); + return i.i % j.i; + } + + public static Blah operator ~ (Blah i) + { + Console.WriteLine ("Overloaded ~ operator"); + return new Blah (~i.i); + } + + public static bool operator ! (Blah i) + { + Console.WriteLine ("Overloaded ! operator"); + return (i.i == 1); + } + + public static Blah operator ++ (Blah i) + { + Blah b = new Blah (i.i + 1); + Console.WriteLine ("Incrementing i"); + return b; + } + + public static Blah operator -- (Blah i) + { + Blah b = new Blah (i.i - 1); + Console.WriteLine ("Decrementing i"); + return b; + } + + public static bool operator true (Blah i) + { + Console.WriteLine ("Overloaded true operator"); + return (i.i == 3); + } + + public static bool operator false (Blah i) + { + Console.WriteLine ("Overloaded false operator"); + return (i.i != 1); + } + + public static implicit operator int (Blah i) + { + Console.WriteLine ("Converting implicitly from Blah->int"); + return i.i; + } + + public static explicit operator double (Blah i) + { + Console.WriteLine ("Converting explicitly from Blah->double"); + return (double) i.i; + } + + } + +} diff --git a/mcs/tests/test-70.cs b/mcs/tests/test-70.cs new file mode 100755 index 00000000000..6fe8da995e8 --- /dev/null +++ b/mcs/tests/test-70.cs @@ -0,0 +1,48 @@ +// +// Tests the right settings for overrides +// + +class X { + + public virtual int A { + get { + return 1; + } + } + + public virtual int B () + { + return 1; + } +} + +class Y : X { + public override int A { + get { + return base.A + 2; + } + } + + public override int B () + { + return base.B () + 1; + } +} + +class Z { + static int Main () + { + Y y = new Y (); + X x = new X (); + + if (y.B () != 2) + return 1; + if (y.A != 3) + return 2; + if (x.A != 1) + return 3; + if (x.B () != 1) + return 4; + return 0; + } +} diff --git a/mcs/tests/test-71.cs b/mcs/tests/test-71.cs new file mode 100755 index 00000000000..e7bd956c5f6 --- /dev/null +++ b/mcs/tests/test-71.cs @@ -0,0 +1,28 @@ +// +// struct with a constructor +// +using System; + +class X { + + static void Main () + { + MethodSignature ms = new MethodSignature ("hello", null, null); + + Console.WriteLine ("About to look for: " + ms.Name); + } +} + + struct MethodSignature { + public string Name; + public Type RetType; + public Type [] Parameters; + + public MethodSignature (string name, Type ret_type, Type [] parameters) + { + Name = name; + RetType = ret_type; + Parameters = parameters; + } + } + diff --git a/mcs/tests/test-72.cs b/mcs/tests/test-72.cs new file mode 100755 index 00000000000..06d1cee18f9 --- /dev/null +++ b/mcs/tests/test-72.cs @@ -0,0 +1,21 @@ +// +// Compile test for referencing types on nested types +// + +using System; + +public class outer { + public class inner { + public void meth(Object o) { + inner inst = (inner)o; + } + } + + static int Main () + { + // We only test that this compiles. + + return 0; + } + } + diff --git a/mcs/tests/test-73.cs b/mcs/tests/test-73.cs new file mode 100755 index 00000000000..2acf9806895 --- /dev/null +++ b/mcs/tests/test-73.cs @@ -0,0 +1,28 @@ +// +// This test is used to test that we do not use the .override +// command on abstract method implementations. +// + +public abstract class Abstract { + public abstract int A (); +} + +public class Concrete : Abstract { + public override int A () { + return 1; + } +} + +class Test { + + static int Main () + { + Concrete c = new Concrete (); + + if (c.A () != 1) + return 1; + + return 0; + } +} + diff --git a/mcs/tests/test-74.cs b/mcs/tests/test-74.cs new file mode 100755 index 00000000000..0d134af57e9 --- /dev/null +++ b/mcs/tests/test-74.cs @@ -0,0 +1,29 @@ +// +// This test excercises #pre-processor directives in non-1 column +// as well as the literal strings +// +class X { + #if Blah + #else + static int Main () + { + #endif + string s = @"Hola\"; + string d = "Hola\\"; + string e = @"Co""a"; + string f = "Co\"a"; + + if (s != d) + return 1; + if (e != f) + return 2; + + string g = "Hello\nworld"; + string h = @"Hello +world"; + if (g != h) + return 3; + + return 0; + } +} diff --git a/mcs/tests/test-75.cs b/mcs/tests/test-75.cs new file mode 100755 index 00000000000..a16816cbbf0 --- /dev/null +++ b/mcs/tests/test-75.cs @@ -0,0 +1,36 @@ +// +// This test probes using an operator overloaded in a parents' parent +// + +class X { + public static bool called = false; + + static public X operator + (X a, X b) + { + called = true; + return null; + } +} + +class Y : X { +} + +class Z : Y { +} + +class driver { + + static int Main () + { + Z a = new Z (); + Z b = new Z (); + X c = a + b; + + if (X.called) + return 0; + + return 1; + } + +} + diff --git a/mcs/tests/test-76.cs b/mcs/tests/test-76.cs new file mode 100755 index 00000000000..91377cee80a --- /dev/null +++ b/mcs/tests/test-76.cs @@ -0,0 +1,35 @@ +// +// This test is used to verify that we handle functions that have +// only an array parameter +// + +using System; +using System.Text; + +class foo { + + static string strcat (params string [] values) + { + StringBuilder s = new StringBuilder (); + + foreach (string val in values) { + s.Append (val); + } + + return s.ToString (); + } + + public static int Main () + { + if (strcat ("Hello", "World") != "HelloWorld") + return 1; + + if (strcat () != "") + return 2; + + if (strcat ("a", "b", "c", "d", "e") != "abcde") + return 3; + + return 0; + } +}; diff --git a/mcs/tests/test-77.cs b/mcs/tests/test-77.cs new file mode 100755 index 00000000000..8f3119b2a88 --- /dev/null +++ b/mcs/tests/test-77.cs @@ -0,0 +1,41 @@ +// +// Tests the various string implicit conversions +// + +class XX { + + enum X { + A = 1 + } + + static int Main () + { + int one = 1; + int two = 2; + + if (("a" + "b") != "ab") + return 1; + + if (("one" + one) != "one1") + return 2; + + if ((one + "one") != "1one") + return 3; + + if ((one + "two" + two) != "1two2") + return 4; + + if ((X.A + "a") != "Aa") + return 5; + + if (((int)X.A) + "a" != "1a") + return 6; + + if ((1 + " " + "hello") != "1 hello") + return 7; + + System.Console.WriteLine ("test ok"); + return 0; + } +} + diff --git a/mcs/tests/test-78.cs b/mcs/tests/test-78.cs new file mode 100755 index 00000000000..3787fe6b9e2 --- /dev/null +++ b/mcs/tests/test-78.cs @@ -0,0 +1,59 @@ +// +// This test exhibits an old bug where we did not +// go into the underlying type for an enumeration, and +// hence implicit and explicit casts were not working when +// they were going from a type to an enum +// + +namespace N1 +{ + public enum A + { + A_1, A_2, A_3 + } + + public class B + { + static bool ShortCasting () + { + short i = 0; + N1.A a = N1.A.A_1; + + i = (short) a; //<- crash + a = (N1.A)i;//<- used to fail, can't convert + + if (a != N1.A.A_1) + return false; + return true; + } + + static bool IntCasting () + { + int i = 0; + N1.A a = N1.A.A_1; + + i = (int) a;//<- works fine + a = (N1.A)i;//<- used to fail, can't convert + + if (a != N1.A.A_1) + return false; + return true; + } + + static int Main () + { + if (!IntCasting ()) + return 1; + if (!ShortCasting ()) + return 2; + return 0; + } + + } +} + + + + + + diff --git a/mcs/tests/test-79.cs b/mcs/tests/test-79.cs new file mode 100755 index 00000000000..8a4012db8ad --- /dev/null +++ b/mcs/tests/test-79.cs @@ -0,0 +1,17 @@ +// +// This test excercises the compiler being able to compute +// correctly the return type in the presence of null (as null +// will be implicitly convertible to anything +// +class X { + + static int Main () + { + object o = null; + + string s = o == null ? "string" : null; + string d = o == null ? null : "string"; + + return 0; + } +} diff --git a/mcs/tests/test-8.cs b/mcs/tests/test-8.cs new file mode 100644 index 00000000000..5de9804f341 --- /dev/null +++ b/mcs/tests/test-8.cs @@ -0,0 +1,29 @@ +class X { + static public int Main (string [] args) + { + int a, b, c, d; + + a = b = 10; + c = d = 14; + + if ((a + b) != 20) + return 1; + if ((a + d) != 24) + return 2; + if ((c + d) != 28) + return 3; + if ((b + c) != 24) + return 4; + + if (a++ != 10) + return 5; + if (++a != 12) + return 6; + if (b-- != 10) + return 7; + if (--b != 8) + return 8; + + return 0; + } +} diff --git a/mcs/tests/test-80.cs b/mcs/tests/test-80.cs new file mode 100755 index 00000000000..ec2270b1c40 --- /dev/null +++ b/mcs/tests/test-80.cs @@ -0,0 +1,32 @@ +// +// This test is used to check that we can actually use implementations +// provided in our parent to interfaces declared afterwards. +// + +using System; + +public interface A { + int Add (int a, int b); +} + +public class X { + public int Add (int a, int b) + { + return a + b; + } +} + +class Y : X, A { + + static int Main () + { + Y y = new Y (); + + if (y.Add (1, 1) != 2) + return 1; + + Console.WriteLine ("parent interface implementation test passes"); + return 0; + } + +} diff --git a/mcs/tests/test-81.cs b/mcs/tests/test-81.cs new file mode 100644 index 00000000000..005708bfc86 --- /dev/null +++ b/mcs/tests/test-81.cs @@ -0,0 +1,37 @@ +// +// Tests if we can invoke static members using the short +// names +// +using System; + +namespace N1 +{ + public class A + { + int x; + string s; + + void Bar () + { + x = int.Parse ("0"); + s = string.Format("{0}", x); + } + + public static int Main () + { + A a = new A (); + + a.Bar (); + + if (a.x != 0) + return 1; + + if (a.s != "0") + return 1; + + Console.WriteLine ("Bar set s to " + a.s); + + return 0; + } + } +} diff --git a/mcs/tests/test-82.cs b/mcs/tests/test-82.cs new file mode 100644 index 00000000000..9ff4032897b --- /dev/null +++ b/mcs/tests/test-82.cs @@ -0,0 +1,40 @@ +// +// Test to ensure that we correctly perform type lookups - thanks to Felix A.I +// +namespace N1 +{ + public enum A + { + A_1, A_2, A_3 + } + + namespace N2 + { + public class B + { + A member; + + void Method (ref A a) + { + } + + public static int Main () + { + return 0; + } + } + + } +} + +namespace N1.N3 +{ + public class B + { + A member; + + void Method (ref A a) + { + } + } +} diff --git a/mcs/tests/test-83.cs b/mcs/tests/test-83.cs new file mode 100755 index 00000000000..f416ddb4a6d --- /dev/null +++ b/mcs/tests/test-83.cs @@ -0,0 +1,47 @@ +// +// This test probes that we treat events differently than fields +// This used to cause a compiler crash. +// +using System; + +delegate void PersonArrivedHandler (object source, PersonArrivedArgs args); + +class PersonArrivedArgs /*: EventArgs*/ { + public string name; + public PersonArrivedArgs (string name) { + this.name = name; + } +} + +class Greeter { + string greeting; + + public Greeter (string greeting) { + this.greeting = greeting; + } + + public void HandlePersonArrived (object source, PersonArrivedArgs args) { + Console.WriteLine(greeting, args.name); + } +} + +class Room { + public event PersonArrivedHandler PersonArrived; + + public Room () { + // Assign a value to it, this also used to crash the compiler. + PersonArrived = null; + } + + public void AddPerson (string name) { + PersonArrived(this, null); //(this, PersonArrivedArgs(name)); + } +} + +class DelegateTest { + static int Main () { + return 0; + } +} + + diff --git a/mcs/tests/test-84.cs b/mcs/tests/test-84.cs new file mode 100755 index 00000000000..e6b3d4e3f0d --- /dev/null +++ b/mcs/tests/test-84.cs @@ -0,0 +1,22 @@ +// +// This test shows how a variable can be created with the +// same name as the class, and then the class referenced again +// +// This was a bug exposed by Digger, as we incorrectly tried to +// do some work ahead of time during the resolution process +// (ie, we created LocalVariableReferences for the int variable `Ghost', +// which stopped `Ghost' from being useful as a type afterwards +// + +class Ghost { + + static int Main () + { + int Ghost = 0; + + if (true){ + Ghost g = null; + } + return 0; + } +} diff --git a/mcs/tests/test-85.cs b/mcs/tests/test-85.cs new file mode 100755 index 00000000000..a50379568f3 --- /dev/null +++ b/mcs/tests/test-85.cs @@ -0,0 +1,23 @@ +// +// This test declares a field variable called `UnmanagedType' of type +// UnmanagedType. +// +// The test is used to test the cast of 0 to UnmanagedType, as before +// that would have been resolved to a variable instead of a type. +// +using System.Runtime.InteropServices; + +class X { + static UnmanagedType UnmanagedType; + + static int Main () + { + UnmanagedType = (UnmanagedType) 0; + + if (UnmanagedType != 0) + return 1; + + return 0; + } +} + diff --git a/mcs/tests/test-86.cs b/mcs/tests/test-86.cs new file mode 100644 index 00000000000..faf1ae20a18 --- /dev/null +++ b/mcs/tests/test-86.cs @@ -0,0 +1,45 @@ +using System; + +namespace T { + public class T { + + static int method1 (Type t, int val) + { + Console.WriteLine ("You passed in " + val); + return 1; + } + + static int method1 (Type t, Type[] types) + { + Console.WriteLine ("Wrong method called !"); + return 2; + } + + static int method2 (Type t, int val) + { + Console.WriteLine ("MEthod2 : " + val); + return 3; + } + + static int method2 (Type t, Type [] types) + { + Console.WriteLine ("Correct one this time!"); + return 4; + } + + public static int Main() + { + int i = method1 (null, 1); + + if (i != 1) + return 1; + + i = method2 (null, null); + + if (i != 4) + return 1; + + return 0; + } + } +} diff --git a/mcs/tests/test-87.cs b/mcs/tests/test-87.cs new file mode 100755 index 00000000000..aaa809f8bc4 --- /dev/null +++ b/mcs/tests/test-87.cs @@ -0,0 +1,62 @@ +// +// Tests the lookup of names on nested classes. +// +// Tests nested interfaces +// +class Top { + + class X { + + } + + class Y : X { + } + + interface A { + int get_one (); + } + + interface B : A { + int get_two (); + } + + public class XA : A { + public int get_one () { return 1; } + } + + class XB : B { + public int get_one () { return 1; } + public int get_two () { return 2; } + } + + static int Main () + { + XA x = new XA (); + + if (x.get_one () != 1) + return 1; + + XB b = new XB (); + if (x.get_one () != 1) + return 2; + if (b.get_two () != 2) + return 3; + + XB [] xb = null; + + return 0; + } +} + +// +// The following tests that the compiler will actually properly +// find the types that are requested (they are nested types) +// +class Other { + public void X () + { + Top.XA xa = null; + Top.XA [] xb = null; + } +} + diff --git a/mcs/tests/test-88.cs b/mcs/tests/test-88.cs new file mode 100755 index 00000000000..a45aafe7e5b --- /dev/null +++ b/mcs/tests/test-88.cs @@ -0,0 +1,18 @@ +class X { + +static void f (string s) +{ +s. Split ('a'); +} + + static int Main () + { + string s = ""; + + s.Split ('a'); + s.Split (); + s.Split ('a', 'b', 'c'); + return 0; + } +} + diff --git a/mcs/tests/test-89.cs b/mcs/tests/test-89.cs new file mode 100755 index 00000000000..3f1b86ed6b2 --- /dev/null +++ b/mcs/tests/test-89.cs @@ -0,0 +1,34 @@ +// +// This test is used to make sure that we correctly create value +// types in the presence of arrays. Check bug 21801 for a history +// of the bug +// +using System; + +struct X { + int value; + + X (int a) + { + value = a; + } + + static X F (int a) + { + return new X (a); + } + + static int Main () + { + X [] x = { new X (40), F (10) }; + + if (x [0].value != 40) + return 1; + + if (x [1].value != 10) + return 2; + + Console.WriteLine ("test ok"); + return 0; + } +} diff --git a/mcs/tests/test-9.cs b/mcs/tests/test-9.cs new file mode 100755 index 00000000000..4fd35e3714b --- /dev/null +++ b/mcs/tests/test-9.cs @@ -0,0 +1,24 @@ +class X { + static public int Main (string [] args) + { + decimal a, b, c, d; + + a = 0; + b = 1; + c = d = 3; + + if (b + b + b != c) + return 1; + + if (a != (b - 1)) + return 2; + + if (c != d) + return 3; + + if (!(c == d)) + return 4; + + return 0; + } +} diff --git a/mcs/tests/test-90.cs b/mcs/tests/test-90.cs new file mode 100755 index 00000000000..8d7c147ec3f --- /dev/null +++ b/mcs/tests/test-90.cs @@ -0,0 +1,37 @@ +// +// This test just makes sure that we can compile C.A, there used to be +// a bug in the compiler that was doing the lookups in the wrong namespace +// +// +namespace N1 +{ + public enum A + { + A_1, A_2, A_3 + } + + public interface B + { + N1.A myProp + { + get; + set; // <-- This always worked. + } + } + + public interface C + { + A myProp + { + get; + set; // <-- This used to fail. + } + } + + public class Blah { + static int Main () + { + return 0; + } + } +} diff --git a/mcs/tests/test-91.cs b/mcs/tests/test-91.cs new file mode 100755 index 00000000000..11dddc6b45c --- /dev/null +++ b/mcs/tests/test-91.cs @@ -0,0 +1,53 @@ +using System; +using System.Reflection; + +class Test { + + static protected internal void MyProtectedInternal () { } + static internal void MyInternal() { } + static public void MyPublic () { } + static void MyPrivate () {} + + static int Main () + { + Type myself = typeof (Test); + BindingFlags bf = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public; + MethodAttributes mpia; + MethodInfo mpi; + + // + // protected internal + // + mpi = myself.GetMethod ("MyProtectedInternal", bf); + mpia = mpi.Attributes & MethodAttributes.MemberAccessMask; + if (mpia != MethodAttributes.FamORAssem) + return 1; + + // + // internal + // + mpi = myself.GetMethod ("MyInternal", bf); + mpia = mpi.Attributes & MethodAttributes.MemberAccessMask; + if (mpia != MethodAttributes.Assembly) + return 2; + + // + // public + // + mpi = myself.GetMethod ("MyPublic", bf); + mpia = mpi.Attributes & MethodAttributes.MemberAccessMask; + if (mpia != MethodAttributes.Public) + return 3; + + // + // private + // + mpi = myself.GetMethod ("MyPrivate", bf); + mpia = mpi.Attributes & MethodAttributes.MemberAccessMask; + if (mpia != MethodAttributes.Private) + return 4; + + Console.WriteLine ("All tests pass"); + return 0; + } +} diff --git a/mcs/tests/test-92.cs b/mcs/tests/test-92.cs new file mode 100755 index 00000000000..1de5aa71a7d --- /dev/null +++ b/mcs/tests/test-92.cs @@ -0,0 +1,20 @@ +// +// This test exposed a bug that Dan found: +// +// The InnerBase used to be the `builder' that was passed to InnerBase, +// so even if InnerBase was a toplevel, it would be defined in the context +// of being nested. Buggy. +// +class Outer { + class Inner : InnerBase { + } +} + +abstract class InnerBase { +} + +class MainClass { + public static int Main () { + return 0; + } +} diff --git a/mcs/tests/test-93.cs b/mcs/tests/test-93.cs new file mode 100755 index 00000000000..0ce693979d6 --- /dev/null +++ b/mcs/tests/test-93.cs @@ -0,0 +1,47 @@ +// +// This tests member lookups on inherited interfaces. +// +// The bug was exposed because FindMembers in MemberLookup +// would not return all the members on interfaces, but only +// the members from the most close type. +// + +using System; +using System.Collections; + +namespace N1 +{ + interface A + { + void method1 (); + } + + interface B:A + { + void method2 (); + } + + public class C + { + void method (ref B p) + { + p.method2();//<- works declared in 'B' + p.method1();//<- fails declared in 'A' + } + } +} + + +class Test { + public static int Main () { + IList list = new ArrayList (); + int n = list.Count; + + return 0; + } +} + + + + + diff --git a/mcs/tests/test-94.cs b/mcs/tests/test-94.cs new file mode 100755 index 00000000000..a8c5fea996f --- /dev/null +++ b/mcs/tests/test-94.cs @@ -0,0 +1,59 @@ +using System; + +public interface IVehicle { + int Start (); + int Stop (); + int Turn (); +} + +public class Base : IVehicle { + int IVehicle.Start () { return 1; } + public int Stop () { return 2; } + public virtual int Turn () { return 3; } +} + +public class Derived1 : Base { + // replaces Base.Turn + IVehice.Turn + public override int Turn () { return 4; } +} + +public class Derived2 : Base, IVehicle { + // legal - we redeclared IVehicle support + public new int Stop () { return 6; } + // legal - we redeclared IVehicle support + int IVehicle.Start () { return 5; } + // replaces IVehicle.Turn + int IVehicle.Turn () { return 7; } + // replaces Base.Turn + public override int Turn () { return 8; } +} + +public class Test { + + static int Main () { + Derived1 d1 = new Derived1 (); + Derived2 d2 = new Derived2 (); + Base b1 = d1; + Base b2 = d2; + + if (d1.Turn () != 4) + return 1; + + if (((IVehicle)d1).Turn () != 4) + return 2; + + if (((IVehicle)d2).Turn () != 7) + return 3; + + if (b2.Turn () != 8) + return 4; + + if (((IVehicle)b2).Turn () != 7) + return 5; + + //Console.WriteLine ("TEST {0}", ((IVehicle)b2).Turn ()); + + return 0; + } +} + diff --git a/mcs/tests/test-95.cs b/mcs/tests/test-95.cs new file mode 100755 index 00000000000..8a134a566e1 --- /dev/null +++ b/mcs/tests/test-95.cs @@ -0,0 +1,18 @@ +class X { + + double d = 0; + + X () + { + } + + static int Main () + { + X x = new X (); + + if (x.d != 0) + return 1; + + return 0; + } +} diff --git a/mcs/tests/test-96.cs b/mcs/tests/test-96.cs new file mode 100755 index 00000000000..718a95f1749 --- /dev/null +++ b/mcs/tests/test-96.cs @@ -0,0 +1,20 @@ +// +// Compilation test +// +// This used to be a bug in the name lookups in delegate declarations +// +namespace N1 +{ + public class A + { + static int Main () + { + return 0; + } + } + + // + // A used to not be resolved + // + public delegate void C(object sender, A a); +} diff --git a/mcs/tests/test-97.cs b/mcs/tests/test-97.cs new file mode 100755 index 00000000000..612185cf1aa --- /dev/null +++ b/mcs/tests/test-97.cs @@ -0,0 +1,18 @@ +// +// This test excercises the simple name lookups on +// unfinished enumerations. +// + +public enum FL { + EMPTY = 0, + USHIFT = 11, + USER0 = (1<<(USHIFT+0)), +} + +class X { + + static int Main () + { + return 0; + } +} diff --git a/mcs/tests/test-98.cs b/mcs/tests/test-98.cs new file mode 100755 index 00000000000..17842abe407 --- /dev/null +++ b/mcs/tests/test-98.cs @@ -0,0 +1,18 @@ +class X { + int a; + Y x; + + void b () + { + if (x.a == 1) + return; + } +} + +class Y : X { + + public static int Main () + { + return 0; + } +} diff --git a/mcs/tests/test-99.cs b/mcs/tests/test-99.cs new file mode 100755 index 00000000000..385330dfa55 --- /dev/null +++ b/mcs/tests/test-99.cs @@ -0,0 +1,25 @@ +using System; +class X { + enum A : int { + a = 1, b, c + } + + static int Main () + { + int v = 1; + object foo = (v + A.a); + object foo2 = (1 + A.a); + + if (foo.GetType ().ToString () != "X+A"){ + Console.WriteLine ("Expression evaluator bug in E operator + (U x, E y)"); + return 1; + } + + if (foo2.GetType ().ToString () != "X+A"){ + Console.WriteLine ("Constant folder bug in E operator + (U x, E y)"); + return 2; + } + + return 0; + } +} diff --git a/mcs/tests/try.cs b/mcs/tests/try.cs index c1746f92b2d..5bc1d408d0c 100755 --- a/mcs/tests/try.cs +++ b/mcs/tests/try.cs @@ -45,7 +45,7 @@ class t { a = 0x3; } catch { a = 0x1; - } finalize { + } finally { a = 111; } } diff --git a/mcs/tests/unsafe-1.cs b/mcs/tests/unsafe-1.cs new file mode 100755 index 00000000000..2a35ac8ec4e --- /dev/null +++ b/mcs/tests/unsafe-1.cs @@ -0,0 +1,180 @@ +// +// Tests unsafe operators. address-of, dereference, member access +// +using System; + +unsafe struct Y { + public int a; + public int s; +} + +unsafe class X { + static int TestDereference () + { + Y y; + Y *z; + Y a; + + z = &y; + y.a = 1; + y.s = 2; + + a.a = z->a; + a.s = z->s; + + if (a.a != y.a) + return 1; + if (a.s != y.s) + return 2; + + return 0; + } + + static int TestPtrAdd () + { + int [] a = new int [10]; + int i; + + for (i = 0; i < 10; i++) + a [i] = i; + + i = 0; + fixed (int *b = &a [0]){ + int *p = b; + + for (i = 0; i < 10; i++){ + if (*p != a [i]) + return 10+i; + p++; + } + } + return 0; + } + + static int i = 1; + static char c = 'a'; + static long l = 123; + static double d = 1.2; + static float f = 1.3F; + static short s = 4; + + static int TestPtrAssign () + { + + fixed (int *ii = &i){ + *ii = 10; + } + + fixed (char *cc = &c){ + *cc = 'b'; + } + + fixed (long *ll = &l){ + *ll = 100; + } + + fixed (double *dd = &d){ + *dd = 3.0; + } + + fixed (float *ff = &f){ + *ff = 1.2F; + } + + fixed (short *ss = &s){ + *ss = 102; + } + + if (i != 10) + return 100; + if (c != 'b') + return 101; + if (l != 100) + return 102; + if (d != 3.0) + return 103; + if (f != 1.2F) + return 104; + if (s != 102) + return 105; + return 0; + } + + static int TestPtrArithmetic () + { + char [] array = new char [10]; + char *pb; + + array [5] = 'j'; + fixed (char *pa = array){ + pb = pa + 1; + + + // + // This one tests pointer element access + // + if (pa [5] != 'j') + return 199; + + Console.WriteLine ("V: " + (pb - pa)); + if ((pb - pa) != 1) + return 200; + + pb++; + + if (pb == pa) + return 201; + if (pb < pa) + return 202; + if (pa > pb) + return 203; + if (pa >= pb) + return 204; + if (pb <= pa) + return 205; + pb = pb - 2; + if (pb != pa){ + Console.WriteLine ("VV: " + (pb - pa)); + return 206; + } + } + + return 0; + } + + static int TestMultiple () + { + char [] array = new char [10]; + int count = 0; + + fixed (char *pa = array, pb = array){ + count++; + } + if (count != 1) + return 300; + return 0; + } + + static int Main () + { + int v; + + if ((v = TestDereference ()) != 0) + return v; + + if ((v = TestPtrAdd ()) != 0) + return v; + + if ((v = TestPtrAssign ()) != 0) + return v; + + if ((v = TestPtrArithmetic ()) != 0) + return v; + + if ((v = TestMultiple ()) != 0) + return v; + + Console.WriteLine ("Ok"); + return 0; + } +} diff --git a/mcs/tests/unsafe-2.cs b/mcs/tests/unsafe-2.cs new file mode 100755 index 00000000000..adedee29633 --- /dev/null +++ b/mcs/tests/unsafe-2.cs @@ -0,0 +1,25 @@ +// +// This test excercises stackalloc, some pointer arithmetic, +// and dereferences +// +using System; +unsafe class X { + static int Main () + { + char *ptr = stackalloc char [10]; + int i; + + for (i = 0; i < 10; i++) + ptr [i] = (char) (i + 10); + + for (i = 0; i < 10; i++){ + if (*ptr != (char) (i + 10)) + return 200 + i; + ptr++; + } + Console.WriteLine ("Ok"); + return 0; + } +} + + diff --git a/mcs/tests/unsafe-3.cs b/mcs/tests/unsafe-3.cs new file mode 100644 index 00000000000..371b5bcdac2 --- /dev/null +++ b/mcs/tests/unsafe-3.cs @@ -0,0 +1,31 @@ +// this tests making a pointer to a pointer + +using System; + +unsafe class Foo +{ + public static int Main () + { + int a; + int *b; + int **c; + + a = 42; + b = &a; + c = &b; + + Console.WriteLine ("*c == b : {0}", *c == b); + Console.WriteLine ("**c == a : {0}", **c == a); + + if (*c == b && **c == a) + { + Console.WriteLine ("Test passed"); + return 0; + } + else + { + Console.WriteLine ("Test failed"); + return 1; + } + } +} diff --git a/mcs/tests/unsafe-4.cs b/mcs/tests/unsafe-4.cs new file mode 100755 index 00000000000..730bb4915a1 --- /dev/null +++ b/mcs/tests/unsafe-4.cs @@ -0,0 +1,21 @@ +unsafe class X { + static int v; + static int v_calls; + + static int* get_v () + { + v_calls++; + return &v; + } + + static int Main () + { + if ((*get_v ())++ != 0) + return 1; + if (v != 1) + return 2; + if (v_calls != 1) + return 3; + return 0; + } +} diff --git a/mcs/tests/verify-1.cs b/mcs/tests/verify-1.cs new file mode 100644 index 00000000000..3d167030d66 --- /dev/null +++ b/mcs/tests/verify-1.cs @@ -0,0 +1,47 @@ +using System; +class T { + int stuff () { + try { + throw new Exception (); + } finally { + stuff_finally (); + } + } + int stuff2 () { + try { + throw new Exception (); + } catch { + try { + throw new Exception (); + } finally { + stuff_finally (); + } + } finally { + stuff_finally (); + } + } + int stuff3 () { + try { + throw new Exception (); + } catch { + try { + throw new Exception (); + } finally { + stuff_finally (); + } + } finally { + stuff_finally (); + } + } + void stuff4 () { + try { + throw new Exception(); + } catch { + throw; + } + } + void stuff_finally () { + } + static void Main() { + } +} diff --git a/mcs/tests/verify-2.cs b/mcs/tests/verify-2.cs new file mode 100644 index 00000000000..e0655b25609 --- /dev/null +++ b/mcs/tests/verify-2.cs @@ -0,0 +1,41 @@ +using System; + +class X { + ~X () + { + Console.WriteLine ("DESTRUCTOR!"); + } + + public static int Test1() + { + try { + return 8; + } catch (Exception) {} + System.Console.WriteLine("Shouldn't get here"); + return 9; + } + + public static void Test2() + { + int[] vars = { 3, 4, 5 }; + + foreach (int a in vars) { + try { + continue; + } catch (Exception) { + break; + } + } + } + + public static void Main() { + Test1 (); + Test2 (); + + try { + return; + } catch (Exception) {} + System.Console.WriteLine("Shouldn't get here"); + return; + } +} diff --git a/mcs/tests/verify-3.cs b/mcs/tests/verify-3.cs new file mode 100644 index 00000000000..4c13a026fb6 --- /dev/null +++ b/mcs/tests/verify-3.cs @@ -0,0 +1,12 @@ +using System; + +public delegate void MyEventHandler (int a); + +public class X +{ + public static event MyEventHandler TestEvent; + + public static void Main () + { + } +} diff --git a/mcs/tests/verify-4.cs b/mcs/tests/verify-4.cs new file mode 100644 index 00000000000..32b2a018348 --- /dev/null +++ b/mcs/tests/verify-4.cs @@ -0,0 +1,19 @@ +using System; +using System.Threading; + +enum A { + Hello, + Bye +} + +class X { + + static void Main () { + switch (0) { + default: + throw new Exception("FOO"); + break; + } + } +} + diff --git a/mcs/tests/verify-5.cs b/mcs/tests/verify-5.cs new file mode 100644 index 00000000000..9a2bc27e519 --- /dev/null +++ b/mcs/tests/verify-5.cs @@ -0,0 +1,51 @@ +class T { + static int fib (int n) { + int f0 = 0, f1 = 1, f2 = 0, i; + + if (n <= 1) goto L3; + i = 2; + L1: + if (i <= n) goto L2; + return f2; + L2: + f2 = f0 + f1; + f0 = f1; + f1 = f2; + i++; + goto L1; + L3: + return n; + } + + static int xx (int n) { + if (n <= 1) goto L3; + L1: + if (1 <= n) goto L2; + return n; + L2: + goto L1; + L3: + return n; + } + + // This is from System.Text.RegularExpressions.Syntax.Parser::ParseGroup. + void foo (int a) + { + bool b = false; + + while (true) { + switch (a) { + case 3: + break; + } + + if (b) + goto EndOfGroup; + } + + EndOfGroup: + ; + } + + static void Main() {} +} diff --git a/mcs/tests/verify-6.cs b/mcs/tests/verify-6.cs new file mode 100644 index 00000000000..a776fbc14a4 --- /dev/null +++ b/mcs/tests/verify-6.cs @@ -0,0 +1,24 @@ +using System; + +class X +{ + enum Foo { + A, B + } + + enum Bar { + C, D + } + + public static void Main () + { + Foo foo = Foo.A; + Enum se = (Enum) foo; + Enum sc = (Enum) Foo.A; + object obj1 = (object) foo; + object obj2 = (object) Foo.A; + + Bar bar = (Bar) se; + Foo blah = (Foo) obj1; + } +} |