future fully integrated PinoutLogic test

This commit is contained in:
rusefillc 2023-02-11 15:12:55 -05:00
parent fab6076224
commit c14d791d53
3 changed files with 81 additions and 8 deletions

View File

@ -176,8 +176,7 @@ public class ConfigDefinition {
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
if (pinoutLogic != null) {
pinoutLogic.readFiles();
pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), state, parseState);
pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), parseState, state.getEnumsReader());
}
// Parse the input files

View File

@ -43,7 +43,7 @@ public class PinoutLogic {
return null;
}
private static void registerPins(String boardName, ArrayList<PinState> listPins, VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) {
private static void registerPins(String boardName, ArrayList<PinState> listPins, VariableRegistry registry, DefinitionsState parseState, EnumsReader enumsReader) {
if (listPins == null || listPins.isEmpty()) {
return;
}
@ -61,7 +61,7 @@ public class PinoutLogic {
}
PinType listPinType = PinType.find(className);
String pinType = listPinType.getPinType();
EnumsReader.EnumState enumList = state.getEnumsReader().getEnums().get(pinType);
EnumsReader.EnumState enumList = enumsReader.getEnums().get(pinType);
Objects.requireNonNull(enumList, "Enum for " + pinType);
Map.Entry<String, Value> kv = find(enumList, id);
if (kv == null) {
@ -80,7 +80,7 @@ public class PinoutLogic {
String outputEnumName = namePinType.getOutputEnumName();
String pinType = namePinType.getPinType();
String nothingName = namePinType.getNothingName();
EnumsReader.EnumState enumList = state.getEnumsReader().getEnums().get(pinType);
EnumsReader.EnumState enumList = enumsReader.getEnums().get(pinType);
EnumPair pair = enumToOptionsList(nothingName, enumList, kv.getValue());
if (pair.getSimpleForm().length() > 0) {
// we seem to be here if specific pin category like switch_inputs has no pins
@ -194,8 +194,9 @@ public class PinoutLogic {
return new PinoutLogic(new FileSystemBoardInputsImpl(boardName));
}
public void registerBoardSpecificPinNames(VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) throws IOException {
registerPins(boardInputs.getName(), globalList, registry, state, parseState);
public void registerBoardSpecificPinNames(VariableRegistry registry, DefinitionsState parseState, EnumsReader enumsReader) throws IOException {
readFiles();
registerPins(boardInputs.getName(), globalList, registry, parseState, enumsReader);
try (Writer getTsNameByIdFile = boardInputs.getWriter()) {
getTsNameByIdFile.append(header);
@ -218,7 +219,7 @@ public class PinoutLogic {
}
}
public void readFiles() throws IOException {
private void readFiles() throws IOException {
for (Object yamlFile : boardInputs.getBoardYamlKeys()) {
header.append("// auto-generated by PinoutLogic.java based on " + yamlFile + "\n");
readMetaInfo(yamlFile.toString(), boardInputs.getReader(yamlFile));

View File

@ -0,0 +1,73 @@
package com.rusefi.pinout;
import com.rusefi.EnumsReader;
import com.rusefi.VariableRegistry;
import com.rusefi.newparse.ParseState;
import org.junit.Test;
import java.io.*;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class PinoutLogicIntegratedTest {
@Test
public void testWholeThing() throws IOException {
StringWriter testWriter = new StringWriter();
Reader input = new StringReader("pins:\n" +
" - pin: 1\n" +
" id: [E11, E11]\n" +
" class: [event_inputs, switch_inputs]\n" +
" function: Digital trigger/switch input for instance Hall type CAM\n" +
" ts_name: Digital 2\n" +
" type: din");
BoardInputs testBoard = new BoardInputs() {
@Override
public List<?> getBoardYamlKeys() {
return Collections.singletonList("key");
}
@Override
public Reader getReader(Object yamlKey) {
return input;
}
@Override
public String getName() {
return "test";
}
@Override
public List<String> getInputFiles() {
throw new UnsupportedOperationException();
}
@Override
public Writer getWriter() {
return testWriter;
}
};
VariableRegistry registry = new VariableRegistry();
EnumsReader enumsReader = new EnumsReader();
enumsReader.read(new StringReader("#define output_pin_e_enum \"NONE\", \"INVALID\", \"PA0\", \"PA1\", \"PA2\"\n" +
"custom output_pin_e 2 bits, U16, @OFFSET@, [0:7], @@output_pin_e_enum@@\n"));
enumsReader.read(new StringReader("#define Gpio_enum \"NONE\", \"INVALID\", \"PA0\", \"PA1\", \"PA2\", \"PA3\"\n" +
"\n" +
"custom Gpio 2 bits, U16, @OFFSET@, [0:7], @@Gpio_enum@@"));
ParseState definitionState = new ParseState();
PinoutLogic logic = new PinoutLogic(testBoard);
//logic.registerBoardSpecificPinNames(registry, definitionState, enumsReader);
// assertEquals("", testWriter.getBuffer().toString());
}
}