2005-11-25 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / nunit24 / NUnitCore / interfaces / Filters / NotFilter.cs
diff --git a/mcs/nunit24/NUnitCore/interfaces/Filters/NotFilter.cs b/mcs/nunit24/NUnitCore/interfaces/Filters/NotFilter.cs
new file mode 100644 (file)
index 0000000..42af81b
--- /dev/null
@@ -0,0 +1,64 @@
+// ****************************************************************\r
+// Copyright 2007, Charlie Poole\r
+// This is free software licensed under the NUnit license. You may\r
+// obtain a copy of the license at http://nunit.org/?p=license&r=2.4\r
+// ****************************************************************\r
+using System;\r
+\r
+namespace NUnit.Core.Filters\r
+{\r
+       /// <summary>\r
+       /// NotFilter negates the operation of another filter\r
+       /// </summary>\r
+       [Serializable]\r
+       public class NotFilter : TestFilter\r
+       {\r
+               ITestFilter baseFilter;\r
+\r
+               /// <summary>\r
+               /// Construct a not filter on another filter\r
+               /// </summary>\r
+               /// <param name="baseFilter">The filter to be negated</param>\r
+               public NotFilter( ITestFilter baseFilter)\r
+               {\r
+                       this.baseFilter = baseFilter;\r
+               }\r
+\r
+               /// <summary>\r
+               /// Gets the base filter\r
+               /// </summary>\r
+               public ITestFilter BaseFilter\r
+               {\r
+                       get { return baseFilter; }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Check whether the filter matches a test\r
+               /// </summary>\r
+               /// <param name="test">The test to be matched</param>\r
+               /// <returns>True if it matches, otherwise false</returns>\r
+               public override bool Match( ITest test )\r
+               {\r
+                       return test.RunState != RunState.Explicit && !baseFilter.Pass( test );\r
+               }\r
+\r
+               /// <summary>\r
+               /// Determine whether any descendant of the test matches the filter criteria.\r
+               /// </summary>\r
+               /// <param name="test">The test to be matched</param>\r
+               /// <returns>True if at least one descendant matches the filter criteria</returns>\r
+               protected override bool MatchDescendant(ITest test)\r
+               {\r
+                       if (!test.IsSuite || test.Tests == null || test.RunState == RunState.Explicit)\r
+                               return false;\r
+\r
+                       foreach (ITest child in test.Tests)\r
+                       {\r
+                               if (Match(child) || MatchDescendant(child))\r
+                                       return true;\r
+                       }\r
+\r
+                       return false;\r
+               }       \r
+       }\r
+}\r