@@ -102,6 +102,31 @@ TEST_F(PseudoTerminalTest, ParameterizedConstructor) {
102102 libserial::Serial serial_port (slave_port_);
103103}
104104
105+ TEST_F (PseudoTerminalTest, SetTermios2WithFail) {
106+ libserial::Serial serial_port;
107+
108+ serial_port.open (slave_port_);
109+
110+ // Inject failure into ioctl for setTermios2
111+ serial_port.setIoctlSystemFunction (
112+ [](int , unsigned long , void *) -> int { // NOLINT
113+ errno = EIO;
114+ return -1 ;
115+ });
116+
117+ EXPECT_THROW ({
118+ serial_port.setBaudRate (9600 );
119+ }, libserial::SerialException);
120+
121+ // Restore ioctl function for cleanup
122+ serial_port.setIoctlSystemFunction (
123+ [](int fd, unsigned long request, void * arg) -> int { // NOLINT
124+ return ::ioctl (fd, request, arg);
125+ });
126+
127+ serial_port.close ();
128+ }
129+
105130TEST_F (PseudoTerminalTest, SetAndGetBaudRate) {
106131 libserial::Serial serial_port;
107132
@@ -125,6 +150,45 @@ TEST_F(PseudoTerminalTest, SetAndGetBaudRate) {
125150 serial_port.close ();
126151}
127152
153+ // TEST_F(PseudoTerminalTest, SetAndGetDataLength) {
154+ // libserial::Serial serial_port;
155+
156+ // serial_port.open(slave_port_);
157+
158+ // // Test multiple data lengths to be more thorough
159+ // std::vector<libserial::DataLength> test_lengths = {
160+ // libserial::DataLength::FIVE,
161+ // libserial::DataLength::SIX,
162+ // libserial::DataLength::SEVEN,
163+ // libserial::DataLength::EIGHT
164+ // };
165+
166+ // for (const auto& expected_length : test_lengths) {
167+ // // Set data length
168+ // EXPECT_NO_THROW({
169+ // serial_port.setDataLength(expected_length);
170+ // });
171+
172+ // // Add a small delay and flush
173+ // std::this_thread::sleep_for(std::chrono::milliseconds(50));
174+
175+ // // Force a re-read of the current settings
176+ // serial_port.close();
177+ // serial_port.open(slave_port_);
178+
179+ // // Get data length and verify
180+ // libserial::DataLength actual_length;
181+ // EXPECT_NO_THROW({
182+ // actual_length = serial_port.getDataLength();
183+ // });
184+
185+ // EXPECT_EQ(actual_length, expected_length)
186+ // << "Failed for data length: " << static_cast<int>(expected_length);
187+ // }
188+
189+ // serial_port.close();
190+ // }
191+
128192TEST_F (PseudoTerminalTest, SetParity) {
129193 libserial::Serial serial_port;
130194
@@ -309,10 +373,11 @@ TEST_F(PseudoTerminalTest, ReadWithReadFail) {
309373 auto read_buffer = std::make_shared<std::string>();
310374
311375 for (const auto & [error_num, error_msg] : errors_read_) {
312- serial_port.setSystemCallFunctions (
376+ serial_port.setPollSystemFunction (
313377 [](struct pollfd *, nfds_t , int ) -> int {
314378 return 1 ;
315- },
379+ });
380+ serial_port.setReadSystemFunction (
316381 [error_num](int , void *, size_t ) -> ssize_t {
317382 errno = error_num;
318383 return -1 ;
@@ -337,13 +402,10 @@ TEST_F(PseudoTerminalTest, ReadWithPollFail) {
337402 auto read_buffer = std::make_shared<std::string>();
338403
339404 for (const auto & [error_num, error_msg] : errors_poll_) {
340- serial_port.setSystemCallFunctions (
405+ serial_port.setPollSystemFunction (
341406 [error_num](struct pollfd *, nfds_t , int ) -> int {
342407 errno = error_num;
343408 return -1 ;
344- },
345- [](int , void *, size_t ) -> ssize_t {
346- return 1 ;
347409 });
348410
349411 auto expected_what = " Error in poll(): " + error_msg;
@@ -436,10 +498,7 @@ TEST_F(PseudoTerminalTest, ReadBytesWithReadFail) {
436498 auto read_buffer = std::make_shared<std::string>();
437499
438500 for (const auto & [error_num, error_msg] : errors_read_) {
439- serial_port.setSystemCallFunctions (
440- [](struct pollfd *, nfds_t , int ) -> int {
441- return 1 ;
442- },
501+ serial_port.setReadSystemFunction (
443502 [error_num](int , void *, size_t ) -> ssize_t {
444503 errno = error_num;
445504 return -1 ;
@@ -554,10 +613,11 @@ TEST_F(PseudoTerminalTest, ReadUntilWithReadFail) {
554613 // Skip these as they are handled differently in readUntil
555614 continue ;
556615 }
557- serial_port.setSystemCallFunctions (
616+ serial_port.setPollSystemFunction (
558617 [](struct pollfd *, nfds_t , int ) -> int {
559618 return 1 ;
560- },
619+ });
620+ serial_port.setReadSystemFunction (
561621 [error_num](int , void *, size_t ) -> ssize_t {
562622 errno = error_num;
563623 return -1 ;
@@ -582,13 +642,10 @@ TEST_F(PseudoTerminalTest, ReadUntilWithPollFail) {
582642 auto read_buffer = std::make_shared<std::string>();
583643
584644 for (const auto & [error_num, error_msg] : errors_poll_) {
585- serial_port.setSystemCallFunctions (
645+ serial_port.setPollSystemFunction (
586646 [error_num](struct pollfd *, nfds_t , int ) -> int {
587647 errno = error_num;
588648 return -1 ;
589- },
590- [](int , void *, size_t ) -> ssize_t {
591- return 1 ;
592649 });
593650
594651 auto expected_what = " Error in poll(): " + error_msg;
0 commit comments