void HardwareManipulator::constructSMSMessage( const QString &sender, const QString &serviceCenter, const QString &text )
{
    QSMSMessage m;
    if ( sender.isEmpty() ) {
        warning(tr("Invalid Sender"),
                tr("Sender must not be empty"));
        return;
    }
    m.setSender(sender);

    if ( serviceCenter.contains(QRegExp("\\D")) ) {
        warning(tr("Invalid Service Center"),
                tr("Service Center must not be empty and contain "
                   "only digits"));
        return;
    }
    m.setServiceCenter(serviceCenter);

    m.setText(text);
    m.setTimestamp(QDateTime::currentDateTime());

    SMSList.appendSMS( m.toPdu() );
}
void HardwareManipulator::constructSMSDatagram(int port, const QString &sender, const QByteArray &data,
                                               const QByteArray &contentType)
{
    QWspPush pdu;
    pdu.setIdentifier(0);
    pdu.setPduType(6);

    pdu.setData(data.data(),data.length());

    QBuffer buffer;
    buffer.open(QBuffer::ReadWrite);
    QWspPduEncoder encoder(&buffer);

    if ( contentType.length() != 0 ) {
        pdu.addHeader("Content-Type", contentType);
        encoder.encodePush(pdu);
    } else {
        pdu.writeData(&buffer);
    }
    QByteArray appData = buffer.buffer();
    buffer.close();

    QSMSMessage m;
    m.setDestinationPort(port);
    m.setSender(sender);
    m.setApplicationData(appData);

    if( m.shouldSplit() ) {
        QList<QSMSMessage> list = m.split();

        for( int i =0; i < list.count(); i++ ) {
           SMSList.appendSMS( list[i].toPdu() );
        }
    } else {
        SMSList.appendSMS( m.toPdu() );
    }
}
Beispiel #3
0
void tst_QSimToolkit::testEncodeSendSMS()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( QByteArray, tpdu );
    QFETCH( int, resptype );
    QFETCH( QString, text );
    QFETCH( QString, number );
    QFETCH( bool, smsPacking );
    QFETCH( int, iconId );
    QFETCH( bool, iconSelfExplanatory );
    QFETCH( QByteArray, textAttribute );
    QFETCH( QString, html );
    QFETCH( int, options );

    // Output a dummy line to give some indication of which test we are currently running.
    qDebug() << "";

    // Check that the command PDU can be parsed correctly.
    QSimCommand decoded = QSimCommand::fromPdu(data);
    QVERIFY( decoded.type() == QSimCommand::SendSMS );
    QVERIFY( decoded.destinationDevice() == QSimCommand::Network );
    QCOMPARE( decoded.text(), text );
    if ( text.isEmpty() ) {
        if ( ( options & QSimCommand::EncodeEmptyStrings ) != 0 )
            QVERIFY( decoded.suppressUserFeedback() );
        else
            QVERIFY( !decoded.suppressUserFeedback() );
    } else {
        QVERIFY( !decoded.suppressUserFeedback() );
    }
    QCOMPARE( decoded.number(), number );
    QCOMPARE( decoded.smsPacking(), smsPacking );
    QCOMPARE( (int)decoded.iconId(), iconId );
    QCOMPARE( decoded.iconSelfExplanatory(), iconSelfExplanatory );
    QCOMPARE( decoded.textAttribute(), textAttribute );
    if ( !textAttribute.isEmpty() )
        QCOMPARE( decoded.textHtml(), html );

    // Check the final TPDU.  If packing is specified, we have to parse the SMS
    // and then re-encode it with the 7-bit alphabet.
    QByteArray newtpdu = decoded.extensionField(0x8B);
    if ( smsPacking ) {
        // Add dummy service center address that isn't in the TPDU before decoding.
        QSMSMessage msg = QSMSMessage::fromPdu( QByteArray( 1, 0 ) + newtpdu );
        msg.setDataCodingScheme( msg.dataCodingScheme() & 0xF3 );   // Convert to 7-bit

        // Convert back into a pdu and strip off the dummy service center address.
        newtpdu = msg.toPdu().mid(1);
    }

    // The TPDU in the command will have a message reference of 0.
    // We need to change it to the transmission message reference of 1
    // before we do the comparison.
    newtpdu[1] = (char)1;
    QCOMPARE( newtpdu, tpdu );

    // Check that the original command PDU can be reconstructed correctly.
    QByteArray encoded = decoded.toPdu( (QSimCommand::ToPduOptions)options );
    QCOMPARE( encoded, data );

    // Check that the terminal response PDU can be parsed correctly.
    QSimTerminalResponse decodedResp = QSimTerminalResponse::fromPdu(resp);
    QVERIFY( data.contains( decodedResp.commandPdu() ) );
    if ( resptype < 0x0100 ) {
        QVERIFY( decodedResp.result() == (QSimTerminalResponse::Result)resptype );
        QVERIFY( decodedResp.causeData().isEmpty() );
        QVERIFY( decodedResp.cause() == QSimTerminalResponse::NoSpecificCause );
    } else {
        QVERIFY( decodedResp.result() == (QSimTerminalResponse::Result)(resptype >> 8) );
        QVERIFY( decodedResp.causeData().size() == 1 );
        QVERIFY( decodedResp.cause() == (QSimTerminalResponse::Cause)(resptype & 0xFF) );
    }

    // Check that the original terminal response PDU can be reconstructed correctly.
    QCOMPARE( decodedResp.toPdu(), resp );
}