static void runChprintfTest() { static MemoryStream ts; static char testBuffer[200]; msObjectInit(&ts, (uint8_t *) testBuffer, sizeof(testBuffer), 0); // it's a very, very long and mostly forgotten story how this became our %.2f precision format ts.eos = 0; // reset chprintf((BaseSequentialStream*)&ts, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234); ts.buffer[ts.eos] = 0; 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"); } { LoggingWithStorage testLogging("test"); appendFloat(&testLogging, -1.23, 5); assertString(testLogging.buffer, "-1.23000"); } { LoggingWithStorage testLogging("test"); appendPrintf(&testLogging, "a%.2fb%fc", -1.2, -3.4); assertString(testLogging.buffer, "a-1.20b-3.400000095c"); } }
bool StartupTests::perform() { LogContext log("StartupTests"); log.log(1, "Running startup tests..."); bool testRes = testLogging() && testPath() && testNICsHwAddr() && testNICs(); log.log(1, "Startup tests complete"); return testRes; }