c16e08e5f904748d16ccab66a6d1218f5189f368
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / filter / TmfFilterMatchesNodeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.tests.filter;
14
15 import static org.junit.Assert.assertArrayEquals;
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertTrue;
19
20 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
21 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
22 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
23 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
24 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
25 import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 /**
30 * Test suite for the {@link TmfFilterMatchesNode} class.
31 *
32 * @author Patrick Tasse
33 */
34 @SuppressWarnings("javadoc")
35 public class TmfFilterMatchesNodeTest extends TmfFilterTreeNodeTestBase {
36
37 // ------------------------------------------------------------------------
38 // Variables
39 // ------------------------------------------------------------------------
40
41 private ITmfEventField[] fFields1 = new ITmfEventField[] { new TmfEventField(FIELD, "value 1", null) };
42 private ITmfEventField[] fFields2 = new ITmfEventField[] { new TmfEventField(FIELD, "value 2", null) };
43 private ITmfEventField fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields1);
44 private ITmfEventField fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, fFields2);
45 private TmfEvent fEvent1 = new TmfEvent(TRACE, 0, new TmfNanoTimestamp(1), EVENT_TYPE, fContent1);
46 private TmfEvent fEvent2 = new TmfEvent(TRACE, 1, new TmfNanoTimestamp(2), EVENT_TYPE, fContent2);
47 private TmfFilterMatchesNode fFilter;
48
49 // ------------------------------------------------------------------------
50 // Tests
51 // ------------------------------------------------------------------------
52
53 @Before
54 public void createFilter() {
55 fFilter = new TmfFilterMatchesNode(null);
56 fFilterNode = fFilter;
57 }
58
59 @Test
60 public void testMatches() {
61 fFilter.setEventAspect(new TmfContentFieldAspect(FIELD, FIELD));
62
63 fFilter.setRegex("value");
64 assertTrue(fFilter.matches(fEvent1));
65 assertTrue(fFilter.matches(fEvent2));
66
67 fFilter.setRegex(".*value.*");
68 assertTrue(fFilter.matches(fEvent1));
69 assertTrue(fFilter.matches(fEvent2));
70
71 fFilter.setRegex("^value");
72 assertTrue(fFilter.matches(fEvent1));
73 assertTrue(fFilter.matches(fEvent2));
74
75 fFilter.setRegex("value$");
76 assertFalse(fFilter.matches(fEvent1));
77 assertFalse(fFilter.matches(fEvent2));
78
79 fFilter.setRegex(".* 1");
80 assertTrue(fFilter.matches(fEvent1));
81 assertFalse(fFilter.matches(fEvent2));
82
83 fFilter.setNot(true);
84 assertFalse(fFilter.matches(fEvent1));
85 assertTrue(fFilter.matches(fEvent2));
86 }
87
88 @Test
89 public void testGetName() {
90 assertEquals("getName()", "MATCHES", fFilter.getNodeName());
91 }
92
93 @Test
94 public void testGetValidChildren() {
95 assertArrayEquals("getValidChildren()", new String[] {}, fFilter.getValidChildren().toArray());
96 }
97 }
This page took 0.038477 seconds and 4 git commands to generate.