#include "../src/serial.h" #include #include #include #include #if defined(__APPLE__) #include #else #include #endif int main() { using namespace bfebbx; using namespace std::chrono_literals; int master = -1, slave = -1; assert(openpty(&master, &slave, nullptr, nullptr, nullptr) == 0); // Pre-load a canned response into the master's read buffer. const char* resp = "hello world#"; assert(write(slave, resp, 12) == 12); Serial s = Serial::fromFd(master); std::string got = s.readUntil("#", 1000ms); assert(got == "hello world#"); // Timeout path: nothing more to read, returns what it has within the window. std::string none = s.readUntil("#", 100ms); assert(none.empty()); close(slave); return 0; }