libNbiotCore/test/serial_test.cpp
// Tests that URCs are filtered properly and the callback function is called.
Tests that URCs are filtered properly and the callback function is called.
Tests that URCs are filtered properly and the callback function is called .
TEST_F(SerialFixture, UrcFilter) {
    Serial s;
    Sequence s1;
    pSerCom = new MockSerialCom();
    nbiot::string line;
    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));
    number_of_calls = 0;
    s.addUrcFilter("+NSOMNI", do_nothing);
    s.addUrcFilter("+NSTAT", do_nothing);
    const char my_str[] = "+NSOMNI\n+NSOMNI\n+NSTAT\nOK\n";
    size_t result;
    for (int i = 0; i < 26; ++i) {
        EXPECT_CALL(*pSerCom, readByte())
                .InSequence(s1)
                .WillOnce(Return(my_str[i]));
    }
    result = s.readLine(line, 10, Serial::SerialReadMode::Simple);
    EXPECT_TRUE(number_of_calls)
                        << "Callback function wasn't called.";
    EXPECT_THAT(line.c_str(), Not(HasSubstr("+NSOMNI")))
                        << "At least one URC was not filtered properly during readLine.";
    EXPECT_THAT(line.c_str(), Not(HasSubstr("+NSTAT")))
                        << "At least one URC was not filtered properly during readLine.";
    EXPECT_STREQ("OK", line.c_str());
    EXPECT_EQ(2, result);
    EXPECT_EQ(3, number_of_calls) << "URC callback function should be called " << 3 << " times";
    delete (pSerCom);
}
TEST_F ( SerialFixture , UrcFilter ) { Serial s ; Sequence s1 ; pSerCom = new MockSerialCom ( ) ; nbiot :: string line ; 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 ) ) ; number_of_calls = 0 ; s . addUrcFilter ( " " , do_nothing ) ; s . addUrcFilter ( " " , do_nothing ) ; const char my_str [ ] = " \n \n \n \n " ; size_t result ; for ( int i = 0 ; i < 26 ; ++ i ) { EXPECT_CALL ( * pSerCom , readByte ( ) ) . InSequence ( s1 ) . WillOnce ( Return ( my_str [ i ] ) ) ; } result = s . readLine ( line , 10 , Serial :: SerialReadMode :: Simple ) ; EXPECT_TRUE ( number_of_calls ) << " " ; EXPECT_THAT ( line . c_str ( ) , Not ( HasSubstr ( " " ) ) ) << " " ; EXPECT_THAT ( line . c_str ( ) , Not ( HasSubstr ( " " ) ) ) << " " ; EXPECT_STREQ ( " " , line . c_str ( ) ) ; EXPECT_EQ ( 2 , result ) ; EXPECT_EQ ( 3 , number_of_calls ) << " " << 3 << " " ; delete ( pSerCom ) ; }
Tests that URCs are filtered properly and the callback function is called.
Tests that URCs are filtered properly and the callback function is called .