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