1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00
esp8266/tests/device/test_Print_printf/test_Print_printf.ino
2016-04-26 16:04:19 +08:00

39 lines
810 B
C++

#include <BSTest.h>
#include <StreamString.h>
BS_ENV_DECLARE();
void setup()
{
Serial.begin(115200);
BS_RUN(Serial);
}
TEST_CASE("Print::printf works for any reasonable output length", "[Print]")
{
auto test_printf = [](size_t size) {
StreamString str;
auto buf = new char[size + 1];
for (int i = 0; i < size; ++i) {
buf[i] = 'a';
}
buf[size] = 0;
str.printf("%s%8d", buf, 56789102);
delete[] buf;
CHECK(str.length() == size + 8);
CHECK(str.substring(size) == "56789102");
};
auto before = ESP.getFreeHeap();
test_printf(1);
test_printf(10);
test_printf(100);
test_printf(1000);
test_printf(10000);
auto after = ESP.getFreeHeap();
CHECK(before == after);
}
void loop() {}