From d7c131dba08f89cb05b459ae53f164c61d43476f Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 14 Dec 2019 14:46:20 -0500 Subject: [PATCH] Config generation handles padding after packed booleans (bits) wrong #1057 everything should start with a unit test --- .../src/com/rusefi/ReaderState.java | 2 + .../test/ConfigFieldParserIssue1057Test.java | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserIssue1057Test.java diff --git a/java_tools/configuration_definition/src/com/rusefi/ReaderState.java b/java_tools/configuration_definition/src/com/rusefi/ReaderState.java index 3062add732..8071e3a417 100644 --- a/java_tools/configuration_definition/src/com/rusefi/ReaderState.java +++ b/java_tools/configuration_definition/src/com/rusefi/ReaderState.java @@ -46,6 +46,8 @@ public class ReaderState { } ConfigField bitField = new ConfigField(state, bitName, comment, null, BOOLEAN_T, 0, null, false, false, null, -1); + if (state.stack.isEmpty()) + throw new IllegalStateException("Parent structure expected"); state.stack.peek().addBoth(bitField); } diff --git a/java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserIssue1057Test.java b/java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserIssue1057Test.java new file mode 100644 index 0000000000..2dfd06c0d4 --- /dev/null +++ b/java_tools/configuration_definition/src/com/rusefi/test/ConfigFieldParserIssue1057Test.java @@ -0,0 +1,40 @@ +package com.rusefi.test; + +import com.rusefi.ReaderState; +import com.rusefi.output.JavaFieldsConsumer; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public class ConfigFieldParserIssue1057Test { + @Test + public void testBitsPadding() throws IOException { + ReaderState state = new ReaderState(); + JavaFieldsConsumer javaFieldsConsumer = new JavaFieldsConsumer(state) { + @Override + public void startFile() { + } + + @Override + public void endFile() { + } + }; + + String inputString = "struct pid_s\nbit activateAuxPid1;\n" + + "int fieldName;\n" + + "end_struct\n"; + BufferedReader reader = new BufferedReader(new StringReader(inputString)); + + + state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer)); + + assertEquals("\tpublic static final Field ACTIVATEAUXPID1 = Field.create(\"ACTIVATEAUXPID1\", 0, FieldType.BIT, 0);\n" + + "\tpublic static final Field FIELDNAME = Field.create(\"FIELDNAME\", 4, FieldType.INT);\n", + javaFieldsConsumer.getJavaFieldsWriter()); + } +}