custom.parsers: bug 494697 Define event names in custom parsers
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / filter / TmfFilterTraceTypeNodeTest.java
CommitLineData
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
13package org.eclipse.tracecompass.tmf.core.tests.filter;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertTrue;
18
19import java.util.Arrays;
20import java.util.HashSet;
21import java.util.Set;
22
53f17e49 23import org.eclipse.jdt.annotation.NonNull;
ebc1e992
PT
24import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
25import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
26import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
27import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
28import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
29import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
30import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
31import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
32import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
33import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
34import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
35import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
36import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEventType;
37import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
38import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
39import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
40import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEventType;
41import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement;
42import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
43import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
b2c971ec 44import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
ebc1e992
PT
45import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
46import org.junit.AfterClass;
47import org.junit.Before;
48import org.junit.Test;
49
50/**
51 * Test suite for the {@link TmfFilterTraceTypeNode} class.
52 *
53 * @author Patrick Tasse
54 */
55@SuppressWarnings("javadoc")
b0d2c558 56public 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}
This page took 0.078017 seconds and 5 git commands to generate.