diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java index 4d6c8c4..50e3549 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java @@ -243,13 +243,13 @@ public class FtrDbLoader implements IWaveformDbLoader { FtrTx scvTx = new FtrTx(txId, stream.getId(), genId, startTime, endTime, blockId, blockOffset); updateTransactions(txId, scvTx); if (scvTx.beginTime == scvTx.endTime) { - stream.addEvent(new TxEvent(this, EventKind.SINGLE, txId, scvTx.beginTime)); - gen.addEvent(new TxEvent(this, EventKind.SINGLE, txId, scvTx.beginTime)); + stream.addEvent(new TxEvent(this, EventKind.SINGLE, txId, scvTx.beginTime, stream.getType())); + gen.addEvent(new TxEvent(this, EventKind.SINGLE, txId, scvTx.beginTime, gen.getType())); } else { - stream.addEvent(new TxEvent(this, EventKind.BEGIN, txId, scvTx.beginTime)); - gen.addEvent(new TxEvent(this, EventKind.BEGIN, txId, scvTx.beginTime)); - stream.addEvent(new TxEvent(this, EventKind.END, txId, scvTx.endTime)); - gen.addEvent(new TxEvent(this, EventKind.END, txId, scvTx.endTime)); + stream.addEvent(new TxEvent(this, EventKind.BEGIN, txId, scvTx.beginTime, stream.getType())); + gen.addEvent(new TxEvent(this, EventKind.BEGIN, txId, scvTx.beginTime, gen.getType())); + stream.addEvent(new TxEvent(this, EventKind.END, txId, scvTx.endTime, stream.getType())); + gen.addEvent(new TxEvent(this, EventKind.END, txId, scvTx.endTime, gen.getType())); } break; default: { // skip over 7:begin attr, 8:record attr, 9:end attr diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxEvent.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxEvent.java index 6b5e33a..eb3f67c 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxEvent.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxEvent.java @@ -26,6 +26,8 @@ class TxEvent implements ITxEvent { /** The kind. */ final EventKind kind; + private final WaveformType waveformType; + /** The transaction. */ final long transaction; @@ -40,12 +42,14 @@ class TxEvent implements ITxEvent { * @param kind the kind * @param transaction the transaction * @param time the time + * @param waveformType the type of the owning waveform */ - TxEvent(FtrDbLoader loader, EventKind kind, Long transaction, Long time) { + TxEvent(FtrDbLoader loader, EventKind kind, Long transaction, Long time, WaveformType waveformType) { this.loader = loader; this.kind = kind; this.transaction = transaction; this.time = time; + this.waveformType = waveformType; } /** @@ -56,7 +60,7 @@ class TxEvent implements ITxEvent { */ @Override public ITxEvent duplicate() throws CloneNotSupportedException { - return new TxEvent(loader, kind, transaction, time); + return new TxEvent(loader, kind, transaction, time, waveformType); } /** @@ -69,16 +73,6 @@ class TxEvent implements ITxEvent { return kind.toString() + "@" + time + " of tx #" + transaction; } - /** - * Gets the type. - * - * @return the type - */ - @Override - public WaveformType getType() { - return WaveformType.STREAM; - } - /** * Gets the kind. * diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxGenerator.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxGenerator.java index d8ba9b0..0ffe96f 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxGenerator.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxGenerator.java @@ -16,6 +16,7 @@ import java.util.List; import com.minres.scviewer.database.DirectionType; import com.minres.scviewer.database.IEventList; import com.minres.scviewer.database.IWaveform; +import com.minres.scviewer.database.WaveformType; /** * The Class TxGenerator. @@ -45,6 +46,11 @@ class TxGenerator extends AbstractTxStream { stream.addChild(this); } + @Override + public WaveformType getType() { + return WaveformType.GENERATOR; + } + /** * Checks if is same. * diff --git a/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxEvent.java b/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxEvent.java index 509a730..af35deb 100644 --- a/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxEvent.java +++ b/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxEvent.java @@ -57,11 +57,6 @@ public class TxEvent implements ITxEvent { return type.toString()+"@"+getTime()+" of tx #"+tx.getId(); } - @Override - public WaveformType getType() { - return WaveformType.STREAM; - } - @Override public int getRowIndex() { return inGenerator ? tx.getConcurrencyIdxInGen() : tx.getConcurrencyIndxInStream(); diff --git a/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxGenerator.java b/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxGenerator.java index 1a0d16f..88dbe82 100644 --- a/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxGenerator.java +++ b/plugins/com.minres.scviewer.database.sqlite/src/com/minres/scviewer/database/sqlite/TxGenerator.java @@ -18,6 +18,7 @@ import java.util.TreeMap; import com.minres.scviewer.database.DirectionType; import com.minres.scviewer.database.IWaveform; +import com.minres.scviewer.database.WaveformType; import com.minres.scviewer.database.sqlite.db.IDatabase; import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler; import com.minres.scviewer.database.sqlite.tables.ScvGenerator; @@ -39,6 +40,11 @@ public class TxGenerator extends AbstractTxStream { stream.addChild(this); } + @Override + public WaveformType getType() { + return WaveformType.GENERATOR; + } + @Override public long getId() { return (long) scvGenerator.getId(); diff --git a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.java b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.java index 813af4f..ddb1aa9 100644 --- a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.java +++ b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TextDbLoader.java @@ -421,13 +421,13 @@ public class TextDbLoader implements IWaveformDbLoader { TxGenerator gen = loader.txGenerators.get(scvTx.generatorId); TxStream stream = loader.txStreams.get(gen.stream.getId()); if (scvTx.beginTime == scvTx.endTime) { - stream.addEvent(new TxEvent(loader, EventKind.SINGLE, id, scvTx.beginTime)); - gen.addEvent(new TxEvent(loader, EventKind.SINGLE, id, scvTx.beginTime)); + stream.addEvent(new TxEvent(loader, EventKind.SINGLE, id, scvTx.beginTime, stream.getType())); + gen.addEvent(new TxEvent(loader, EventKind.SINGLE, id, scvTx.beginTime, gen.getType())); } else { - stream.addEvent(new TxEvent(loader, EventKind.BEGIN, id, scvTx.beginTime)); - gen.addEvent(new TxEvent(loader, EventKind.BEGIN, id, scvTx.beginTime)); - stream.addEvent(new TxEvent(loader, EventKind.END, id, scvTx.endTime)); - gen.addEvent(new TxEvent(loader, EventKind.END, id, scvTx.endTime)); + stream.addEvent(new TxEvent(loader, EventKind.BEGIN, id, scvTx.beginTime, stream.getType())); + gen.addEvent(new TxEvent(loader, EventKind.BEGIN, id, scvTx.beginTime, gen.getType())); + stream.addEvent(new TxEvent(loader, EventKind.END, id, scvTx.endTime, stream.getType())); + gen.addEvent(new TxEvent(loader, EventKind.END, id, scvTx.endTime, gen.getType())); } if (nextLine != null && nextLine.charAt(0) == 'a') { int idx = 0; diff --git a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxEvent.java b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxEvent.java index 8a183e4..69721b2 100644 --- a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxEvent.java +++ b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxEvent.java @@ -26,6 +26,8 @@ class TxEvent implements ITxEvent { /** The kind. */ final EventKind kind; + private final WaveformType waveformType; + /** The transaction. */ final long transaction; @@ -40,12 +42,14 @@ class TxEvent implements ITxEvent { * @param kind the kind * @param transaction the transaction * @param time the time + * @param waveformType the type of the owning waveform */ - TxEvent(TextDbLoader loader, EventKind kind, Long transaction, Long time) { + TxEvent(TextDbLoader loader, EventKind kind, Long transaction, Long time, WaveformType waveformType) { this.loader = loader; this.kind = kind; this.transaction = transaction; this.time = time; + this.waveformType = waveformType; } /** @@ -56,7 +60,7 @@ class TxEvent implements ITxEvent { */ @Override public ITxEvent duplicate() throws CloneNotSupportedException { - return new TxEvent(loader, kind, transaction, time); + return new TxEvent(loader, kind, transaction, time, waveformType); } /** @@ -69,16 +73,6 @@ class TxEvent implements ITxEvent { return kind.toString() + "@" + time + " of tx #" + transaction; } - /** - * Gets the type. - * - * @return the type - */ - @Override - public WaveformType getType() { - return WaveformType.STREAM; - } - /** * Gets the kind. * diff --git a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxGenerator.java b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxGenerator.java index cafc839..d556fa5 100644 --- a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxGenerator.java +++ b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxGenerator.java @@ -16,6 +16,7 @@ import java.util.List; import com.minres.scviewer.database.DirectionType; import com.minres.scviewer.database.IWaveform; +import com.minres.scviewer.database.WaveformType; /** * The Class TxGenerator. @@ -45,6 +46,11 @@ class TxGenerator extends AbstractTxStream { stream.addChild(this); } + @Override + public WaveformType getType() { + return WaveformType.GENERATOR; + } + /** * Checks if is same. * diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java index 8c47ac4..fc76c22 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java @@ -633,7 +633,7 @@ public class WaveformView implements IWaveformView { private void addPainter(boolean even, TrackEntry streamEntry) { streamEntry.height = styleProvider.getTrackHeight(); streamEntry.vOffset = tracksVerticalHeight; - if (streamEntry.waveform.getType() == WaveformType.STREAM) { + if (streamEntry.waveform.getType().isTransaction()) { streamEntry.currentValue = ""; streamEntry.height *= streamEntry.waveform.getRowCount(); IWaveformPainter painter = new StreamPainter(waveformCanvas, even, streamEntry); @@ -690,7 +690,7 @@ public class WaveformView implements IWaveformView { else entry.currentValue = Double.toString(val); } - } else if (entry.waveform.getType() == WaveformType.STREAM) { + } else if (entry.waveform.getType().isTransaction()) { ITx[] resultsList = new ITx[entry.waveform.getRowCount()]; EventEntry firstTx = entry.waveform.getEvents().floorEntry(time); if (firstTx != null) { @@ -956,7 +956,7 @@ public class WaveformView implements IWaveformView { return; TrackEntry selectedWaveform = currentWaveformSelection.size() == 1 ? currentWaveformSelection.get(0) : getEntryFor(currentTxSelection); - if (selectedWaveform.waveform.getType() == WaveformType.STREAM && currentTxSelection != null) { + if (selectedWaveform.waveform.getType().isTransaction() && currentTxSelection != null) { if (relationType.equals(IWaveformView.NEXT_PREV_IN_STREAM)) { ITx transaction = null; if (direction == GotoDirection.NEXT) { @@ -1078,7 +1078,7 @@ public class WaveformView implements IWaveformView { TrackEntry sel = currentWaveformSelection.get(0); long time = getCursorTime(); IEventList map = null; - if (sel.waveform.getType() == WaveformType.STREAM || sel.waveform.getType() == WaveformType.SIGNAL) { + if (sel.waveform.getType().isTransaction() || sel.waveform.getType() == WaveformType.SIGNAL) { map = sel.waveform.getEvents(); } if (map != null) { @@ -1634,7 +1634,7 @@ public class WaveformView implements IWaveformView { } public boolean waveformsContainsTx() { - return streams.stream().filter(e -> e.waveform.getType() == WaveformType.STREAM).findFirst().isPresent(); + return streams.stream().filter(e -> e.waveform.getType().isTransaction()).findFirst().isPresent(); } @Override diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java index 30474c6..ab5ef49 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java @@ -238,16 +238,6 @@ public class BitVector implements IEvent { return EventKind.SINGLE; } - /** - * Gets the type. - * - * @return the type - */ - @Override - public WaveformType getType() { - return WaveformType.SIGNAL; - } - /** * Duplicate. * diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/DoubleVal.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/DoubleVal.java index fc90023..3eca2e9 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/DoubleVal.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/DoubleVal.java @@ -37,16 +37,6 @@ public class DoubleVal implements IEvent { return EventKind.SINGLE; } - /** - * Gets the type. - * - * @return the type - */ - @Override - public WaveformType getType() { - return WaveformType.SIGNAL; - } - /** * Duplicate. * diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IEvent.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IEvent.java index 08d235f..8d1bcd9 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IEvent.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IEvent.java @@ -30,11 +30,4 @@ public interface IEvent { */ public EventKind getKind(); - /** - * Gets the type. - * - * @return the type - */ - public WaveformType getType(); - } diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java index 33cfba4..dd0e447 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/WaveformType.java @@ -19,10 +19,15 @@ public enum WaveformType { SIGNAL, /** The transaction stream. */ STREAM, - /** The transaction stream. */ + /** The transaction generator. */ GENERATOR, /** The filter. */ FILTER, /** The blank line. */ - EMPTY + EMPTY; + + /** Whether this waveform contains transactions, in a stream or a generator. */ + public boolean isTransaction() { + return this == STREAM || this == GENERATOR; + } } diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java index 4ca18ca..1fcf22c 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/SearchHandler.java @@ -17,7 +17,6 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.widgets.Shell; -import com.minres.scviewer.database.WaveformType; import com.minres.scviewer.database.ui.TrackEntry; import com.minres.scviewer.e4.application.parts.WaveformViewer; public class SearchHandler { @@ -32,7 +31,7 @@ public class SearchHandler { Object[] elem = ((StructuredSelection)sel).toArray(); if(elem.length ==0) return false; TrackEntry e = findTrackEntry(elem); - return e!=null && e.waveform.getType()==WaveformType.STREAM; + return e!=null && e.waveform.getType().isTransaction(); } } return false; diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java index a6aec5a..609f157 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionList.java @@ -35,7 +35,6 @@ import com.minres.scviewer.database.DataType; import com.minres.scviewer.database.EventEntry; import com.minres.scviewer.database.EventKind; import com.minres.scviewer.database.IWaveform; -import com.minres.scviewer.database.WaveformType; import com.minres.scviewer.database.tx.ITx; import com.minres.scviewer.database.tx.ITxEvent; import com.minres.scviewer.database.ui.TrackEntry; @@ -237,7 +236,7 @@ public class TransactionList extends Composite { } public void setInput(TrackEntry trackEntry) { - if(trackEntry==null || trackEntry.waveform.getType()!=WaveformType.STREAM) { + if(trackEntry==null || !trackEntry.waveform.getType().isTransaction()) { attrNames.clear(); tableViewer.setInput(emptyList); } else if(stream != trackEntry.waveform) { diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index 396c549..25c9403 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -1030,13 +1030,13 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis } } - showTxDetails(waveformPane.getStreamList().stream().filter(t -> t.waveform.getType() == WaveformType.STREAM).findFirst().isPresent()); + showTxDetails(waveformPane.getStreamList().stream().filter(t -> t.waveform.getType().isTransaction()).findFirst().isPresent()); setFocus(); } public void removeSelectedStreamsFromList() { waveformPane.deleteSelectedTracks(); - showTxDetails(waveformPane.getStreamList().stream().filter(t -> t.waveform.getType() == WaveformType.STREAM).findFirst().isPresent()); + showTxDetails(waveformPane.getStreamList().stream().filter(t -> t.waveform.getType().isTransaction()).findFirst().isPresent()); } /** diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbLabelProvider.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbLabelProvider.java index 7229d39..c896b7a 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbLabelProvider.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/provider/TxDbLabelProvider.java @@ -177,6 +177,7 @@ public class TxDbLabelProvider implements ILabelProvider { }else if(element instanceof IWaveform){ switch(((IWaveform) element).getType()) { case STREAM: + case GENERATOR: return stream; case FILTER: break; diff --git a/plugins/com.minres.scviewer.ui/src/com/minres/scviewer/ui/views/provider/TxDbTreeLabelProvider.java b/plugins/com.minres.scviewer.ui/src/com/minres/scviewer/ui/views/provider/TxDbTreeLabelProvider.java index 2477450..2276cf2 100644 --- a/plugins/com.minres.scviewer.ui/src/com/minres/scviewer/ui/views/provider/TxDbTreeLabelProvider.java +++ b/plugins/com.minres.scviewer.ui/src/com/minres/scviewer/ui/views/provider/TxDbTreeLabelProvider.java @@ -63,6 +63,7 @@ public class TxDbTreeLabelProvider implements ILabelProvider { }else if(element instanceof IWaveform){ switch(((IWaveform) element).getType()) { case STREAM: + case GENERATOR: return stream; case FILTER: break; diff --git a/tests/com.minres.scviewer.database.test/src/com/minres/scviewer/database/test/WaveformTypeTest.java b/tests/com.minres.scviewer.database.test/src/com/minres/scviewer/database/test/WaveformTypeTest.java new file mode 100644 index 0000000..7654cac --- /dev/null +++ b/tests/com.minres.scviewer.database.test/src/com/minres/scviewer/database/test/WaveformTypeTest.java @@ -0,0 +1,89 @@ +package com.minres.scviewer.database.test; + +import static org.junit.Assert.*; + +import java.beans.PropertyChangeEvent; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.minres.scviewer.database.EventEntry; +import com.minres.scviewer.database.IEvent; +import com.minres.scviewer.database.IWaveform; +import com.minres.scviewer.database.IWaveformDb; +import com.minres.scviewer.database.IWaveformDbLoader; +import com.minres.scviewer.database.WaveformType; +import com.minres.scviewer.database.ftr.FtrDbLoader; +import com.minres.scviewer.database.sqlite.SQLiteDbLoader; +import com.minres.scviewer.database.sqlite.TxStream; +import com.minres.scviewer.database.text.TextDbLoader; + +public class WaveformTypeTest { + private void checkWaveform(IWaveform waveform, WaveformType expected) throws Exception { + assertEquals(expected, waveform.getType()); + } + + @Test + public void transactionTypesIncludeStreamsAndGenerators() { + for (WaveformType type : WaveformType.values()) + assertEquals(type == WaveformType.STREAM || type == WaveformType.GENERATOR, type.isTransaction()); + } + + @Test + public void ftrAndTextClassifyWaveformsBeforePublishingThem() throws Exception { + for (String input : new String[] {"my_db.ftr", "my_db_c.ftr", "my_db.txlog", "my_db_truncated.txlog"}) { + IWaveformDbLoader loader = input.endsWith("txlog") ? new TextDbLoader() : new FtrDbLoader(); + List published = new ArrayList<>(); + loader.addPropertyChangeListener(event -> { + if (IWaveformDbLoader.STREAM_ADDED.equals(event.getPropertyName()) + || IWaveformDbLoader.GENERATOR_ADDED.equals(event.getPropertyName())) { + WaveformType expected = IWaveformDbLoader.STREAM_ADDED.equals(event.getPropertyName()) + ? WaveformType.STREAM : WaveformType.GENERATOR; + assertEquals(expected, ((IWaveform) event.getNewValue()).getType()); + published.add(event); + } + }); + try { + loader.load(TxTestSupport.input(input)); + assertEquals(8, published.size()); + for (IWaveform waveform : loader.getAllWaves()) + checkWaveform(waveform, waveform.getParent() instanceof IWaveform + ? WaveformType.GENERATOR : WaveformType.STREAM); + } finally { loader.dispose(); } + } + } + + @Test + public void sqliteClassifiesStreamsAndLazilyLoadedGenerators() throws Exception { + SQLiteDbLoader loader = new SQLiteDbLoader(); + try { + loader.load(TxTestSupport.input("my_sqldb.txdb")); + int streams = 0, generators = 0; + for (IWaveform stream : loader.getAllWaves()) { + streams++; + assertEquals(WaveformType.STREAM, stream.getType()); + for (IWaveform generator : ((TxStream) stream).getGenerators()) { + generators++; + checkWaveform(generator, WaveformType.GENERATOR); + } + checkWaveform(stream, WaveformType.STREAM); + } + assertEquals(3, streams); + assertEquals(5, generators); + } finally { loader.dispose(); } + } + + @Test + public void vcdAndFstStillClassifySignalsCorrectly() throws Exception { + for (String input : new String[] {"my_db.vcd", "my_db.fst"}) { + IWaveformDb database = TestWaveformDbFactory.getDatabase(); + try { + assertTrue(database.load(TxTestSupport.input(input))); + assertEquals(14, database.getAllWaves().size()); + for (IWaveform signal : database.getAllWaves()) + checkWaveform(signal, WaveformType.SIGNAL); + } finally { database.close(); } + } + } +}