| 1 |
/* |
| 2 |
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions are met: |
| 7 |
* * Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* * Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* * Neither the name of the <organization> nor the |
| 13 |
* names of its contributors may be used to endorse or promote products |
| 14 |
* derived from this software without specific prior written permission. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY |
| 17 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 |
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY |
| 20 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "CppUTest/TestHarness.h" |
| 29 |
#include "CppUTest/TestFilter.h" |
| 30 |
|
| 31 |
TEST_GROUP(TestFilter) |
| 32 |
{ |
| 33 |
}; |
| 34 |
|
| 35 |
TEST(TestFilter, emptyFilterMatchesEverything) |
| 36 |
{ |
| 37 |
TestFilter filter; |
| 38 |
CHECK(filter.match("random_name")); |
| 39 |
CHECK(filter.match("")); |
| 40 |
CHECK(filter.match("*&%#^&%$(*&^@#(&*@#^(&*$^@#")); |
| 41 |
} |
| 42 |
|
| 43 |
TEST(TestFilter, defaultAbsoluteMismatches) |
| 44 |
{ |
| 45 |
TestFilter filter("filtername"); |
| 46 |
CHECK(!filter.match("notevenclose")); |
| 47 |
CHECK(!filter.match("filterrname")); |
| 48 |
CHECK(!filter.match("")); |
| 49 |
} |
| 50 |
|
| 51 |
TEST(TestFilter, strictMatching) |
| 52 |
{ |
| 53 |
TestFilter filter("filter"); |
| 54 |
filter.strictMatching(); |
| 55 |
CHECK(filter.match("filter")); |
| 56 |
CHECK(!filter.match("filterr")); |
| 57 |
CHECK(!filter.match(" filter")); |
| 58 |
} |
| 59 |
|
| 60 |
TEST(TestFilter, invertMatching) |
| 61 |
{ |
| 62 |
TestFilter filter("filter"); |
| 63 |
filter.invertMatching(); |
| 64 |
CHECK(!filter.match("filter")); |
| 65 |
CHECK(!filter.match("filterr")); |
| 66 |
CHECK(filter.match("notevenclose")); |
| 67 |
CHECK(filter.match("")); |
| 68 |
} |
| 69 |
|
| 70 |
TEST(TestFilter, invertStrictMatching) |
| 71 |
{ |
| 72 |
TestFilter filter("filter"); |
| 73 |
filter.invertMatching(); |
| 74 |
filter.strictMatching(); |
| 75 |
CHECK(!filter.match("filter")); |
| 76 |
CHECK(filter.match("filterr")); |
| 77 |
CHECK(filter.match(" filter")); |
| 78 |
} |
| 79 |
|
| 80 |
TEST(TestFilter, equality) |
| 81 |
{ |
| 82 |
TestFilter filter1("filter"); |
| 83 |
TestFilter filter2("filter"); |
| 84 |
TestFilter filter3("filter3"); |
| 85 |
CHECK(filter1 == filter2); |
| 86 |
CHECK(! (filter1 == filter3)); |
| 87 |
} |
| 88 |
|
| 89 |
TEST(TestFilter, equalityWithStrictness) |
| 90 |
{ |
| 91 |
TestFilter filter1("filter"); |
| 92 |
TestFilter filter2("filter"); |
| 93 |
filter2.strictMatching(); |
| 94 |
CHECK(! (filter1 == filter2)); |
| 95 |
} |
| 96 |
|
| 97 |
TEST(TestFilter, equalityWithInvertion) |
| 98 |
{ |
| 99 |
TestFilter filter1("filter"); |
| 100 |
TestFilter filter2("filter"); |
| 101 |
filter2.invertMatching(); |
| 102 |
CHECK(! (filter1 == filter2)); |
| 103 |
} |
| 104 |
|
| 105 |
TEST(TestFilter, notEqual) |
| 106 |
{ |
| 107 |
TestFilter filter1("filter"); |
| 108 |
TestFilter filter2("filter"); |
| 109 |
TestFilter filter3("filter3"); |
| 110 |
CHECK(filter1 != filter3); |
| 111 |
CHECK(! (filter1 != filter2)); |
| 112 |
} |
| 113 |
|
| 114 |
TEST(TestFilter, stringFrom) |
| 115 |
{ |
| 116 |
TestFilter filter("filter"); |
| 117 |
STRCMP_EQUAL("TestFilter: \"filter\"", StringFrom(filter).asCharString()); |
| 118 |
} |
| 119 |
|
| 120 |
TEST(TestFilter, stringFromWithStrictMatching) |
| 121 |
{ |
| 122 |
TestFilter filter("filter"); |
| 123 |
filter.strictMatching(); |
| 124 |
STRCMP_EQUAL("TestFilter: \"filter\" with strict matching", StringFrom(filter).asCharString()); |
| 125 |
} |
| 126 |
|
| 127 |
TEST(TestFilter, stringFromWithInvertMatching) |
| 128 |
{ |
| 129 |
TestFilter filter("filter"); |
| 130 |
filter.invertMatching(); |
| 131 |
STRCMP_EQUAL("TestFilter: \"filter\" with invert matching", StringFrom(filter).asCharString()); |
| 132 |
} |
| 133 |
|
| 134 |
TEST(TestFilter, stringFromWithStrictInvertMatching) |
| 135 |
{ |
| 136 |
TestFilter filter("filter"); |
| 137 |
filter.strictMatching(); |
| 138 |
filter.invertMatching(); |
| 139 |
STRCMP_EQUAL("TestFilter: \"filter\" with strict, invert matching", StringFrom(filter).asCharString()); |
| 140 |
} |
| 141 |
|
| 142 |
TEST(TestFilter, listOfFilters) |
| 143 |
{ |
| 144 |
TestFilter *listOfFilters = NULLPTR; |
| 145 |
TestFilter first("foo"); |
| 146 |
TestFilter secnd("bar"); |
| 147 |
listOfFilters = first.add(listOfFilters); |
| 148 |
listOfFilters = secnd.add(listOfFilters); |
| 149 |
TestFilter *current = listOfFilters; |
| 150 |
STRCMP_EQUAL("TestFilter: \"bar\"", StringFrom(*current).asCharString()); |
| 151 |
current = current->getNext(); |
| 152 |
STRCMP_EQUAL("TestFilter: \"foo\"", StringFrom(*current).asCharString()); |
| 153 |
POINTERS_EQUAL(NULLPTR, current->getNext()); |
| 154 |
} |
| 155 |
|
| 156 |
TEST(TestFilter, constructors) |
| 157 |
{ |
| 158 |
TestFilter filter1; |
| 159 |
TestFilter filter2(SimpleString("a")); |
| 160 |
TestFilter filter3("a"); |
| 161 |
CHECK(filter1.getNext() == NULLPTR); |
| 162 |
CHECK(filter2.getNext() == NULLPTR); |
| 163 |
CHECK(filter3.getNext() == NULLPTR); |
| 164 |
CHECK(filter2.match("ab")); |
| 165 |
CHECK(filter3.match("ab")); |
| 166 |
} |