1 // ***********************************************************************
2 // Copyright (c) 2007-2015 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 NUnit.Framework.Interfaces;
32 namespace NUnit.Framework.Internal.Filters
35 /// NotFilter negates the operation of another filter
38 public class NotFilter : TestFilter
41 /// Construct a not filter on another filter
43 /// <param name="baseFilter">The filter to be negated</param>
44 public NotFilter( TestFilter baseFilter)
46 BaseFilter = baseFilter;
50 /// Gets the base filter
52 public TestFilter BaseFilter { get; private set; }
55 /// Determine if a particular test passes the filter criteria. The default
56 /// implementation checks the test itself, its parents and any descendants.
58 /// Derived classes may override this method or any of the Match methods
59 /// to change the behavior of the filter.
61 /// <param name="test">The test to which the filter is applied</param>
62 /// <returns>True if the test passes the filter, otherwise false</returns>
63 public override bool Pass(ITest test)
65 return !BaseFilter.Match (test) && !BaseFilter.MatchParent (test);
69 /// Check whether the filter matches a test
71 /// <param name="test">The test to be matched</param>
72 /// <returns>True if it matches, otherwise false</returns>
73 public override bool Match( ITest test )
75 return !BaseFilter.Match( test );
79 /// Determine if a test matches the filter expicitly. That is, it must
80 /// be a direct match of the test itself or one of it's children.
82 /// <param name="test">The test to which the filter is applied</param>
83 /// <returns>True if the test matches the filter explicityly, otherwise false</returns>
84 public override bool IsExplicitMatch(ITest test)
90 ///// Determine whether any descendant of the test matches the filter criteria.
92 ///// <param name="test">The test to be matched</param>
93 ///// <returns>True if at least one descendant matches the filter criteria</returns>
94 //protected override bool MatchDescendant(ITest test)
96 // if (!test.HasChildren || test.Tests == null || TopLevel && test.RunState == RunState.Explicit)
99 // foreach (ITest child in test.Tests)
101 // if (Match(child) || MatchDescendant(child))
111 /// <param name="parentNode">Parent node</param>
112 /// <param name="recursive">True if recursive</param>
113 /// <returns>The added XML node</returns>
114 public override TNode AddToXml(TNode parentNode, bool recursive)
116 TNode result = parentNode.AddElement("not");
118 BaseFilter.AddToXml(result, true);