New test.
[mono.git] / mono / tests / test-inline-call-stack.cs
1 using System;
2 using System.Diagnostics;
3 using System.Reflection;
4 using Library;
5
6
7 namespace Program {
8         public class Test {
9                 public static string TestPassed (bool value) {
10                         return value ? "PASSED" : "FAILED";
11                 }
12                 public static string TestFailed (bool value) {
13                         return TestPassed (! value);
14                 }
15                 
16                 public static int Main () {
17                         MethodBase myMethodBase = MethodBase.GetCurrentMethod ();
18                         MethodBase inlinedMethodBase = InlinedMethods.GetCurrentMethod ();
19                         
20                         Assembly myExecutingAssembly = Assembly.GetExecutingAssembly ();
21                         Assembly inlinedExecutingAssembly = InlinedMethods.GetExecutingAssembly ();
22                         
23                         Assembly myCallingAssembly = Assembly.GetCallingAssembly ();
24                         Assembly inlinedCallingAssembly = InlinedMethods.CallCallingAssembly ();
25                         
26                         StackFrame myStackFrame = new StackFrame ();
27                         StackFrame inlinedStackFrame = InlinedMethods.GetStackFrame ();
28                         
29                         string myConstructorCalledFrom = new CallingAssemblyDependant ().CalledFrom;
30                         string inlinedConstructorCalledFrom = CallingAssemblyDependant.CalledFromLibrary ();
31                         
32                         StaticFlag.Flag = true;
33                         bool strictFlag = ResourceStrictFieldInit.Single.Flag;
34                         bool relaxedFlag = ResourceRelaxedFieldInit.Single.Flag;
35                         
36                         Console.WriteLine ("[{0}]CurrentMethod: my {1}, inlined {2}, equals {3}",
37                                         TestFailed (myMethodBase == inlinedMethodBase),
38                                         myMethodBase.Name, inlinedMethodBase.Name,
39                                         myMethodBase == inlinedMethodBase);
40                         
41                         Console.WriteLine ("[{0}]ExecutingAssembly: my {1}, inlined {2}, equals {3}",
42                                         TestFailed (myExecutingAssembly == inlinedExecutingAssembly),
43                                         myExecutingAssembly.GetName ().Name, inlinedExecutingAssembly.GetName ().Name,
44                                         myExecutingAssembly == inlinedExecutingAssembly);
45                         
46                         Console.WriteLine ("[{0}]CallingAssembly: my {1}, inlined {2}, equals {3}",
47                                         TestFailed (myCallingAssembly == inlinedCallingAssembly),
48                                         myCallingAssembly.GetName ().Name, inlinedCallingAssembly.GetName ().Name,
49                                         myCallingAssembly == inlinedCallingAssembly);
50                         
51                         Console.WriteLine ("[{0}]StackFrame.GetMethod: my {1}, inlined {2}, equals {3}",
52                                         TestFailed (myStackFrame.GetMethod ().Name == inlinedStackFrame.GetMethod ().Name),
53                                         myStackFrame.GetMethod ().Name, inlinedStackFrame.GetMethod ().Name,
54                                         myStackFrame.GetMethod ().Name == inlinedStackFrame.GetMethod ().Name);
55                         
56                         Console.WriteLine ("[{0}]ConstructorCalledFrom: my {1}, inlined {2}, equals {3}",
57                                         TestFailed (myConstructorCalledFrom == inlinedConstructorCalledFrom),
58                                         myConstructorCalledFrom, inlinedConstructorCalledFrom,
59                                         myConstructorCalledFrom == inlinedConstructorCalledFrom);
60                         
61                         Console.WriteLine ("[{0}]strictFlag: {1}, relaxedFlag: {2}",
62                                         TestFailed ((strictFlag != relaxedFlag)),
63                                         strictFlag, relaxedFlag);
64                         if ((myMethodBase != inlinedMethodBase) &&
65                                         (myExecutingAssembly != inlinedExecutingAssembly) &&
66                                         (myCallingAssembly != inlinedCallingAssembly) &&
67                                         (myStackFrame.GetMethod ().Name != inlinedStackFrame.GetMethod ().Name) &&
68                                         (myConstructorCalledFrom != inlinedConstructorCalledFrom) &&
69                                         (strictFlag == relaxedFlag)) {
70                                 return 0;
71                         } else {
72                                 return 1;
73                         }
74                 }
75         }
76 }
77