libNbiotCore/test/serial_test.cpp
// Tests if ReadLine reads a line from buffer when there are characters in the buffer
// is set to simple
Tests if ReadLine reads a line from buffer when there are characters in the buffer
is set to simple
Tests if ReadLine reads a line from buffer when there are characters in the buffer is set to simple
TEST(SerialTest, ReadLineModes) {
    Serial s;
    Sequence s1;
    pSerCom = new MockSerialCom();
    nbiot::string line, line2, line3;
    s.configSetWriteStatus(writeStatus);
    s.configSetReadStatus(readStatus);
    s.configSetReadByte(readByte);
    s.configSetPutChar(writeByte);
    EXPECT_CALL(*pSerCom, writeStatus())
            .WillRepeatedly(Return(tx_empty));
    EXPECT_CALL(*pSerCom, readStatus())
            .WillRepeatedly(Return(rx_avail));
    const char my_str[] = "blabla\n";
    size_t result;
    for (int i = 0; i < 7; ++i) {
        EXPECT_CALL(*pSerCom, readByte())
                .InSequence(s1)
                .WillOnce(Return(my_str[i]));
    }
    result = s.readLine(line, 10, Serial::SerialReadMode::Simple);
    EXPECT_STREQ("blabla", line.c_str())
                        << "SerialReadModeSimple should read exactly one line from buffer until a line escape character";
    EXPECT_EQ(6, result);
    const char my_str2[] = "\nblabla\n";
    for (int i = 0; i < 8; ++i) {
        EXPECT_CALL(*pSerCom, readByte())
                .InSequence(s1)
                .WillOnce(Return(my_str2[i]));
    }
    result = s.readLine(line2, 10, Serial::SerialReadMode::Normal);
    EXPECT_STREQ("blabla", line2.c_str())
                        << "SerialReadMode Normal should ignore the first line escape character";
    EXPECT_EQ(6, result);
    const char my_str3[] = "\nblabla\n";
    for (int i = 0; i < 8; ++i) {
        EXPECT_CALL(*pSerCom, readByte())
                .InSequence(s1)
                .WillOnce(Return(my_str3[i]));
    }
    result = s.readLine(line3, 10, Serial::SerialReadMode::Ignore);
    EXPECT_STREQ("", line3.c_str())
                        << "SerialReadMode Ignore should ignore the next line in the buffer";
    EXPECT_EQ(6, result);
    delete (pSerCom);
}
TEST ( SerialTest , ReadLineModes ) { Serial s ; Sequence s1 ; pSerCom = new MockSerialCom ( ) ; nbiot :: string line , line2 , line3 ; s . configSetWriteStatus ( writeStatus ) ; s . configSetReadStatus ( readStatus ) ; s . configSetReadByte ( readByte ) ; s . configSetPutChar ( writeByte ) ; EXPECT_CALL ( * pSerCom , writeStatus ( ) ) . WillRepeatedly ( Return ( tx_empty ) ) ; EXPECT_CALL ( * pSerCom , readStatus ( ) ) . WillRepeatedly ( Return ( rx_avail ) ) ; const char my_str [ ] = " \n " ; size_t result ; for ( int i = 0 ; i < 7 ; ++ i ) { EXPECT_CALL ( * pSerCom , readByte ( ) ) . InSequence ( s1 ) . WillOnce ( Return ( my_str [ i ] ) ) ; } result = s . readLine ( line , 10 , Serial :: SerialReadMode :: Simple ) ; EXPECT_STREQ ( " " , line . c_str ( ) ) << " " ; EXPECT_EQ ( 6 , result ) ; const char my_str2 [ ] = " \n \n " ; for ( int i = 0 ; i < 8 ; ++ i ) { EXPECT_CALL ( * pSerCom , readByte ( ) ) . InSequence ( s1 ) . WillOnce ( Return ( my_str2 [ i ] ) ) ; } result = s . readLine ( line2 , 10 , Serial :: SerialReadMode :: Normal ) ; EXPECT_STREQ ( " " , line2 . c_str ( ) ) << " " ; EXPECT_EQ ( 6 , result ) ; const char my_str3 [ ] = " \n \n " ; for ( int i = 0 ; i < 8 ; ++ i ) { EXPECT_CALL ( * pSerCom , readByte ( ) ) . InSequence ( s1 ) . WillOnce ( Return ( my_str3 [ i ] ) ) ; } result = s . readLine ( line3 , 10 , Serial :: SerialReadMode :: Ignore ) ; EXPECT_STREQ ( " " , line3 . c_str ( ) ) << " " ; EXPECT_EQ ( 6 , result ) ; delete ( pSerCom ) ; }
Tests if ReadLine reads a line from buffer when there are characters in the buffer
is set to simple
Tests if ReadLine reads a line from buffer when there are characters in the buffer is set to simple