OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #region | |
6 | |
7 using System; | |
8 using System.Collections.Generic; | |
9 using Google.MsAd7.BaseImpl; | |
10 using Google.MsAd7.BaseImpl.DebugProperties; | |
11 using Google.MsAd7.BaseImpl.Interfaces.SimpleSymbolTypes; | |
12 using Microsoft.VisualStudio.Debugger.Interop; | |
13 using Microsoft.VisualStudio.TestTools.UnitTesting; | |
14 | |
15 #endregion | |
16 | |
17 namespace MsAd7.BaseImpl_UnitTestProject { | |
18 ///<summary> | |
19 /// This is a test class for StackFrameTest and is intended | |
20 /// to contain all StackFrameTest Unit Tests | |
21 ///</summary> | |
22 [TestClass] | |
23 public class StackFrameTest { | |
24 ///<summary> | |
25 /// A test for EnumProperties | |
26 ///</summary> | |
27 [TestMethod] | |
28 public void EnumPropertiesTest() { | |
29 var debuggerMock = new SimpleDebuggerMock(); | |
30 var target = testStackFrameConstructor(debuggerMock); | |
31 var symbolProviderMock = debuggerMock.Symbols as SymbolProviderMock; | |
32 PrimeMockForRefreshProperties(symbolProviderMock); | |
33 //This guid was taken from a run with a debugger. | |
34 var guidFilter = new Guid( | |
35 -414768709, 4288, 16629, 128, 127, 146, 13, 55, 249, 84, 25); | |
36 IEnumDebugPropertyInfo2 output; | |
37 uint pcelt; | |
38 target.EnumProperties( | |
39 enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_NAME, | |
40 16, | |
41 ref guidFilter, | |
42 10000, | |
43 out pcelt, | |
44 out output); | |
45 uint propertiesFound; | |
46 output.GetCount(out propertiesFound); | |
47 Assert.AreEqual((uint) 4, pcelt); | |
48 } | |
49 | |
50 ///<summary> | |
51 /// A test for RefreshProperties | |
52 ///</summary> | |
53 [TestMethod] | |
54 [DeploymentItem("MsAd7.BaseImpl.dll")] | |
55 public void RefreshPropertiesTest() { | |
56 var debuggerMock = new SimpleDebuggerMock(); | |
57 var target = testStackFrameConstructor(debuggerMock); | |
58 var symbolProviderMock = debuggerMock.Symbols as SymbolProviderMock; | |
59 PrimeMockForRefreshProperties(symbolProviderMock); | |
60 var privates = new PrivateObject(target); | |
61 privates.Invoke("RefreshProperties"); | |
62 | |
63 var properties = privates.GetField("properties_") | |
64 as Dictionary<string, DebugPropertyBase>; | |
65 Assert.AreEqual(3, properties.Count); | |
66 } | |
67 | |
68 /// <summary> | |
69 /// The actual test is bundled into a private function so the other unit | |
70 /// tests can use the functionality as well. | |
71 /// </summary> | |
72 [TestMethod] | |
73 public void StackFrameConstructorTest() { | |
74 var debuggerMock = new SimpleDebuggerMock(); | |
75 testStackFrameConstructor(debuggerMock); | |
76 } | |
77 | |
78 #region Private Implementation | |
79 | |
80 private const ulong kIpRegisterContent = 123456; | |
81 | |
82 #endregion | |
83 | |
84 #region Private Implementation | |
85 | |
86 /// <summary> | |
87 /// This test tests RefreshProperties. | |
88 /// The actual test is bundled into a private function so the other unit | |
89 /// tests can use the functionality as well. | |
90 /// </summary> | |
91 /// <param name = "symbolProviderMock"></param> | |
92 /// <param name = "stackFrame"></param> | |
93 private static void PrimeMockForRefreshProperties( | |
94 SymbolProviderMock symbolProviderMock) { | |
95 var symbol1 = new Symbol {Name = "Symbol_1"}; | |
96 var symbol2 = new Symbol {Name = "Symbol_2"}; | |
97 var symbol3 = new Symbol {Name = "Symbol_3"}; | |
98 var symbols = new List<Symbol> {symbol1, symbol2, symbol3}; | |
99 symbolProviderMock.RecordCall( | |
100 "GetSymbolsInScope", kIpRegisterContent, symbols); | |
101 } | |
102 | |
103 /// <summary> | |
104 /// This is a test for the construction of our representation of a | |
105 /// StackFrame. It is bundled into a private function so the other unit | |
106 /// tests can use the functionality as well. | |
107 /// </summary> | |
108 /// <param name = "debuggerMock">This is passed in as a parameter so that a | |
109 /// test function can use this constructor test and the run other tests | |
110 /// using the same mock.</param> | |
111 /// <returns>The newly allocated StackFrame instance</returns> | |
112 private StackFrame testStackFrameConstructor( | |
113 SimpleDebuggerMock debuggerMock) { | |
114 // Set up the classes we need. | |
115 var docPosition = new DocumentPosition("/test/path", 314); | |
116 var debugPropertyBase = new DebugPropertyBase( | |
117 null, | |
118 "DebugPropertyName", | |
119 "UsefulType", | |
120 null, | |
121 123456, | |
122 enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_NONE, | |
123 debuggerMock); | |
124 | |
125 var registerSet = new RegisterSet( | |
126 RegisterSetSchema.DwarfAmd64Integer, | |
127 debugPropertyBase); | |
128 registerSet["RIP"] = kIpRegisterContent; | |
129 var debugThreadMock = new DebugThread2Mock(); | |
130 var module = new Module(); | |
131 // Prime the mocks. | |
132 var symbolProviderMock = debuggerMock.Symbols as SymbolProviderMock; | |
133 symbolProviderMock.RecordCall( | |
134 "PositionFromAddress", | |
135 kIpRegisterContent, | |
136 docPosition); | |
137 symbolProviderMock.RecordCall( | |
138 "AddressesFromPosition", | |
139 docPosition, | |
140 new List<ulong> {kIpRegisterContent}); | |
141 symbolProviderMock.RecordCall( | |
142 "PositionFromAddress", | |
143 kIpRegisterContent, | |
144 docPosition); | |
145 symbolProviderMock.RecordCall( | |
146 "FunctionFromAddress", | |
147 kIpRegisterContent, | |
148 new Function()); | |
149 // Run the test. | |
150 var stackFrame = new StackFrame( | |
151 registerSet, debugThreadMock, module, debuggerMock); | |
152 Assert.IsNotNull(stackFrame); | |
153 return stackFrame; | |
154 } | |
155 | |
156 #endregion | |
157 } | |
158 } | |
OLD | NEW |