Commit | Line | Data |
---|---|---|
ebc1e992 | 1 | /******************************************************************************* |
53f17e49 | 2 | * Copyright (c) 2015, 2016 Ericsson |
ebc1e992 PT |
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 | ||
53f17e49 | 23 | import org.eclipse.jdt.annotation.NonNull; |
ebc1e992 PT |
24 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; |
25 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
26 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; | |
27 | import org.eclipse.tracecompass.tmf.core.event.TmfEventType; | |
28 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode; | |
29 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode; | |
30 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode; | |
31 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode; | |
32 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode; | |
33 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode; | |
34 | import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode; | |
35 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent; | |
36 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEventType; | |
37 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace; | |
38 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition; | |
39 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent; | |
40 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEventType; | |
41 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement; | |
42 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; | |
43 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; | |
b2c971ec | 44 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; |
ebc1e992 PT |
45 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub; |
46 | import org.junit.AfterClass; | |
47 | import org.junit.Before; | |
48 | import org.junit.Test; | |
49 | ||
50 | /** | |
51 | * Test suite for the {@link TmfFilterTraceTypeNode} class. | |
52 | * | |
53 | * @author Patrick Tasse | |
54 | */ | |
55 | @SuppressWarnings("javadoc") | |
b0d2c558 | 56 | public class TmfFilterTraceTypeNodeTest extends TmfFilterTreeNodeTestBase { |
ebc1e992 PT |
57 | |
58 | // ------------------------------------------------------------------------ | |
59 | // Variables | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
62 | private static final String CATEGORY_TXT = "txt"; | |
63 | private static final String CATEGORY_XML = "xml"; | |
53f17e49 GB |
64 | private static final @NonNull String DEFINITION_NAME_TXT = "name txt"; |
65 | private static final @NonNull String DEFINITION_NAME_XML = "name xml"; | |
ebc1e992 | 66 | private static final String SEP = ":"; |
c9b31f60 BH |
67 | private static final String CUSTOM_TXT_TRACE_TYPE_PREFIX = "custom.txt.trace" + SEP; |
68 | private static final String CUSTOM_XML_TRACE_TYPE_PREFIX = "custom.xml.trace" + SEP; | |
ebc1e992 PT |
69 | private static CustomTxtTraceDefinition fCustomTxtDefinition = new CustomTxtTraceDefinition(); |
70 | private static CustomXmlTraceDefinition fCustomXmlDefinition = new CustomXmlTraceDefinition(); | |
71 | static { | |
72 | fCustomTxtDefinition.categoryName = CATEGORY_TXT; | |
73 | fCustomTxtDefinition.definitionName = DEFINITION_NAME_TXT; | |
74 | fCustomXmlDefinition.categoryName = CATEGORY_XML; | |
75 | fCustomXmlDefinition.definitionName = DEFINITION_NAME_XML; | |
76 | fCustomXmlDefinition.rootInputElement = new CustomXmlInputElement(); | |
77 | } | |
78 | private static CustomTxtTrace fCustomTxtTrace = new CustomTxtTrace(fCustomTxtDefinition); | |
79 | private static CustomXmlTrace fCustomXmlTrace = new CustomXmlTrace(fCustomXmlDefinition); | |
53f17e49 GB |
80 | private static TmfEventType fCustomTxtEventType = new CustomTxtEventType(DEFINITION_NAME_TXT, null); |
81 | private static TmfEventType fCustomXmlEventType = new CustomXmlEventType(DEFINITION_NAME_XML, null); | |
ebc1e992 | 82 | private ITmfEventField fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, null); |
b2c971ec MK |
83 | private TmfEvent fEvent1 = new TmfEvent(TRACE, 0, TmfTimestamp.fromNanos(1), EVENT_TYPE, fContent); |
84 | private TmfEvent fEvent2 = new CustomTxtEvent(fCustomTxtDefinition, fCustomTxtTrace, TmfTimestamp.fromNanos(2), fCustomTxtEventType); | |
85 | private TmfEvent fEvent3 = new CustomXmlEvent(fCustomXmlDefinition, fCustomXmlTrace, TmfTimestamp.fromNanos(3), fCustomXmlEventType); | |
ebc1e992 PT |
86 | private TmfFilterTraceTypeNode fFilter; |
87 | ||
88 | @AfterClass | |
89 | public static void disposeCustomTraces() { | |
90 | fCustomTxtTrace.dispose(); | |
91 | fCustomXmlTrace.dispose(); | |
92 | } | |
93 | ||
94 | // ------------------------------------------------------------------------ | |
95 | // Tests | |
96 | // ------------------------------------------------------------------------ | |
97 | ||
98 | @Before | |
99 | public void createFilter() { | |
100 | fFilter = new TmfFilterTraceTypeNode(null); | |
101 | fFilterNode = fFilter; | |
102 | } | |
103 | ||
104 | @Test | |
105 | public void testMatches() { | |
106 | fFilter.setTraceClass(TmfTraceStub.class); | |
107 | assertTrue(fFilter.matches(fEvent1)); | |
108 | assertFalse(fFilter.matches(fEvent2)); | |
109 | assertFalse(fFilter.matches(fEvent3)); | |
110 | ||
111 | fFilter.setTraceClass(CustomTxtTrace.class); | |
c9b31f60 | 112 | fFilter.setTraceTypeId(CUSTOM_TXT_TRACE_TYPE_PREFIX + CATEGORY_TXT + SEP + DEFINITION_NAME_TXT); |
ebc1e992 PT |
113 | assertFalse(fFilter.matches(fEvent1)); |
114 | assertTrue(fFilter.matches(fEvent2)); | |
115 | assertFalse(fFilter.matches(fEvent3)); | |
116 | ||
117 | fFilter.setTraceClass(CustomXmlTrace.class); | |
c9b31f60 | 118 | fFilter.setTraceTypeId(CUSTOM_XML_TRACE_TYPE_PREFIX + CATEGORY_XML + SEP + DEFINITION_NAME_XML); |
ebc1e992 PT |
119 | assertFalse(fFilter.matches(fEvent1)); |
120 | assertFalse(fFilter.matches(fEvent2)); | |
121 | assertTrue(fFilter.matches(fEvent3)); | |
122 | ||
123 | fFilter.setTraceClass(CustomTxtTrace.class); | |
c9b31f60 | 124 | fFilter.setTraceTypeId(CUSTOM_TXT_TRACE_TYPE_PREFIX + CATEGORY_XML + SEP + DEFINITION_NAME_XML); |
ebc1e992 PT |
125 | assertFalse(fFilter.matches(fEvent1)); |
126 | assertFalse(fFilter.matches(fEvent2)); | |
127 | assertFalse(fFilter.matches(fEvent3)); | |
128 | } | |
129 | ||
130 | @Test | |
131 | public void testGetName() { | |
132 | assertEquals("getName()", "TRACETYPE", fFilter.getNodeName()); | |
133 | } | |
134 | ||
135 | @Test | |
136 | public void testGetValidChildren() { | |
137 | Set<String> validChildren = new HashSet<>(Arrays.asList( | |
138 | TmfFilterTraceTypeNode.NODE_NAME, | |
139 | TmfFilterAndNode.NODE_NAME, | |
140 | TmfFilterOrNode.NODE_NAME, | |
141 | TmfFilterContainsNode.NODE_NAME, | |
142 | TmfFilterEqualsNode.NODE_NAME, | |
143 | TmfFilterMatchesNode.NODE_NAME, | |
144 | TmfFilterCompareNode.NODE_NAME)); | |
145 | assertEquals("getValidChildren()", validChildren, new HashSet<>(fFilter.getValidChildren())); | |
146 | } | |
147 | } |