rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / event / CTFEventDefinitionTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.tracecompass.ctf.core.tests.event;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.assertTrue;
18
19 import java.nio.ByteOrder;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
24 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
25 import org.eclipse.tracecompass.ctf.core.event.types.Definition;
26 import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
27 import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
28 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
29 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
30 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
31 import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
32 import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
33 import org.junit.Before;
34 import org.junit.Test;
35
36 /**
37 * Test the event definition
38 *
39 * @author Matthew Khouzam
40 *
41 */
42 public class CTFEventDefinitionTest {
43 List<EventDefinition> fixture;
44
45 /**
46 * Making a power set of configurations to test the event definition
47 */
48 @Before
49 public void init() {
50 fixture = new ArrayList<>();
51 IntegerDeclaration pidDec = IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8);
52 IntegerDeclaration ctxDec = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8);
53 IntegerDefinition pid = new IntegerDefinition(pidDec, null, "pid", 3);
54 IntegerDefinition pod = new IntegerDefinition(pidDec, null, "pod", 3);
55 IntegerDefinition ctx = new IntegerDefinition(pidDec, null, "ctx", 3);
56
57 StructDeclaration streamContextDec = new StructDeclaration(8);
58 streamContextDec.addField("pid", pidDec);
59 streamContextDec.addField("ctx", ctxDec);
60 StructDeclaration eventContextDec = new StructDeclaration(8);
61 eventContextDec.addField("pod", pidDec);
62 eventContextDec.addField("ctx", pidDec);
63 StructDeclaration fDec = new StructDeclaration(8);
64 EventDeclaration eventDeclaration = new EventDeclaration();
65
66 fDec.addField("pid", pidDec);
67 fDec.addField("ctx", ctxDec);
68 fDec.addField("pod", pidDec);
69
70 Definition[] sDefs = { pid, ctx };
71 Definition[] eDefs = { pod, ctx };
72 Definition[] fDefs = { pid, ctx, pod };
73
74 StructDeclaration pContextDec = new StructDeclaration(8);
75
76 StructDefinition sContext = new StructDefinition(streamContextDec, null, ILexicalScope.STREAM_PACKET_CONTEXT.getPath(), sDefs);
77 StructDefinition eContext = new StructDefinition(eventContextDec, null, ILexicalScope.STREAM_EVENT_CONTEXT.getPath(), eDefs);
78 StructDefinition pContext = new StructDefinition(pContextDec, null, ILexicalScope.FIELDS.getPath(), new Definition[0]);
79 StructDefinition fields = new StructDefinition(fDec, null, ILexicalScope.FIELDS.getPath(), fDefs);
80
81 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, null));
82 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, fields));
83 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, pContext, null));
84 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, pContext, fields));
85 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, null, null));
86 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, null, fields));
87 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, pContext, null));
88 fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, pContext, fields));
89 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, null, null));
90 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, null, fields));
91 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, pContext, null));
92 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, pContext, fields));
93 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, null, null));
94 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, null, fields));
95 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, pContext, null));
96 fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, pContext, fields));
97 }
98
99 /**
100 * Test all the events
101 */
102 @Test
103 public void testEvents() {
104 int i = 0;
105 for (EventDefinition ed : fixture) {
106 test(i, ed);
107 i++;
108 }
109 }
110
111 private static void test(int rank, EventDefinition ed) {
112 String title = "event #" + rank;
113 assertEquals(title, 100L, ed.getTimestamp());
114 ICompositeDefinition context = ed.getContext();
115 if (rank >= 4) {
116 assertNotNull(title, context);
117 if (rank >= 12) {
118 assertEquals(title, 3, context.getFieldNames().size());
119 } else {
120 assertEquals(title, 2, context.getFieldNames().size());
121 }
122
123 } else {
124 assertNull(title, context);
125 }
126 if (((rank / 4) % 2) == 1) {
127 assertNotNull(title, ed.getEventContext());
128 }else{
129 assertNull(title, ed.getEventContext());
130 }
131 if (rank % 2 == 1) {
132 assertNotNull(title, ed.getFields());
133 assertEquals(title, 3, ed.getFields().getFieldNames().size());
134 } else {
135 assertNull(title, ed.getFields());
136 }
137 assertTrue(title, ed.toString().startsWith("Event type: null" + System.getProperty("line.separator") + "Timestamp: 100"));
138 }
139
140 }
This page took 0.043225 seconds and 5 git commands to generate.