diff --git a/pom.xml b/pom.xml
index 85afb62..41d0a6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,13 @@
${junit.version}
test
+
+
+ org.mockito
+ mockito-core
+ 5.17.0
+ test
+
@@ -113,6 +120,24 @@
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+
+ properties
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ @{argLine} -javaagent:${org.mockito:mockito-core:jar}
+
+
\ No newline at end of file
diff --git a/src/main/java/fabrik/simulator/pic16f84/Commands.java b/src/main/java/fabrik/simulator/pic16f84/Commands.java
index 8116fde..7fab199 100644
--- a/src/main/java/fabrik/simulator/pic16f84/Commands.java
+++ b/src/main/java/fabrik/simulator/pic16f84/Commands.java
@@ -4,6 +4,7 @@ import fabrik.simulator.pic16f84.interfaces.*;
public class Commands extends PICComponent implements CommandInterface {
private int wRegister;
private long totalExecutionTime;
+ private double executionTimeMultiplier = 1;
public Commands(){
super();
@@ -22,7 +23,7 @@ public class Commands extends PICComponent implements CommandInterface {
}
public double getTotalExecutionTime() {
- return (totalExecutionTime * frontendController.getExecutionTimeMultiplier());
+ return (totalExecutionTime * getExecutionTimeMultiplier());
}
public void resetTotalExecutionTime() {
@@ -248,8 +249,6 @@ public class Commands extends PICComponent implements CommandInterface {
else{
System.out.println("Nicht gefunden!");
}
-
-
}
public void SLEEP() {
@@ -557,9 +556,39 @@ public class Commands extends PICComponent implements CommandInterface {
}
}
+ public double getExecutionTimeMultiplier(){
+ return executionTimeMultiplier;
+ }
+
+ public void setExecutionTimeMultiplier(String option){
+ switch (option) {
+ case "8 MHZ":
+ executionTimeMultiplier = 0.5;
+ break;
+
+ case "4 MHZ":
+ executionTimeMultiplier = 1;
+ break;
+ case "1 MHZ":
+ executionTimeMultiplier = 4;
+ break;
+ case "500 HZ":
+ executionTimeMultiplier = 8;
+ break;
+
+ case "100 HZ":
+ executionTimeMultiplier = 40;
+ break;
+
+ case "32 HZ":
+ executionTimeMultiplier = 125;
+ break;
+ }
+ }
+
+
@Override
public void initialize(PICComponents picComponents) {
- System.out.println("Commands");
super.initialize(picComponents);
}
}
diff --git a/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java b/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java
index 587b4a2..45ff56e 100644
--- a/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java
+++ b/src/main/java/fabrik/simulator/pic16f84/Controller_Frontend.java
@@ -43,13 +43,6 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
private int [][] read;
private int [] ind;
private PICComponents picComponents;
- private double executionTimeMultiplier = 1;
-
-
-
- public double getExecutionTimeMultiplier(){
- return executionTimeMultiplier;
- }
private boolean isBreakpointReached = false;
@@ -160,29 +153,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
private void updateExecutionTimeMultiplier() {
String selectedOption = executionTimeComboBox.getValue();
- switch (selectedOption) {
- case "8 MHZ":
- executionTimeMultiplier = 0.5;
- break;
-
- case "4 MHZ":
- executionTimeMultiplier = 1;
- break;
- case "1 MHZ":
- executionTimeMultiplier = 4;
- break;
- case "500 HZ":
- executionTimeMultiplier = 8;
- break;
-
- case "100 HZ":
- executionTimeMultiplier = 40;
- break;
-
- case "32 HZ":
- executionTimeMultiplier = 125;
- break;
- }
+ commands.setExecutionTimeMultiplier(selectedOption);
}
@FXML
diff --git a/src/main/java/fabrik/simulator/pic16f84/EEPROM.java b/src/main/java/fabrik/simulator/pic16f84/EEPROM.java
index ddd3034..19791a1 100644
--- a/src/main/java/fabrik/simulator/pic16f84/EEPROM.java
+++ b/src/main/java/fabrik/simulator/pic16f84/EEPROM.java
@@ -36,6 +36,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
}
public long read (int address) {
+ if (address < 0) return 0;
FileReader reader;
try {
reader = new FileReader("eeprom.json");
@@ -60,6 +61,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
}
public void write (int address, long data) {
+ if (address < 0) return;
FileReader reader;
try {
reader = new FileReader("eeprom.json");
@@ -172,7 +174,6 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
@Override
public void initialize(PICComponents picComponents) {
- System.out.println("EEPROM");
super.initialize(picComponents);
}
}
diff --git a/src/main/java/fabrik/simulator/pic16f84/PICComponent.java b/src/main/java/fabrik/simulator/pic16f84/PICComponent.java
index 1989679..f5fe00e 100644
--- a/src/main/java/fabrik/simulator/pic16f84/PICComponent.java
+++ b/src/main/java/fabrik/simulator/pic16f84/PICComponent.java
@@ -5,7 +5,7 @@ import fabrik.simulator.pic16f84.interfaces.*;
public abstract class PICComponent {
DataRegisterInterface dataRegister;
EEPROMInterface eeprom;
- PreScaler preScaler;
+ PreScalerInterface preScaler;
IOPortInterface ioPorts;
TimerInterface timer;
InterruptInterface interrupts;
@@ -22,7 +22,7 @@ public abstract class PICComponent {
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
eeprom = (EEPROMInterface) picComponents.getComponent(EEPROMInterface.class);
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
- preScaler = (PreScaler) picComponents.getComponent(PreScalerInterface.class);
+ preScaler = (PreScalerInterface) picComponents.getComponent(PreScalerInterface.class);
timer = (TimerInterface) picComponents.getComponent(TimerInterface.class);
interrupts = (InterruptInterface) picComponents.getComponent(InterruptInterface.class);
//table = (TableInterface) picComponents.getComponent(TableInterface.class);
diff --git a/src/main/java/fabrik/simulator/pic16f84/WatchdogTimer.java b/src/main/java/fabrik/simulator/pic16f84/WatchdogTimer.java
index 8c9f352..e1b3b7f 100644
--- a/src/main/java/fabrik/simulator/pic16f84/WatchdogTimer.java
+++ b/src/main/java/fabrik/simulator/pic16f84/WatchdogTimer.java
@@ -26,7 +26,7 @@ public class WatchdogTimer extends PICComponent implements WatchdogTimerInterfac
}
else {
rawtimer++;
- realtimer = (long) (rawtimer * frontendController.getExecutionTimeMultiplier());
+ realtimer = (long) (rawtimer * commands.getExecutionTimeMultiplier());
}
}
}
diff --git a/src/main/java/fabrik/simulator/pic16f84/interfaces/CommandInterface.java b/src/main/java/fabrik/simulator/pic16f84/interfaces/CommandInterface.java
index a05f745..4cbeacb 100644
--- a/src/main/java/fabrik/simulator/pic16f84/interfaces/CommandInterface.java
+++ b/src/main/java/fabrik/simulator/pic16f84/interfaces/CommandInterface.java
@@ -10,4 +10,10 @@ public interface CommandInterface extends PICComponentInterface {
void decode(int i);
void resetTotalExecutionTime();
+
+ void addExecutionTime(int i);
+
+ double getExecutionTimeMultiplier();
+
+ void setExecutionTimeMultiplier(String option);
}
diff --git a/src/main/java/fabrik/simulator/pic16f84/interfaces/EEPROMInterface.java b/src/main/java/fabrik/simulator/pic16f84/interfaces/EEPROMInterface.java
index 776b4bd..4f4c49f 100644
--- a/src/main/java/fabrik/simulator/pic16f84/interfaces/EEPROMInterface.java
+++ b/src/main/java/fabrik/simulator/pic16f84/interfaces/EEPROMInterface.java
@@ -4,4 +4,8 @@ public interface EEPROMInterface extends PICComponentInterface {
void registerTime(boolean b);
void parse(int i, int content, int i1);
+
+ long read(int address);
+
+ void write (int address, long data);
}
diff --git a/src/main/java/fabrik/simulator/pic16f84/interfaces/FrontendControllerInterface.java b/src/main/java/fabrik/simulator/pic16f84/interfaces/FrontendControllerInterface.java
index bc4364e..bc7aeb8 100644
--- a/src/main/java/fabrik/simulator/pic16f84/interfaces/FrontendControllerInterface.java
+++ b/src/main/java/fabrik/simulator/pic16f84/interfaces/FrontendControllerInterface.java
@@ -1,7 +1,6 @@
package fabrik.simulator.pic16f84.interfaces;
public interface FrontendControllerInterface extends PICComponentInterface {
- double getExecutionTimeMultiplier();
void sleep();
diff --git a/src/test/java/fabrik/simulator/pic16f84/CommandsTests.java b/src/test/java/fabrik/simulator/pic16f84/CommandsTests.java
new file mode 100644
index 0000000..a81e121
--- /dev/null
+++ b/src/test/java/fabrik/simulator/pic16f84/CommandsTests.java
@@ -0,0 +1,88 @@
+package fabrik.simulator.pic16f84;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+import fabrik.simulator.pic16f84.interfaces.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+
+class CommandsTests {
+ PICComponents picComponents;
+
+ public CommandsTests() {}
+
+ @BeforeEach
+ void resetComponents() {
+ picComponents = new PICComponents();
+ }
+
+ @Test
+ @DisplayName("Execution Time wird korrekt addiert")
+ void executionTimeIsAddedCorrectly() {
+ TimerInterface timerMock = mock(TimerInterface.class);
+ picComponents.registerComponent(TimerInterface.class, timerMock);
+
+ EEPROMInterface eepromMock = mock(EEPROMInterface.class);
+ picComponents.registerComponent(EEPROMInterface.class, eepromMock);
+
+ CommandInterface commands = new Commands();
+ picComponents.registerComponent(CommandInterface.class, commands);
+ picComponents.initAll();
+
+
+ commands.addExecutionTime(5);
+
+
+ assertEquals(5, commands.getTotalExecutionTime());
+ }
+
+ @Test
+ @DisplayName("Execution Time wird korrekt zurückgesetzt")
+ void executionTimeResetWorks() {
+ TimerInterface timerMock = mock(TimerInterface.class);
+ picComponents.registerComponent(TimerInterface.class, timerMock);
+
+ EEPROMInterface eepromMock = mock(EEPROMInterface.class);
+ picComponents.registerComponent(EEPROMInterface.class, eepromMock);
+
+ CommandInterface commands = new Commands();
+ picComponents.registerComponent(CommandInterface.class, commands);
+ picComponents.initAll();
+
+
+ commands.addExecutionTime(5);
+ commands.resetTotalExecutionTime();
+
+
+ assertEquals(0, commands.getTotalExecutionTime());
+ }
+
+ @Test
+ @DisplayName("Execution Time Faktor wird berücksichtigt")
+ void executionTimeMultiplierIsUsed() {
+ TimerInterface timerMock = mock(TimerInterface.class);
+ picComponents.registerComponent(TimerInterface.class, timerMock);
+
+ EEPROMInterface eepromMock = mock(EEPROMInterface.class);
+ picComponents.registerComponent(EEPROMInterface.class, eepromMock);
+
+ CommandInterface commands = new Commands();
+ picComponents.registerComponent(CommandInterface.class, commands);
+ picComponents.initAll();
+
+ commands.addExecutionTime(5);
+ commands.setExecutionTimeMultiplier("100 HZ");
+
+ assertEquals(5 * 40, commands.getTotalExecutionTime());
+ }
+
+ @Test
+ @DisplayName("Decode mit ungültigem Opcode wirft keine Exception")
+ void decodeInvalidOpcodeDoesNotCrash() {
+ CommandInterface commands = new Commands();
+
+ assertDoesNotThrow(() -> commands.decode(1));
+ }
+}
diff --git a/src/test/java/fabrik/simulator/pic16f84/DataRegisterTests.java b/src/test/java/fabrik/simulator/pic16f84/DataRegisterTests.java
new file mode 100644
index 0000000..b40c794
--- /dev/null
+++ b/src/test/java/fabrik/simulator/pic16f84/DataRegisterTests.java
@@ -0,0 +1,50 @@
+package fabrik.simulator.pic16f84;
+
+import fabrik.simulator.pic16f84.interfaces.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+
+class DataRegisterTests {
+ PICComponents picComponents;
+
+ public DataRegisterTests() {}
+
+ @BeforeEach
+ void resetComponents() {
+ picComponents = new PICComponents();
+ }
+
+
+ @Test
+ @DisplayName("DataRegister wird durch Components initialisiert und enthält dann die korrekten Startwerte")
+ void registerGetsInitializedThroughComponents() {
+ IOPortInterface mockIOPorts = mock(IOPortInterface.class);
+ picComponents.registerComponent(IOPortInterface.class, mockIOPorts);
+
+ DataRegisterInterface dataRegister = new DataRegister();
+ picComponents.registerComponent(DataRegisterInterface.class, dataRegister);
+
+
+ picComponents.initAll();
+ int [] expected = {0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 255, 0, 24, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ int [] actual = dataRegister.getDataRegister();
+
+ assertEquals(expected.length, actual.length);
+ for (int i = 0; i