summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Rowe <erowe@google.com>2013-03-21 15:06:04 -0700
committerEric Rowe <erowe@google.com>2013-04-04 16:41:25 -0700
commitbbeb7adf6f109c33ab7693c0dedbfc55ab25f3b6 (patch)
tree7e6103ee3bb6635b72cd4a153eb9ade2913c3c3d /tests
parent6de23358ec9005e5577fbb983786ef3a4474f850 (diff)
downloadloganalysis-bbeb7adf6f109c33ab7693c0dedbfc55ab25f3b6.tar.gz
Add LogPatternUtil.
Change-Id: I208a187d72301a8b88fe3ebc8b1ca412a27b5b92
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/loganalysis/UnitTests.java2
-rw-r--r--tests/src/com/android/loganalysis/util/LogPatternUtilTest.java57
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/src/com/android/loganalysis/UnitTests.java b/tests/src/com/android/loganalysis/UnitTests.java
index 86cb05b..a419153 100644
--- a/tests/src/com/android/loganalysis/UnitTests.java
+++ b/tests/src/com/android/loganalysis/UnitTests.java
@@ -32,6 +32,7 @@ import com.android.loganalysis.parser.SystemPropsParserTest;
import com.android.loganalysis.parser.TopParserTest;
import com.android.loganalysis.parser.TracesParserTest;
import com.android.loganalysis.util.ArrayUtilTest;
+import com.android.loganalysis.util.LogPatternUtilTest;
import com.android.loganalysis.util.LogTailUtilTest;
import com.android.loganalysis.util.RegexTrieTest;
@@ -69,6 +70,7 @@ public class UnitTests extends TestSuite {
// util
addTestSuite(ArrayUtilTest.class);
+ addTestSuite(LogPatternUtilTest.class);
addTestSuite(LogTailUtilTest.class);
addTestSuite(RegexTrieTest.class);
}
diff --git a/tests/src/com/android/loganalysis/util/LogPatternUtilTest.java b/tests/src/com/android/loganalysis/util/LogPatternUtilTest.java
new file mode 100644
index 0000000..98226d4
--- /dev/null
+++ b/tests/src/com/android/loganalysis/util/LogPatternUtilTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.loganalysis.util;
+
+import junit.framework.TestCase;
+
+import java.util.regex.Pattern;
+
+/**
+ * Unit tests for {@link LogPatternUtil}.
+ */
+public class LogPatternUtilTest extends TestCase {
+
+ /**
+ * Test basic pattern matching.
+ */
+ public void testPatternMatching() {
+ LogPatternUtil patternUtil = new LogPatternUtil();
+ patternUtil.addPattern(Pattern.compile("abc"), "cat1");
+ patternUtil.addPattern(Pattern.compile("123"), "cat2");
+
+ assertNull(patternUtil.checkMessage("xyz"));
+ assertEquals("cat1", patternUtil.checkMessage("abc"));
+ assertEquals("cat2", patternUtil.checkMessage("123"));
+ }
+
+ /**
+ * Test pattern matching with extras.
+ */
+ public void testExtrasMatching() {
+ LogPatternUtil patternUtil = new LogPatternUtil();
+ patternUtil.addPattern(Pattern.compile("abc"), null, "cat1");
+ patternUtil.addPattern(Pattern.compile("123"), "E/tag1", "cat2");
+ patternUtil.addPattern(Pattern.compile("123"), "E/tag2", "cat3");
+
+ assertNull(patternUtil.checkMessage("xyz"));
+ assertEquals("cat1", patternUtil.checkMessage("abc"));
+ assertEquals("cat1", patternUtil.checkMessage("abc", "E/tag1"));
+ assertEquals("cat1", patternUtil.checkMessage("abc", "E/tag2"));
+ assertNull(patternUtil.checkMessage("123"));
+ assertEquals("cat2", patternUtil.checkMessage("123", "E/tag1"));
+ assertEquals("cat3", patternUtil.checkMessage("123", "E/tag2"));
+ }
+}