SCViewer/tests/com.minres.scviewer.databas.../src/com/minres/scviewer/database/test/DatabaseServicesTest.java

111 lines
3.4 KiB
Java
Raw Normal View History

/*******************************************************************************
2021-01-09 20:10:58 +01:00
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
2015-01-06 17:14:16 +01:00
package com.minres.scviewer.database.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import java.util.Map.Entry;
2015-01-06 17:14:16 +01:00
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
2020-11-28 10:22:22 +01:00
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IWaveform;
2015-01-06 17:14:16 +01:00
import com.minres.scviewer.database.IWaveformDb;
public class DatabaseServicesTest {
private IWaveformDb waveformDb;
2021-01-14 23:14:05 +01:00
2015-01-06 17:14:16 +01:00
@Before
public void setUp() throws Exception {
2021-01-14 23:14:05 +01:00
waveformDb=TestWaveformDbFactory.getDatabase();
}
2015-01-06 17:14:16 +01:00
@After
public void tearDown() throws Exception {
}
@Test
public void testVCD() throws Exception {
2015-01-06 17:14:16 +01:00
File f = new File("inputs/my_db.vcd").getAbsoluteFile();
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
List<IWaveform> waves= waveformDb.getAllWaves();
assertEquals(14, waves.size());
assertEquals(2, waveformDb.getChildNodes().size());
IWaveform bus_data_wave = waves.get(0);
2020-11-28 10:22:22 +01:00
Entry<Long, IEvent[]> bus_data_entry = bus_data_wave.getEvents().floorEntry(1400000000L);
2021-01-09 20:10:58 +01:00
assertEquals("01111000", bus_data_entry.getValue()[0].toString());
IWaveform rw_wave = waves.get(2);
2020-11-28 10:22:22 +01:00
Entry<Long, IEvent[]> rw_entry = rw_wave.getEvents().floorEntry(2360000000L);
2021-01-09 20:10:58 +01:00
assertEquals("1", rw_entry.getValue()[0].toString());
2015-01-06 17:14:16 +01:00
}
@Test
public void testTxSQLite() throws Exception {
File f = new File("inputs/my_sqldb.txdb").getAbsoluteFile();
2015-01-06 17:14:16 +01:00
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
assertEquals(3, waveformDb.getAllWaves().size());
assertEquals(1, waveformDb.getChildNodes().size());
2015-01-06 17:14:16 +01:00
}
@Test
public void testTxText() throws Exception {
2015-01-06 17:14:16 +01:00
File f = new File("inputs/my_db.txlog").getAbsoluteFile();
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
List<IWaveform> waveforms = waveformDb.getAllWaves();
assertEquals(3, waveforms.size());
assertEquals(1, waveformDb.getChildNodes().size());
for(IWaveform w:waveforms) {
if(w.getId().equals(1l)) {
2021-01-14 23:14:05 +01:00
assertEquals(2, w.getRowCount());
} else if(w.getId().equals(2l)) {
2021-01-14 23:14:05 +01:00
assertEquals(1, w.getRowCount());
} else if(w.getId().equals(3l)) {
2021-01-14 23:14:05 +01:00
assertEquals(1, w.getRowCount());
}
}
2015-01-06 17:14:16 +01:00
}
@Test
public void testTxTextTruncated() throws Exception {
File f = new File("inputs/my_db_truncated.txlog").getAbsoluteFile();
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
assertEquals(3, waveformDb.getAllWaves().size());
assertEquals(1, waveformDb.getChildNodes().size());
}
2018-07-14 11:42:55 +02:00
@Test
public void testHierarchicalVCD() throws Exception {
File f = new File("inputs/simple_system.vcd").getAbsoluteFile();
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
assertEquals(779, waveformDb.getAllWaves().size());
2018-07-16 13:17:58 +02:00
assertEquals(1, waveformDb.getChildNodes().size());
2018-07-14 11:42:55 +02:00
}
2015-01-06 17:14:16 +01:00
}