1 // **************************************************************** 2 // Copyright 2007, Charlie Poole 3 // This is free software licensed under the NUnit license. You may 4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4 5 // **************************************************************** 6 7 using System; 8 using System.IO; 9 using System.Collections; 10 using NUnit.Framework.Constraints; 11 12 namespace NUnit.Framework 13 { 14 /// <summary> 15 /// MessageWriter is the abstract base for classes that write 16 /// constraint descriptions and messages in some form. The 17 /// class has separate methods for writing various components 18 /// of a message, allowing implementations to tailor the 19 /// presentation as needed. 20 /// </summary> 21 public abstract class MessageWriter : StringWriter 22 { 23 24 /// <summary> 25 /// Construct a MessageWriter given a culture 26 /// </summary> MessageWriter()27 public MessageWriter() : base( System.Globalization.CultureInfo.InvariantCulture ) { } 28 29 /// <summary> 30 /// Abstract method to get the max line length 31 /// </summary> 32 public abstract int MaxLineLength { get; set; } 33 34 /// <summary> 35 /// Method to write single line message with optional args, usually 36 /// written to precede the general failure message. 37 /// </summary> 38 /// <param name="message">The message to be written</param> 39 /// <param name="args">Any arguments used in formatting the message</param> WriteMessageLine(string message, params object[] args)40 public void WriteMessageLine(string message, params object[] args) 41 { 42 WriteMessageLine(0, message, args); 43 } 44 45 /// <summary> 46 /// Method to write single line message with optional args, usually 47 /// written to precede the general failure message, at a givel 48 /// indentation level. 49 /// </summary> 50 /// <param name="level">The indentation level of the message</param> 51 /// <param name="message">The message to be written</param> 52 /// <param name="args">Any arguments used in formatting the message</param> WriteMessageLine(int level, string message, params object[] args)53 public abstract void WriteMessageLine(int level, string message, params object[] args); 54 55 /// <summary> 56 /// Display Expected and Actual lines for a constraint. This 57 /// is called by MessageWriter's default implementation of 58 /// WriteMessageTo and provides the generic two-line display. 59 /// </summary> 60 /// <param name="constraint">The constraint that failed</param> DisplayDifferences(Constraint constraint)61 public abstract void DisplayDifferences(Constraint constraint); 62 63 /// <summary> 64 /// Display Expected and Actual lines for given values. This 65 /// method may be called by constraints that need more control over 66 /// the display of actual and expected values than is provided 67 /// by the default implementation. 68 /// </summary> 69 /// <param name="expected">The expected value</param> 70 /// <param name="actual">The actual value causing the failure</param> DisplayDifferences(object expected, object actual)71 public abstract void DisplayDifferences(object expected, object actual); 72 73 /// <summary> 74 /// Display Expected and Actual lines for given values, including 75 /// a tolerance value on the Expected line. 76 /// </summary> 77 /// <param name="expected">The expected value</param> 78 /// <param name="actual">The actual value causing the failure</param> 79 /// <param name="tolerance">The tolerance within which the test was made</param> DisplayDifferences(object expected, object actual, object tolerance)80 public abstract void DisplayDifferences(object expected, object actual, object tolerance); 81 82 /// <summary> 83 /// Display the expected and actual string values on separate lines. 84 /// If the mismatch parameter is >=0, an additional line is displayed 85 /// line containing a caret that points to the mismatch point. 86 /// </summary> 87 /// <param name="expected">The expected string value</param> 88 /// <param name="actual">The actual string value</param> 89 /// <param name="mismatch">The point at which the strings don't match or -1</param> 90 /// <param name="ignoreCase">If true, case is ignored in locating the point where the strings differ</param> 91 /// <param name="clipping">If true, the strings should be clipped to fit the line</param> DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase, bool clipping)92 public abstract void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase, bool clipping); 93 94 /// <summary> 95 /// Writes the text for a connector. 96 /// </summary> 97 /// <param name="connector">The connector.</param> WriteConnector(string connector)98 public abstract void WriteConnector(string connector); 99 100 /// <summary> 101 /// Writes the text for a predicate. 102 /// </summary> 103 /// <param name="predicate">The predicate.</param> WritePredicate(string predicate)104 public abstract void WritePredicate(string predicate); 105 106 /// <summary> 107 /// Writes the text for an expected value. 108 /// </summary> 109 /// <param name="expected">The expected value.</param> WriteExpectedValue(object expected)110 public abstract void WriteExpectedValue(object expected); 111 112 /// <summary> 113 /// Writes the text for a modifier 114 /// </summary> 115 /// <param name="modifier">The modifier.</param> WriteModifier(string modifier)116 public abstract void WriteModifier(string modifier); 117 118 /// <summary> 119 /// Writes the text for an actual value. 120 /// </summary> 121 /// <param name="actual">The actual value.</param> WriteActualValue(object actual)122 public abstract void WriteActualValue(object actual); 123 124 /// <summary> 125 /// Writes the text for a generalized value. 126 /// </summary> 127 /// <param name="val">The value.</param> WriteValue(object val)128 public abstract void WriteValue(object val); 129 130 /// <summary> 131 /// Writes the text for a collection value, 132 /// starting at a particular point, to a max length 133 /// </summary> 134 /// <param name="collection">The collection containing elements to write.</param> 135 /// <param name="start">The starting point of the elements to write</param> 136 /// <param name="max">The maximum number of elements to write</param> WriteCollectionElements(ICollection collection, int start, int max)137 public abstract void WriteCollectionElements(ICollection collection, int start, int max); 138 } 139 } 140