extra state validation is needed

This commit is contained in:
rusefi 2021-07-09 01:11:20 -04:00
parent 1abf933213
commit 9fcca87332
6 changed files with 18 additions and 4 deletions

View File

@ -3520,7 +3520,6 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
commandButton = "TLE8888 test bench", cmd_set_engine_type_8888_test@@if_show_test_presets
commandButton = "Reset firmware settings", cmd_set_engine_type_default
; Board->ECU stimulator
dialog = ecuStimulator, "ECU stimulator"
field = "Trigger Simulator", triggerSimulatorFrequency

Binary file not shown.

View File

@ -582,6 +582,10 @@ public class ConfigDefinition {
int v = Integer.parseInt(line);
registry.register(name, v);
} else {
if (line.contains(" ") && !VariableRegistry.isQuoted(line, '\"') && !VariableRegistry.isQuoted(line, '\'')) {
throw new IllegalStateException("Unexpected space in unquoted " + line);
}
registry.register(name, line);
}
}

View File

@ -19,7 +19,7 @@ import static com.rusefi.ConfigField.BOOLEAN_T;
*/
public class ReaderState {
public static final String BIT = "bit";
protected static final String DEFINE = "#define";
public static final String DEFINE = "#define";
private static final String CUSTOM = "custom";
private static final String END_STRUCT = "end_struct";
private static final String STRUCT_NO_PREFIX = "struct_no_prefix ";

View File

@ -171,7 +171,7 @@ public class VariableRegistry {
}
}
private static boolean isQuoted(String value, char quote) {
public static boolean isQuoted(String value, char quote) {
if (value == null)
return false;
value = value.trim();

View File

@ -81,12 +81,23 @@ public class ConfigFieldParserTest {
new ReaderState().readBufferedReader(reader, Collections.emptyList());
}
@Test(expected = IllegalStateException.class)
public void invalidDefine() throws IOException {
String test = "struct pid_s\n" +
ReaderState.DEFINE + " show show_Hellen121vag_presets true\n" +
"end_struct\n" +
"";
VariableRegistry.INSTANCE.clear();
BufferedReader reader = new BufferedReader(new StringReader(test));
new ReaderState().readBufferedReader(reader, Collections.emptyList());
}
@Test
public void multiplicationInDefine() throws IOException {
String test = "struct pid_s\n" +
"#define ERROR_BUFFER_SIZE 120\n" +
"#define ERROR_BUFFER_COUNT 120\n" +
"#define RESULT @@ERROR_BUFFER_SIZE@@ * @@ERROR_BUFFER_COUNT@@\n" +
"#define RESULT @@ERROR_BUFFER_SIZE@@*@@ERROR_BUFFER_COUNT@@\n" +
"\tint16_t periodMs;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"end_struct\n" +
"";