David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 1 | // Copyright (C) 2017 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 15 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
| 16 | #include "matchers/matcher_util.h" |
| 17 | #include "stats_util.h" |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 18 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
| 20 | #include <log/log_event_list.h> |
| 21 | #include <log/log_read.h> |
| 22 | #include <log/logprint.h> |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 23 | |
| 24 | #include <stdio.h> |
| 25 | |
| 26 | using namespace android::os::statsd; |
| 27 | using std::unordered_map; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 28 | using std::vector; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 29 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 30 | const int TAG_ID = 123; |
| 31 | const int FIELD_ID_1 = 1; |
| 32 | const int FIELD_ID_2 = 2; |
| 33 | const int FIELD_ID_3 = 2; |
| 34 | |
| 35 | // Private API from liblog. |
| 36 | extern "C" void android_log_rewind(android_log_context ctx); |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 37 | |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 38 | #ifdef __ANDROID__ |
| 39 | TEST(LogEntryMatcherTest, TestSimpleMatcher) { |
| 40 | // Set up the matcher |
| 41 | LogEntryMatcher matcher; |
| 42 | auto simpleMatcher = matcher.mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 43 | simpleMatcher->set_tag(TAG_ID); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 44 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 45 | LogEvent event(TAG_ID); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 46 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 47 | // Convert to a LogEvent |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 48 | event.init(); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 49 | |
| 50 | // Test |
| 51 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | TEST(LogEntryMatcherTest, TestBoolMatcher) { |
| 55 | // Set up the matcher |
| 56 | LogEntryMatcher matcher; |
| 57 | auto simpleMatcher = matcher.mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 58 | simpleMatcher->set_tag(TAG_ID); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 59 | auto keyValue1 = simpleMatcher->add_key_value_matcher(); |
| 60 | keyValue1->mutable_key_matcher()->set_key(FIELD_ID_1); |
| 61 | auto keyValue2 = simpleMatcher->add_key_value_matcher(); |
| 62 | keyValue2->mutable_key_matcher()->set_key(FIELD_ID_2); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 63 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 64 | // Set up the event |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 65 | LogEvent event(TAG_ID); |
| 66 | auto list = event.GetAndroidLogEventList(); |
| 67 | *list << true; |
| 68 | *list << false; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 69 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 70 | // Convert to a LogEvent |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 71 | event.init(); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 72 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 73 | // Test |
| 74 | keyValue1->set_eq_bool(true); |
| 75 | keyValue2->set_eq_bool(false); |
| 76 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 77 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 78 | keyValue1->set_eq_bool(false); |
| 79 | keyValue2->set_eq_bool(false); |
| 80 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 81 | |
| 82 | keyValue1->set_eq_bool(true); |
| 83 | keyValue2->set_eq_bool(false); |
| 84 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
| 85 | |
| 86 | keyValue1->set_eq_bool(true); |
| 87 | keyValue2->set_eq_bool(true); |
| 88 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | TEST(LogEntryMatcherTest, TestStringMatcher) { |
| 92 | // Set up the matcher |
| 93 | LogEntryMatcher matcher; |
| 94 | auto simpleMatcher = matcher.mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 95 | simpleMatcher->set_tag(TAG_ID); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 96 | auto keyValue = simpleMatcher->add_key_value_matcher(); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 97 | keyValue->mutable_key_matcher()->set_key(FIELD_ID_1); |
| 98 | keyValue->set_eq_string("some value"); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 99 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 100 | // Set up the event |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 101 | LogEvent event(TAG_ID); |
| 102 | auto list = event.GetAndroidLogEventList(); |
| 103 | *list << "some value"; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 104 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 105 | // Convert to a LogEvent |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 106 | event.init(); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 107 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 108 | // Test |
| 109 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | TEST(LogEntryMatcherTest, TestIntComparisonMatcher) { |
| 113 | // Set up the matcher |
| 114 | LogEntryMatcher matcher; |
| 115 | auto simpleMatcher = matcher.mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 116 | |
| 117 | simpleMatcher->set_tag(TAG_ID); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 118 | auto keyValue = simpleMatcher->add_key_value_matcher(); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 119 | keyValue->mutable_key_matcher()->set_key(FIELD_ID_1); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 120 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 121 | // Set up the event |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 122 | LogEvent event(TAG_ID); |
| 123 | auto list = event.GetAndroidLogEventList(); |
| 124 | *list << 11; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 125 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame^] | 126 | event.init(); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 127 | |
| 128 | // Test |
| 129 | |
| 130 | // eq_int |
| 131 | keyValue->set_eq_int(10); |
| 132 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 133 | keyValue->set_eq_int(11); |
| 134 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
| 135 | keyValue->set_eq_int(12); |
| 136 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 137 | |
| 138 | // lt_int |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 139 | keyValue->set_lt_int(10); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 140 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 141 | keyValue->set_lt_int(11); |
| 142 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 143 | keyValue->set_lt_int(12); |
| 144 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 145 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 146 | // lte_int |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 147 | keyValue->set_lte_int(10); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 148 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 149 | keyValue->set_lte_int(11); |
| 150 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
| 151 | keyValue->set_lte_int(12); |
| 152 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 153 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 154 | // gt_int |
| 155 | keyValue->set_gt_int(10); |
| 156 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
| 157 | keyValue->set_gt_int(11); |
| 158 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 159 | keyValue->set_gt_int(12); |
| 160 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 161 | |
| 162 | // gte_int |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 163 | keyValue->set_gte_int(10); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 164 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
| 165 | keyValue->set_gte_int(11); |
| 166 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
| 167 | keyValue->set_gte_int(12); |
| 168 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 171 | #if 0 |
| 172 | |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 173 | TEST(LogEntryMatcherTest, TestFloatComparisonMatcher) { |
| 174 | // Set up the matcher |
| 175 | LogEntryMatcher matcher; |
| 176 | auto simpleMatcher = matcher.mutable_simple_log_entry_matcher(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 177 | simpleMatcher->set_tag(TAG_ID); |
| 178 | |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 179 | auto keyValue = simpleMatcher->add_key_value_matcher(); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 180 | keyValue->mutable_key_matcher()->set_key(FIELD_ID_1); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 181 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 182 | LogEvent event; |
| 183 | event.tagId = TAG_ID; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 184 | |
| 185 | keyValue->set_lt_float(10.0); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 186 | event.floatMap[FIELD_ID_1] = 10.1; |
| 187 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
| 188 | event.floatMap[FIELD_ID_1] = 9.9; |
| 189 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 190 | |
| 191 | keyValue->set_gt_float(10.0); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 192 | event.floatMap[FIELD_ID_1] = 10.1; |
| 193 | EXPECT_TRUE(matchesSimple(*simpleMatcher, event)); |
| 194 | event.floatMap[FIELD_ID_1] = 9.9; |
| 195 | EXPECT_FALSE(matchesSimple(*simpleMatcher, event)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 196 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 197 | #endif |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 198 | |
| 199 | // Helper for the composite matchers. |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 200 | void addSimpleMatcher(SimpleLogEntryMatcher* simpleMatcher, int tag, int key, int val) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 201 | simpleMatcher->set_tag(tag); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 202 | auto keyValue = simpleMatcher->add_key_value_matcher(); |
| 203 | keyValue->mutable_key_matcher()->set_key(key); |
| 204 | keyValue->set_eq_int(val); |
| 205 | } |
| 206 | |
| 207 | TEST(LogEntryMatcherTest, TestAndMatcher) { |
| 208 | // Set up the matcher |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 209 | LogicalOperation operation = LogicalOperation::AND; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 210 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 211 | vector<int> children; |
| 212 | children.push_back(0); |
| 213 | children.push_back(1); |
| 214 | children.push_back(2); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 215 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 216 | vector<MatchingState> matcherResults; |
| 217 | matcherResults.push_back(MatchingState::kMatched); |
| 218 | matcherResults.push_back(MatchingState::kNotMatched); |
| 219 | matcherResults.push_back(MatchingState::kMatched); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 220 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 221 | EXPECT_FALSE(combinationMatch(children, operation, matcherResults)); |
| 222 | |
| 223 | matcherResults.clear(); |
| 224 | matcherResults.push_back(MatchingState::kMatched); |
| 225 | matcherResults.push_back(MatchingState::kMatched); |
| 226 | matcherResults.push_back(MatchingState::kMatched); |
| 227 | |
| 228 | EXPECT_TRUE(combinationMatch(children, operation, matcherResults)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | TEST(LogEntryMatcherTest, TestOrMatcher) { |
| 232 | // Set up the matcher |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 233 | LogicalOperation operation = LogicalOperation::OR; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 234 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 235 | vector<int> children; |
| 236 | children.push_back(0); |
| 237 | children.push_back(1); |
| 238 | children.push_back(2); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 239 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 240 | vector<MatchingState> matcherResults; |
| 241 | matcherResults.push_back(MatchingState::kMatched); |
| 242 | matcherResults.push_back(MatchingState::kNotMatched); |
| 243 | matcherResults.push_back(MatchingState::kMatched); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 244 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 245 | EXPECT_TRUE(combinationMatch(children, operation, matcherResults)); |
| 246 | |
| 247 | matcherResults.clear(); |
| 248 | matcherResults.push_back(MatchingState::kNotMatched); |
| 249 | matcherResults.push_back(MatchingState::kNotMatched); |
| 250 | matcherResults.push_back(MatchingState::kNotMatched); |
| 251 | |
| 252 | EXPECT_FALSE(combinationMatch(children, operation, matcherResults)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | TEST(LogEntryMatcherTest, TestNotMatcher) { |
| 256 | // Set up the matcher |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 257 | LogicalOperation operation = LogicalOperation::NOT; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 258 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 259 | vector<int> children; |
| 260 | children.push_back(0); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 261 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 262 | vector<MatchingState> matcherResults; |
| 263 | matcherResults.push_back(MatchingState::kMatched); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 264 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 265 | EXPECT_FALSE(combinationMatch(children, operation, matcherResults)); |
| 266 | |
| 267 | matcherResults.clear(); |
| 268 | matcherResults.push_back(MatchingState::kNotMatched); |
| 269 | EXPECT_TRUE(combinationMatch(children, operation, matcherResults)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 272 | TEST(LogEntryMatcherTest, TestNandMatcher) { |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 273 | // Set up the matcher |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 274 | LogicalOperation operation = LogicalOperation::NAND; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 275 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 276 | vector<int> children; |
| 277 | children.push_back(0); |
| 278 | children.push_back(1); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 279 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 280 | vector<MatchingState> matcherResults; |
| 281 | matcherResults.push_back(MatchingState::kMatched); |
| 282 | matcherResults.push_back(MatchingState::kNotMatched); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 283 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 284 | EXPECT_TRUE(combinationMatch(children, operation, matcherResults)); |
| 285 | |
| 286 | matcherResults.clear(); |
| 287 | matcherResults.push_back(MatchingState::kNotMatched); |
| 288 | matcherResults.push_back(MatchingState::kNotMatched); |
| 289 | EXPECT_TRUE(combinationMatch(children, operation, matcherResults)); |
| 290 | |
| 291 | matcherResults.clear(); |
| 292 | matcherResults.push_back(MatchingState::kMatched); |
| 293 | matcherResults.push_back(MatchingState::kMatched); |
| 294 | EXPECT_FALSE(combinationMatch(children, operation, matcherResults)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 297 | TEST(LogEntryMatcherTest, TestNorMatcher) { |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 298 | // Set up the matcher |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 299 | LogicalOperation operation = LogicalOperation::NOR; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 300 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 301 | vector<int> children; |
| 302 | children.push_back(0); |
| 303 | children.push_back(1); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 304 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 305 | vector<MatchingState> matcherResults; |
| 306 | matcherResults.push_back(MatchingState::kMatched); |
| 307 | matcherResults.push_back(MatchingState::kNotMatched); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 308 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 309 | EXPECT_FALSE(combinationMatch(children, operation, matcherResults)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 310 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 311 | matcherResults.clear(); |
| 312 | matcherResults.push_back(MatchingState::kNotMatched); |
| 313 | matcherResults.push_back(MatchingState::kNotMatched); |
| 314 | EXPECT_TRUE(combinationMatch(children, operation, matcherResults)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 315 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 316 | matcherResults.clear(); |
| 317 | matcherResults.push_back(MatchingState::kMatched); |
| 318 | matcherResults.push_back(MatchingState::kMatched); |
| 319 | EXPECT_FALSE(combinationMatch(children, operation, matcherResults)); |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 320 | } |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 321 | |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 322 | #else |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 323 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
David Chen | dd89694 | 2017-09-26 11:44:40 -0700 | [diff] [blame] | 324 | #endif |