+ /**
+ * Test a changing endian event field
+ *
+ * @throws CTFException
+ * won't happen
+ */
+ @Test
+ public void testEndian() throws CTFException {
+ testEndianess(ENDIAN_CHANGE_L_B, ByteOrder.LITTLE_ENDIAN, ByteOrder.BIG_ENDIAN);
+ testEndianess(ENDIAN_CHANGE_L_N, ByteOrder.LITTLE_ENDIAN, ByteOrder.LITTLE_ENDIAN);
+ testEndianess(ENDIAN_CHANGE_L_L, ByteOrder.LITTLE_ENDIAN, ByteOrder.LITTLE_ENDIAN);
+ testEndianess(ENDIAN_CHANGE_B_L, ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN);
+ testEndianess(ENDIAN_CHANGE_B_N, ByteOrder.BIG_ENDIAN, ByteOrder.BIG_ENDIAN);
+ testEndianess(ENDIAN_CHANGE_B_B, ByteOrder.BIG_ENDIAN, ByteOrder.BIG_ENDIAN);
+ }
+
+ private void testEndianess(String tsdl, ByteOrder traceEndian, ByteOrder fieldEndian) throws CTFException {
+ fixture = new Metadata();
+ CTFTrace trace = fixture.getTrace();
+ fixture.parseText(tsdl);
+ assertEquals(traceEndian, trace.getByteOrder());
+ final Iterable<IEventDeclaration> eventDeclarations = trace.getEventDeclarations(0L);
+ assertNotNull(eventDeclarations);
+ IEventDeclaration event = Iterables.getFirst(eventDeclarations, null);
+ assertNotNull(event);
+ assertNotNull(event.getFields());
+ final @Nullable IDeclaration field = event.getFields().getField("data");
+ assertNotNull(field);
+ if (field instanceof ISimpleDatatypeDeclaration) {
+ ISimpleDatatypeDeclaration declaration = (ISimpleDatatypeDeclaration) field;
+ assertEquals(fieldEndian, declaration.getByteOrder());
+ } else {
+ fail("data is not the right type");
+ }
+ }
+