diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index f2dbca1e95..b69725b58d 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -52,6 +52,12 @@ float getMap(void) { return getRawMap(); } +static void assertString(const char*actual, const char *expected) { + if (strcmp(actual, expected) != 0) { + firmwareError(OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", actual, expected); + } +} + static void runChprintfTest() { static MemoryStream testStream; static char testBuffer[200]; @@ -63,21 +69,26 @@ static void runChprintfTest() { chprintf((BaseSequentialStream*)&testStream, "%f/%.4f/%.4f", 0.239f, 239.932, 0.1234); testStream.buffer[testStream.eos] = 0; -#define FLOAT_STRING_EXPECTED "0.23/239.9320/0.1234" - if (strcmp(FLOAT_STRING_EXPECTED, testBuffer) != 0) { - firmwareError(OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", testBuffer, FLOAT_STRING_EXPECTED); - } + assertString(testBuffer, "0.23/239.9320/0.1234"); + { LoggingWithStorage testLogging("test"); appendFloat(&testLogging, 1.23, 5); appendFloat(&testLogging, 1.234, 2); + assertString(testLogging.buffer, "1.230001.23"); -#define FLOAT_STRING_EXPECTED2 "1.230001.23" - if (strcmp(FLOAT_STRING_EXPECTED2, testLogging.buffer) != 0) { - firmwareError(OBD_PCM_Processor_Fault, "chprintf test2: got %s while %s", testLogging.buffer, FLOAT_STRING_EXPECTED2); - } + } + { + LoggingWithStorage testLogging("test"); + appendFloat(&testLogging, -1.23, 5); + assertString(testLogging.buffer, "-1.23000"); + } + { + LoggingWithStorage testLogging("test"); + appendPrintf(&testLogging, "a%fb", -1.2); + assertString(testLogging.buffer, "a-1.20b"); } }