ソースを参照

Split test into multiple files, add test for header

Baglio Tabifata 4 年 前
コミット
26d80c47b5

+ 25 - 0
src/test/java/info/hkzlab/dupal/analyzer/CommandInterfaceTest.java

@@ -0,0 +1,25 @@
+package info.hkzlab.dupal.analyzer;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
+import org.junit.Test;
+
+import info.hkzlab.dupal.analyzer.board.boardio.DuPALCmdInterface;
+import info.hkzlab.dupal.analyzer.board.boardio.DuPALManager;
+import info.hkzlab.dupal.analyzer.devices.PAL16L8Specs;
+import info.hkzlab.dupal.analyzer.exceptions.DuPALBoardException;
+
+public class CommandInterfaceTest 
+{
+    @Test
+    public void commandInterfaceShouldBuildCorrectCommands() throws DuPALBoardException {
+        DuPALManager dpmMock = mock(DuPALManager.class);
+        DuPALCmdInterface dpci = new DuPALCmdInterface(dpmMock, new PAL16L8Specs());
+
+        when(dpmMock.readResponse()).thenReturn("[R 57]");
+        assertEquals("Issuing a read command via DPCI should return us the correct value", 0x57, dpci.read());
+        when(dpmMock.readResponse()).thenReturn("[W 00BBCCDD]");
+        assertEquals("Issuing a write command via DPCI should return us the same value as written", 0xBBCCDD, dpci.write(0xBBCCDD));
+    }
+}

+ 27 - 0
src/test/java/info/hkzlab/dupal/analyzer/FormattersTest.java

@@ -0,0 +1,27 @@
+package info.hkzlab.dupal.analyzer;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import info.hkzlab.dupal.analyzer.devices.PAL16L8Specs;
+import info.hkzlab.dupal.analyzer.exceptions.DuPALBoardException;
+import info.hkzlab.dupal.analyzer.palanalisys.formatter.EspressoFormatter;
+
+public class FormattersTest 
+{
+    @Test
+    public void espressoFormatterShouldBuildCorrect16L8Header() throws DuPALBoardException {
+        PAL16L8Specs pSpecs = new PAL16L8Specs();
+        int ioAsOutMask = 0x03;
+        String header = EspressoFormatter.formatEspressoTableHeader(pSpecs, ioAsOutMask);
+        String expectedHeader = "# PAL16L8\n" +
+                                ".i 16\n" +
+                                ".o 8\n" +
+                                ".ilb i1 i2 i3 i4 i5 i6 i7 i8 i9 i11 io16 io15 io14 io13 fio18 fio17 \n" +
+                                ".ob o19 o12 io18 io17 o19oe o12oe io18oe io17oe \n" +
+                                ".phase 00001111\n\n";
+        
+        assertEquals("EspressoFormatter should build a correct 16L8 header", expectedHeader, header);
+    }
+}

+ 1 - 23
src/test/java/info/hkzlab/dupal/analyzer/AppTest.java → src/test/java/info/hkzlab/dupal/analyzer/UtilsTest.java

@@ -1,24 +1,13 @@
 package info.hkzlab.dupal.analyzer;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.*;
 
 import org.junit.Test;
 
-import info.hkzlab.dupal.analyzer.board.boardio.DuPALCmdInterface;
-import info.hkzlab.dupal.analyzer.board.boardio.DuPALManager;
-import info.hkzlab.dupal.analyzer.devices.PAL16L8Specs;
-import info.hkzlab.dupal.analyzer.exceptions.DuPALBoardException;
 import info.hkzlab.dupal.analyzer.utilities.BitUtils;
 
-/**
- * Unit test for simple App.
- */
-public class AppTest 
+public class UtilsTest 
 {
-    /**
-     * Test BitUtils
-     */
     @Test
     public void bitUtilsShouldCorrectlyModifyBitfields() {
         assertEquals("0b01010101 with a selection mask 0x55 should be consolidated into 0b1111", 0x0F, BitUtils.consolidateBitField(0x55, 0x55));
@@ -31,15 +20,4 @@ public class AppTest
         assertEquals("0b01010101 with a scatter mask 0x0F should be scattered into 0b00000101", 0x05, BitUtils.scatterBitField(0x55, 0x0F));
         assertEquals("0b01011111 with a scatter mask 0xF0 should be scattered into 0b11110000", 0xF0, BitUtils.scatterBitField(0x5F, 0xF0));
     }
-
-    @Test
-    public void commandInterfaceShouldBuildCorrectCommands() throws DuPALBoardException {
-        DuPALManager dpmMock = mock(DuPALManager.class);
-        DuPALCmdInterface dpci = new DuPALCmdInterface(dpmMock, new PAL16L8Specs());
-
-        when(dpmMock.readResponse()).thenReturn("[R 57]");
-        assertEquals("Issuing a read command via DPCI should return us the correct value", 0x57, dpci.read());
-        when(dpmMock.readResponse()).thenReturn("[W 00BBCCDD]");
-        assertEquals("Issuing a write command via DPCI should return us the same value as written", 0xBBCCDD, dpci.write(0xBBCCDD));
-    }
 }