| 10 | } |
| 11 | |
| 12 | void execute() override |
| 13 | { |
| 14 | TEST_CASE("SerialBuffer write/read") |
| 15 | { |
| 16 | static constexpr size_t BUFSIZE = 128; |
| 17 | SerialBuffer txbuf; |
| 18 | txbuf.resize(BUFSIZE); |
| 19 | |
| 20 | auto read = [&]() { |
| 21 | String s; |
| 22 | void* data; |
| 23 | unsigned count; |
| 24 | while((count = txbuf.getReadData(data)) != 0) { |
| 25 | s.concat(static_cast<const char*>(data), count); |
| 26 | txbuf.skipRead(count); |
| 27 | } |
| 28 | return s; |
| 29 | }; |
| 30 | |
| 31 | REQUIRE(txbuf.getFreeSpace() == BUFSIZE - 1); |
| 32 | REQUIRE(txbuf.available() == 0); |
| 33 | |
| 34 | for(unsigned i = 0; i < 64; ++i) { |
| 35 | TEST_ASSERT(txbuf.writeChar('A') == 1); |
| 36 | } |
| 37 | REQUIRE(txbuf.available() == 64); |
| 38 | REQUIRE(txbuf.getFreeSpace() == BUFSIZE - 1 - 64); |
| 39 | REQUIRE(read().length() == 64); |
| 40 | |
| 41 | String compareBuffer; |
| 42 | String readBuffer; |
| 43 | for(unsigned i = 0; i < 10; ++i) { |
| 44 | Serial << _F("txfree = ") << txbuf.getFreeSpace() << endl; |
| 45 | for(char c = 'a'; c <= 'z'; ++c) { |
| 46 | if(txbuf.getFreeSpace() < 10) { |
| 47 | readBuffer += read(); |
| 48 | } |
| 49 | txbuf.writeChar(c); |
| 50 | compareBuffer += c; |
| 51 | } |
| 52 | txbuf.writeChar('\n'); |
| 53 | compareBuffer += '\n'; |
| 54 | } |
| 55 | readBuffer += read(); |
| 56 | REQUIRE(txbuf.available() == 0); |
| 57 | REQUIRE(compareBuffer == readBuffer); |
| 58 | } |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | void REGISTER_TEST(Serial) |
nothing calls this directly
no test coverage detected