Commit | Line | Data |
---|---|---|
ebc1e992 PT |
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; | |
40dfafb3 | 23 | import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect; |
ebc1e992 PT |
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 TmfFilterTreeNodeTest { | |
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() { | |
40dfafb3 | 61 | fFilter.setEventAspect(new TmfContentFieldAspect(FIELD, FIELD)); |
ebc1e992 PT |
62 | |
63 | fFilter.setRegex("value"); | |
64 | assertFalse(fFilter.matches(fEvent1)); | |
65 | assertFalse(fFilter.matches(fEvent2)); | |
66 | ||
67 | fFilter.setRegex(".* 1"); | |
68 | assertTrue(fFilter.matches(fEvent1)); | |
69 | assertFalse(fFilter.matches(fEvent2)); | |
70 | ||
71 | fFilter.setNot(true); | |
72 | assertFalse(fFilter.matches(fEvent1)); | |
73 | assertTrue(fFilter.matches(fEvent2)); | |
74 | } | |
75 | ||
76 | @Test | |
77 | public void testGetName() { | |
78 | assertEquals("getName()", "MATCHES", fFilter.getNodeName()); | |
79 | } | |
80 | ||
81 | @Test | |
82 | public void testGetValidChildren() { | |
83 | assertArrayEquals("getValidChildren()", new String[] {}, fFilter.getValidChildren().toArray()); | |
84 | } | |
85 | } |