X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Ftests%2Fgenerics-sharing.2.cs;h=6110cf2f8fad627ea0ccfb11c59fb75767efc348;hb=HEAD;hp=5f0118e25ddb43bd1085b92017fc4e05ca68d2d0;hpb=30c97cb81da5e8e9ff5a06055d238ef63cba69db;p=mono.git diff --git a/mono/tests/generics-sharing.2.cs b/mono/tests/generics-sharing.2.cs index 5f0118e25dd..6110cf2f8fa 100644 --- a/mono/tests/generics-sharing.2.cs +++ b/mono/tests/generics-sharing.2.cs @@ -46,6 +46,8 @@ public class GenBi { } public struct GenStruct { + public static int staticField; + public int field; public int dummy1; public int dummy2; @@ -69,10 +71,34 @@ public interface IGen { GenStruct valueIMethod (int x); } +public class IGenImpl : IGen { + public int field; + + public T[] iMethod () { + return new T[3]; + } + + public void voidIMethod (int x) { + field = x; + } + + public long longIMethod (long x) { + return x + 1; + } + + public float floatIMethod () { + return 1.0f; + } + + public GenStruct valueIMethod (int x) { + return new GenStruct (x); + } +} + public class GenA { public static T[] arr; - public static GenA () { + static GenA () { arr = new T [3]; } @@ -94,6 +120,10 @@ public class GenA { return NonGen.field; } + public int getGenStructStaticField () { + return GenStruct.staticField; + } + public T[] getArr () { return arr; } @@ -127,6 +157,10 @@ public class GenA { return (T)obj; } + public GenStruct structCast (Object obj) { + return (GenStruct)obj; + } + public Type ldtokenT () { return typeof (T); } @@ -143,6 +177,14 @@ public class GenA { return typeof (GenB<>); } + public GenStruct? makeNullable (Object obj) { + return (GenStruct?)obj; + } + + public object unmakeNullable (GenStruct? obj) { + return (object)obj; + } + public void except () { try { NonGen.doThrow (); @@ -212,6 +254,32 @@ public class GenA { public static long staticBiLongCaller (long x) { return GenBi.staticLongMethod (x); } + + public int structCaller (int x) { + GenStruct> gs = new GenStruct> (123); + + return gs.method (x); + } + + public T[] callInterface (IGen ig) { + return ig.iMethod (); + } + + public void callVoidInterface (IGen ig, int x) { + ig.voidIMethod (x); + } + + public long callLongInterface (IGen ig, long x) { + return ig.longIMethod (x); + } + + public float callFloatInterface (IGen ig) { + return ig.floatIMethod (); + } + + public GenStruct callValueInterface (IGen ig, int x) { + return ig.valueIMethod (x); + } } public class GenB { @@ -221,7 +289,7 @@ public class GenB { public class GenC { public static int field ; - public static GenC () { + static GenC () { field = 1234; } } @@ -258,7 +326,7 @@ public class GenABDeriv : GenA> { public class NonGenUser where T : NonGen { public int getNonGenField () { - return T.field; + return NonGen.field; } } @@ -347,22 +415,36 @@ public class RGCTXTestSubASubSub : RGCTXTestSubASub { } public class main { + delegate void ActionDelegate (); + static bool haveError = false; - public static void error (string message) { + static void error (string message) { haveError = true; Console.WriteLine (message); } - public static void typeCheck (String method, Object obj, Type t) { + static void typeCheck (String method, Object obj, Type t) { if (obj.GetType () != t) error ("object from " + method + " should have type " + t.ToString () + " but has type " + obj.GetType ().ToString ()); } - public static int callStaticMethod () { + static int callStaticMethod () { return GenA.staticMethod (); } + static void checkException (String method, ActionDelegate action) where T : Exception { + try { + try { + action (); + } catch (T) { + return; + } + } catch (Exception exc) { + error ("method " + method + " should have thrown " + typeof (T).ToString () + " but did throw " + exc); + } + } + public static void work (T obj, bool mustCatch) { EqualityComparer comp = EqualityComparer.Default; @@ -382,6 +464,11 @@ public class main { if (ga.getNonGenField () != 123) error ("getNonGenField"); + GenStruct.staticField = 321; + if (ga.getGenStructStaticField () != 321) + error ("getGenStructStaticField"); + GenStruct.staticField = -1; + ga.hash (obj); if (!comp.Equals (ga.ident (obj), obj)) @@ -389,6 +476,22 @@ public class main { if (!comp.Equals (ga.cast (obj), obj)) error ("cast"); + if (typeof (T).IsValueType) { + checkException ("cast null value", delegate { ga.cast (null); }); + } else { + if (ga.cast (null) != null) + error ("cast null"); + } + + GenStruct genstructt = new GenStruct (453); + if (ga.structCast ((object)genstructt).field != 453) + error ("structCast"); + checkException ("structCast null", delegate { ga.structCast (null); }); + + if (ga.makeNullable ((object)genstructt).Value.field != 453) + error ("makeNullable"); + if (ga.makeNullable (null) != null) + error ("makeNullable null"); if (ga.ldtokenT () != typeof (T)) error ("ldtokenT"); @@ -443,28 +546,28 @@ public class main { if (GenA.staticFloatMethod () != 1.0) error ("staticFloatMethod"); - new GenADeriv (); + if (ga.structCaller (234) != 357) + error ("structCaller"); - if (mustCatch) { - bool didCatch = false; + IGenImpl igi = new IGenImpl (); - try { - ga.except (); - } catch (GenExc) { - didCatch = true; - } - if (!didCatch) - error ("except"); + typeCheck ("callInterface", ga.callInterface (igi), typeof (T[])); + if (ga.callLongInterface (igi, 345) != 346) + error ("callLongInterface"); + GenStruct gst = ga.callValueInterface (igi, 543); + if (gst.field != 543) + error ("callValueInterface"); + ga.callVoidInterface (igi, 654); + if (igi.field != 654) + error ("callVoidInterface"); + if (ga.callFloatInterface (igi) != 1.0f) + error ("callFloatInterface"); - didCatch = false; + new GenADeriv (); - try { - GenA.staticExcept (); - } catch (GenExc) { - didCatch = true; - } - if (!didCatch) - error ("staticExcept"); + if (mustCatch) { + checkException> ("except", delegate { ga.except (); }); + checkException> ("staticExcept", delegate { GenA.staticExcept (); }); } else { ga.except (); GenA.staticExcept (); @@ -529,10 +632,14 @@ public class main { { work (new ClassA (), false); work (new ClassB (), true); + work (new ClassB (), true); work (new ClassC (), true); work> (new GenA (), true); work (new int[3], true); work (123, true); + work (123, true); + work?> (new GenStruct (123), true); + work?> (null, true); StaticTest sa = new StaticTest (1234); StaticTest sb = new StaticTest (2345);