public void DRT_TestValidator(SimpleTest test, Type expectedExceptionType) { try { test(); } catch (Exception ex) { if (expectedExceptionType != null && expectedExceptionType == ex.GetType()) { return; } else { // otherwise we got an unexpected exception DRT.Assert(false, "XAML Test '{0}' failed.{1}", test.Method.Name, ex.ToString()); return; } } if (expectedExceptionType != null) { DRT.Assert(false, "XAAML Test '{0}' did not throw expected exception of type '{1}'.", test.Method.Name, expectedExceptionType); } }
private void VerifyHwndDestruction() { // Run through each class atom and attempt to query info on the class // If that fails, we know it's already been cleaned up. // Note that we don't need to verify the windows are gone since a // class can't be unregistered until all its windows are destroyed. int returnValue; WNDCLASSEX wndclass = new WNDCLASSEX(); IntPtr hInstance = GetModuleHandle(null); if (hInstance == IntPtr.Zero) { throw new Win32Exception(); } for (int i = 0; i < _classAtoms.Count; i++) { returnValue = GetClassInfoEx(hInstance, new IntPtr(_classAtoms[i]), wndclass); // A return value of 0 means that UnregisterClass failed DRT.Assert(returnValue == 0, "Error: Window class wasn't unregistered properly"); } }
public void ResourceResolutionForwardReference1() { bool caughtException = false; try { var rr = new ResourceResolutionForwardReference1(); } catch (System.Windows.Markup.XamlParseException) { caughtException = true; } DRT.Assert(caughtException, "Static Resource forward reference did not throw"); }
public object DRT_XamlLoader(string name, string xamlString, XamlStringParser loader, Type expectedExceptionType, PostTreeValidator validator) { object root = null; bool hasExpectedException = (expectedExceptionType != null); try { root = loader(xamlString); } catch (Exception ex) { if (expectedExceptionType != null && expectedExceptionType == ex.GetType()) { hasExpectedException = false; } else { // otherwise we got the unexpected exception; DRT.Assert(false, "XAML Test '{0}' failed.{1}", name, ex.ToString()); return(null); } } if (hasExpectedException) { DRT.Assert(false, "XAAML Test '{0}' did not throw expected exception of type '{1}'.", name, expectedExceptionType); } if (validator != null) { try { validator(root); } catch (Exception ex) { DRT.Assert(false, "XAML Test String '{0}' failed post validation.{1}", name, ex.ToString()); } } return(root); }
/// <summary> /// Creates the HwndSource and check the resulting style /// </summary> private void CheckResultingStyles() { TestHwndHost test = null; // First series with a top level window test = new TestHwndHost(child: false, usesPerPixelOpacity: false, usesPerPixelTransparency: false, style: 0); _rootBorder.Child = test; DRT.Assert(test.SourceCreated && (test.OutUsesPerPixelOpacity == false) && (test.LayeredWindow == false) && (test.ExceptionType == null), test.Description); test = new TestHwndHost(child: false, usesPerPixelOpacity: false, usesPerPixelTransparency: true, style: 0); _rootBorder.Child = test; DRT.Assert(test.SourceCreated && (test.OutUsesPerPixelOpacity == true) && (test.LayeredWindow == true) && (test.ExceptionType == null), test.Description); test = new TestHwndHost(child: false, usesPerPixelOpacity: true, usesPerPixelTransparency: false, style: 0); _rootBorder.Child = test; DRT.Assert(test.SourceCreated && (test.OutUsesPerPixelOpacity == true) && (test.LayeredWindow == true) && (test.ExceptionType == null), test.Description); test = new TestHwndHost(child: false, usesPerPixelOpacity: true, usesPerPixelTransparency: true, style: 0); _rootBorder.Child = test; DRT.Assert(!test.SourceCreated && (test.OutUsesPerPixelOpacity == false) && (test.LayeredWindow == false) && (test.ExceptionType == typeof(InvalidOperationException)), test.Description); // Second series with a child window test = new TestHwndHost(child: true, usesPerPixelOpacity: false, usesPerPixelTransparency: false, style: 0); _rootBorder.Child = test; DRT.Assert(test.SourceCreated && (test.OutUsesPerPixelOpacity == false) && (test.LayeredWindow == false) && (test.ExceptionType == null), test.Description); // This is the only test where W7 and W8 should differ test = new TestHwndHost(child: true, usesPerPixelOpacity: false, usesPerPixelTransparency: true, style: 0); _rootBorder.Child = test; DRT.Assert(test.SourceCreated && (test.OutUsesPerPixelOpacity == DoesPlatformSupportTransparentChildWindows) && (test.LayeredWindow == DoesPlatformSupportTransparentChildWindows) && (test.ExceptionType == null), test.Description); test = new TestHwndHost(child: true, usesPerPixelOpacity: true, usesPerPixelTransparency: false, style: 0); _rootBorder.Child = test; DRT.Assert(test.SourceCreated && (test.OutUsesPerPixelOpacity == false) && (test.LayeredWindow == false) && (test.ExceptionType == null), test.Description); test = new TestHwndHost(child: true, usesPerPixelOpacity: true, usesPerPixelTransparency: true, style: 0); _rootBorder.Child = test; DRT.Assert(!test.SourceCreated && (test.OutUsesPerPixelOpacity == false) && (test.LayeredWindow == false) && (test.ExceptionType == typeof(InvalidOperationException)), test.Description); }
//---------------------------------------------------------------------- // Private Methods - Handlers TestServices //---------------------------------------------------------------------- /// <summary> /// Bridges TestServices Messages to DrtBase or Console. /// </summary> /// <param name="sender">Unused.</param> /// <param name="args">The message arguments.</param> private void MessageSentHandler(object sender, MessageEventArgs args) { switch (args.Category) { case MessageEventArgs.MessageCategory.Internal: if (TestServices.Diagnose) { if (base.DelayOutput) { DRT.LogOutput(args.Message); } else { Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(args.Message); Console.ResetColor(); } } break; case MessageEventArgs.MessageCategory.Trace: DRT.Trace(args.Message); break; case MessageEventArgs.MessageCategory.Log: DRT.LogOutput(args.Message); break; case MessageEventArgs.MessageCategory.Warning: Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(args.Message); Console.ResetColor(); break; case MessageEventArgs.MessageCategory.Assert: DRT.Assert(false, args.Message); break; } }
/// <summary> /// Tests that EffectivePerPixelOpacity has the expected value /// </summary> /// <param name="platformSupport"></param> /// <param name="child"></param> /// <param name="usesPerPixelOpacity"></param> /// <param name="usesPerPixelTransparency"></param> /// <param name="expectedEffectiveOpacity"></param> /// <param name="expectedException"></param> void TestOpacity(bool platformSupport, bool child, bool usesPerPixelOpacity, bool usesPerPixelTransparency, bool expectedEffectiveOpacity, Type expectedException) { string description = string.Format("platformSupport={0}, child={1}, usesPerPixelOpacity={2}, usesPerPixelTransparency={3}", platformSupport, child, usesPerPixelOpacity, usesPerPixelTransparency); try { SetPlatformSupportsTransparentChildWindows(platformSupport); HwndSourceParameters p = new HwndSourceParameters(); p.WindowStyle = child ? Win32.WS_CHILD : 0; p.UsesPerPixelOpacity = usesPerPixelOpacity; p.UsesPerPixelTransparency = usesPerPixelTransparency; DRT.Assert(GetEffectivePerPixelOpacity(p) == expectedEffectiveOpacity, description); } catch (TargetInvocationException ex) { // Caused by use of reflection to get EffectivePerPixelOpacity DRT.Assert(ex.InnerException.GetType() == expectedException, description); } catch (Exception ex) { DRT.Assert(ex.GetType() == expectedException, description); } }