1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.scope
;
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
;
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
;
27 * @author Matthew Khouzam
29 public class LexicalScopeTest
{
35 public void testRoot() {
36 ILexicalScope scope
= ILexicalScope
.ROOT
;
41 * Test a more complex node
44 public void testComplexNode() {
45 ILexicalScope scope
= ILexicalScope
.STREAM_EVENT_CONTEXT
;
46 assertEquals("context", scope
.getName());
47 assertEquals("stream.event.context", scope
.getPath());
51 * Test that getChild returns the same items for event headers
54 public void testEventHeaders() {
55 ILexicalScope child
= ILexicalScope
.ROOT
.getChild("event");
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
);
64 assertNotNull(scope2
);
65 ILexicalScope id
= scope2
.getChild("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
);
73 ILexicalScope ts2
= v
.getChild("timestamp");
74 assert (ILexicalScope
.EVENT_HEADER_V_TIMESTAMP
== ts2
);
76 id
= v
.getChild("id");
77 assert (ILexicalScope
.EVENT_HEADER_V_ID
== id
);
79 ILexicalScope other
= v
.getChild("other");
84 * Test that getChild returns the same items for event headers
87 public void testFields() {
88 ILexicalScope child
= ILexicalScope
.ROOT
.getChild("fields");
90 ILexicalScope scope2
= child
.getChild("_ret");
91 ILexicalScope scope3
= child
.getChild("_tid");
92 ILexicalScope empty
= child
.getChild("other");
94 assertEquals(ILexicalScope
.FIELDS_RET
, scope2
);
95 // they should be the same
96 assert (ILexicalScope
.FIELDS_RET
== scope2
);
98 assertEquals(ILexicalScope
.FIELDS_TID
, scope3
);
99 // they should be the same
100 assert (ILexicalScope
.FIELDS_TID
== scope2
);
106 * Check contexts are not equals
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);
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());