import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
import org.junit.Test;
import com.google.common.collect.ImmutableList;
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>ArrayDeclaration2Test</code> contains tests for the class
+ * <code>{@link ArrayDeclaration}</code>.
+ *
+ * @author Matthew Khouzam
+ * @version $Revision: 1.0 $
+ */
+public class ArrayDeclaration2Test {
+
+ private ArrayDeclaration fixture;
+
+ /**
+ * Perform pre-test initialization.
+ */
+ @Before
+ public void setUp() {
+ fixture = new ArrayDeclaration(1, new StringDeclaration());
+ }
+
+ /**
+ * Run the ArrayDeclaration(int,Declaration) constructor test.
+ */
+ @Test
+ public void testArrayDeclaration() {
+ int length = 1;
+ IDeclaration elemType = new StringDeclaration();
+ ArrayDeclaration result = new ArrayDeclaration(length, elemType);
+
+ assertNotNull(result);
+ String left = "[declaration] array[";
+ String right = result.toString().substring(0, left.length());
+ assertEquals(left, right);
+ assertEquals(1, result.getLength());
+ }
+
+ /**
+ * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
+ * test.
+ *
+ * @throws CTFReaderException
+ * error in the bitbuffer
+ */
+ @Test
+ public void testCreateDefinition() throws CTFReaderException {
+ String fieldName = "";
+ IDefinitionScope definitionScope = null;
+ AbstractArrayDefinition result;
+ byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+ ByteBuffer byb = ByteBuffer.wrap(array);
+ BitBuffer bb = new BitBuffer(byb);
+ result = fixture.createDefinition(definitionScope, fieldName, bb);
+
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the Declaration getElementType() method test.
+ */
+ @Test
+ public void testGetElementType() {
+ IDeclaration result = fixture.getElementType();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the int getLength() method test.
+ */
+ @Test
+ public void testGetLength() {
+ int result = fixture.getLength();
+ assertEquals(1, result);
+ }
+
+ /**
+ * Run the boolean isString() method test.
+ */
+ @Test
+ public void testIsString_ownDefs() {
+ // it's an array of strings, not a string
+ assertFalse(fixture.isString());
+ }
+
+ /**
+ * Run the boolean isString() method test.
+ */
+ @Test
+ public void testIsString_complex() {
+ final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
+ ArrayDeclaration ad = new ArrayDeclaration(0, id);
+
+ boolean result = ad.isString();
+
+ assertTrue(result);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString() {
+ String result = fixture.toString();
+ String left = "[declaration] array[";
+ String right = result.substring(0, left.length());
+
+ assertEquals(left, right);
+ }
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.*;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>ArrayDeclarationTest</code> contains tests for the class
- * <code>{@link ArrayDeclaration}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class ArrayDeclarationTest {
-
- private ArrayDeclaration fixture;
-
- /**
- * Perform pre-test initialization.
- */
- @Before
- public void setUp() {
- fixture = new ArrayDeclaration(1, new StringDeclaration());
- }
-
- /**
- * Run the ArrayDeclaration(int,Declaration) constructor test.
- */
- @Test
- public void testArrayDeclaration() {
- int length = 1;
- IDeclaration elemType = new StringDeclaration();
- ArrayDeclaration result = new ArrayDeclaration(length, elemType);
-
- assertNotNull(result);
- String left = "[declaration] array[";
- String right = result.toString().substring(0, left.length());
- assertEquals(left, right);
- assertEquals(1, result.getLength());
- }
-
- /**
- * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
- * test.
- *
- * @throws CTFReaderException
- * error in the bitbuffer
- */
- @Test
- public void testCreateDefinition() throws CTFReaderException {
- String fieldName = "";
- IDefinitionScope definitionScope = null;
- ArrayDefinition result;
- byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
- ByteBuffer byb = ByteBuffer.wrap(array);
- BitBuffer bb = new BitBuffer(byb);
- result = fixture.createDefinition(definitionScope, fieldName, bb);
-
- assertNotNull(result);
- }
-
- /**
- * Run the Declaration getElementType() method test.
- */
- @Test
- public void testGetElementType() {
- IDeclaration result = fixture.getElementType();
- assertNotNull(result);
- }
-
- /**
- * Run the int getLength() method test.
- */
- @Test
- public void testGetLength() {
- int result = fixture.getLength();
- assertEquals(1, result);
- }
-
- /**
- * Run the boolean isString() method test.
- */
- @Test
- public void testIsString_ownDefs() {
- // it's an array of strings, not a string
- assertFalse(fixture.isString());
- }
-
- /**
- * Run the boolean isString() method test.
- */
- @Test
- public void testIsString_complex() {
- final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
- ArrayDeclaration ad = new ArrayDeclaration(0, id);
-
- boolean result = ad.isString();
-
- assertTrue(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString() {
- String result = fixture.toString();
- String left = "[declaration] array[";
- String right = result.substring(0, left.length());
-
- assertEquals(left, right);
- }
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * The class <code>ArrayDefinition2Test</code> contains tests for the class
+ * <code>{@link ArrayDefinition}</code>.
+ *
+ */
+public class ArrayDefinition2Test {
+
+ @NonNull private CTFTrace trace = new CTFTrace();
+ private ArrayDefinition charArrayFixture;
+ private ArrayDefinition stringArrayFixture;
+ private ArrayDefinition longArrayFixture;
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * structDef shouldn't be null after parsing the CTFTraceReader object, so
+ * we can ignore the warning.
+ */
+ @Before
+ public void setUp() {
+ charArrayFixture = createCharArray();
+ stringArrayFixture = createStringArray();
+ longArrayFixture = createLongArray();
+ }
+
+ private ArrayDefinition createLongArray() {
+ IntegerDeclaration decl = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none", 8);
+ List<Definition> defs = createIntDefs(10, 32);
+ ArrayDefinition temp = setUpDeclaration(decl, defs);
+ return temp;
+ }
+
+ private ArrayDefinition createCharArray() {
+ IntegerDeclaration decl = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none", 8);
+ List<Definition> defs = createIntDefs(4, 8);
+ ArrayDefinition temp = setUpDeclaration(decl, defs);
+ return temp;
+ }
+
+ private ArrayDefinition createStringArray() {
+ StringDeclaration strDecl = new StringDeclaration();
+ List<Definition> defs = createDefs();
+ ArrayDefinition temp = setUpDeclaration(strDecl, defs);
+ return temp;
+ }
+
+ private ArrayDefinition setUpDeclaration(IDeclaration decl,
+ @NonNull List<Definition> defs) {
+ ArrayDeclaration ad = new ArrayDeclaration(0, decl);
+ ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs);
+ return temp;
+ }
+
+ private @NonNull
+ static List<Definition> createIntDefs(int size, int bits) {
+ List<Definition> defs = new ArrayList<>(size);
+ for (int i = 0; i < size; i++) {
+ String content = "test" + i;
+ defs.add(new IntegerDefinition(IntegerDeclaration.createDeclaration(bits, false,
+ 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content, i));
+ }
+ return defs;
+ }
+
+ private @NonNull
+ static List<Definition> createDefs() {
+ int size = 4;
+ List<Definition> defs = new ArrayList<>();
+ for (int i = 0; i < size; i++) {
+ String content = "test" + i;
+ defs.add(new StringDefinition(
+ new StringDeclaration(Encoding.UTF8), null, content, content));
+ }
+ return defs;
+ }
+
+ /**
+ * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
+ * constructor test.
+ */
+ @Test
+ public void testArrayDefinition_baseDeclaration() {
+ ArrayDeclaration declaration = (ArrayDeclaration) charArrayFixture.getDeclaration();
+ String fieldName = "";
+
+ @SuppressWarnings("null")
+ ArrayDefinition result = new ArrayDefinition(declaration, this.trace, fieldName, Arrays.asList(new Definition[0]));
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
+ * constructor test.
+ */
+ @Test
+ public void testArrayDefinition_newDeclaration() {
+ ArrayDeclaration declaration = new ArrayDeclaration(0,
+ new StringDeclaration());
+ IDefinitionScope definitionScope = getDefinitionScope();
+
+ String fieldName = "";
+ @SuppressWarnings("null")
+ ArrayDefinition result = new ArrayDefinition(declaration, definitionScope, fieldName , Arrays.asList(new Definition[0]));
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the ArrayDeclaration getDeclaration() method test.
+ */
+ @Test
+ public void testGetDeclaration() {
+ ArrayDeclaration result = (ArrayDeclaration) charArrayFixture.getDeclaration();
+
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the Definition getDefinitions().get(int) method test.
+ */
+ @Test
+ public void testgetElem_noDefs() {
+ int i = 0;
+ Definition result = charArrayFixture.getDefinitions().get(i);
+
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the Definition getDefinitions().get(int) method test.
+ */
+ @Test
+ public void testgetElem_withDefs() {
+ List<Definition> defs = createDefs();
+ IDefinitionScope definitionScope = getDefinitionScope();
+ ArrayDefinition ad = new ArrayDefinition((CompoundDeclaration) charArrayFixture.getDeclaration(), definitionScope, "test", defs);
+ int j = 1;
+
+ Definition result = ad.getDefinitions().get(j);
+
+ assertNotNull(result);
+ }
+
+ @NonNull private static IDefinitionScope getDefinitionScope() {
+ return new IDefinitionScope() {
+
+ @Override
+ public Definition lookupDefinition(String lookupPath) {
+ return null;
+ }
+
+ @Override
+ public LexicalScope getScopePath() {
+ return null;
+ }
+ };
+ }
+
+ /**
+ * Run the void read(BitBuffer) method test.
+ *
+ * @throws CTFReaderException
+ * error
+ */
+ @Test
+ public void testRead_noDefs() throws CTFReaderException {
+ BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
+ charArrayFixture.getDeclaration().createDefinition(null, "test", input);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString_char() {
+ String result = charArrayFixture.toString();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString_long() {
+ String result = longArrayFixture.toString();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString_string() {
+ String result = stringArrayFixture.toString();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString_withDefs() {
+ String result = charArrayFixture.toString();
+
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToStringStringArray() {
+ String result = stringArrayFixture.toString();
+
+ assertNotNull(result);
+ }
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>ArrayDefinitionTest</code> contains tests for the class
- * <code>{@link ArrayDefinition}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class ArrayDefinitionTest {
-
- @NonNull private CTFTrace trace = new CTFTrace();
- private ArrayDefinition charArrayFixture;
- private ArrayDefinition stringArrayFixture;
- private ArrayDefinition longArrayFixture;
-
- /**
- * Perform pre-test initialization.
- *
- * structDef shouldn't be null after parsing the CTFTraceReader object, so
- * we can ignore the warning.
- */
- @Before
- public void setUp() {
- charArrayFixture = createCharArray();
- stringArrayFixture = createStringArray();
- longArrayFixture = createLongArray();
- }
-
- private ArrayDefinition createLongArray() {
- IntegerDeclaration decl = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none", 8);
- List<Definition> defs = createIntDefs(10, 32);
- ArrayDefinition temp = setUpDeclaration(decl, defs);
- return temp;
- }
-
- private ArrayDefinition createCharArray() {
- IntegerDeclaration decl = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none", 8);
- List<Definition> defs = createIntDefs(4, 8);
- ArrayDefinition temp = setUpDeclaration(decl, defs);
- return temp;
- }
-
- private ArrayDefinition createStringArray() {
- StringDeclaration strDecl = new StringDeclaration();
- List<Definition> defs = createDefs();
- ArrayDefinition temp = setUpDeclaration(strDecl, defs);
- return temp;
- }
-
- private ArrayDefinition setUpDeclaration(IDeclaration decl,
- @NonNull List<Definition> defs) {
- ArrayDeclaration ad = new ArrayDeclaration(0, decl);
- ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs);
- return temp;
- }
-
- private @NonNull
- static List<Definition> createIntDefs(int size, int bits) {
- List<Definition> defs = new ArrayList<>(size);
- for (int i = 0; i < size; i++) {
- String content = "test" + i;
- defs.add(new IntegerDefinition(IntegerDeclaration.createDeclaration(bits, false,
- 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content, i));
- }
- return defs;
- }
-
- private @NonNull
- static List<Definition> createDefs() {
- int size = 4;
- List<Definition> defs = new ArrayList<>();
- for (int i = 0; i < size; i++) {
- String content = "test" + i;
- defs.add(new StringDefinition(
- new StringDeclaration(Encoding.UTF8), null, content, content));
- }
- return defs;
- }
-
- /**
- * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
- * constructor test.
- */
- @Test
- public void testArrayDefinition_baseDeclaration() {
- ArrayDeclaration declaration = charArrayFixture.getDeclaration();
- String fieldName = "";
-
- @SuppressWarnings("null")
- ArrayDefinition result = new ArrayDefinition(declaration, this.trace, fieldName, Arrays.asList(new Definition[0]));
- assertNotNull(result);
- }
-
- /**
- * Run the ArrayDefinition(ArrayDeclaration,DefinitionScope,String)
- * constructor test.
- */
- @Test
- public void testArrayDefinition_newDeclaration() {
- ArrayDeclaration declaration = new ArrayDeclaration(0,
- new StringDeclaration());
- IDefinitionScope definitionScope = getDefinitionScope();
-
- String fieldName = "";
- @SuppressWarnings("null")
- ArrayDefinition result = new ArrayDefinition(declaration, definitionScope, fieldName , Arrays.asList(new Definition[0]));
- assertNotNull(result);
- }
-
- /**
- * Run the ArrayDeclaration getDeclaration() method test.
- */
- @Test
- public void testGetDeclaration() {
- ArrayDeclaration result = charArrayFixture.getDeclaration();
-
- assertNotNull(result);
- }
-
- /**
- * Run the Definition getElem(int) method test.
- */
- @Test
- public void testGetElem_noDefs() {
- int i = 0;
- Definition result = charArrayFixture.getElem(i);
-
- assertNotNull(result);
- }
-
- /**
- * Run the Definition getElem(int) method test.
- */
- @Test
- public void testGetElem_withDefs() {
- List<Definition> defs = createDefs();
- IDefinitionScope definitionScope = getDefinitionScope();
- ArrayDefinition ad = new ArrayDefinition(charArrayFixture.getDeclaration(), definitionScope, "test", defs);
- int j = 1;
-
- Definition result = ad.getElem(j);
-
- assertNotNull(result);
- }
-
- @NonNull private static IDefinitionScope getDefinitionScope() {
- return new IDefinitionScope() {
-
- @Override
- public Definition lookupDefinition(String lookupPath) {
- return null;
- }
-
- @Override
- public LexicalScope getScopePath() {
- return null;
- }
- };
- }
-
- /**
- * Run the void read(BitBuffer) method test.
- *
- * @throws CTFReaderException
- * error
- */
- @Test
- public void testRead_noDefs() throws CTFReaderException {
- BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
- charArrayFixture.getDeclaration().createDefinition(null, "test", input);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString_char() {
- String result = charArrayFixture.toString();
- assertNotNull(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString_long() {
- String result = longArrayFixture.toString();
- assertNotNull(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString_string() {
- String result = stringArrayFixture.toString();
- assertNotNull(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString_withDefs() {
- String result = charArrayFixture.toString();
-
- assertNotNull(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToStringStringArray() {
- String result = stringArrayFixture.toString();
-
- assertNotNull(result);
- }
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * The class <code>SequenceDeclarationTest</code> contains tests for the class
+ * <code>{@link SequenceDeclaration}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class SequenceDeclaration2Test {
+
+ @NonNull private static final String FIELD_NAME = "LengthName";
+
+ private SequenceDeclaration fixture;
+ @NonNull private BitBuffer input = new BitBuffer();
+
+ @Before
+ public void setUp() {
+ fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration());
+ byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+ ByteBuffer byb = ByteBuffer.wrap(array);
+ input = new BitBuffer(byb);
+ }
+
+ /**
+ * Run the SequenceDeclaration(String,Declaration) constructor test.
+ */
+ @Test
+ public void testSequenceDeclaration() {
+ String lengthName = "";
+ IDeclaration elemType = new StringDeclaration();
+
+ SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType);
+ assertNotNull(result);
+ String string = "[declaration] sequence[";
+ assertEquals(string, result.toString().substring(0, string.length()));
+ }
+
+ /**
+ * Run the SequenceDefinition createDefinition(DefinitionScope,String)
+ * method test.
+ *
+ * @throws CTFReaderException
+ * an error in the bitbuffer
+ */
+ @Test
+ public void testCreateDefinition() throws CTFReaderException {
+ long seqLen = 2;
+ IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
+ StructDeclaration structDec = new StructDeclaration(0);
+ structDec.addField(FIELD_NAME, id);
+ StructDefinition structDef = new StructDefinition(
+ structDec,
+ null,
+ "x",
+ ImmutableList.of(FIELD_NAME),
+ new Definition[] {
+ new IntegerDefinition(
+ id,
+ null,
+ FIELD_NAME,
+ seqLen)
+ });
+ AbstractArrayDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the Declaration getElementType() method test.
+ */
+ @Test
+ public void testGetElementType() {
+ IDeclaration result = fixture.getElementType();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString() {
+ String result = fixture.toString();
+ String left = "[declaration] sequence[";
+ assertEquals(left, result.substring(0, left.length()));
+ }
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * The class <code>SequenceDeclarationTest</code> contains tests for the class
- * <code>{@link SequenceDeclaration}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class SequenceDeclarationTest {
-
- @NonNull private static final String FIELD_NAME = "LengthName";
-
- private SequenceDeclaration fixture;
- @NonNull private BitBuffer input = new BitBuffer();
-
- @Before
- public void setUp() {
- fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration());
- byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
- ByteBuffer byb = ByteBuffer.wrap(array);
- input = new BitBuffer(byb);
- }
-
- /**
- * Run the SequenceDeclaration(String,Declaration) constructor test.
- */
- @Test
- public void testSequenceDeclaration() {
- String lengthName = "";
- IDeclaration elemType = new StringDeclaration();
-
- SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType);
- assertNotNull(result);
- String string = "[declaration] sequence[";
- assertEquals(string, result.toString().substring(0, string.length()));
- }
-
- /**
- * Run the SequenceDefinition createDefinition(DefinitionScope,String)
- * method test.
- *
- * @throws CTFReaderException
- * an error in the bitbuffer
- */
- @Test
- public void testCreateDefinition() throws CTFReaderException {
- long seqLen = 2;
- IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
- StructDeclaration structDec = new StructDeclaration(0);
- structDec.addField(FIELD_NAME, id);
- StructDefinition structDef = new StructDefinition(
- structDec,
- null,
- "x",
- ImmutableList.of(FIELD_NAME),
- new Definition[] {
- new IntegerDefinition(
- id,
- null,
- FIELD_NAME,
- seqLen)
- });
- SequenceDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
- assertNotNull(result);
- }
-
- /**
- * Run the Declaration getElementType() method test.
- */
- @Test
- public void testGetElementType() {
- IDeclaration result = fixture.getElementType();
- assertNotNull(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString() {
- String result = fixture.toString();
- String left = "[declaration] sequence[";
- assertEquals(left, result.substring(0, left.length()));
- }
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.types;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.nio.ByteOrder;
+
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ByteArrayDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * The class <code>SequenceDefinition2Test</code> contains tests for the class
+ * <code>{@link SequenceDefinition2}</code>.
+ *
+ * @author ematkho
+ * @version $Revision: 1.0 $
+ */
+@SuppressWarnings("javadoc")
+public class SequenceDefinition2Test {
+
+ private ByteArrayDefinition fixture;
+ private final static int seqLen = 15;
+
+ private static ImmutableList<String> wrap(String s) {
+ return ImmutableList.<String> builder().add(s).build();
+ }
+
+ /**
+ * Perform pre-test initialization.
+ *
+ * @throws CTFReaderException
+ */
+ @Before
+ public void setUp() throws CTFReaderException {
+ fixture = initString();
+ }
+
+ private static ByteArrayDefinition initString() throws CTFReaderException {
+ StructDeclaration structDec;
+ StructDefinition structDef;
+
+ int len = 8;
+ IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
+ String lengthName = "LengthName";
+ structDec = new StructDeclaration(0);
+ structDec.addField(lengthName, id);
+
+ structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
+
+ SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
+ BitBuffer input = new BitBuffer(
+ java.nio.ByteBuffer.allocateDirect(seqLen * len));
+ for (int i = 0; i < seqLen; i++) {
+ input.putInt(i);
+ }
+
+ ByteArrayDefinition ret = (ByteArrayDefinition) sd.createDefinition(structDef, "TestX", input);
+ assertNotNull(ret);
+ return ret;
+ }
+
+ /**
+ * Run the FixedStringDefinition(SequenceDeclaration,DefinitionScope,String)
+ * constructor test.
+ */
+ @Test
+ public void testFixedStringDefinition() {
+ assertNotNull(fixture);
+ }
+
+ /**
+ * Run the SequenceDeclaration getDeclaration() method test.
+ */
+ @Test
+ public void testGetDeclaration() {
+ SequenceDeclaration result = (SequenceDeclaration) fixture.getDeclaration();
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the Definition getElem(int) method test.
+ */
+ @Test
+ public void testGetElem() {
+ int i = 1;
+ Definition result = fixture.getDefinitions().get(i);
+ assertNotNull(result);
+ }
+
+ /**
+ * Run the String toString() method test.
+ */
+ @Test
+ public void testToString() {
+ String result = fixture.toString();
+ assertNotNull(result);
+ }
+
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013 Ericsson
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.tests.types;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.nio.ByteOrder;
-
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * The class <code>SequenceDefinitionTest</code> contains tests for the class
- * <code>{@link SequenceDefinition}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-@SuppressWarnings("javadoc")
-public class SequenceDefinitionTest {
-
- private SequenceDefinition fixture;
- private final static int seqLen = 15;
-
- private static ImmutableList<String> wrap(String s) {
- return ImmutableList.<String> builder().add(s).build();
- }
-
- /**
- * Perform pre-test initialization.
- *
- * @throws CTFReaderException
- */
- @Before
- public void setUp() throws CTFReaderException {
- StructDeclaration structDec;
- StructDefinition structDef;
-
- IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
- String lengthName = "LengthName";
- structDec = new StructDeclaration(0);
- structDec.addField(lengthName, id);
- structDef = new StructDefinition(structDec, null, "x",
- wrap(lengthName),
- new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
-
- SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
- BitBuffer input = new BitBuffer(
- java.nio.ByteBuffer.allocateDirect(seqLen * 8));
- for (int i = 0; i < seqLen; i++) {
- input.putInt(i);
- }
-
- fixture = sd.createDefinition(structDef, "TestX", input);
- assert (fixture != null);
- }
-
- private static SequenceDefinition initNonString() throws CTFReaderException {
- StructDeclaration structDec;
- StructDefinition structDef;
-
- int len = 32;
- IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
- String lengthName = "LengthName";
- structDec = new StructDeclaration(0);
- structDec.addField(lengthName, id);
-
- structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
-
- SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
- BitBuffer input = new BitBuffer(
- java.nio.ByteBuffer.allocateDirect(seqLen * len));
- for (int i = 0; i < seqLen; i++) {
- input.putInt(i);
- }
-
- SequenceDefinition ret = sd.createDefinition(structDef, "TestX", input);
- assertNotNull(ret);
- return ret;
- }
-
- /**
- * Run the SequenceDefinition(SequenceDeclaration,DefinitionScope,String)
- * constructor test.
- */
- @Test
- public void testSequenceDefinition() {
- assertNotNull(fixture);
- }
-
- /**
- * Run the SequenceDeclaration getDeclaration() method test.
- */
- @Test
- public void testGetDeclaration() {
- SequenceDeclaration result = fixture.getDeclaration();
- assertNotNull(result);
- }
-
- /**
- * Run the Definition getElem(int) method test.
- */
- @Test
- public void testGetElem() {
- int i = 1;
- Definition result = fixture.getElem(i);
- assertNotNull(result);
- }
-
- /**
- * Run the int getLength() method test.
- */
- @Test
- public void testGetLength() {
- int result = fixture.getLength();
-
- assertEquals(seqLen, result);
- }
-
- /**
- * Run the boolean isString() method test.
- */
- @Test
- public void testIsString() {
- boolean result = fixture.getDeclaration().isString();
- assertTrue(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString() {
- String result = fixture.toString();
- assertNotNull(result);
- }
-
- /**
- * Run the String toString() method test.
- */
- @Test
- public void testToString_nonString() throws Exception {
- fixture = initNonString();
- String result = fixture.toString();
- assertNotNull(result);
- }
-}
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
import org.junit.Before;
import org.junit.Test;
@Test
public void testLookupArray() {
String name = INT_ID;
- ArrayDefinition result = fixture.lookupArray(name);
-
+ AbstractArrayDefinition result = fixture.lookupArray2(name);
assertNull(result);
}
* Run the SequenceDefinition lookupSequence(String) method test.
*/
@Test
- public void testLookupSequence() {
+ public void testLookupFixedStringDefinition() {
String name = SEQUENCE_ID;
- SequenceDefinition result = fixture.lookupSequence(name);
+ AbstractArrayDefinition result = fixture.lookupArray2(name);
assertNotNull(result);
}
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- ArrayDeclarationTest.class,
- ArrayDefinitionTest.class,
+ ArrayDeclaration2Test.class,
+ ArrayDefinition2Test.class,
DefinitionTest.class,
EnumDeclarationTest.class,
EnumDefinitionTest.class,
IntegerDeclarationTest.class,
IntegerDefinitionTest.class,
IntegerEndiannessTest.class,
- SequenceDeclarationTest.class,
- SequenceDefinitionTest.class,
+ SequenceDeclaration2Test.class,
+ SequenceDefinition2Test.class,
StringDeclarationTest.class,
StringDefinitionTest.class,
StructDeclarationTest.class,
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
import org.junit.Before;
import org.junit.Test;
*/
@Test
public void testLookupArray() {
- ArrayDefinition result = fixture.lookupArray(ENUM_3);
+ AbstractArrayDefinition result = fixture.lookupArray2(ENUM_3);
assertNull(result);
}
assertNull(result);
}
- /**
- * Run the SequenceDefinition lookupSequence(String) method test.
- */
- @Test
- public void testLookupSequence_1() {
- SequenceDefinition result = fixture.lookupSequence(ENUM_4);
- assertNull(result);
- }
-
/**
* Run the StringDefinition lookupString(String) method test.
*/
org.eclipse.linuxtools.internal.ctf.core.event;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
org.eclipse.linuxtools.internal.ctf.core.event.metadata;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
+ org.eclipse.linuxtools.internal.ctf.core.event.types;x-friends:="org.eclipse.linuxtools.ctf.core.tests,org.eclipse.linuxtools.tmf.ctf.core,org.eclipse.linuxtools.tmf.ctf.core.tests",
org.eclipse.linuxtools.internal.ctf.core.trace;x-friends:="org.eclipse.linuxtools.ctf.core.tests"
Import-Package: com.google.common.base,
com.google.common.collect,
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+
+/**
+ * Array definition, used for compound definitions and fixed length strings
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public abstract class AbstractArrayDefinition extends Definition {
+
+ /**
+ * Constructor
+ *
+ * @param declaration
+ * the event declaration
+ *
+ * @param definitionScope
+ * the definition is in a scope, (normally a struct) what is it?
+ * @param fieldName
+ * the name of the definition. (it is a field in the parent
+ * scope)
+ */
+ public AbstractArrayDefinition(IDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName) {
+ super(declaration, definitionScope, fieldName);
+ }
+
+ /**
+ * Get the defintions, an array is a collection of definitions
+ *
+ * @return the definitions
+ */
+ public abstract List<Definition> getDefinitions();
+
+}
\ No newline at end of file
* can refer to any type not containing the type of the array being declared (no
* circular dependency). The length is the number of elements in an array.
*
+ * @deprecated use {@link org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration}
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
+@Deprecated
public class ArrayDeclaration extends Declaration {
// ------------------------------------------------------------------------
/**
* @since 3.0
*/
+ @Deprecated
@Override
public ArrayDefinition createDefinition(IDefinitionScope definitionScope,
@NonNull String fieldName, BitBuffer input) throws CTFReaderException {
* can refer to any type not containing the type of the array being declared (no
* circular dependency). The length is the number of elements in an array.
*
+ * @deprecated use {@link AbstractArrayDefinition}
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
@NonNullByDefault
+@Deprecated
public final class ArrayDefinition extends Definition {
// ------------------------------------------------------------------------
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.types;
+
+
+/**
+ * Parent of sequences and arrays
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public abstract class CompoundDeclaration extends Declaration {
+
+ /**
+ * Get the element type
+ *
+ * @return the type of element in the array
+ */
+ public abstract IDeclaration getElementType();
+
+}
fBase = base;
@SuppressWarnings("null")
- @NonNull ByteOrder actualByteOrder = (byteOrder == null ? ByteOrder.nativeOrder() : byteOrder);
+ @NonNull
+ ByteOrder actualByteOrder = (byteOrder == null ? ByteOrder.nativeOrder() : byteOrder);
fByteOrder = actualByteOrder;
fEncoding = encoding;
return (fLength == 8) && (fEncoding != Encoding.NONE);
}
+ /**
+ * Is the integer an unsigned byte (8 bits and no sign)?
+ *
+ * @return is the integer an unsigned byte
+ * @since 3.1
+ */
+ public boolean isUnsignedByte() {
+ return (fLength == 8) && (!fSigned);
+ }
+
/**
* Get the length in bits for this integer
*
*/
@SuppressWarnings("null")
- @NonNull BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).subtract(BigInteger.ONE);
+ @NonNull
+ BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).subtract(BigInteger.ONE);
return ret;
}
public BigInteger getMinValue() {
if (!fSigned) {
@SuppressWarnings("null")
- @NonNull BigInteger ret = BigInteger.ZERO;
+ @NonNull
+ BigInteger ret = BigInteger.ZERO;
return ret;
}
* (1 << N).
*/
@SuppressWarnings("null")
- @NonNull BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).negate();
+ @NonNull
+ BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).negate();
return ret;
}
*
* @param name
* the name of the array
- * @return the array or null if a definition is not found or it does not
- * match the desired datatype.
+ * @return the array or null.
+ */
+ @Nullable
+ public AbstractArrayDefinition lookupArray2(String name){
+ Definition def = lookupDefinition(name);
+ return (AbstractArrayDefinition) ((def instanceof AbstractArrayDefinition) ? def : null);
+ }
+
+ /**
+ * Lookup an array in a struct. If the name returns a non-array (like an
+ * int) then the method returns null
+ *
+ * @param name
+ * the name of the array
+ * @return the array or null.
*/
+ @Deprecated
@Nullable
public ArrayDefinition lookupArray(String name) {
Definition def = lookupDefinition(name);
* match the desired datatype.
* @since 3.0
*/
+ @Deprecated
@Nullable
public SequenceDefinition lookupSequence(String name) {
Definition def = lookupDefinition(name);
*
* An array where the size is fixed but declared in the trace, unlike array
* where it is declared with a literal
- *
+ * @deprecated use {@link org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration}
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
+@Deprecated
public class SequenceDeclaration extends Declaration {
// ------------------------------------------------------------------------
* An array where the size is fixed but declared in the trace, unlike array
* where it is declared with a literal
*
+ * @deprecated use {@link AbstractArrayDefinition}
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
+@Deprecated
public final class SequenceDefinition extends Definition {
- // TODO: investigate merging with arraydefinition
-
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.internal.ctf.core.event.CTFCallsiteComparator;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
/**
* A CTF trace on the file system.
import java.util.UUID;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
/**
/**
* Performs an unsigned long comparison on two unsigned long numbers.
*
- * <strong> As Java does not support unsigned types and arithmetic, parameters
- * are received encoded as a signed long (two-complement) but the
- * operation is an unsigned comparator.</strong>
+ * <strong> As Java does not support unsigned types and arithmetic,
+ * parameters are received encoded as a signed long (two-complement) but the
+ * operation is an unsigned comparator.</strong>
*
* @param left
* Left operand of the comparator.
* @return the UUID
* @throws CTFReaderException
* if the definition contains less than 16 elements
- * @since 3.0
+ * @since 3.1
*/
- public static UUID getUUIDfromDefinition(ArrayDefinition uuidDef) throws CTFReaderException {
+ public static UUID getUUIDfromDefinition(AbstractArrayDefinition uuidDef) throws CTFReaderException {
+ byte[] uuidArray = new byte[16];
+ IDeclaration declaration = uuidDef.getDeclaration();
+ if (!(declaration instanceof CompoundDeclaration)) {
+ throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$
+ }
+ CompoundDeclaration uuidDec = (CompoundDeclaration) declaration;
+
+ IDeclaration uuidElem = uuidDec.getElementType();
+ if (!(uuidElem instanceof IntegerDeclaration)) {
+ throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$
+ }
+ IntegerDeclaration intUuidElem = (IntegerDeclaration) uuidElem;
+ if (!intUuidElem.isUnsignedByte()) {
+ throw new CTFReaderException("UUID must be a sequence of unsigned bytes"); //$NON-NLS-1$
+ }
+ for (int i = 0; i < uuidArray.length; i++) {
+ IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getDefinitions().get(i);
+ if (uuidByteDef == null) {
+ throw new CTFReaderException("UUID incomplete, only " + i + " bytes available"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ uuidArray[i] = (byte) uuidByteDef.getValue();
+ }
+
+ UUID uuid = Utils.makeUUID(uuidArray);
+ return uuid;
+ }
+
+ /**
+ * Gets a UUID from an array defintion
+ *
+ * @param uuidDef
+ * the array defintions, must contain integer bytes
+ * @return the UUID
+ * @throws CTFReaderException
+ * if the definition contains less than 16 elements
+ * @since 3.1
+ * @deprecated use
+ * {@link Utils#getUUIDfromDefinition(AbstractArrayDefinition uuidDef)}
+ */
+ @Deprecated
+ public static UUID getUUIDfromDefinition(org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition uuidDef) throws CTFReaderException {
byte[] uuidArray = new byte[16];
for (int i = 0; i < uuidArray.length; i++) {
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.CTFClock;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
-import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.parser.CTFParser;
import org.eclipse.linuxtools.internal.ctf.core.Activator;
import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
/**
* IOStructGen
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+/**
+ * A CTF array declaration
+ *
+ * Arrays are fixed-length. Their length is declared in the type declaration
+ * within the meta-data. They contain an array of "inner type" elements, which
+ * can refer to any type not containing the type of the array being declared (no
+ * circular dependency). The length is the number of elements in an array.
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public final class ArrayDeclaration extends CompoundDeclaration {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private final int fLength;
+ private final IDeclaration fElemType;
+
+ /**
+ * <pre>
+ * Cache where we can pre-generate the children names
+ * Key: parent name
+ * Value: children names
+ * ex: field → {field[0], field[1], … field[n]}
+ * </pre>
+ *
+ * TODO: investigate performance
+ */
+ private final ArrayListMultimap<String, String> fChildrenNames = ArrayListMultimap.create();
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param length
+ * how many elements in the array
+ * @param elemType
+ * what type of element is in the array
+ */
+ public ArrayDeclaration(int length, IDeclaration elemType) {
+ fLength = length;
+ fElemType = elemType;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ @Override
+ public IDeclaration getElementType() {
+ return fElemType;
+ }
+
+ /**
+ * Get the length of the array
+ *
+ * @return the length of the array
+ */
+ public int getLength() {
+ return fLength;
+ }
+
+ /**
+ * Sometimes, strings are encoded as an array of 1-byte integers (each one
+ * being an UTF-8 byte).
+ *
+ * @return true if this array is in fact an UTF-8 string. false if it's a
+ * "normal" array of generic Definition's.
+ */
+ public boolean isString() {
+ if (fElemType instanceof IntegerDeclaration) {
+ /*
+ * If the first byte is a "character", we'll consider the whole
+ * array a character string.
+ */
+ IntegerDeclaration elemInt = (IntegerDeclaration) fElemType;
+ if (elemInt.isCharacter()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public long getAlignment() {
+ return getElementType().getAlignment();
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ @Override
+ public AbstractArrayDefinition createDefinition(IDefinitionScope definitionScope,
+ @NonNull String fieldName, BitBuffer input) throws CTFReaderException {
+ alignRead(input);
+ if (isString()) {
+ byte[] data = new byte[fLength];
+ input.get(data);
+ return new ByteArrayDefinition(this, definitionScope, fieldName, data);
+ }
+ List<Definition> definitions = read(input, definitionScope, fieldName);
+ return new ArrayDefinition(this, definitionScope, fieldName, definitions);
+ }
+
+ @Override
+ public String toString() {
+ /* Only used for debugging */
+ return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
+ }
+
+ @NonNull
+ private List<Definition> read(@NonNull BitBuffer input, IDefinitionScope definitionScope, String fieldName) throws CTFReaderException {
+ Builder<Definition> definitions = new ImmutableList.Builder<>();
+ if (!fChildrenNames.containsKey(fieldName)) {
+ for (int i = 0; i < fLength; i++) {
+ fChildrenNames.put(fieldName, fieldName + '[' + i + ']');
+ }
+ }
+ List<String> elemNames = fChildrenNames.get(fieldName);
+ for (int i = 0; i < fLength; i++) {
+ String name = elemNames.get(i);
+ if (name == null) {
+ throw new IllegalStateException();
+ }
+ definitions.add(fElemType.createDefinition(definitionScope, name, input));
+ }
+ @SuppressWarnings("null")
+ @NonNull ImmutableList<Definition> ret = definitions.build();
+ return ret;
+ }
+
+ @Override
+ public int getMaximumSize() {
+ long val = (long) fLength * fElemType.getMaximumSize();
+ return (int) Math.min(Integer.MAX_VALUE, val);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * A CTF array definition
+ *
+ * Arrays are fixed-length. Their length is declared in the type declaration
+ * within the meta-data. They contain an array of "inner type" elements, which
+ * can refer to any type not containing the type of the array being declared (no
+ * circular dependency). The length is the number of elements in an array.
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public final class ArrayDefinition extends AbstractArrayDefinition {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private final ImmutableList<Definition> fDefinitions;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param declaration
+ * the parent declaration
+ * @param definitionScope
+ * the parent scope
+ * @param fieldName
+ * the field name
+ * @param definitions
+ * the content of the array
+ */
+ public ArrayDefinition(CompoundDeclaration declaration,
+ @Nullable IDefinitionScope definitionScope,
+ String fieldName,
+ List<Definition> definitions) {
+ super(declaration, definitionScope, fieldName);
+ @SuppressWarnings("null")
+ @NonNull ImmutableList<Definition> list = ImmutableList.copyOf(definitions);
+ fDefinitions = list;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ @Override
+ public List<Definition> getDefinitions() {
+ return fDefinitions;
+ }
+
+ /**
+ * Get the the number of elements in the array
+ *
+ * @return how many elements in the array
+ */
+ public int getLength() {
+ return fDefinitions.size();
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append('[');
+ Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
+ b.append(joiner.join(fDefinitions));
+ b.append(']');
+ @SuppressWarnings("null")
+ @NonNull String ret = b.toString();
+ return ret;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * A fixed length string definition
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public final class ByteArrayDefinition extends AbstractArrayDefinition {
+
+ private final byte[] fContent;
+ private transient @Nullable List<Definition> fDefs;
+
+ /**
+ * An fixed length string declaration, it's created by sequence or array
+ * defintions
+ *
+ * @param declaration
+ * the declaration
+ * @param definitionScope
+ * the definition scope
+ * @param fieldName
+ * the field name
+ * @param content
+ * the string content
+ */
+ public ByteArrayDefinition(CompoundDeclaration declaration,
+ @Nullable IDefinitionScope definitionScope,
+ String fieldName,
+ byte[] content) {
+ super(declaration, definitionScope, fieldName);
+ fContent = content;
+
+ }
+
+ @Override
+ public synchronized List<Definition> getDefinitions() {
+ List<Definition> defs = fDefs;
+ if (defs == null) {
+ ImmutableList.Builder<Definition> builder = new ImmutableList.Builder<>();
+ for (int i = 0; i < fContent.length; i++) {
+ IntegerDeclaration charDecl = IntegerDeclaration.UINT_8_DECL;
+ String fieldName = getFieldName() + '[' + i + ']';
+ byte fieldValue = fContent[i];
+ builder.add(new IntegerDefinition(charDecl, getDefinitionScope(), fieldName, fieldValue));
+ }
+ @SuppressWarnings("null")
+ @NonNull List<Definition> ret = builder.build();
+ fDefs = ret;
+ return ret;
+ }
+
+ return defs;
+ }
+
+ @Override
+ public String toString() {
+ /*
+ * the string is a byte array and may contain more than the string plus
+ * a null char, this will truncate it back to a null char
+ */
+ int pos = -1;
+ for (int i = 0; i < fContent.length; i++) {
+ if (fContent[i] == 0) {
+ pos = i;
+ break;
+ }
+ }
+ byte[] bytes = (pos != -1) ? (Arrays.copyOf(fContent, pos)) : fContent;
+ return new String(bytes);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson, Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.types;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.Multimap;
+
+/**
+ * A CTF sequence declaration.
+ *
+ * An array where the size is fixed but declared in the trace, unlike array
+ * where it is declared with a literal
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+public class SequenceDeclaration extends CompoundDeclaration {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private final IDeclaration fElemType;
+ private final String fLengthName;
+ private final Multimap<String, String> fPaths = ArrayListMultimap.create();
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param lengthName
+ * the name of the field describing the length
+ * @param elemType
+ * The element type
+ */
+ public SequenceDeclaration(String lengthName, IDeclaration elemType) {
+ fElemType = elemType;
+ fLengthName = lengthName;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ @Override
+ public IDeclaration getElementType() {
+ return fElemType;
+ }
+
+ /**
+ * Gets the name of the length field
+ *
+ * @return the name of the length field
+ */
+ public String getLengthName() {
+ return fLengthName;
+ }
+
+ @Override
+ public long getAlignment() {
+ return getElementType().getAlignment();
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ /**
+ * Is the Sequence a string?
+ *
+ * @return true, if the elements are chars, false otherwise
+ */
+ public boolean isString() {
+ IntegerDeclaration elemInt;
+ IDeclaration elementType = getElementType();
+ if (elementType instanceof IntegerDeclaration) {
+ elemInt = (IntegerDeclaration) elementType;
+ if (elemInt.isCharacter()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public AbstractArrayDefinition createDefinition(
+ IDefinitionScope definitionScope, String fieldName, BitBuffer input) throws CTFReaderException {
+ Definition lenDef = null;
+
+ if (definitionScope != null) {
+ lenDef = definitionScope.lookupDefinition(getLengthName());
+ }
+
+ if (lenDef == null) {
+ throw new CTFReaderException("Sequence length field not found"); //$NON-NLS-1$
+ }
+
+ if (!(lenDef instanceof IntegerDefinition)) {
+ throw new CTFReaderException("Sequence length field not integer"); //$NON-NLS-1$
+ }
+
+ IntegerDefinition lengthDefinition = (IntegerDefinition) lenDef;
+
+ if (lengthDefinition.getDeclaration().isSigned()) {
+ throw new CTFReaderException("Sequence length must not be signed"); //$NON-NLS-1$
+ }
+
+ long length = lengthDefinition.getValue();
+ if ((length > Integer.MAX_VALUE) || (!input.canRead((int) length * fElemType.getMaximumSize()))) {
+ throw new CTFReaderException("Sequence length too long " + length); //$NON-NLS-1$
+ }
+
+ if (isString()) {
+ // Don't create "useless" definitions
+ byte[] data = new byte[(int) length];
+ input.get(data);
+ return new ByteArrayDefinition(this, definitionScope, fieldName, data);
+ }
+ Collection<String> collection = fPaths.get(fieldName);
+ while (collection.size() < length) {
+ fPaths.put(fieldName, fieldName + '[' + collection.size() + ']');
+ }
+ List<String> paths = (List<String>) fPaths.get(fieldName);
+ Builder<Definition> definitions = new ImmutableList.Builder<>();
+ for (int i = 0; i < length; i++) {
+ @SuppressWarnings("null")
+ @NonNull String elemName = paths.get(i);
+ definitions.add(fElemType.createDefinition(definitionScope, elemName, input));
+ }
+ @SuppressWarnings("null")
+ @NonNull ImmutableList<Definition> build = definitions.build();
+ return new ArrayDefinition(this, definitionScope, fieldName, build);
+ }
+
+ @Override
+ public String toString() {
+ /* Only used for debugging */
+ return "[declaration] sequence[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
+ }
+
+ @Override
+ public int getMaximumSize() {
+ return Integer.MAX_VALUE;
+ }
+
+}
\ No newline at end of file
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.SequenceDeclaration;
import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEventField;
import org.junit.Before;
import org.junit.Test;
*/
@Test
public void testParseField_array_float() {
- Definition fieldDef = fixture.lookupArray(ARRAY_FLOAT);
+ Definition fieldDef = fixture.lookupArray2(ARRAY_FLOAT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
assertEquals("test=[2.0, 2.0]", result.toString());
}
*/
@Test
public void testParseField_array_int() {
- Definition fieldDef = fixture.lookupArray(ARRAY_INT);
+ Definition fieldDef = fixture.lookupArray2(ARRAY_INT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
assertEquals("test=[2, 2]", result.toString());
}
*/
@Test
public void testParseField_array_string() {
- Definition fieldDef = fixture.lookupArray(ARRAY_STR);
+ Definition fieldDef = fixture.lookupArray2(ARRAY_STR);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
assertEquals("test=[two, two]", result.toString());
}
*/
@Test
public void testParseField_array_struct() {
- Definition fieldDef = fixture.lookupArray(ARRAY_STRUCT);
+ Definition fieldDef = fixture.lookupArray2(ARRAY_STRUCT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
assertEquals("test=[[str=two, int=2], [str=two, int=2]]", result.toString());
}
*/
@Test
public void testParseField_array_enum() {
- Definition fieldDef = fixture.lookupArray(ARRAY_ENUM);
+ Definition fieldDef = fixture.lookupArray2(ARRAY_ENUM);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
assertEquals("test=[float, float]", result.toString());
}
*/
@Test
public void testParseField_array_variant() {
- Definition fieldDef = fixture.lookupArray(ARRAY_VARIANT);
+ Definition fieldDef = fixture.lookupArray2(ARRAY_VARIANT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
assertEquals("test=[float=2.0, float=2.0]", result.toString());
}
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ByteArrayDefinition;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
} else if (fieldDef instanceof ArrayDefinition) {
ArrayDefinition arrayDef = (ArrayDefinition) fieldDef;
-
- if (arrayDef.getDeclaration().isString()) {
- /* This is an array of UTF-8 bytes, a.k.a. a String! */
- field = new CTFStringField(fieldName, fieldDef.toString());
+ IDeclaration decl = arrayDef.getDeclaration();
+ if (!(decl instanceof CompoundDeclaration)) {
+ throw new IllegalArgumentException("Array definitions should only come from sequence or array declarations"); //$NON-NLS-1$
+ }
+ CompoundDeclaration arrDecl = (CompoundDeclaration) decl;
+ IDeclaration elemType = null;
+ Collection<Definition> definitions = arrayDef.getDefinitions();
+ elemType = arrDecl.getElementType();
+ if (elemType instanceof IntegerDeclaration) {
+ /* Array of integers => CTFIntegerArrayField */
+ IntegerDeclaration elemIntType = (IntegerDeclaration) elemType;
+ long[] values = new long[arrayDef.getLength()];
+ for (int i = 0; i < arrayDef.getLength(); i++) {
+ Definition elem = arrayDef.getDefinitions().get(i);
+ if (elem == null) {
+ break;
+ }
+ values[i] = ((IntegerDefinition) elem).getValue();
+ }
+ field = new CTFIntegerArrayField(fieldName, values,
+ elemIntType.getBase(),
+ elemIntType.isSigned());
} else {
/* Arrays of elements of any other type */
- List<Definition> definitions = arrayDef.getDefinitions();
- CtfTmfEventField[] elements = new CtfTmfEventField[definitions.size()];
-
+ CtfTmfEventField[] elements = new CtfTmfEventField[arrayDef.getLength()];
/* Parse the elements of the array. */
- for (int i = 0; i < definitions.size(); i++) {
+ int i = 0;
+ for (Definition definition : definitions) {
CtfTmfEventField curField = CtfTmfEventField.parseField(
- definitions.get(i), fieldName + '[' + i + ']');
+ definition, fieldName + '[' + i + ']');
elements[i] = curField;
+ i++;
}
field = new CTFArrayField(fieldName, elements);
}
- } else if (fieldDef instanceof SequenceDefinition) {
- SequenceDefinition seqDef = (SequenceDefinition) fieldDef;
- SequenceDeclaration seqDecl = seqDef.getDeclaration();
-
- if (seqDef.getLength() == 0) {
- /* Some sequences have length = 0. Simply use an empty string */
- field = new CTFStringField(fieldName, ""); //$NON-NLS-1$
- } else if (seqDecl.isString()) {
- /* Interpret this sequence as a String */
- field = new CTFStringField(fieldName, seqDef.toString());
- } else if (seqDecl.getElementType() instanceof IntegerDeclaration) {
- /* Sequence of integers => CTFIntegerArrayField */
- long[] values = new long[seqDef.getLength()];
- for (int i = 0; i < seqDef.getLength(); i++) {
- values[i] = ((IntegerDefinition) seqDef.getElem(i)).getValue();
- }
- field = new CTFIntegerArrayField(fieldName, values,
- ((IntegerDeclaration) seqDecl.getElementType()).getBase(),
- ((IntegerDeclaration) seqDecl.getElementType()).isSigned());
-
- }
- /* Add other Sequence types here */
+ } else if (fieldDef instanceof ByteArrayDefinition) {
+ /* This is an array of ascii bytes, a.k.a. a String! */
+ field = new CTFStringField(fieldName, fieldDef.toString());
} else if (fieldDef instanceof StructDefinition) {
StructDefinition strDef = (StructDefinition) fieldDef;