/**
* The class <code>CTFEventFieldTest</code> contains tests for the class
* <code>{@link CTFEventField}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
* @param <CTFIntegerArrayField>
*/
public class CTFEventFieldTest {
-
+
private static final String fieldName = "id"; //$NON-NLS-1$
-
-
+
+
/**
* Perform pre-test initialization.
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
public void testParseField_complex() throws CTFReaderException {
int len = 32;
IntegerDeclaration id = new IntegerDeclaration(len, false, len,
- ByteOrder.LITTLE_ENDIAN, Encoding.ASCII);
+ ByteOrder.LITTLE_ENDIAN, Encoding.ASCII, null);
String lengthName = "LengthName"; //$NON-NLS-1$
StructDeclaration structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
assertNotNull(fieldDef);
}
-
+
/**
* Run the CTFEventField parseField(Definition,String) method test.
*/
public void testParseField_simple2() {
IntegerDefinition fieldDef = new IntegerDefinition(
new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII), null, fieldName);
+ Encoding.ASCII, null), null, fieldName);
fieldDef.setValue(1L);
assertNotNull(fieldDef);
}
-
+
/**
- *
+ *
*/
@Test
public void testParseField_simple3() {
@Test
public void testParseField_manual() {
Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(20,
- new IntegerDeclaration(8, false, 8, null, Encoding.UTF8)),
+ new IntegerDeclaration(8, false, 8, null, Encoding.UTF8, null)),
null, fieldName);
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
@Test
public void testParseField_manual2() {
Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(12,
- new IntegerDeclaration(32, false, 32, null, null)), null,
+ new IntegerDeclaration(32, false, 32, null, null, null)), null,
fieldName);
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
/**
* The class <code>ArrayDefinitionTest</code> contains tests for the class
* <code>{@link ArrayDefinition}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
/**
* Perform pre-test initialization.
- *
+ *
* structDef shouldn't be null after parsing the CTFTraceReader object, so
* we can ignore the warning.
*
@Test
public void testIsString_complex() {
final IntegerDeclaration id = new IntegerDeclaration(8, false, 16,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
ArrayDeclaration ad = new ArrayDeclaration(0, id);
ArrayDefinition ownFixture = new ArrayDefinition(ad, this.trace,
"Testx"); //$NON-NLS-1$
String content = "test" + i; //$NON-NLS-1$
defs[i] = new IntegerDefinition(new IntegerDeclaration(8, false,
- 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8), null, content);
+ 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content), null, content);
defs[i].setValue(i);
}
/**
* The class <code>EnumDeclarationTest</code> contains tests for the class
* <code>{@link EnumDeclaration}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@Before
public void setUp() {
fixture = new EnumDeclaration(new IntegerDeclaration(1, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII));
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null));
}
/**
@Test
public void testEnumDeclaration() {
IntegerDeclaration containerType = new IntegerDeclaration(1, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII);
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
EnumDeclaration result = new EnumDeclaration(containerType);
/**
* The class <code>EnumDefinitionTest</code> contains tests for the class
* <code>{@link EnumDefinition}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
public void setUp() {
EnumDeclaration declaration = new EnumDeclaration(
new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII));
+ Encoding.ASCII, null));
String fieldName = ""; //$NON-NLS-1$
fixture = new EnumDefinition(declaration, null, fieldName);
/**
* The class <code>IntegerDeclarationTest</code> contains tests for the class
* <code>{@link IntegerDeclaration}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@Before
public void setUp() {
fixture = new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII);
+ Encoding.ASCII, null);
}
/**
Encoding encoding = Encoding.ASCII;
IntegerDeclaration result = new IntegerDeclaration(len, signed, base,
- byteOrder, encoding);
+ byteOrder, encoding, null);
assertNotNull(result);
assertEquals(1, result.getBase());
@Test
public void testIsCharacter_8bytes() {
IntegerDeclaration fixture8 = new IntegerDeclaration(8, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII);
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
boolean result = fixture8.isCharacter();
assertEquals(true, result);
@Test
public void testIsSigned_unsigned() {
IntegerDeclaration fixture_unsigned = new IntegerDeclaration(1, false,
- 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII);
+ 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
boolean result = fixture_unsigned.isSigned();
assertEquals(false, result);
/**
* The class <code>IntegerDefinitionTest</code> contains tests for the class
* <code>{@link IntegerDefinition}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@Test
public void testIntegerDefinition() {
IntegerDeclaration declaration = new IntegerDeclaration(1, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII);
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
IDefinitionScope definitionScope = null;
String fieldName = ""; //$NON-NLS-1$
String result = fixture.toString();
assertNotNull(result);
}
-}
\ No newline at end of file
+}
/**
* The class <code>SequenceDeclarationTest</code> contains tests for the class
* <code>{@link SequenceDeclaration}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
@Test
public void testCreateDefinition() {
IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
String fieldName = "LengthName"; //$NON-NLS-1$
StructDeclaration structDec = new StructDeclaration(0);
structDec.addField(fieldName, id);
/**
* The class <code>SequenceDefinitionTest</code> contains tests for the class
* <code>{@link SequenceDefinition}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
StructDefinition structDef;
IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
String lengthName = "LengthName"; //$NON-NLS-1$
structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
int len = 32;
IntegerDeclaration id = new IntegerDeclaration(len, false, len,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8);
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
String lengthName = "LengthName"; //$NON-NLS-1$
structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
/**
* The class <code>VariantDefinitionTest</code> contains tests for the class
* <code>{@link VariantDefinition}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
/**
* Perform pre-test initialization.
- *
+ *
* Not sure it needs to be that complicated, oh well...
*
* @throws CTFReaderException
sDef2 = new StructDefinition(new StructDeclaration(1L), vDef2, fName);
eDef = new EnumDefinition(new EnumDeclaration(new IntegerDeclaration(1,
- true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII)), sDef2, fName);
+ true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, fName)), sDef2, fName);
fixture = new VariantDefinition(vDecl1, sDef1, fName);
fixture.setTagDefinition(eDef);
structDef = new StructDefinition(new StructDeclaration(1L), vDef, fName);
tagDefinition = new EnumDefinition(new EnumDeclaration(
new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII)), structDef, fName);
+ Encoding.ASCII, fName)), structDef, fName);
fixture.setTagDefinition(tagDefinition);
}
switch (type) {
case CTFParser.INTEGER:
case CTFParser.DECIMAL_LITERAL:
- //FIXME
- //HACK
- //EVIL
+ /*
+ * Not a pretty hack, this is to make sure that there is no number
+ * overflow due to 63 bit integers. The offset should only really
+ * be an issue in the year 2262. the tracer in C/ASM can write an offset in
+ * an unsigned 64 bit long. In java, the last bit, being set to 1 will
+ * be read as a negative number, but since it is too big a positive it will
+ * throw an exception. this will happen in 2^63 ns from 1970.
+ * Therefore 293 years from 1970
+ */
Long numValue;
try{
numValue = Long.parseLong(value.getText());
* sequence. For example, int a[3][len] means that we have an array of 3
* (sequences of length 'len' of (int)).
*/
- if (lengths != null) {
+ if (lengths.size() > 0 ) {
/* We begin at the end */
Collections.reverse(lengths);
long size = 0;
long alignment = 0;
int base = 10;
- @SuppressWarnings("unused")
- String clock;
+ String clock = null;
Encoding encoding = Encoding.NONE;
}
integerDeclaration = new IntegerDeclaration((int) size, signed, base,
- byteOrder, encoding);
+ byteOrder, encoding, clock);
assert (integerDeclaration != null);
return integerDeclaration;
}
- private String getClock(CommonTree rightNode) {
+ private static String getClock(CommonTree rightNode) {
return rightNode.getChild(1).getChild(0).getChild(0).getText();
}
private int base;
private ByteOrder byteOrder;
private Encoding encoding;
+ private final String clock;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
public IntegerDeclaration(int len, boolean signed, int base,
- ByteOrder byteOrder, Encoding encoding) {
+ ByteOrder byteOrder, Encoding encoding, String clock) {
this.length = len;
this.signed = signed;
this.base = base;
this.byteOrder = byteOrder;
this.encoding = encoding;
+ this.clock = clock;
}
// ------------------------------------------------------------------------