only:junit5

This commit is contained in:
rusefillc 2023-12-15 11:29:56 -05:00
parent 9644a01d10
commit c2b1ba7e01
23 changed files with 335 additions and 319 deletions

View File

@ -2,8 +2,8 @@ package com.rusefi.pinout;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.newparse.DefinitionsState; import com.rusefi.newparse.DefinitionsState;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.*; import java.io.*;
@ -13,7 +13,7 @@ import static junit.framework.TestCase.assertFalse;
public class PinoutLogicHellen112_17_Test { public class PinoutLogicHellen112_17_Test {
@Test @Test
@Ignore // this was only useful while figuring out the problem @Disabled // this was only useful while figuring out the problem
public void testRealFiled() throws IOException { public void testRealFiled() throws IOException {
// a bit nasty, do we have similar anywhere else already? // a bit nasty, do we have similar anywhere else already?
FileSystemBoardInputsReaderImpl.PREFIX = FIRMWARE + File.separator; FileSystemBoardInputsReaderImpl.PREFIX = FIRMWARE + File.separator;

View File

@ -3,7 +3,7 @@ package com.rusefi.pinout;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.enum_reader.Value; import com.rusefi.enum_reader.Value;
import com.rusefi.newparse.DefinitionsState; import com.rusefi.newparse.DefinitionsState;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.*; import java.io.*;
import java.util.Arrays; import java.util.Arrays;

View File

@ -2,7 +2,7 @@ package com.rusefi.pinout;
import com.rusefi.EnumsReader; import com.rusefi.EnumsReader;
import com.rusefi.enum_reader.Value; import com.rusefi.enum_reader.Value;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;

View File

@ -4,7 +4,7 @@ import com.rusefi.ReaderStateImpl;
import com.rusefi.TsFileContent; import com.rusefi.TsFileContent;
import com.rusefi.output.TSProjectConsumer; import com.rusefi.output.TSProjectConsumer;
import com.rusefi.util.Output; import com.rusefi.util.Output;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.*; import java.io.*;

View File

@ -1,7 +1,7 @@
package com.rusefi.test; package com.rusefi.test;
import com.rusefi.output.BaseCHeaderConsumer; import com.rusefi.output.BaseCHeaderConsumer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -3,7 +3,7 @@ package com.rusefi.test;
import com.rusefi.EnumsReader; import com.rusefi.EnumsReader;
import com.rusefi.VariableRegistry; import com.rusefi.VariableRegistry;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;

View File

@ -2,7 +2,7 @@ package com.rusefi.test;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.output.JavaFieldsConsumer; import com.rusefi.output.JavaFieldsConsumer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -3,9 +3,9 @@ package com.rusefi.test;
import com.rusefi.*; import com.rusefi.*;
import com.rusefi.output.*; import com.rusefi.output.*;
import com.rusefi.parse.TypesHelper; import com.rusefi.parse.TypesHelper;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*;
/** /**
* Andrey Belomutskiy, (c) 2013-2020 * Andrey Belomutskiy, (c) 2013-2020
@ -22,7 +22,7 @@ public class ConfigFieldParserTest {
assertEquals(cf.getArraySizes().length, 1); assertEquals(cf.getArraySizes().length, 1);
assertEquals(cf.getArraySizes()[0], 8); assertEquals(cf.getArraySizes()[0], 8);
assertEquals(cf.getSize(null), 8); assertEquals(cf.getSize(null), 8);
assertFalse("isIterate", cf.isIterate()); assertFalse(cf.isIterate(), "isIterate");
} }
} }
@ -36,7 +36,7 @@ public class ConfigFieldParserTest {
assertEquals(cf.getArraySizes()[0], 8); assertEquals(cf.getArraySizes()[0], 8);
assertEquals(cf.getArraySizes()[1], 16); assertEquals(cf.getArraySizes()[1], 16);
assertEquals(cf.getSize(null), 128); assertEquals(cf.getSize(null), 128);
assertFalse("isIterate", cf.isIterate()); assertFalse(cf.isIterate(), "isIterate");
} }
} }
@ -68,17 +68,19 @@ public class ConfigFieldParserTest {
"; total TS size = 12\n", tsProjectConsumer.getContent()); "; total TS size = 12\n", tsProjectConsumer.getContent());
} }
@Test(expected = IllegalStateException.class) @Test
public void testSameFieldTwice() { public void testSameFieldTwice() {
assertThrows(IllegalStateException.class, () -> {
String test = "struct pid_s\n" + String test = "struct pid_s\n" +
"int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" + "int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"int afr_type2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" + "int afr_type2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" + "int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"end_struct\n"; "end_struct\n";
ReaderStateImpl state = new ReaderStateImpl(); ReaderStateImpl state = new ReaderStateImpl();
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer(); BaseCHeaderConsumer consumer = new BaseCHeaderConsumer();
state.readBufferedReader(test, consumer); state.readBufferedReader(test, consumer);
});
} }
@Test @Test
@ -205,13 +207,15 @@ public class ConfigFieldParserTest {
new ReaderStateImpl().readBufferedReader(test); new ReaderStateImpl().readBufferedReader(test);
} }
@Test(expected = IllegalStateException.class) @Test
public void invalidDefine() { public void invalidDefine() {
assertThrows(IllegalStateException.class, () -> {
String test = "struct pid_s\n" + String test = "struct pid_s\n" +
VariableRegistry.DEFINE + " show show_Hellen121vag_presets true\n" + VariableRegistry.DEFINE + " show show_Hellen121vag_presets true\n" +
"end_struct\n" + "end_struct\n" +
""; "";
new ReaderStateImpl().readBufferedReader(test); new ReaderStateImpl().readBufferedReader(test);
});
} }
@Test @Test
@ -364,7 +368,7 @@ public class ConfigFieldParserTest {
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int field"); ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int field");
assertEquals(cf.getType(), "int"); assertEquals(cf.getType(), "int");
assertEquals("Name", cf.getName(), "field"); assertEquals(cf.getName(), "field", "Unexpected Field Name");
} }
{ {
@ -671,7 +675,7 @@ public class ConfigFieldParserTest {
{ {
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int field"); ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int field");
assertEquals(cf.getType(), "int"); assertEquals(cf.getType(), "int");
assertEquals("Name", cf.getName(), "field"); assertEquals(cf.getName(), "field", "Name");
} }
{ {
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_4 fie4_ld"); ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_4 fie4_ld");
@ -682,7 +686,7 @@ public class ConfigFieldParserTest {
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_8 fi_eld;comm_;ts,1,1"); ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_8 fi_eld;comm_;ts,1,1");
assertEquals(cf.getType(), "int_8"); assertEquals(cf.getType(), "int_8");
assertEquals(cf.getName(), "fi_eld"); assertEquals(cf.getName(), "fi_eld");
assertEquals("Comment", cf.getComment(), "comm_"); assertEquals(cf.getComment(), "comm_", "Comment");
assertEquals(cf.getTsInfo(), "ts,1,1"); assertEquals(cf.getTsInfo(), "ts,1,1");
} }
{ {
@ -690,7 +694,7 @@ public class ConfigFieldParserTest {
assertEquals(cf.getType(), "int"); assertEquals(cf.getType(), "int");
assertEquals(cf.getArraySizes().length, 1); assertEquals(cf.getArraySizes().length, 1);
assertEquals(cf.getArraySizes()[0], 3); assertEquals(cf.getArraySizes()[0], 3);
assertTrue("isIterate", cf.isIterate()); assertTrue(cf.isIterate(), "isIterate");
} }
{ {
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int16_t crankingRpm;This,. value controls what RPM values we consider 'cranking' (any RPM below 'crankingRpm')\\nAnything above 'crankingRpm' would be 'running'"); ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int16_t crankingRpm;This,. value controls what RPM values we consider 'cranking' (any RPM below 'crankingRpm')\\nAnything above 'crankingRpm' would be 'running'");

View File

@ -2,7 +2,7 @@ package com.rusefi.test;
import com.rusefi.EnumsReader; import com.rusefi.EnumsReader;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;

View File

@ -1,7 +1,7 @@
package com.rusefi.test; package com.rusefi.test;
import com.rusefi.FiringOrderTSLogic; import com.rusefi.FiringOrderTSLogic;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class FiringOrderTSLogicTest { public class FiringOrderTSLogicTest {
@Test @Test

View File

@ -2,7 +2,7 @@ package com.rusefi.test;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.output.FragmentDialogConsumer; import com.rusefi.output.FragmentDialogConsumer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -3,272 +3,276 @@ package com.rusefi.test;
import com.rusefi.MaybeSemicolonWasMissedException; import com.rusefi.MaybeSemicolonWasMissedException;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.output.GetConfigValueConsumer; import com.rusefi.output.GetConfigValueConsumer;
import org.junit.Test; import org.junit.function.ThrowingRunnable;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class GetConfigValueConsumerTest { public class GetConfigValueConsumerTest {
@Test @Test
public void testStructArrayAndCharArgument() { public void testStructArrayAndCharArgument() {
ReaderStateImpl state = new ReaderStateImpl(); ReaderStateImpl state = new ReaderStateImpl();
String test = "struct total\n" + String test = "struct total\n" +
"custom lua_script_t 200 string, ASCII, @OFFSET@, 200\n" + "custom lua_script_t 200 string, ASCII, @OFFSET@, 200\n" +
"lua_script_t luaScript;\n" + "lua_script_t luaScript;\n" +
"struct dc_io\n" + "struct dc_io\n" +
"\tint disablePin;\n" + "\tint disablePin;\n" +
"end_struct\n" + "end_struct\n" +
"\tdc_io[2 iterate] etbIn\n" + "\tdc_io[2 iterate] etbIn\n" +
"end_struct\n"; "end_struct\n";
GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer(); GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer();
state.readBufferedReader(test, getConfigValueConsumer); state.readBufferedReader(test, getConfigValueConsumer);
assertEquals( assertEquals(
"float getConfigValueByName(const char *name) {\n" + "float getConfigValueByName(const char *name) {\n" +
"\treturn EFI_ERROR_CODE;\n" + "\treturn EFI_ERROR_CODE;\n" +
"}\n", getConfigValueConsumer.getCompleteGetterBody()); "}\n", getConfigValueConsumer.getCompleteGetterBody());
} }
@Test @Test
public void generateEmbeddedStruct() { public void generateEmbeddedStruct() {
ReaderStateImpl state = new ReaderStateImpl(); ReaderStateImpl state = new ReaderStateImpl();
String test = "struct total\n" + String test = "struct total\n" +
"struct_no_prefix thermistor_conf_s @brief Thermistor known values\n" + "struct_no_prefix thermistor_conf_s @brief Thermistor known values\n" +
"float tempC_1;these values are in Celcius;\"*C\", 1, 0, -40, 200, 1\n" + "float tempC_1;these values are in Celcius;\"*C\", 1, 0, -40, 200, 1\n" +
"\n" + "\n" +
"end_struct\n" + "end_struct\n" +
"struct ThermistorConf @brief Thermistor curve parameters\n" + "struct ThermistorConf @brief Thermistor curve parameters\n" +
"\tthermistor_conf_s config;\n" + "\tthermistor_conf_s config;\n" +
"\tint adcChannel;\n" + "\tint adcChannel;\n" +
"end_struct\n" + "end_struct\n" +
"ThermistorConf iat;\n" + "ThermistorConf iat;\n" +
"end_struct\n"; "end_struct\n";
GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer(); GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer();
state.readBufferedReader(test, getConfigValueConsumer); state.readBufferedReader(test, getConfigValueConsumer);
assertEquals("\tint hash = djb2lowerCase(name);\n" + assertEquals("\tint hash = djb2lowerCase(name);\n" +
"\tswitch(hash) {\n" + "\tswitch(hash) {\n" +
"\t\tcase -672272162:\n" + "\t\tcase -672272162:\n" +
"\t{\n" + "\t{\n" +
"\t\tconfig->iat.config.tempC_1 = value;\n" + "\t\tconfig->iat.config.tempC_1 = value;\n" +
"\t\treturn 1;\n" + "\t\treturn 1;\n" +
"\t}\n" + "\t}\n" +
"\t\tcase -1237776078:\n" + "\t\tcase -1237776078:\n" +
"\t{\n" + "\t{\n" +
"\t\tconfig->iat.adcChannel = (int)value;\n" + "\t\tconfig->iat.adcChannel = (int)value;\n" +
"\t\treturn 1;\n" + "\t\treturn 1;\n" +
"\t}\n" + "\t}\n" +
"\t}\n" + "\t}\n" +
"\treturn 0;\n", "\treturn 0;\n",
getConfigValueConsumer.getSetterBody()); getConfigValueConsumer.getSetterBody());
assertEquals("// generated by GetConfigValueConsumer.java\n" + assertEquals("// generated by GetConfigValueConsumer.java\n" +
"#include \"pch.h\"\n" + "#include \"pch.h\"\n" +
"#include \"value_lookup.h\"\n" + "#include \"value_lookup.h\"\n" +
"float getConfigValueByName(const char *name) {\n" + "float getConfigValueByName(const char *name) {\n" +
"\tint hash = djb2lowerCase(name);\n" + "\tint hash = djb2lowerCase(name);\n" +
"\tswitch(hash) {\n" + "\tswitch(hash) {\n" +
"// iat.config.tempC_1\n" + "// iat.config.tempC_1\n" +
"\t\tcase -672272162:\n" + "\t\tcase -672272162:\n" +
"\t\t\treturn config->iat.config.tempC_1;\n" + "\t\t\treturn config->iat.config.tempC_1;\n" +
"// iat.adcChannel\n" + "// iat.adcChannel\n" +
"\t\tcase -1237776078:\n" + "\t\tcase -1237776078:\n" +
"\t\t\treturn config->iat.adcChannel;\n" + "\t\t\treturn config->iat.adcChannel;\n" +
"\t}\n" + "\t}\n" +
"\treturn EFI_ERROR_CODE;\n" + "\treturn EFI_ERROR_CODE;\n" +
"}\n" + "}\n" +
"bool setConfigValueByName(const char *name, float value) {\n" + "bool setConfigValueByName(const char *name, float value) {\n" +
"\tint hash = djb2lowerCase(name);\n" + "\tint hash = djb2lowerCase(name);\n" +
"\tswitch(hash) {\n" + "\tswitch(hash) {\n" +
"\t\tcase -672272162:\n" + "\t\tcase -672272162:\n" +
"\t{\n" + "\t{\n" +
"\t\tconfig->iat.config.tempC_1 = value;\n" + "\t\tconfig->iat.config.tempC_1 = value;\n" +
"\t\treturn 1;\n" + "\t\treturn 1;\n" +
"\t}\n" + "\t}\n" +
"\t\tcase -1237776078:\n" + "\t\tcase -1237776078:\n" +
"\t{\n" + "\t{\n" +
"\t\tconfig->iat.adcChannel = (int)value;\n" + "\t\tconfig->iat.adcChannel = (int)value;\n" +
"\t\treturn 1;\n" + "\t\treturn 1;\n" +
"\t}\n" + "\t}\n" +
"\t}\n" + "\t}\n" +
"\treturn 0;\n" + "\treturn 0;\n" +
"}\n", getConfigValueConsumer.getContent()); "}\n", getConfigValueConsumer.getContent());
assertEquals("float getConfigValueByName(const char *name) {\n" + assertEquals("float getConfigValueByName(const char *name) {\n" +
"\tint hash = djb2lowerCase(name);\n" + "\tint hash = djb2lowerCase(name);\n" +
"\tswitch(hash) {\n" + "\tswitch(hash) {\n" +
"// iat.config.tempC_1\n" + "// iat.config.tempC_1\n" +
"\t\tcase -672272162:\n" + "\t\tcase -672272162:\n" +
"\t\t\treturn config->iat.config.tempC_1;\n" + "\t\t\treturn config->iat.config.tempC_1;\n" +
"// iat.adcChannel\n" + "// iat.adcChannel\n" +
"\t\tcase -1237776078:\n" + "\t\tcase -1237776078:\n" +
"\t\t\treturn config->iat.adcChannel;\n" + "\t\t\treturn config->iat.adcChannel;\n" +
"\t}\n" + "\t}\n" +
"\treturn EFI_ERROR_CODE;\n" + "\treturn EFI_ERROR_CODE;\n" +
"}\n", getConfigValueConsumer.getCompleteGetterBody()); "}\n", getConfigValueConsumer.getCompleteGetterBody());
} }
@Test @Test
public void generateGetConfig() { public void generateGetConfig() {
String test = "struct total\n" + String test = "struct total\n" +
"struct_no_prefix thermistor_conf_s @brief Thermistor known values\n" + "struct_no_prefix thermistor_conf_s @brief Thermistor known values\n" +
"float tempC_1;these values are in Celcius;\"*C\", 1, 0, -40, 200, 1\n" + "float tempC_1;these values are in Celcius;\"*C\", 1, 0, -40, 200, 1\n" +
"\n" + "\n" +
"custom air_pressure_sensor_type_e 4 bits, U32, @OFFSET@, [0:4], \"Custom\", \"DENSO183\", \"MPX4250\", \"HONDA3BAR\", \"NEON_2003\", \"22012AA090\", \"3 Bar\", \"MPX4100\", \"Toyota 89420-02010\", \"MPX4250A\", \"Bosch 2.5\", \"Mazda1Bar\", \"GM 2 Bar\", \"GM 1 Bar\", \"MPXH6400\"\n" + "custom air_pressure_sensor_type_e 4 bits, U32, @OFFSET@, [0:4], \"Custom\", \"DENSO183\", \"MPX4250\", \"HONDA3BAR\", \"NEON_2003\", \"22012AA090\", \"3 Bar\", \"MPX4100\", \"Toyota 89420-02010\", \"MPX4250A\", \"Bosch 2.5\", \"Mazda1Bar\", \"GM 2 Bar\", \"GM 1 Bar\", \"MPXH6400\"\n" +
"struct air_pressure_sensor_config_s\n" + "struct air_pressure_sensor_config_s\n" +
"float highValue;kPa value at high volts;\"kpa\", 1, 0, -400, 800, 2\n" + "float highValue;kPa value at high volts;\"kpa\", 1, 0, -400, 800, 2\n" +
"air_pressure_sensor_type_e type;\n" + "air_pressure_sensor_type_e type;\n" +
"int hwChannel;\n" + "int hwChannel;\n" +
"uint8_t[3] alignmentFill;;\"unit\", 1, 0, 0, 100, 0\n" + "uint8_t[3] alignmentFill;;\"unit\", 1, 0, 0, 100, 0\n" +
"\n" + "\n" +
"end_struct\n" + "end_struct\n" +
"\n" + "\n" +
"struct MAP_sensor_config_s @brief MAP averaging configuration\n" + "struct MAP_sensor_config_s @brief MAP averaging configuration\n" +
"float[6] samplingAngleBins;;\"\", 1, 0, 0, 18000, 2\n" + "float[6] samplingAngleBins;;\"\", 1, 0, 0, 18000, 2\n" +
"air_pressure_sensor_config_s sensor\n" + "air_pressure_sensor_config_s sensor\n" +
"end_struct\n" + "end_struct\n" +
"MAP_sensor_config_s map;@see isMapAveragingEnabled\n" + "MAP_sensor_config_s map;@see isMapAveragingEnabled\n" +
"struct injector_s\n" + "struct injector_s\n" +
"\tfloat flow;This is your injector flow at the fuel pressure used in the vehicle. cc/min, cubic centimetre per minute\\nBy the way, g/s = 0.125997881 * (lb/hr)\\ng/s = 0.125997881 * (cc/min)/10.5\\ng/s = 0.0119997981 * cc/min;\"cm3/min\", 1, 0, 0, 99999, 2\n" + "\tfloat flow;This is your injector flow at the fuel pressure used in the vehicle. cc/min, cubic centimetre per minute\\nBy the way, g/s = 0.125997881 * (lb/hr)\\ng/s = 0.125997881 * (cc/min)/10.5\\ng/s = 0.0119997981 * cc/min;\"cm3/min\", 1, 0, 0, 99999, 2\n" +
"\n" + "\n" +
"float[8] battLagCorr;ms delay between injector open and close dead times;\"ms\", 1, 0, 0, 50, 2\n" + "float[8] battLagCorr;ms delay between injector open and close dead times;\"ms\", 1, 0, 0, 50, 2\n" +
"\n" + "\n" +
"end_struct\n" + "end_struct\n" +
"\n" + "\n" +
"injector_s injector\n" + "injector_s injector\n" +
"\tint[12 iterate] ignitionPins;\n" + "\tint[12 iterate] ignitionPins;\n" +
"\tfloat bias_resistor;Pull-up resistor value on your board;\"Ohm\", 1, 0, 0, 200000, 1\n" + "\tfloat bias_resistor;Pull-up resistor value on your board;\"Ohm\", 1, 0, 0, 200000, 1\n" +
"end_struct\n" + "end_struct\n" +
"struct ThermistorConf @brief Thermistor curve parameters\n" + "struct ThermistorConf @brief Thermistor curve parameters\n" +
"\tthermistor_conf_s config;\n" + "\tthermistor_conf_s config;\n" +
"\tint adcChannel;\n" + "\tint adcChannel;\n" +
"end_struct\n" + "end_struct\n" +
"ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here!\n" + "ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here!\n" +
"bit issue_294_31,\"si_example\",\"nada_example\"\n" + "bit issue_294_31,\"si_example\",\"nada_example\"\n" +
"uint8_t[2 iterate] autoscale knock;;\"\",1, 0, 0, 0, 0\n" + "uint8_t[2 iterate] autoscale knock;;\"\",1, 0, 0, 0, 0\n" +
"\tuint16_t autoscale baseFuel;@@GAUGE_NAME_FUEL_BASE@@\\nThis is the raw value we take from the fuel map or base fuel algorithm, before the corrections;\"mg\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" + "\tuint16_t autoscale baseFuel;@@GAUGE_NAME_FUEL_BASE@@\\nThis is the raw value we take from the fuel map or base fuel algorithm, before the corrections;\"mg\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" +
"float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" + "float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"uint16_t autoscale speedToRpmRatio;s2rpm;\"value\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" + "uint16_t autoscale speedToRpmRatio;s2rpm;\"value\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" +
"uint8_t afr_typet;;\"ms\", 1, 0, 0, 3000, 0\n" + "uint8_t afr_typet;;\"ms\", 1, 0, 0, 3000, 0\n" +
"uint8_t autoscale vehicleSpeedKph;;\"kph\",1, 0, 0, 0, 0\n" + "uint8_t autoscale vehicleSpeedKph;;\"kph\",1, 0, 0, 0, 0\n" +
"bit isForcedInduction;Does the vehicle have a turbo or supercharger?\n" + "bit isForcedInduction;Does the vehicle have a turbo or supercharger?\n" +
"\tuint8_t unused37;;\"\",1, 0, 0, 0, 0\n" + "\tuint8_t unused37;;\"\",1, 0, 0, 0, 0\n" +
"bit enableFan1WithAc;Turn on this fan when AC is on.\n" + "bit enableFan1WithAc;Turn on this fan when AC is on.\n" +
"end_struct\n"; "end_struct\n";
ReaderStateImpl state = new ReaderStateImpl(); ReaderStateImpl state = new ReaderStateImpl();
state.getVariableRegistry().register("PACK_MULT_PERCENT", 100); state.getVariableRegistry().register("PACK_MULT_PERCENT", 100);
state.getVariableRegistry().register("GAUGE_NAME_FUEL_BASE", "hello"); state.getVariableRegistry().register("GAUGE_NAME_FUEL_BASE", "hello");
GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer(); GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer();
state.readBufferedReader(test, getConfigValueConsumer); state.readBufferedReader(test, getConfigValueConsumer);
assertEquals("// generated by GetConfigValueConsumer.java\n" + assertEquals("// generated by GetConfigValueConsumer.java\n" +
"#include \"pch.h\"\n" + "#include \"pch.h\"\n" +
"#include \"value_lookup.h\"\n" + "#include \"value_lookup.h\"\n" +
"float getConfigValueByName(const char *name) {\n" + "float getConfigValueByName(const char *name) {\n" +
"\tint hash = djb2lowerCase(name);\n" + "\tint hash = djb2lowerCase(name);\n" +
"\tswitch(hash) {\n" + "\tswitch(hash) {\n" +
"// clt.config.tempC_1\n" + "// clt.config.tempC_1\n" +
"\t\tcase -1832527325:\n" + "\t\tcase -1832527325:\n" +
"\t\t\treturn config->clt.config.tempC_1;\n" + "\t\t\treturn config->clt.config.tempC_1;\n" +
"// clt.config.map.sensor.highValue\n" + "// clt.config.map.sensor.highValue\n" +
"\t\tcase 1819278123:\n" + "\t\tcase 1819278123:\n" +
"\t\t\treturn config->clt.config.map.sensor.highValue;\n" + "\t\t\treturn config->clt.config.map.sensor.highValue;\n" +
"// clt.config.map.sensor.hwChannel\n" + "// clt.config.map.sensor.hwChannel\n" +
"\t\tcase 581685574:\n" + "\t\tcase 581685574:\n" +
"\t\t\treturn config->clt.config.map.sensor.hwChannel;\n" + "\t\t\treturn config->clt.config.map.sensor.hwChannel;\n" +
"// clt.config.injector.flow\n" + "// clt.config.injector.flow\n" +
"\t\tcase 382574846:\n" + "\t\tcase 382574846:\n" +
"\t\t\treturn config->clt.config.injector.flow;\n" + "\t\t\treturn config->clt.config.injector.flow;\n" +
"// clt.config.bias_resistor\n" + "// clt.config.bias_resistor\n" +
"\t\tcase -653172717:\n" + "\t\tcase -653172717:\n" +
"\t\t\treturn config->clt.config.bias_resistor;\n" + "\t\t\treturn config->clt.config.bias_resistor;\n" +
"// clt.adcChannel\n" + "// clt.adcChannel\n" +
"\t\tcase -1144186889:\n" + "\t\tcase -1144186889:\n" +
"\t\t\treturn config->clt.adcChannel;\n" + "\t\t\treturn config->clt.adcChannel;\n" +
"// issue_294_31\n" + "// issue_294_31\n" +
"\t\tcase -1571463185:\n" + "\t\tcase -1571463185:\n" +
"\t\t\treturn config->issue_294_31;\n" + "\t\t\treturn config->issue_294_31;\n" +
"// baseFuel\n" + "// baseFuel\n" +
"\t\tcase 727098956:\n" + "\t\tcase 727098956:\n" +
"\t\t\treturn config->baseFuel;\n" + "\t\t\treturn config->baseFuel;\n" +
"// afr_type\n" + "// afr_type\n" +
"\t\tcase -1120008897:\n" + "\t\tcase -1120008897:\n" +
"\t\t\treturn config->afr_type;\n" + "\t\t\treturn config->afr_type;\n" +
"// speedToRpmRatio\n" + "// speedToRpmRatio\n" +
"\t\tcase -685727673:\n" + "\t\tcase -685727673:\n" +
"\t\t\treturn config->speedToRpmRatio;\n" + "\t\t\treturn config->speedToRpmRatio;\n" +
"// afr_typet\n" + "// afr_typet\n" +
"\t\tcase 1694412179:\n" + "\t\tcase 1694412179:\n" +
"\t\t\treturn config->afr_typet;\n" + "\t\t\treturn config->afr_typet;\n" +
"// vehicleSpeedKph\n" + "// vehicleSpeedKph\n" +
"\t\tcase -1925174695:\n" + "\t\tcase -1925174695:\n" +
"\t\t\treturn config->vehicleSpeedKph;\n" + "\t\t\treturn config->vehicleSpeedKph;\n" +
"// isForcedInduction\n" + "// isForcedInduction\n" +
"\t\tcase -617915487:\n" + "\t\tcase -617915487:\n" +
"\t\t\treturn config->isForcedInduction;\n" + "\t\t\treturn config->isForcedInduction;\n" +
"// enableFan1WithAc\n" + "// enableFan1WithAc\n" +
"\t\tcase -298185774:\n" + "\t\tcase -298185774:\n" +
"\t\t\treturn config->enableFan1WithAc;\n" + "\t\t\treturn config->enableFan1WithAc;\n" +
"\t}\n" + "\t}\n" +
"\treturn EFI_ERROR_CODE;\n" + "\treturn EFI_ERROR_CODE;\n" +
"}\n", getConfigValueConsumer.getHeaderAndGetter()); "}\n", getConfigValueConsumer.getHeaderAndGetter());
assertEquals("### clt.config.tempC_1\n" + assertEquals("### clt.config.tempC_1\n" +
"these values are in Celcius\n" + "these values are in Celcius\n" +
"\n" + "\n" +
"### clt.config.map.sensor.highValue\n" + "### clt.config.map.sensor.highValue\n" +
"kPa value at high volts\n" + "kPa value at high volts\n" +
"\n" + "\n" +
"### clt.config.map.sensor.hwChannel\n" + "### clt.config.map.sensor.hwChannel\n" +
"\n" + "\n" +
"\n" + "\n" +
"### clt.config.injector.flow\n" + "### clt.config.injector.flow\n" +
"This is your injector flow at the fuel pressure used in the vehicle. cc/min, cubic centimetre per minute\\nBy the way, g/s = 0.125997881 * (lb/hr)\\ng/s = 0.125997881 * (cc/min)/10.5\\ng/s = 0.0119997981 * cc/min\n" + "This is your injector flow at the fuel pressure used in the vehicle. cc/min, cubic centimetre per minute\\nBy the way, g/s = 0.125997881 * (lb/hr)\\ng/s = 0.125997881 * (cc/min)/10.5\\ng/s = 0.0119997981 * cc/min\n" +
"\n" + "\n" +
"### clt.config.bias_resistor\n" + "### clt.config.bias_resistor\n" +
"Pull-up resistor value on your board\n" + "Pull-up resistor value on your board\n" +
"\n" + "\n" +
"### clt.adcChannel\n" + "### clt.adcChannel\n" +
"\n" + "\n" +
"\n" + "\n" +
"### issue_294_31\n" + "### issue_294_31\n" +
"\n" + "\n" +
"\n" + "\n" +
"### baseFuel\n" + "### baseFuel\n" +
"@@GAUGE_NAME_FUEL_BASE@@\\nThis is the raw value we take from the fuel map or base fuel algorithm, before the corrections\n" + "@@GAUGE_NAME_FUEL_BASE@@\\nThis is the raw value we take from the fuel map or base fuel algorithm, before the corrections\n" +
"\n" + "\n" +
"### afr_type\n" + "### afr_type\n" +
"PID dTime\n" + "PID dTime\n" +
"\n" + "\n" +
"### speedToRpmRatio\n" + "### speedToRpmRatio\n" +
"s2rpm\n" + "s2rpm\n" +
"\n" + "\n" +
"### afr_typet\n" + "### afr_typet\n" +
"\n" + "\n" +
"\n" + "\n" +
"### vehicleSpeedKph\n" + "### vehicleSpeedKph\n" +
"\n" + "\n" +
"\n" + "\n" +
"### isForcedInduction\n" + "### isForcedInduction\n" +
"Does the vehicle have a turbo or supercharger?\n" + "Does the vehicle have a turbo or supercharger?\n" +
"\n" + "\n" +
"### enableFan1WithAc\n" + "### enableFan1WithAc\n" +
"Turn on this fan when AC is on.\n" + "Turn on this fan when AC is on.\n" +
"\n", getConfigValueConsumer.getMdContent()); "\n", getConfigValueConsumer.getMdContent());
} }
@Test(expected = MaybeSemicolonWasMissedException.class) @Test
public void generateSuspiciousTsInfo() { public void generateSuspiciousTsInfo() {
String test = "struct total\n" + assertThrows(MaybeSemicolonWasMissedException.class, () -> {
"uint8_t hello;\"unit\", 1, 0, 0, 100, 0\n" + String test = "struct total\n" +
"end_struct\n"; "uint8_t hello;\"unit\", 1, 0, 0, 100, 0\n" +
ReaderStateImpl state = new ReaderStateImpl(); "end_struct\n";
ReaderStateImpl state = new ReaderStateImpl();
GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer(); GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer();
state.readBufferedReader(test, getConfigValueConsumer); state.readBufferedReader(test, getConfigValueConsumer);
} });
}
} }

View File

@ -3,7 +3,7 @@ package com.rusefi.test;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.output.GetOutputValueConsumer; import com.rusefi.output.GetOutputValueConsumer;
import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFile;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -1,7 +1,7 @@
package com.rusefi.test; package com.rusefi.test;
import com.rusefi.output.HashUtil; import com.rusefi.output.HashUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -2,7 +2,7 @@ package com.rusefi.test;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.output.JavaSensorsConsumer; import com.rusefi.output.JavaSensorsConsumer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -7,9 +7,11 @@ import com.rusefi.output.DataLogConsumer;
import com.rusefi.output.GaugeConsumer; import com.rusefi.output.GaugeConsumer;
import com.rusefi.output.OutputsSectionConsumer; import com.rusefi.output.OutputsSectionConsumer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.junit.Test; import org.junit.function.ThrowingRunnable;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class OutputsTest { public class OutputsTest {
@Test @Test
@ -35,15 +37,17 @@ public class OutputsTest {
assertEquals(expectedLegacy, runOriginalImplementation(test, state).getContent()); assertEquals(expectedLegacy, runOriginalImplementation(test, state).getContent());
} }
@Test(expected = BitState.TooManyBitsInARow.class) @Test
public void tooManyBits() { public void tooManyBits() {
assertThrows(BitState.TooManyBitsInARow.class, () -> {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < 40; i++) for (int i = 0; i < 40; i++)
sb.append("bit b" + i + "\n"); sb.append("bit b" + i + "\n");
String test = "struct total\n" + String test = "struct total\n" +
sb + sb +
"end_struct\n"; "end_struct\n";
runOriginalImplementation(test); runOriginalImplementation(test);
});
} }
private static OutputsSectionConsumer runOriginalImplementation(String test) { private static OutputsSectionConsumer runOriginalImplementation(String test) {
@ -191,18 +195,21 @@ public class OutputsTest {
"\ttriggerSimulatorPins3 = \"Each rusEFI piece can provide synthetic trigger signal for external ECU. Sometimes these wires are routed back into trigger inputs of the same rusEFI board.\\nSee also directSelfStimulation which is different. 3\"\n", tsProjectConsumer.getSettingContextHelpForUnitTest()); "\ttriggerSimulatorPins3 = \"Each rusEFI piece can provide synthetic trigger signal for external ECU. Sometimes these wires are routed back into trigger inputs of the same rusEFI board.\\nSee also directSelfStimulation which is different. 3\"\n", tsProjectConsumer.getSettingContextHelpForUnitTest());
} }
@Test(expected = IllegalStateException.class) @Test
public void nameDuplicate() { public void nameDuplicate() {
assertThrows(IllegalStateException.class, () -> {
System.out.println("run");
String test = "struct total\n" + String test = "struct total\n" +
"float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" + "float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"uint8_t afr_type;123;\"ms\", 1, 0, 0, 3000, 0\n" + "uint8_t afr_type;123;\"ms\", 1, 0, 0, 3000, 0\n" +
"end_struct\n"; "end_struct\n";
String expectedLegacy = "afr_type = scalar, F32, 0, \"ms\", 1, 0\n" + String expectedLegacy = "afr_type = scalar, F32, 0, \"ms\", 1, 0\n" +
"afr_type = scalar, U08, 0, \"ms\", 1, 0\n" + "afr_type = scalar, U08, 0, \"ms\", 1, 0\n" +
"; total TS size = 1\n"; "; total TS size = 1\n";
assertEquals(expectedLegacy, runOriginalImplementation(test).getContent()); assertEquals(expectedLegacy, runOriginalImplementation(test).getContent());
});
} }
@Test @Test

View File

@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals;
import com.rusefi.ReaderStateImpl; import com.rusefi.ReaderStateImpl;
import com.rusefi.util.LazyFile; import com.rusefi.util.LazyFile;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class SdCardFieldsGeneratorTest { public class SdCardFieldsGeneratorTest {
@Test @Test
@ -99,4 +99,4 @@ public class SdCardFieldsGeneratorTest {
state.readBufferedReader(input, consumer); state.readBufferedReader(input, consumer);
assertEquals(expectedOutput, consumer.getBody()); assertEquals(expectedOutput, consumer.getBody());
} }
} }

View File

@ -4,7 +4,7 @@ import com.rusefi.ReaderStateImpl;
import com.rusefi.output.BaseCHeaderConsumer; import com.rusefi.output.BaseCHeaderConsumer;
import com.rusefi.output.JavaFieldsConsumer; import com.rusefi.output.JavaFieldsConsumer;
import com.rusefi.output.TSProjectConsumer; import com.rusefi.output.TSProjectConsumer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -1,7 +1,7 @@
package com.rusefi.test; package com.rusefi.test;
import com.rusefi.VariableRegistry; import com.rusefi.VariableRegistry;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;

View File

@ -1,7 +1,7 @@
package com.rusefi.test; package com.rusefi.test;
import com.rusefi.VariableRegistry; import com.rusefi.VariableRegistry;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;

View File

@ -1,8 +1,8 @@
package com.rusefi; package com.rusefi;
import com.rusefi.enum_reader.Value; import com.rusefi.enum_reader.Value;
import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.function.Executable;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
@ -11,8 +11,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import static com.rusefi.EnumsReader.isKeyValueLine; import static com.rusefi.EnumsReader.isKeyValueLine;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.Assert.assertTrue;
public class EnumToStringTest { public class EnumToStringTest {
public static EnumToString process(EnumsReader enumsReader) { public static EnumToString process(EnumsReader enumsReader) {
@ -204,28 +203,31 @@ public class EnumToStringTest {
} }
} }
@Test(expected = IllegalStateException.class) @Test
public void testWithInputOutOfOrder() throws IOException { public void testWithInputOutOfOrder() throws IOException {
assertThrows(IllegalStateException.class, () -> {
final StringReader reader = new StringReader( final StringReader reader = new StringReader(
"typedef enum {\n" + "typedef enum {\n" +
"\tGPIO_UNASSIGNED = XXXX,\n" + "\tGPIO_UNASSIGNED = XXXX,\n" +
"}brain_pin_e; // hello"); "}brain_pin_e; // hello");
VariableRegistry registry = new VariableRegistry(); VariableRegistry registry = new VariableRegistry();
registry.readPrependValues(new StringReader("#define XXXX 12")); registry.readPrependValues(new StringReader("#define XXXX 12"));
EnumsReader enumsReader = new EnumsReader().read(reader); EnumsReader enumsReader = new EnumsReader().read(reader);
for (Map.Entry<String /*enum name*/, EnumsReader.EnumState> e : enumsReader.getEnums().entrySet()) { for (Map.Entry<String /*enum name*/, EnumsReader.EnumState> e : enumsReader.getEnums().entrySet()) {
String java = ToJavaEnum.generate(registry, e.getKey(), e.getValue()); String java = ToJavaEnum.generate(registry, e.getKey(), e.getValue());
assertEquals("package com.rusefi.enums;\n" + assertEquals("package com.rusefi.enums;\n" +
"//auto-generated by ToJavaEnum.java\n" + "//auto-generated by ToJavaEnum.java\n" +
"\n" + "\n" +
"\n" + "\n" +
"\n" + "\n" +
"public enum brain_pin_e {\n" + "public enum brain_pin_e {\n" +
"\tGPIO_UNASSIGNED,\n" + "\tGPIO_UNASSIGNED,\n" +
"}\n", java); "}\n", java);
} }
});
} }

View File

@ -1,9 +1,9 @@
package com.rusefi.util.test; package com.rusefi.util.test;
import com.rusefi.util.LazyFileImpl; import com.rusefi.util.LazyFileImpl;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.*;
public class LazyFileTest { public class LazyFileTest {
@Test @Test

View File

@ -1,12 +1,11 @@
package rusefi; package rusefi;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.Assert.assertNotNull;
public class GccMapReaderTest { public class GccMapReaderTest {
private static final String BSS = "bss"; private static final String BSS = "bss";