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 Google.MsAd7.BaseImpl; | |
8 using Google.MsAd7.BaseImpl.Ad7Enumerators; | |
9 using Microsoft.VisualStudio; | |
10 using Microsoft.VisualStudio.Debugger.Interop; | |
11 using Microsoft.VisualStudio.TestTools.UnitTesting; | |
12 | |
13 #endregion | |
14 | |
15 namespace NaClVsx.Package_UnitTestProject { | |
16 ///<summary> | |
17 /// This is a test class for BreakpointErrorEnumTest and is intended | |
18 /// to contain all BreakpointErrorEnumTest Unit Tests | |
19 ///</summary> | |
20 [TestClass] | |
21 public class ErrorBreakpointEnumeratorTest { | |
22 ///<summary> | |
23 /// Gets or sets the test context which provides | |
24 /// information about and functionality for the current test run. | |
25 ///</summary> | |
26 public TestContext TestContext { get; set; } | |
27 | |
28 #region Additional test attributes | |
29 | |
30 // | |
31 //You can use the following additional attributes as you write your tests: | |
32 // | |
33 //Use ClassInitialize to run code before running the first test in the class | |
34 //[ClassInitialize()] | |
35 //public static void MyClassInitialize(TestContext testContext) | |
36 //{ | |
37 //} | |
38 // | |
39 //Use ClassCleanup to run code after all tests in a class have run | |
40 //[ClassCleanup()] | |
41 //public static void MyClassCleanup() | |
42 //{ | |
43 //} | |
44 // | |
45 //Use TestInitialize to run code before running each test | |
46 //[TestInitialize()] | |
47 //public void MyTestInitialize() | |
48 //{ | |
49 //} | |
50 // | |
51 //Use TestCleanup to run code after each test has run | |
52 //[TestCleanup()] | |
53 //public void MyTestCleanup() | |
54 //{ | |
55 //} | |
56 // | |
57 | |
58 #endregion | |
59 | |
60 ///<summary> | |
61 /// A test for Skip | |
62 ///</summary> | |
63 [TestMethod] | |
64 public void SkipTest() { | |
65 var target = new ErrorBreakpointEnumerator(); | |
66 const uint kSkipSize = 33; | |
67 // Skip should fail until there's something in the enum. | |
68 Assert.AreNotEqual(target.Skip(kSkipSize), VSConstants.S_OK); | |
69 PopulateErrorEnum(target, 123); | |
70 // Now it should not fail. | |
71 Assert.AreEqual(target.Skip(kSkipSize), VSConstants.S_OK); | |
72 uint nextCount = 0; | |
73 // We now check to make sure we skipped to the correct place. | |
74 var errorPointer = new ErrorBreakpoint[1]; | |
75 Assert.AreEqual( | |
76 target.Next(1, errorPointer, ref nextCount), VSConstants.S_OK); | |
77 Assert.AreEqual( | |
78 GetIntMessage(kSkipSize), | |
79 GetMessageFromBreakpointError(errorPointer[0])); | |
80 } | |
81 | |
82 ///<summary> | |
83 /// A test for Reset | |
84 ///</summary> | |
85 [TestMethod] | |
86 public void ResetTest() { | |
87 var target = new ErrorBreakpointEnumerator(); | |
88 | |
89 uint count = 0; | |
90 const uint kArraySize = 20; | |
91 var errors = new ErrorBreakpoint[kArraySize]; | |
92 // Now make sure we can iterate when data is available. | |
93 PopulateErrorEnum(target, 123); | |
94 Assert.AreEqual( | |
95 target.Next(kArraySize, errors, ref count), VSConstants.S_OK); | |
96 Assert.IsTrue(count == kArraySize); | |
97 // The NextTest method verifies that errors would now be filled with entri
es | |
98 // 0 through 19 and that the next call to next would return entry 20. | |
99 target.Reset(); | |
100 Assert.AreEqual(target.Next(1, errors, ref count), VSConstants.S_OK); | |
101 Assert.AreEqual( | |
102 GetMessageFromBreakpointError(errors[0]), GetIntMessage(0)); | |
103 } | |
104 | |
105 ///<summary> | |
106 /// A test for PopulateBreakpoint | |
107 ///</summary> | |
108 [TestMethod] | |
109 public void PopulateBreakpointTest() { | |
110 var target = new ErrorBreakpointEnumerator(); | |
111 var breakpoint = | |
112 NaClPackageTestUtils.GetPendingBreakpoint(); | |
113 // If PopulateBreakpoint works for a few entries it should work for any nu
mber | |
114 const int kSampleSize = 3; | |
115 uint returnedCount = 0; | |
116 var breakpointErrors = new IDebugErrorBreakpoint2[kSampleSize]; | |
117 IDebugPendingBreakpoint2 returnedBreakpoint; | |
118 PopulateErrorEnum(target, kSampleSize); | |
119 // First, we verify that we cannot get pendingBreakpoints out of the Break
pointErrors before | |
120 // we call PopulateBreakpoint. | |
121 Assert.AreEqual( | |
122 target.Next(kSampleSize, breakpointErrors, ref returnedCount), | |
123 VSConstants.S_OK); | |
124 for (var i = 0; i < kSampleSize; ++i) { | |
125 Assert.AreNotEqual( | |
126 breakpointErrors[i].GetPendingBreakpoint(out returnedBreakpoint), | |
127 VSConstants.S_OK); | |
128 } | |
129 // Now we call it and make sure that PendingBreakpoint was populated on al
l | |
130 // BreakpointErrors. | |
131 target.PopulateBreakpoint(breakpoint); | |
132 target.Reset(); | |
133 Assert.AreEqual( | |
134 target.Next(kSampleSize, breakpointErrors, ref returnedCount), | |
135 VSConstants.S_OK); | |
136 for (var i = 0; i < kSampleSize; ++i) { | |
137 Assert.AreEqual( | |
138 breakpointErrors[i].GetPendingBreakpoint(out returnedBreakpoint), | |
139 VSConstants.S_OK); | |
140 Assert.AreEqual(returnedBreakpoint, breakpoint); | |
141 } | |
142 } | |
143 | |
144 ///<summary> | |
145 /// A test for Next | |
146 ///</summary> | |
147 [TestMethod] | |
148 public void NextTest() { | |
149 var target = new ErrorBreakpointEnumerator(); | |
150 // We should not be able to call next successfully until breakpoints have
been added. | |
151 uint count = 0; | |
152 const uint kArraySize = 20; | |
153 var errors = new ErrorBreakpoint[kArraySize]; | |
154 Assert.AreNotEqual( | |
155 target.Next(kArraySize, errors, ref count), VSConstants.S_OK); | |
156 // Now make sure we can iterate when data is available. | |
157 PopulateErrorEnum(target, 123); | |
158 Assert.AreEqual( | |
159 target.Next(kArraySize, errors, ref count), VSConstants.S_OK); | |
160 Assert.IsTrue(count == kArraySize); | |
161 // Make sure the right errors are in the array); | |
162 for (var i = 0; i < kArraySize; ++i) { | |
163 var expectedMessage = GetIntMessage(i); | |
164 Assert.AreEqual( | |
165 expectedMessage, GetMessageFromBreakpointError(errors[i])); | |
166 } | |
167 Assert.AreEqual(target.Next(1, errors, ref count), VSConstants.S_OK); | |
168 Assert.IsTrue(count == 1); | |
169 | |
170 Assert.AreEqual( | |
171 GetMessageFromBreakpointError(errors[0]), GetIntMessage(kArraySize)); | |
172 } | |
173 | |
174 | |
175 ///<summary> | |
176 /// A test for Insert | |
177 ///</summary> | |
178 [TestMethod] | |
179 public void InsertTest() { | |
180 var target = new ErrorBreakpointEnumerator(); | |
181 IDebugErrorBreakpoint2 breakpointError = | |
182 new ErrorBreakpoint(new ErrorBreakpointResolution()); | |
183 | |
184 uint count; | |
185 Assert.AreEqual(target.GetCount(out count), VSConstants.S_OK); | |
186 Assert.IsTrue(count == 0); | |
187 target.Insert(breakpointError); | |
188 Assert.AreEqual(target.GetCount(out count), VSConstants.S_OK); | |
189 Assert.IsTrue(count == 1); | |
190 | |
191 PopulateErrorEnum(target, 1000); | |
192 Assert.AreEqual(target.GetCount(out count), VSConstants.S_OK); | |
193 Assert.IsTrue(count == 1001); | |
194 } | |
195 | |
196 ///<summary> | |
197 /// A test for GetCount | |
198 ///</summary> | |
199 [TestMethod] | |
200 public void GetCountTest() { | |
201 var target = new ErrorBreakpointEnumerator(); | |
202 PopulateErrorEnum(target, 13233); | |
203 uint count; | |
204 | |
205 Assert.AreEqual(target.GetCount(out count), VSConstants.S_OK); | |
206 Assert.IsTrue(count == 13233); | |
207 } | |
208 | |
209 ///<summary> | |
210 /// A test for Clone | |
211 ///</summary> | |
212 [TestMethod] | |
213 public void CloneTest() { | |
214 var target = new ErrorBreakpointEnumerator(); | |
215 IEnumDebugErrorBreakpoints2 clone = null; | |
216 uint kEnumSize = 23; | |
217 uint returnedEnumSize = 0; | |
218 var targetErrors = new ErrorBreakpoint[kEnumSize]; | |
219 var cloneErrors = new ErrorBreakpoint[kEnumSize]; | |
220 PopulateErrorEnum(target, kEnumSize); | |
221 Assert.AreEqual(target.Clone(out clone), VSConstants.S_OK); | |
222 Assert.AreEqual(clone.GetCount(out returnedEnumSize), VSConstants.S_OK); | |
223 Assert.AreEqual(returnedEnumSize, kEnumSize); | |
224 Assert.AreEqual( | |
225 target.Next(kEnumSize, targetErrors, ref returnedEnumSize), | |
226 VSConstants.S_OK); | |
227 Assert.AreEqual(returnedEnumSize, kEnumSize); | |
228 Assert.AreEqual( | |
229 clone.Next(kEnumSize, cloneErrors, ref returnedEnumSize), | |
230 VSConstants.S_OK); | |
231 Assert.AreEqual(returnedEnumSize, kEnumSize); | |
232 for (uint i = 0; i < kEnumSize; ++i) { | |
233 Assert.AreEqual( | |
234 GetMessageFromBreakpointError(targetErrors[i]), | |
235 GetMessageFromBreakpointError(cloneErrors[i])); | |
236 } | |
237 } | |
238 | |
239 #region Private Implementation | |
240 | |
241 private static string GetIntMessage<T>(T number) { | |
242 return string.Format("This was breakpoint: {0}", number); | |
243 } | |
244 | |
245 private static string GetMessageFromBreakpointError(ErrorBreakpoint error) { | |
246 IDebugErrorBreakpointResolution2 resolution; | |
247 var resolutionInfo = new BP_ERROR_RESOLUTION_INFO[1]; | |
248 | |
249 Assert.AreEqual( | |
250 error.GetBreakpointResolution(out resolution), VSConstants.S_OK); | |
251 Assert.AreEqual( | |
252 resolution.GetResolutionInfo( | |
253 enum_BPERESI_FIELDS.BPERESI_MESSAGE, resolutionInfo), | |
254 VSConstants.S_OK); | |
255 return resolutionInfo[0].bstrMessage; | |
256 } | |
257 | |
258 private static void PopulateErrorEnum(ErrorBreakpointEnumerator target, | |
259 uint numberOfEntriesToAdd) { | |
260 for (uint i = 0; i < numberOfEntriesToAdd; ++i) { | |
261 var errorResolution = new ErrorBreakpointResolution(); | |
262 errorResolution.Message = GetIntMessage(i); | |
263 var newError = new ErrorBreakpoint(errorResolution); | |
264 target.Insert(newError); | |
265 } | |
266 } | |
267 | |
268 #endregion | |
269 } | |
270 } | |
OLD | NEW |