1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.filter
;
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
;
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
;
30 * Test suite for the {@link TmfFilterMatchesNode} class.
32 * @author Patrick Tasse
34 @SuppressWarnings("javadoc")
35 public class TmfFilterMatchesNodeTest
extends TmfFilterTreeNodeTestBase
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
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
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 public void createFilter() {
55 fFilter
= new TmfFilterMatchesNode(null);
56 fFilterNode
= fFilter
;
60 public void testMatches() {
61 fFilter
.setEventAspect(new TmfContentFieldAspect(FIELD
, FIELD
));
63 fFilter
.setRegex("value");
64 assertTrue(fFilter
.matches(fEvent1
));
65 assertTrue(fFilter
.matches(fEvent2
));
67 fFilter
.setRegex(".*value.*");
68 assertTrue(fFilter
.matches(fEvent1
));
69 assertTrue(fFilter
.matches(fEvent2
));
71 fFilter
.setRegex("^value");
72 assertTrue(fFilter
.matches(fEvent1
));
73 assertTrue(fFilter
.matches(fEvent2
));
75 fFilter
.setRegex("value$");
76 assertFalse(fFilter
.matches(fEvent1
));
77 assertFalse(fFilter
.matches(fEvent2
));
79 fFilter
.setRegex(".* 1");
80 assertTrue(fFilter
.matches(fEvent1
));
81 assertFalse(fFilter
.matches(fEvent2
));
84 assertFalse(fFilter
.matches(fEvent1
));
85 assertTrue(fFilter
.matches(fEvent2
));
89 public void testGetName() {
90 assertEquals("getName()", "MATCHES", fFilter
.getNodeName());
94 public void testGetValidChildren() {
95 assertArrayEquals("getValidChildren()", new String
[] {}, fFilter
.getValidChildren().toArray());