refactoring of DataField.java

This commit is contained in:
hneemann 2018-12-18 11:12:24 +01:00
parent 1a2483b546
commit 266c5912c0
13 changed files with 86 additions and 108 deletions

View File

@ -23,7 +23,6 @@ public class DataField implements HGSArray {
*/ */
public static final DataField DEFAULT = new DataField(0); public static final DataField DEFAULT = new DataField(0);
private final int size;
private long[] data; private long[] data;
private final transient ArrayList<DataListener> listeners = new ArrayList<>(); private final transient ArrayList<DataListener> listeners = new ArrayList<>();
@ -34,31 +33,27 @@ public class DataField implements HGSArray {
* @param size size * @param size size
*/ */
public DataField(int size) { public DataField(int size) {
this(new long[size], size); this(new long[size]);
}
/**
* Creates a new data field
*
* @param data the data to copy
*/
public DataField(DataField data) {
this.data = Arrays.copyOf(data.data, data.data.length);
} }
/** /**
* Creates a new data field * Creates a new data field
* *
* @param data the data * @param data the data
* @param size the size
*/ */
public DataField(long[] data, int size) { public DataField(long[] data) {
this.size = size;
this.data = data; this.data = data;
} }
/**
* Create a new instance based on a given instance.
* The data given is copied.
*
* @param dataField the data to use
* @param newSize new size
*/
public DataField(DataField dataField, int newSize) {
this(Arrays.copyOf(dataField.data, newSize), newSize);
}
/** /**
* Creates a new instance and fills it with the data in the given reader * Creates a new instance and fills it with the data in the given reader
* *
@ -86,16 +81,14 @@ public class DataField implements HGSArray {
if (line.length() > 0) { if (line.length() > 0) {
long v = Bits.decode(line, 0, 16); long v = Bits.decode(line, 0, 16);
if (pos == data.length) setData(pos, v);
data = Arrays.copyOf(data, data.length * 2);
data[pos] = v;
pos++; pos++;
} }
} catch (Bits.NumberFormatException e) { } catch (Bits.NumberFormatException e) {
throw new IOException(e); throw new IOException(e);
} }
} }
size = pos; data = Arrays.copyOf(data, pos);
} }
} }
@ -106,11 +99,11 @@ public class DataField implements HGSArray {
* @throws IOException IOException * @throws IOException IOException
*/ */
public void saveTo(File file) throws IOException { public void saveTo(File file) throws IOException {
DataField df = getMinimized(); trim();
try (BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { try (BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) {
w.write("v2.0 raw"); w.write("v2.0 raw");
w.newLine(); w.newLine();
for (long l : df.getData()) { for (long l : data) {
w.write(Long.toHexString(l)); w.write(Long.toHexString(l));
w.newLine(); w.newLine();
} }
@ -130,21 +123,23 @@ public class DataField implements HGSArray {
} }
/** /**
* Sets a data value the DataField * Sets a data value the DataField.
* If the actual data field capacity is to small the size in increased.
* *
* @param addr the address * @param addr the address
* @param value the value * @param value the value
* @return this for chained calls * @return this for chained calls
*/ */
public DataField setData(int addr, long value) { public DataField setData(int addr, long value) {
if (addr < size) { if (addr >= data.length) {
if (addr >= data.length) int newLen = addr * 2;
data = Arrays.copyOf(data, size); if (newLen < 32) newLen = 32;
data = Arrays.copyOf(data, newLen);
}
if (data[addr] != value) { if (data[addr] != value) {
data[addr] = value; data[addr] = value;
fireChanged(addr); fireChanged(addr);
}
} }
return this; return this;
} }
@ -163,27 +158,17 @@ public class DataField implements HGSArray {
} }
/** /**
* Returns the size of this field * Trims the data field to it's minimal size
*
* @return the size
*/
public int size() {
return size;
}
/**
* Returns a new minimal {@link DataField}.
* All trailing zeros are removed. * All trailing zeros are removed.
* *
* @return the new {@link DataField} * @return the new length of the data array
*/ */
public DataField getMinimized() { public int trim() {
int pos = data.length; int pos = data.length;
while (pos > 0 && data[pos - 1] == 0) pos--; while (pos > 0 && data[pos - 1] == 0) pos--;
if (pos == data.length) if (pos < data.length)
return this; data = Arrays.copyOf(data, pos);
else return data.length;
return new DataField(Arrays.copyOf(data, pos), size);
} }
/** /**
@ -226,7 +211,7 @@ public class DataField implements HGSArray {
* @param dataField the data to set to this data field * @param dataField the data to set to this data field
*/ */
public void setDataFrom(DataField dataField) { public void setDataFrom(DataField dataField) {
data = Arrays.copyOf(dataField.data, size); data = Arrays.copyOf(dataField.data, dataField.data.length);
fireChanged(-1); fireChanged(-1);
} }

View File

@ -12,7 +12,6 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import de.neemann.digital.core.Bits; import de.neemann.digital.core.Bits;
import java.util.Arrays;
import java.util.StringTokenizer; import java.util.StringTokenizer;
/** /**
@ -28,9 +27,7 @@ public class DataFieldConverter implements Converter {
@Override @Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) { public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) {
DataField df = (DataField) o; DataField df = (DataField) o;
df = df.getMinimized(); df.trim();
//writer.startNode("data");
writer.addAttribute("size", Integer.toString(df.size()));
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
int pos = 0; int pos = 0;
for (long d : df.getData()) { for (long d : df.getData()) {
@ -49,12 +46,11 @@ public class DataFieldConverter implements Converter {
pos += s.length(); pos += s.length();
} }
writer.setValue(data.toString()); writer.setValue(data.toString());
//writer.endNode();
} }
@Override @Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) { public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) {
if (reader.getAttribute("size") == null) { if (reader.hasMoreChildren()) {
// old type // old type
reader.moveDown(); reader.moveDown();
DataField df = new DataField(Integer.parseInt(reader.getValue())); DataField df = new DataField(Integer.parseInt(reader.getValue()));
@ -70,15 +66,15 @@ public class DataFieldConverter implements Converter {
} else { } else {
try { try {
// new type // new type
int size = Integer.parseInt(reader.getAttribute("size")); DataField df = new DataField(1024);
long[] data = new long[size];
StringTokenizer st = new StringTokenizer(reader.getValue(), ","); StringTokenizer st = new StringTokenizer(reader.getValue(), ",");
int i = 0; int i = 0;
while (st.hasMoreTokens()) { while (st.hasMoreTokens()) {
data[i] = Bits.decode(st.nextToken().trim(), 0, 16); df.setData(i, Bits.decode(st.nextToken().trim(), 0, 16));
i++; i++;
} }
return new DataField(Arrays.copyOf(data, i), size); df.trim();
return df;
} catch (Bits.NumberFormatException e) { } catch (Bits.NumberFormatException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -44,9 +44,10 @@ public final class DataFieldImporter {
} }
private static DataField readByteArray(File file, int dataBits, Reader reader) throws IOException { private static DataField readByteArray(File file, int dataBits, Reader reader) throws IOException {
DataField dataField = new DataField(0x10000); DataField dataField = new DataField(1024);
reader.read(file, create(dataField, dataBits)); reader.read(file, create(dataField, dataBits));
return dataField.getMinimized(); dataField.trim();
return dataField;
} }
interface DataArray { interface DataArray {

View File

@ -44,11 +44,6 @@ public class EEPROM extends RAMSinglePortSel implements ROMInterface {
@Override @Override
protected DataField createDataField(ElementAttributes attr, int size) { protected DataField createDataField(ElementAttributes attr, int size) {
DataField memory = attr.get(Keys.DATA); return attr.get(Keys.DATA);
if (memory.size() != size) {
memory = new DataField(memory, size);
attr.set(Keys.DATA, memory);
}
return memory;
} }
} }

View File

@ -44,12 +44,7 @@ public class EEPROMDualPort extends RAMDualPort implements ROMInterface {
@Override @Override
protected DataField createDataField(ElementAttributes attr, int size) { protected DataField createDataField(ElementAttributes attr, int size) {
DataField memory = attr.get(Keys.DATA); return attr.get(Keys.DATA);
if (memory.size() != size) {
memory = new DataField(memory, size);
attr.set(Keys.DATA, memory);
}
return memory;
} }
} }

View File

@ -54,13 +54,13 @@ public class ROMManger {
} }
/** /**
* Adds a rom's contet to this ROMManager * Adds a rom's content to this ROMManager
* *
* @param label the label * @param label the label
* @param data the data * @param data the data
*/ */
public void addRom(String label, DataField data) { public void addRom(String label, DataField data) {
data = data.getMinimized(); data.trim();
if (data.getData().length > 0) if (data.getData().length > 0)
roms.put(label, data); roms.put(label, data);
} }

View File

@ -26,7 +26,6 @@ import java.awt.*;
*/ */
public class RAMShape extends GenericShape { public class RAMShape extends GenericShape {
private final int dataBits; private final int dataBits;
private final int size;
private final int addrBits; private final int addrBits;
private final String dialogTitle; private final String dialogTitle;
private Model model; private Model model;
@ -63,7 +62,6 @@ public class RAMShape extends GenericShape {
dialogTitle = description.getShortName(); dialogTitle = description.getShortName();
dataBits = attr.get(Keys.BITS); dataBits = attr.get(Keys.BITS);
addrBits = attr.get(Keys.ADDR_BITS); addrBits = attr.get(Keys.ADDR_BITS);
size = 1 << addrBits;
setInverterConfig(attr.get(Keys.INVERTER_CONFIG)); setInverterConfig(attr.get(Keys.INVERTER_CONFIG));
} }
@ -74,7 +72,7 @@ public class RAMShape extends GenericShape {
public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, SyncAccess modelSync) { public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, SyncAccess modelSync) {
if (element instanceof RAMInterface) { if (element instanceof RAMInterface) {
DataField dataField = ((RAMInterface) element).getMemory(); DataField dataField = ((RAMInterface) element).getMemory();
DataEditor dataEditor = new DataEditor(cc, dataField, size, dataBits, addrBits, true, modelSync); DataEditor dataEditor = new DataEditor(cc, dataField, dataBits, addrBits, true, modelSync);
dataEditor.showDialog(dialogTitle, model); dataEditor.showDialog(dialogTitle, model);
} }
return false; return false;

View File

@ -48,25 +48,26 @@ public class DataEditor extends JDialog {
* *
* @param parent the parent * @param parent the parent
* @param dataField the data to edit * @param dataField the data to edit
* @param size the size of the data field to edit
* @param dataBits the bit count of the values to edit * @param dataBits the bit count of the values to edit
* @param addrBits the bit count of the adresses * @param addrBits the bit count of the adresses
* @param modelIsRunning true if model is running * @param modelIsRunning true if model is running
* @param modelSync used to access the running model * @param modelSync used to access the running model
*/ */
public DataEditor(Component parent, DataField dataField, int size, int dataBits, int addrBits, boolean modelIsRunning, SyncAccess modelSync) { public DataEditor(Component parent, DataField dataField, int dataBits, int addrBits, boolean modelIsRunning, SyncAccess modelSync) {
super(SwingUtilities.windowForComponent(parent), Lang.get("key_Data"), modelIsRunning ? ModalityType.MODELESS : ModalityType.APPLICATION_MODAL); super(SwingUtilities.windowForComponent(parent), Lang.get("key_Data"), modelIsRunning ? ModalityType.MODELESS : ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(DISPOSE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
if (modelIsRunning) if (modelIsRunning)
localDataField = dataField; localDataField = dataField;
else else
localDataField = new DataField(dataField, size); localDataField = new DataField(dataField);
final int size = 1 << addrBits;
final int cols = calcCols(size, dataBits); final int cols = calcCols(size, dataBits);
final int rows = (size - 1) / cols + 1;
int tableWidth = 0; int tableWidth = 0;
MyTableModel dm = new MyTableModel(this.localDataField, cols, modelSync); MyTableModel dm = new MyTableModel(this.localDataField, cols, rows, modelSync);
table = new JTable(dm); table = new JTable(dm);
int widthOfZero = table.getFontMetrics(table.getFont()).stringWidth("00000000") / 8; int widthOfZero = table.getFontMetrics(table.getFont()).stringWidth("00000000") / 8;
table.setDefaultRenderer(MyLong.class, new MyLongRenderer(dataBits)); table.setDefaultRenderer(MyLong.class, new MyLongRenderer(dataBits));
@ -184,6 +185,7 @@ public class DataEditor extends JDialog {
* @return the data field * @return the data field
*/ */
public DataField getModifiedDataField() { public DataField getModifiedDataField() {
localDataField.trim();
return localDataField; return localDataField;
} }
@ -247,11 +249,11 @@ public class DataEditor extends JDialog {
private final int rows; private final int rows;
private ArrayList<TableModelListener> listener = new ArrayList<>(); private ArrayList<TableModelListener> listener = new ArrayList<>();
private MyTableModel(DataField dataField, int cols, SyncAccess modelSync) { private MyTableModel(DataField dataField, int cols, int rows, SyncAccess modelSync) {
this.dataField = dataField; this.dataField = dataField;
this.cols = cols; this.cols = cols;
this.rows = rows;
this.modelSync = modelSync; this.modelSync = modelSync;
rows = (dataField.size() - 1) / cols + 1;
} }
@Override @Override

View File

@ -612,8 +612,7 @@ public final class EditorFactory {
// memory, RAM/ROM // memory, RAM/ROM
addrBits = attr.get(Keys.ADDR_BITS); addrBits = attr.get(Keys.ADDR_BITS);
} }
int size = 1 << addrBits; DataEditor de = new DataEditor(panel, data, dataBits, addrBits, false, SyncAccess.NOSYNC);
DataEditor de = new DataEditor(panel, data, size, dataBits, addrBits, false, SyncAccess.NOSYNC);
de.setFileName(attr.getFile(ROM.LAST_DATA_FILE_KEY)); de.setFileName(attr.getFile(ROM.LAST_DATA_FILE_KEY));
if (de.showDialog()) { if (de.showDialog()) {
data = de.getModifiedDataField(); data = de.getModifiedDataField();
@ -647,7 +646,8 @@ public final class EditorFactory {
@Override @Override
public DataField getValue() { public DataField getValue() {
return data.getMinimized(); data.trim();
return data;
} }
@Override @Override

View File

@ -85,7 +85,6 @@ public class ProbeDialog extends JDialog implements ModelStateObserverTyped {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
new DataEditor(ProbeDialog.this, new DataEditor(ProbeDialog.this,
ram.getMemory(), ram.getMemory(),
ram.getSize(),
ram.getDataBits(), ram.getDataBits(),
ram.getAddrBits(), ram.getAddrBits(),
true, true,

View File

@ -138,7 +138,7 @@ public class ROMEditorDialog extends JDialog {
} }
public boolean edit(ROMEditorDialog romEditorDialog) { public boolean edit(ROMEditorDialog romEditorDialog) {
DataEditor de = new DataEditor(romEditorDialog, data, 1 << ri.getAddrBits(), ri.getDataBits(), ri.getAddrBits(), false, SyncAccess.NOSYNC); DataEditor de = new DataEditor(romEditorDialog, data, ri.getDataBits(), ri.getAddrBits(), false, SyncAccess.NOSYNC);
if (de.showDialog()) { if (de.showDialog()) {
data = de.getModifiedDataField(); data = de.getModifiedDataField();
return true; return true;

View File

@ -28,7 +28,7 @@ public class DataFieldConverterTest extends TestCase {
XStream xStream = getxStream(); XStream xStream = getxStream();
String xml = xStream.toXML(d); String xml = xStream.toXML(d);
assertEquals("<dataField size=\"1000\">0,1,2,3,4,5,6,7,8,9</dataField>", xml); assertEquals("<dataField>0,1,2,3,4,5,6,7,8,9</dataField>", xml);
} }
public void testUnmarshal() throws Exception { public void testUnmarshal() throws Exception {
@ -36,7 +36,7 @@ public class DataFieldConverterTest extends TestCase {
DataField df = (DataField) xStream.fromXML("<dataField size=\"1000\">0,1,2,3,4,5,6,7,8,9</dataField>"); DataField df = (DataField) xStream.fromXML("<dataField size=\"1000\">0,1,2,3,4,5,6,7,8,9</dataField>");
assertEquals(1000, df.size()); assertEquals(10, df.getData().length);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
assertEquals(i, df.getDataWord(i)); assertEquals(i, df.getDataWord(i));
} }
@ -64,8 +64,8 @@ public class DataFieldConverterTest extends TestCase {
XStream xs = getxStream(); XStream xs = getxStream();
String xml = xs.toXML(t); String xml = xs.toXML(t);
assertEquals("<test>\n" + assertEquals("<test>\n" +
" <d1 size=\"20\">1,0,0,0,0,2</d1>\n" + " <d1>1,0,0,0,0,2</d1>\n" +
" <d2 size=\"20\">3,0,0,0,0,0,0,0,4</d2>\n" + " <d2>3,0,0,0,0,0,0,0,4</d2>\n" +
"</test>", xml); "</test>", xml);
} }
@ -73,14 +73,14 @@ public class DataFieldConverterTest extends TestCase {
public void testUnarshalObj() throws Exception { public void testUnarshalObj() throws Exception {
XStream xs = getxStream(); XStream xs = getxStream();
Test t = (Test) xs.fromXML("<test>\n" + Test t = (Test) xs.fromXML("<test>\n" +
" <d1 size=\"20\">1,0,0,0,0,2</d1>\n" + " <d1>1,0,0,0,0,2</d1>\n" +
" <d2 size=\"20\">3,0,0,0,0,0,0,0,4</d2>\n" + " <d2>3,0,0,0,0,0,0,0,4</d2>\n" +
"</test>"); "</test>");
assertEquals(20, t.d1.size()); assertEquals(6, t.d1.getData().length);
assertEquals(1, t.d1.getDataWord(0)); assertEquals(1, t.d1.getDataWord(0));
assertEquals(2, t.d1.getDataWord(5)); assertEquals(2, t.d1.getDataWord(5));
assertEquals(20, t.d2.size()); assertEquals(9, t.d2.getData().length);
assertEquals(3, t.d2.getDataWord(0)); assertEquals(3, t.d2.getDataWord(0));
assertEquals(4, t.d2.getDataWord(8)); assertEquals(4, t.d2.getDataWord(8));
} }
@ -94,7 +94,7 @@ public class DataFieldConverterTest extends TestCase {
XStream xStream = getxStream(); XStream xStream = getxStream();
String xml = xStream.toXML(d); String xml = xStream.toXML(d);
assertEquals("<dataField size=\"1000\">0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11,12,13,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,\n" + assertEquals("<dataField>0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11,12,13,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,\n" +
"21,22,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,33,34,35,36,37,38,39,3a,3b,\n" + "21,22,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,33,34,35,36,37,38,39,3a,3b,\n" +
"3c,3d,3e,3f,40,41,42,43,44,45,46,47,48,49,4a,4b,4c,4d,4e,4f,50,51,52,53,54,55,56,\n" + "3c,3d,3e,3f,40,41,42,43,44,45,46,47,48,49,4a,4b,4c,4d,4e,4f,50,51,52,53,54,55,56,\n" +
"57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63</dataField>", xml); "57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63</dataField>", xml);
@ -103,12 +103,12 @@ public class DataFieldConverterTest extends TestCase {
public void testUnmarshalMuch() throws Exception { public void testUnmarshalMuch() throws Exception {
XStream xStream = getxStream(); XStream xStream = getxStream();
DataField df = (DataField) xStream.fromXML("<dataField size=\"1000\">0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11,12,13,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,\n" + DataField df = (DataField) xStream.fromXML("<dataField>0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11,12,13,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,\n" +
"21,22,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,33,34,35,36,37,38,39,3a,3b,\n" + "21,22,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,33,34,35,36,37,38,39,3a,3b,\n" +
"3c,3d,3e,3f,40,41,42,43,44,45,46,47,48,49,4a,4b,4c,4d,4e,4f,50,51,52,53,54,55,56,\n" + "3c,3d,3e,3f,40,41,42,43,44,45,46,47,48,49,4a,4b,4c,4d,4e,4f,50,51,52,53,54,55,56,\n" +
"57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63</dataField>"); "57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63</dataField>");
assertEquals(1000, df.size()); assertEquals(100, df.getData().length);
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
assertEquals(i, df.getDataWord(i)); assertEquals(i, df.getDataWord(i));
} }
@ -130,7 +130,7 @@ public class DataFieldConverterTest extends TestCase {
" <long>8</long>\n" + " <long>8</long>\n" +
" <long>9</long>\n" + " <long>9</long>\n" +
"</dataField>"); "</dataField>");
assertEquals(1000, df.size()); assertEquals(1000, df.getData().length);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
assertEquals(i, df.getDataWord(i)); assertEquals(i, df.getDataWord(i));
} }

View File

@ -13,28 +13,35 @@ import java.io.StringReader;
*/ */
public class DataFieldTest extends TestCase { public class DataFieldTest extends TestCase {
public void testGetMinimized() throws Exception { public void testGetMinimized() {
DataField data = new DataField(100); DataField data = new DataField(100);
data.setData(9, 1); data.setData(9, 1);
data = data.getMinimized(); assertEquals(10, data.trim());
assertEquals(1, data.getDataWord(9)); assertEquals(1, data.getDataWord(9));
data = data.getMinimized(); assertEquals(10, data.trim());
assertEquals(1, data.getDataWord(9)); assertEquals(1, data.getDataWord(9));
} }
public void testGrow() throws Exception { public void testGrow() {
DataField data = new DataField(100); DataField data = new DataField(100);
data.setData(9, 1); data.setData(9, 1);
data = data.getMinimized(); data.trim();
assertEquals(1, data.getDataWord(9)); assertEquals(1, data.getDataWord(9));
data.setData(30, 1); data.setData(30, 1);
assertEquals(1, data.getDataWord(30)); assertEquals(1, data.getDataWord(30));
} }
public void testGrow2() {
DataField data = new DataField(0);
data.setData(0, 1);
assertEquals(1, data.getDataWord(0));
assertEquals(0, data.getDataWord(1));
}
public void testLoad() throws Exception { public void testLoad() throws Exception {
String data = "v2.0 raw\n0\n10\nAA\nFF"; String data = "v2.0 raw\n0\n10\nAA\nFF";
DataField df = new DataField(new StringReader(data)); DataField df = new DataField(new StringReader(data));
assertEquals(4, df.size()); assertEquals(4, df.trim());
assertEquals(0x00, df.getDataWord(0)); assertEquals(0x00, df.getDataWord(0));
assertEquals(0x10, df.getDataWord(1)); assertEquals(0x10, df.getDataWord(1));
assertEquals(0xAA, df.getDataWord(2)); assertEquals(0xAA, df.getDataWord(2));
@ -44,7 +51,7 @@ public class DataFieldTest extends TestCase {
public void testLoad64Bit() throws Exception { public void testLoad64Bit() throws Exception {
String data = "v2.0 raw\n8000000000000000\n10\nAA\nFF"; String data = "v2.0 raw\n8000000000000000\n10\nAA\nFF";
DataField df = new DataField(new StringReader(data)); DataField df = new DataField(new StringReader(data));
assertEquals(4, df.size()); assertEquals(4, df.trim());
assertEquals(0x8000000000000000L, df.getDataWord(0)); assertEquals(0x8000000000000000L, df.getDataWord(0));
assertEquals(0x10, df.getDataWord(1)); assertEquals(0x10, df.getDataWord(1));
assertEquals(0xAA, df.getDataWord(2)); assertEquals(0xAA, df.getDataWord(2));
@ -54,7 +61,7 @@ public class DataFieldTest extends TestCase {
public void testLoadComments() throws Exception { public void testLoadComments() throws Exception {
String data = "v2.0 raw\n#test1 \n 0 \n#test1\n # test2\n10 # test3\n\n\nAA\nFF #test"; String data = "v2.0 raw\n#test1 \n 0 \n#test1\n # test2\n10 # test3\n\n\nAA\nFF #test";
DataField df = new DataField(new StringReader(data)); DataField df = new DataField(new StringReader(data));
assertEquals(4, df.size()); assertEquals(4, df.trim());
assertEquals(0x00, df.getDataWord(0)); assertEquals(0x00, df.getDataWord(0));
assertEquals(0x10, df.getDataWord(1)); assertEquals(0x10, df.getDataWord(1));
assertEquals(0xAA, df.getDataWord(2)); assertEquals(0xAA, df.getDataWord(2));
@ -64,7 +71,7 @@ public class DataFieldTest extends TestCase {
public void testLoadCommentsRealHex() throws Exception { public void testLoadCommentsRealHex() throws Exception {
String data = "v2.0 raw\n#test1 \n 0x0 \n#test1\n # test2\n0x10 # test3\n\n\n0xAA\n0XFF #test"; String data = "v2.0 raw\n#test1 \n 0x0 \n#test1\n # test2\n0x10 # test3\n\n\n0xAA\n0XFF #test";
DataField df = new DataField(new StringReader(data)); DataField df = new DataField(new StringReader(data));
assertEquals(4, df.size()); assertEquals(4, df.trim());
assertEquals(0x00, df.getDataWord(0)); assertEquals(0x00, df.getDataWord(0));
assertEquals(0x10, df.getDataWord(1)); assertEquals(0x10, df.getDataWord(1));
assertEquals(0xAA, df.getDataWord(2)); assertEquals(0xAA, df.getDataWord(2));