Commit | Line | Data |
---|---|---|
a4fa4e36 MK |
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 | ||
f357bcd4 | 13 | package org.eclipse.tracecompass.ctf.core.tests.scope; |
a4fa4e36 MK |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
fbe6fa6f | 16 | import static org.junit.Assert.assertNotEquals; |
a4fa4e36 | 17 | import static org.junit.Assert.assertNotNull; |
fbe6fa6f | 18 | import static org.junit.Assert.assertNull; |
a4fa4e36 | 19 | |
fbe6fa6f | 20 | import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; |
f357bcd4 | 21 | import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; |
a4fa4e36 MK |
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 | |
fbe6fa6f MK |
35 | public void testRoot() { |
36 | ILexicalScope scope = ILexicalScope.ROOT; | |
a4fa4e36 MK |
37 | assertNotNull(scope); |
38 | } | |
39 | ||
40 | /** | |
41 | * Test a more complex node | |
42 | */ | |
43 | @Test | |
fbe6fa6f MK |
44 | public void testComplexNode() { |
45 | ILexicalScope scope = ILexicalScope.STREAM_EVENT_CONTEXT; | |
a4fa4e36 | 46 | assertEquals("context", scope.getName()); |
fbe6fa6f MK |
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()); | |
a4fa4e36 MK |
127 | } |
128 | } |