Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs

Issue 10797040: PPAPI Patching System and Unit Tests (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 namespace UnitTests 5 namespace UnitTests
6 { 6 {
7 using System; 7 using System;
8 using System.Collections.Generic; 8 using System.Collections.Generic;
9 using System.Linq; 9 using System.Linq;
10 using System.Management; 10 using System.Management;
11 11
12 using EnvDTE; 12 using EnvDTE;
13 using EnvDTE80; 13 using EnvDTE80;
14 using Microsoft.VisualStudio.TestTools.UnitTesting;
15 using Microsoft.VisualStudio.VCProjectEngine;
14 16
15 /// <summary> 17 /// <summary>
16 /// This class contains utilities for running tests. 18 /// This class contains utilities for running tests.
17 /// </summary> 19 /// </summary>
18 public static class TestUtilities 20 public static class TestUtilities
19 { 21 {
20 /// <summary> 22 /// <summary>
21 /// This starts an instance of Visual Studio and get it's DTE object. 23 /// This starts an instance of Visual Studio and get it's DTE object.
22 /// </summary> 24 /// </summary>
23 /// <returns>DTE of the started instance.</returns> 25 /// <returns>DTE of the started instance.</returns>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 176 }
175 177
176 throw new Exception(string.Format( 178 throw new Exception(string.Format(
177 "Matching configuration not found for {0}: {1}|{2}", 179 "Matching configuration not found for {0}: {1}|{2}",
178 projectUniqueName, 180 projectUniqueName,
179 platformName, 181 platformName,
180 configurationName)); 182 configurationName));
181 } 183 }
182 184
183 /// <summary> 185 /// <summary>
186 /// Returns a VCConfiguration object with a matching configuration name and platform type.
187 /// </summary>
188 /// <param name="project">Project to get the configuration from.</param>
189 /// <param name="name">Name of configuration (e.g. 'Debug').</param>
190 /// <param name="platform">Name of the platform (e.g. 'NaCl').</param>
191 /// <returns>A matching VCConfiguration object.</returns>
192 public static VCConfiguration GetVCConfiguration(Project project, string nam e, string platform)
193 {
194 VCProject vcproj = (VCProject)project.Object;
195 IVCCollection configs = vcproj.Configurations;
196
197 foreach (VCConfiguration config in configs)
198 {
199 if (config.ConfigurationName == name && config.Platform.Name == platform )
200 {
201 return config;
202 }
203 }
204
205 throw new Exception(
206 string.Format("Project does not have configuration: {0}|{1}", platform , name));
207 }
208
209 /// <summary>
210 /// Tests that a given property has a specific value in a certain VCConfigur ation
211 /// </summary>
212 /// <param name="configuration">Gives the platform and configuration type</p aram>
213 /// <param name="pageName">Property page name where property resides.</param >
214 /// <param name="propertyName">Name of the property to check.</param>
215 /// <param name="expectedValue">Expected value of the property.</param>
216 /// <param name="ignoreCase">Ignore case when comparing the expected and act ual values.</param>
217 public static void AssertPropertyEquals(
218 VCConfiguration configuration,
219 string pageName,
220 string propertyName,
221 string expectedValue,
222 bool ignoreCase)
223 {
224 IVCRulePropertyStorage rule = configuration.Rules.Item(pageName);
225 string callInfo = string.Format(
226 "Page: {0}, Property: {1}, Configuration: {2}",
227 pageName,
228 propertyName,
229 configuration.ConfigurationName);
230
231 Assert.AreEqual(
232 expectedValue,
233 rule.GetUnevaluatedPropertyValue(propertyName),
234 ignoreCase,
235 callInfo);
236 }
237
238 /// <summary>
239 /// Tests that a given property contains a specific string in a certain VCCo nfiguration
240 /// </summary>
241 /// <param name="configuration">Gives the platform and configuration type</p aram>
242 /// <param name="pageName">Property page name where property resides.</param >
243 /// <param name="propertyName">Name of the property to check.</param>
244 /// <param name="expectedValue">Expected string to contain.</param>
245 /// <param name="ignoreCase">Ignore case when comparing the expected and act ual values.</param>
246 public static void AssertPropertyContains(
247 VCConfiguration configuration,
248 string pageName,
249 string propertyName,
250 string expectedValue,
251 bool ignoreCase)
252 {
253 StringComparison caseSensitive = ignoreCase ?
254 StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
255
256 IVCRulePropertyStorage rule = configuration.Rules.Item(pageName);
257 string propertyValue = rule.GetUnevaluatedPropertyValue(propertyName);
258
259 string message = string.Format(
260 "{0} should be contained in {1}. Page: {2}, Property: {3}, Configurati on: {4}",
261 expectedValue,
262 propertyValue,
263 pageName,
264 propertyName,
265 configuration.ConfigurationName);
266
267 Assert.IsTrue(propertyValue.Contains(expectedValue, caseSensitive), messag e);
268 }
269
270 /// <summary>
184 /// Extends the string class to allow checking if a string contains another string 271 /// Extends the string class to allow checking if a string contains another string
185 /// allowing a comparison type (such as case-insensitivity). 272 /// allowing a comparison type (such as case-insensitivity).
186 /// </summary> 273 /// </summary>
187 /// <param name="source">Base string to search.</param> 274 /// <param name="source">Base string to search.</param>
188 /// <param name="toCheck">String to check if contained within base string.</ param> 275 /// <param name="toCheck">String to check if contained within base string.</ param>
189 /// <param name="comparison">Comparison type.</param> 276 /// <param name="comparison">Comparison type.</param>
190 /// <returns>True if toCheck is contained in source.</returns> 277 /// <returns>True if toCheck is contained in source.</returns>
191 public static bool Contains(this string source, string toCheck, StringCompar ison comparison) 278 public static bool Contains(this string source, string toCheck, StringCompar ison comparison)
192 { 279 {
193 return source.IndexOf(toCheck, comparison) != -1; 280 return source.IndexOf(toCheck, comparison) != -1;
194 } 281 }
195 } 282 }
196 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698