MCPcopy Create free account
hub / github.com/SmingHub/Sming / execute

Method execute

tests/HostTests/modules/Serial.cpp:12–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
62void REGISTER_TEST(Serial)

Callers

nothing calls this directly

Calls 9

readFunction · 0.85
resizeMethod · 0.80
getReadDataMethod · 0.80
skipReadMethod · 0.80
getFreeSpaceMethod · 0.80
concatMethod · 0.45
availableMethod · 0.45
writeCharMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected