rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / scope / LexicalScopeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.ctf.core.tests.scope;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotEquals;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertNull;
19
20 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
21 import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope;
22 import org.junit.Test;
23
24 /**
25 * Lexical test
26 *
27 * @author Matthew Khouzam
28 */
29 public class LexicalScopeTest {
30
31 /**
32 * Root test
33 */
34 @Test
35 public void testRoot() {
36 ILexicalScope scope = ILexicalScope.ROOT;
37 assertNotNull(scope);
38 }
39
40 /**
41 * Test a more complex node
42 */
43 @Test
44 public void testComplexNode() {
45 ILexicalScope scope = ILexicalScope.STREAM_EVENT_CONTEXT;
46 assertEquals("context", scope.getName());
47 assertEquals("stream.event.context", scope.getPath());
48 }
49
50 /**
51 * Test that getChild returns the same items for event headers
52 */
53 @Test
54 public void testEventHeaders() {
55 ILexicalScope child = ILexicalScope.ROOT.getChild("event");
56 assertNotNull(child);
57 ILexicalScope scope2 = child.getChild("header");
58 ILexicalScope scope3 = ILexicalScope.ROOT.getChild("event.header");
59 assertEquals(ILexicalScope.EVENT_HEADER, scope2);
60 assertEquals(ILexicalScope.EVENT_HEADER, scope3);
61 // they should be the same
62 assert (ILexicalScope.EVENT_HEADER == scope2);
63
64 assertNotNull(scope2);
65 ILexicalScope id = scope2.getChild("id");
66 assertNotNull(id);
67 assert (ILexicalScope.EVENT_HEADER_ID == id);
68 ILexicalScope ts = scope2.getChild("v.timestamp");
69 ILexicalScope v = scope2.getChild("v");
70 assert (ILexicalScope.EVENT_HEADER_V_TIMESTAMP == ts);
71 assert (ILexicalScope.EVENT_HEADER_V == v);
72 assertNotNull(v);
73 ILexicalScope ts2 = v.getChild("timestamp");
74 assert (ILexicalScope.EVENT_HEADER_V_TIMESTAMP == ts2);
75 assertNotNull(v);
76 id = v.getChild("id");
77 assert (ILexicalScope.EVENT_HEADER_V_ID == id);
78 assertNotNull(v);
79 ILexicalScope other = v.getChild("other");
80 assertNull(other);
81 }
82
83 /**
84 * Test that getChild returns the same items for event headers
85 */
86 @Test
87 public void testFields() {
88 ILexicalScope child = ILexicalScope.ROOT.getChild("fields");
89 assertNotNull(child);
90 ILexicalScope scope2 = child.getChild("_ret");
91 ILexicalScope scope3 = child.getChild("_tid");
92 ILexicalScope empty = child.getChild("other");
93
94 assertEquals(ILexicalScope.FIELDS_RET, scope2);
95 // they should be the same
96 assert (ILexicalScope.FIELDS_RET == scope2);
97
98 assertEquals(ILexicalScope.FIELDS_TID, scope3);
99 // they should be the same
100 assert (ILexicalScope.FIELDS_TID == scope2);
101
102 assertNull(empty);
103 }
104
105 /**
106 * Check contexts are not equals
107 */
108 @Test
109 public void testNotEquals() {
110 assertNotEquals(ILexicalScope.CONTEXT, ILexicalScope.EVENT);
111 LexicalScope context = new LexicalScope(ILexicalScope.CONTEXT, "context");
112 LexicalScope otherContext = new LexicalScope(ILexicalScope.CONTEXT, "context2");
113 assertNotEquals(context, otherContext);
114 assertNotEquals(context, null);
115 }
116
117 /**
118 * Test to strings
119 */
120 @Test
121 public void testGetPath() {
122 ILexicalScope child = ILexicalScope.ROOT.getChild("fields");
123 assertNotNull(child);
124 ILexicalScope scope2 = child.getChild("_ret");
125 assertNotNull(scope2);
126 assertEquals("fields._ret", scope2.getPath());
127 }
128 }
This page took 0.041935 seconds and 5 git commands to generate.