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