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.assertEquals; | |
16 | import static org.junit.Assert.assertFalse; | |
17 | import static org.junit.Assert.assertTrue; | |
18 | ||
19 | import java.util.Arrays; | |
20 | import java.util.HashSet; | |
21 | import java.util.Set; | |
22 | ||
23 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; | |
24 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
25 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; | |
26 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode; | |
27 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode; | |
28 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode; | |
29 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode; | |
30 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode; | |
31 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode; | |
32 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode; | |
b2c971ec | 33 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; |
ebc1e992 PT |
34 | import org.junit.Before; |
35 | import org.junit.Test; | |
36 | ||
37 | /** | |
38 | * Test suite for the {@link TmfFilterOrNode} class. | |
39 | * | |
40 | * @author Patrick Tasse | |
41 | */ | |
42 | @SuppressWarnings("javadoc") | |
b0d2c558 | 43 | public class TmfFilterOrNodeTest extends TmfFilterTreeNodeTestBase { |
ebc1e992 PT |
44 | |
45 | // ------------------------------------------------------------------------ | |
46 | // Variables | |
47 | // ------------------------------------------------------------------------ | |
48 | ||
49 | private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null); | |
b2c971ec | 50 | private TmfEvent fEvent = new TmfEvent(TRACE, 0, TmfTimestamp.fromNanos(1), EVENT_TYPE, fContent); |
ebc1e992 PT |
51 | private TmfFilterOrNode fFilter; |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Tests | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
57 | @Before | |
58 | public void createFilter() { | |
59 | fFilter = new TmfFilterOrNode(null); | |
60 | fFilterNode = fFilter; | |
61 | } | |
62 | ||
63 | @Test | |
64 | public void testMatches() { | |
65 | fFilter.addChild(TRUE_NODE); | |
66 | fFilter.addChild(TRUE_NODE); | |
67 | assertTrue(fFilter.matches(fEvent)); | |
68 | ||
69 | fFilter.replaceChild(0, FALSE_NODE); | |
70 | assertTrue(fFilter.matches(fEvent)); | |
71 | ||
72 | fFilter.setNot(true); | |
73 | assertFalse(fFilter.matches(fEvent)); | |
74 | } | |
75 | ||
76 | @Test | |
77 | public void testGetName() { | |
78 | assertEquals("getName()", "OR", fFilter.getNodeName()); | |
79 | } | |
80 | ||
81 | @Test | |
82 | public void testGetValidChildren() { | |
83 | Set<String> validChildren = new HashSet<>(Arrays.asList( | |
84 | TmfFilterTraceTypeNode.NODE_NAME, | |
85 | TmfFilterAndNode.NODE_NAME, | |
86 | TmfFilterOrNode.NODE_NAME, | |
87 | TmfFilterContainsNode.NODE_NAME, | |
88 | TmfFilterEqualsNode.NODE_NAME, | |
89 | TmfFilterMatchesNode.NODE_NAME, | |
90 | TmfFilterCompareNode.NODE_NAME)); | |
91 | assertEquals("getValidChildren()", validChildren, new HashSet<>(fFilter.getValidChildren())); | |
92 | } | |
93 | } |