1 // ***********************************************************************
2 // Copyright (c) 2007 Charlie Poole
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
30 using System.Collections;
32 namespace NUnit.Framework.Constraints
35 /// MessageWriter is the abstract base for classes that write
36 /// constraint descriptions and messages in some form. The
37 /// class has separate methods for writing various components
38 /// of a message, allowing implementations to tailor the
39 /// presentation as needed.
41 public abstract class MessageWriter : StringWriter
45 /// Construct a MessageWriter given a culture
47 protected MessageWriter() : base(System.Globalization.CultureInfo.InvariantCulture) { }
50 /// Abstract method to get the max line length
52 public abstract int MaxLineLength { get; set; }
55 /// Method to write single line message with optional args, usually
56 /// written to precede the general failure message.
58 /// <param name="message">The message to be written</param>
59 /// <param name="args">Any arguments used in formatting the message</param>
60 public void WriteMessageLine(string message, params object[] args)
62 WriteMessageLine(0, message, args);
66 /// Method to write single line message with optional args, usually
67 /// written to precede the general failure message, at a givel
68 /// indentation level.
70 /// <param name="level">The indentation level of the message</param>
71 /// <param name="message">The message to be written</param>
72 /// <param name="args">Any arguments used in formatting the message</param>
73 public abstract void WriteMessageLine(int level, string message, params object[] args);
76 /// Display Expected and Actual lines for a constraint. This
77 /// is called by MessageWriter's default implementation of
78 /// WriteMessageTo and provides the generic two-line display.
80 /// <param name="result">The failing constraint result</param>
81 public abstract void DisplayDifferences(ConstraintResult result);
84 /// Display Expected and Actual lines for given _values. This
85 /// method may be called by constraints that need more control over
86 /// the display of actual and expected _values than is provided
87 /// by the default implementation.
89 /// <param name="expected">The expected value</param>
90 /// <param name="actual">The actual value causing the failure</param>
91 public abstract void DisplayDifferences(object expected, object actual);
94 /// Display Expected and Actual lines for given _values, including
95 /// a tolerance value on the Expected line.
97 /// <param name="expected">The expected value</param>
98 /// <param name="actual">The actual value causing the failure</param>
99 /// <param name="tolerance">The tolerance within which the test was made</param>
100 public abstract void DisplayDifferences(object expected, object actual, Tolerance tolerance);
103 /// Display the expected and actual string _values on separate lines.
104 /// If the mismatch parameter is >=0, an additional line is displayed
105 /// line containing a caret that points to the mismatch point.
107 /// <param name="expected">The expected string value</param>
108 /// <param name="actual">The actual string value</param>
109 /// <param name="mismatch">The point at which the strings don't match or -1</param>
110 /// <param name="ignoreCase">If true, case is ignored in locating the point where the strings differ</param>
111 /// <param name="clipping">If true, the strings should be clipped to fit the line</param>
112 public abstract void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase, bool clipping);
115 /// Writes the text for an actual value.
117 /// <param name="actual">The actual value.</param>
118 public abstract void WriteActualValue(object actual);
121 /// Writes the text for a generalized value.
123 /// <param name="val">The value.</param>
124 public abstract void WriteValue(object val);
127 /// Writes the text for a collection value,
128 /// starting at a particular point, to a max length
130 /// <param name="collection">The collection containing elements to write.</param>
131 /// <param name="start">The starting point of the elements to write</param>
132 /// <param name="max">The maximum number of elements to write</param>
133 public abstract void WriteCollectionElements(IEnumerable collection, long start, int max);