changes grouping of bits in bitvector to create copies
This commit is contained in:
1 parent
cc28c417c1
commit
9c249b9ba0
3 files changed
+120
No files matched your search
+70
@@ -18,6 +18,76 @@ import com.minres.scviewer.database.ui.TrackEntry;
|
||||
import com.minres.scviewer.database.ui.TrackEntry.HierState;
|
||||
|
||||
public class TrackGroupingTest {
|
||||
@Test
|
||||
public void groupingRecordedAndCombinedVectorBitsCopiesThemAfterTheVector() {
|
||||
var source = new BitVectorExpansionTest.Signal("bus", 3) {
|
||||
@Override public com.minres.scviewer.database.IEventList getEvents() {
|
||||
throw new AssertionError("Grouping must not read signal events");
|
||||
}
|
||||
};
|
||||
var combined = new com.minres.scviewer.database.CombinedBitVectorWaveform("combined", List.of(
|
||||
new com.minres.scviewer.database.CombinedBitVectorWaveform.SourceBit(source, 2),
|
||||
new com.minres.scviewer.database.CombinedBitVectorWaveform.SourceBit(source, 1),
|
||||
new com.minres.scviewer.database.CombinedBitVectorWaveform.SourceBit(source, 0)));
|
||||
for (var waveform : List.of(source, combined)) {
|
||||
TrackEntry bus = new TrackEntry(waveform, null);
|
||||
bus.setExpanded(true);
|
||||
var bits = List.copyOf(bus.waveforms);
|
||||
bits.get(0).valueDisplay = TrackEntry.ValueDisplay.SIGNED;
|
||||
bits.get(2).waveDisplay = TrackEntry.WaveDisplay.STEP_WISE;
|
||||
TrackEntry tail = new TrackEntry(new EmptyWaveform("tail"), null);
|
||||
var roots = new java.util.ArrayList<>(List.of(bus, tail));
|
||||
|
||||
TrackEntry group = TrackEntry.groupTracks(roots, List.of(bits.get(2), bits.get(0)), "bits", null);
|
||||
assertEquals(List.of(bus, group, tail), roots);
|
||||
assertEquals(bits, bus.waveforms);
|
||||
assertEquals(2, group.waveforms.size());
|
||||
for (int index = 0; index < 2; index++) {
|
||||
TrackEntry original = bits.get(index == 0 ? 0 : 2);
|
||||
TrackEntry copy = group.waveforms.get(index);
|
||||
assertNotSame(original, copy);
|
||||
assertSame(original.waveform, copy.waveform);
|
||||
assertEquals(original.valueDisplay, copy.valueDisplay);
|
||||
assertEquals(original.waveDisplay, copy.waveDisplay);
|
||||
}
|
||||
group.waveforms.get(0).valueDisplay = TrackEntry.ValueDisplay.BINARY;
|
||||
assertEquals(TrackEntry.ValueDisplay.SIGNED, bits.get(0).valueDisplay);
|
||||
assertTrue(TrackEntry.ungroupTracks(roots, group));
|
||||
assertEquals(bits, bus.waveforms);
|
||||
assertEquals(List.of(bus, group.waveforms.get(0), group.waveforms.get(1), tail), roots);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupingBitsOfNestedVectorPlacesCopiesInItsParentGroup() {
|
||||
TrackEntry bus = new TrackEntry(new BitVectorExpansionTest.Signal("bus", 2), null);
|
||||
bus.setExpanded(true);
|
||||
var bits = List.copyOf(bus.waveforms);
|
||||
TrackEntry tail = new TrackEntry(new EmptyWaveform("tail"), null);
|
||||
TrackEntry outer = TrackEntry.group("outer", List.of(bus, tail), null);
|
||||
var roots = new java.util.ArrayList<>(List.of(outer));
|
||||
TrackEntry group = TrackEntry.groupTracks(roots, bits, "bits", null);
|
||||
assertEquals(List.of(outer), roots);
|
||||
assertEquals(List.of(bus, group, tail), outer.waveforms);
|
||||
assertEquals(bits, bus.waveforms);
|
||||
bus.setExpanded(false);
|
||||
bus.setExpanded(true);
|
||||
assertEquals(bits, bus.waveforms);
|
||||
assertNotSame(bits.get(0), group.waveforms.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupingStandaloneBitTracksMovesTheirExistingEntries() {
|
||||
var source = new BitVectorExpansionTest.Signal("bus", 2);
|
||||
TrackEntry first = new TrackEntry(new com.minres.scviewer.database.ui.BitWaveform(source, 1), null);
|
||||
TrackEntry second = new TrackEntry(new com.minres.scviewer.database.ui.BitWaveform(source, 0), null);
|
||||
var roots = new java.util.ArrayList<>(List.of(first, second));
|
||||
TrackEntry group = TrackEntry.groupTracks(roots, List.of(second, first), "bits", null);
|
||||
assertEquals(List.of(group), roots);
|
||||
assertSame(first, group.waveforms.get(0));
|
||||
assertSame(second, group.waveforms.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletingNestedSeparatorLeavesItsGroupAndOtherMembersIntact() {
|
||||
TrackEntry separator = new TrackEntry(new EmptyWaveform(), null);
|
||||
|
||||
+26
@@ -465,6 +465,32 @@ public class WaveformScrollTest {
|
||||
assertEquals(List.of(bus), view.getStreamList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupingExpandedBitsKeepsTheVectorIntactAndSelectsTheNewGroup() {
|
||||
var source = new BitVectorExpansionTest.Signal("bus", 3);
|
||||
TrackEntry bus = new TrackEntry(source, null);
|
||||
bus.setExpanded(true);
|
||||
view.getStreamList().add(bus);
|
||||
view.update();
|
||||
var bits = List.copyOf(bus.waveforms);
|
||||
view.setSelection(new StructuredSelection(List.of(bits.get(2), bits.get(0))));
|
||||
TrackEntry group = view.groupSelectedTracks("bits");
|
||||
assertNotNull(group);
|
||||
assertEquals(List.of(bus, group), view.getStreamList());
|
||||
assertEquals(bits, bus.waveforms);
|
||||
assertSame(group, ((StructuredSelection) view.getSelection()).getFirstElement());
|
||||
assertSame(bits.get(0).waveform, group.waveforms.get(0).waveform);
|
||||
assertSame(bits.get(2).waveform, group.waveforms.get(1).waveform);
|
||||
assertNotSame(bits.get(0), group.waveforms.get(0));
|
||||
assertNotSame(bits.get(2), group.waveforms.get(1));
|
||||
view.setGroupExpanded(bus, false);
|
||||
view.setGroupExpanded(bus, true);
|
||||
assertEquals(bits, bus.waveforms);
|
||||
view.ungroupTracks(group);
|
||||
assertEquals(bits, bus.waveforms);
|
||||
assertEquals(List.of(bus, group.waveforms.get(0), group.waveforms.get(1)), view.getStreamList());
|
||||
}
|
||||
|
||||
private Point origin() {
|
||||
try { return (Point) canvas.getClass().getMethod("getOrigin").invoke(canvas); }
|
||||
catch (ReflectiveOperationException e) { throw new AssertionError(e); }
|
||||
|
||||
Reference in new issue
Block a user