Exemplo n.º 1
0
void tst_QSimToolkit::testDeliverSendDTMF()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( int, resptype );
    QFETCH( QString, text );
    QFETCH( QString, number );
    QFETCH( int, iconId );
    QFETCH( bool, iconSelfExplanatory );
    QFETCH( QByteArray, textAttribute );
    QFETCH( QString, html );
    QFETCH( int, options );

    Q_UNUSED(resptype);
    Q_UNUSED(html);

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

    // Clear the client/server state.
    server->clear();
    deliveredCommand = QSimCommand();

    // Compose and send the command.
    QSimCommand cmd;
    cmd.setType( QSimCommand::SendDTMF );
    cmd.setDestinationDevice( QSimCommand::Network );
    cmd.setText( text );
    cmd.setNumber( number );
    cmd.setIconId( (uint)iconId );
    cmd.setIconSelfExplanatory( iconSelfExplanatory );
    cmd.setTextAttribute( textAttribute );
    server->emitCommand( cmd );

    // Wait for the command to arrive in the client.
    QVERIFY( QFutureSignal::wait( this, SIGNAL(commandSeen()), 100 ) );

    // Verify that the command was delivered exactly as we asked.
    QVERIFY( deliveredCommand.type() == cmd.type() );
    QVERIFY( deliveredCommand.text() == cmd.text() );
    QVERIFY( deliveredCommand.number() == cmd.number() );
    QVERIFY( deliveredCommand.iconId() == cmd.iconId() );
    QVERIFY( deliveredCommand.iconSelfExplanatory() == cmd.iconSelfExplanatory() );
    QVERIFY( deliveredCommand.textAttribute() == cmd.textAttribute() );
    QCOMPARE( deliveredCommand.toPdu( (QSimCommand::ToPduOptions)options ), data );

    // The terminal response should have been sent immediately to ack reception of the command.
    // We cannot check the return data explicitly because that will be handled in the modem
    // and will typically be invisible to Qtopia.  We therefore compare against what the
    // response would be without the return data.
    QCOMPARE( server->responseCount(), 1 );
    QCOMPARE( server->envelopeCount(), 0 );
    QSimTerminalResponse resp2;
    resp2.setCommand( deliveredCommand );
    resp2.setResult( QSimTerminalResponse::Success );
    QCOMPARE( server->lastResponse(), resp2.toPdu() );
}
Exemplo n.º 2
0
void tst_QSimToolkit::testDeliverRefresh()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( int, resptype );
    QFETCH( int, refreshtype );
    QFETCH( int, numfiles );
    QFETCH( QString, fileids );
    QFETCH( int, options );

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

    // Clear the client/server state.
    server->clear();
    deliveredCommand = QSimCommand();

    // Compose and send the command.
    QSimCommand cmd;
    cmd.setType( QSimCommand::Refresh );
    cmd.setRefreshType( (QSimCommand::RefreshType)refreshtype );
    if ( numfiles > 0 ) {
        QByteArray extData;
        extData += (char)numfiles;
        extData += QAtUtils::fromHex( fileids );
        cmd.addExtensionField( 0x92, extData );
    }
    server->emitCommand( cmd );

    // Wait for the command to arrive in the client.
    QVERIFY( QFutureSignal::wait( this, SIGNAL(commandSeen()), 100 ) );

    // Verify that the command was delivered exactly as we asked.
    QVERIFY( deliveredCommand.type() == cmd.type() );
    QVERIFY( deliveredCommand.refreshType() == cmd.refreshType() );
    QVERIFY( deliveredCommand.extensionData() == cmd.extensionData() );
    QCOMPARE( deliveredCommand.toPdu( (QSimCommand::ToPduOptions)options ), data );

    // The response should have been sent immediately.
    QCOMPARE( server->responseCount(), 1 );
    QCOMPARE( server->envelopeCount(), 0 );
    if ( resptype != 0x0003 ) {
        QCOMPARE( server->lastResponse(), resp );
    } else {
        // We cannot test the "additional EF's read" case because the qtopiaphone
        // library will always respond with "command performed successfully".
        QByteArray resp2 = resp;
        resp2[resp2.size() - 1] = 0x00;
        QCOMPARE( server->lastResponse(), resp2 );
    }
}
Exemplo n.º 3
0
void tst_QSimToolkit::testEncodeSendDTMF()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( int, resptype );
    QFETCH( QString, text );
    QFETCH( QString, number );
    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::SendDTMF );
    QVERIFY( decoded.destinationDevice() == QSimCommand::Network );
    QCOMPARE( decoded.text(), text );
    QCOMPARE( decoded.number(), number );
    QCOMPARE( (int)decoded.iconId(), iconId );
    QCOMPARE( decoded.iconSelfExplanatory(), iconSelfExplanatory );
    QCOMPARE( decoded.textAttribute(), textAttribute );
    if ( !textAttribute.isEmpty() )
        QCOMPARE( decoded.textHtml(), html );

    // 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 );
}
Exemplo n.º 4
0
void tst_QSimToolkit::testEncodeRefresh()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( int, resptype );
    QFETCH( int, refreshtype );
    QFETCH( int, numfiles );
    QFETCH( QString, fileids );
    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::Refresh );
    QVERIFY( decoded.destinationDevice() == QSimCommand::ME );
    QCOMPARE( (int)decoded.refreshType(), refreshtype );
    if ( numfiles > 0 ) {
        QCOMPARE( decoded.extensionField(0x92)[0] & 0xFF, numfiles );
        QCOMPARE( decoded.extensionField(0x92).mid(1), QAtUtils::fromHex(fileids) );
    } else {
        QCOMPARE( decoded.extensionField(0x92), QByteArray() );
    }

    // 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 );
}
Exemplo n.º 5
0
void tst_QSimToolkit::testDeliverPowerOnCard()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( QByteArray, atr );
    QFETCH( int, resptype );
    QFETCH( int, device );
    QFETCH( int, options );

    Q_UNUSED(resp);
    Q_UNUSED(resptype);
    Q_UNUSED(atr);

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

    // Clear the client/server state.
    server->clear();
    deliveredCommand = QSimCommand();

    // Compose and send the command.
    QSimCommand cmd;
    cmd.setType( QSimCommand::PowerOnCard );
    cmd.setDestinationDevice( (QSimCommand::Device)( device + 0x10 ) );
    server->emitCommand( cmd );

    // Wait for the command to arrive in the client.
    QVERIFY( QFutureSignal::wait( this, SIGNAL(commandSeen()), 100 ) );

    // Verify that the command was delivered exactly as we asked.
    QVERIFY( deliveredCommand.type() == cmd.type() );
    QCOMPARE( deliveredCommand.toPdu( (QSimCommand::ToPduOptions)options ), data );

    // The response should have been sent immediately, and should always be success.
    // We cannot test the answer to reset behaviour with this interface.
    QCOMPARE( server->responseCount(), 1 );
    QCOMPARE( server->envelopeCount(), 0 );
    static unsigned char const ok_resp[] =
        {0x81, 0x03, 0x01, 0x31, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83, 0x01, 0x00};
    QByteArray resp2 = QByteArray( (char *)ok_resp, sizeof( ok_resp ) );
    QCOMPARE( server->lastResponse(), resp2 );
}
Exemplo n.º 6
0
void tst_QSimToolkit::testDeliverPowerOffCard()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( int, resptype );
    QFETCH( int, device );
    QFETCH( int, options );

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

    // Clear the client/server state.
    server->clear();
    deliveredCommand = QSimCommand();

    // Compose and send the command.
    QSimCommand cmd;
    cmd.setType( QSimCommand::PowerOffCard );
    cmd.setDestinationDevice( (QSimCommand::Device)( device + 0x10 ) );
    server->emitCommand( cmd );

    // Wait for the command to arrive in the client.
    QVERIFY( QFutureSignal::wait( this, SIGNAL(commandSeen()), 100 ) );

    // Verify that the command was delivered exactly as we asked.
    QVERIFY( deliveredCommand.type() == cmd.type() );
    QCOMPARE( deliveredCommand.toPdu( (QSimCommand::ToPduOptions)options ), data );

    // The response should have been sent immediately.
    QCOMPARE( server->responseCount(), 1 );
    QCOMPARE( server->envelopeCount(), 0 );
    if ( resptype == 0x0000 ) {
        QCOMPARE( server->lastResponse(), resp );
    } else {
        // We cannot test the "no card inserted" case because the qtopiaphone
        // library will always respond with "command performed successfully".
        static unsigned char const ok_resp[] =
            {0x81, 0x03, 0x01, 0x32, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83, 0x01, 0x00};
        QByteArray resp2 = QByteArray( (char *)ok_resp, sizeof( ok_resp ) );
        QCOMPARE( server->lastResponse(), resp2 );
    }
}
Exemplo n.º 7
0
/*!
    Sends a proactive SIM command, \a cmd, to the ME, and instructs
    SimApplication to invoke \a slot on \a target when the response
    arrives back.  The \a options provides extra information about
    how the command should be transmitted to the ME in PDU form.

    For \c SetupMenu commands, \a target and \a slot should be null.
    When the user responds to the main menu, mainMenuSelection() or
    mainMenuHelpRequest() will be invoked.

    \sa mainMenuSelection(), mainMenuHelpRequest()
*/
void SimApplication::command( const QSimCommand& cmd,
                              QObject *target, const char *slot,
                              QSimCommand::ToPduOptions options )
{
    // Record the command details, together with the type of
    // TERMINAL RESPONSE or ENVELOPE that we expect in answer.
    d->currentCommand = cmd.toPdu( options );
    d->expectedType = cmd.type();
    d->target = target;
    d->slot = slot;

    // Send an unsolicited notification to indicate that a new
    // proactive SIM command is available.  If we are already in
    // the middle of processing a TERMINAL RESPONSE or ENVELOPE,
    // then delay the unsolicited notification until later.
    if ( d->rules && !d->inResponse ) {
        d->rules->unsolicited
            ( "*TCMD: " + QString::number( d->currentCommand.size() ) );
    }
}
Exemplo n.º 8
0
void SimApp::cmdMenu(const QSimCommand &cmd)
{
    if (!simToolkitAvailable) {
        // First time that we have seen the toolkit menu, so this
        // SIM obviously has a SIM toolkit application on it.
        simToolkitAvailable = true;
        mainMenuTitle = cmd.title();
        updateValueSpace();
    }

    // Create QSimIconReader if the menu contains them.
    QList<QSimMenuItem> items = cmd.menuItems();
    QList<QSimMenuItem>::ConstIterator it;
    bool needIcon = false;
    for (it = items.begin(); it != items.end(); ++it) {
        if ( (int)(*it).iconId() ) {
            needIcon = true;
            if ( !iconReader )
                createIconReader();
            else
                break;
        }
    }

    // Create the menu widgetry.
    SimMenu *menu;
    if ( needIcon )
        menu = new SimMenu(cmd, iconReader, stack);
    else
        menu = new SimMenu(cmd, stack);

    // main menu send QSimEnvelope,sub menu sends QSimTerminalResponse
    if (cmd.type() == QSimCommand::SetupMenu) {
        connect(menu, SIGNAL(sendEnvelope(QSimEnvelope)),
                this, SLOT(sendEnvelope(QSimEnvelope)) );
    } else {
        connect(menu, SIGNAL(sendResponse(QSimTerminalResponse)),
                this, SLOT(sendResponse(QSimTerminalResponse)) );
    }
    setView(menu);
}
Exemplo n.º 9
0
void tst_QSimToolkit::testEncodePowerOnCard()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( QByteArray, atr );
    QFETCH( int, resptype );
    QFETCH( int, device );
    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::PowerOnCard );
    QVERIFY( decoded.destinationDevice() == (QSimCommand::Device)( device + 0x10 ) );

    // 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) );
    }
    QCOMPARE( decodedResp.extensionField(0xA1), atr );

    // Check that the original terminal response PDU can be reconstructed correctly.
    QCOMPARE( decodedResp.toPdu(), resp );
}
Exemplo n.º 10
0
void tst_QSimToolkit::testDeliverProvideLocalInformation()
{
    QFETCH( QByteArray, data );
    QFETCH( QByteArray, resp );
    QFETCH( QByteArray, info );
    QFETCH( int, resptype );
    QFETCH( int, localtype );
    QFETCH( int, options );

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

    // Clear the client/server state.
    server->clear();
    deliveredCommand = QSimCommand();

    // Compose and send the command.
    QSimCommand cmd;
    cmd.setType( QSimCommand::ProvideLocalInformation );
    cmd.setQualifier( localtype );
    server->emitCommand( cmd );

    // Wait for the command to arrive in the client.
    QVERIFY( QFutureSignal::wait( this, SIGNAL(commandSeen()), 100 ) );

    // Verify that the command was delivered exactly as we asked.
    QVERIFY( deliveredCommand.type() == cmd.type() );
    QVERIFY( deliveredCommand.qualifier() == cmd.qualifier() );
    QCOMPARE( deliveredCommand.toPdu( (QSimCommand::ToPduOptions)options ), data );

    // The response should have been sent immediately.
    QCOMPARE( server->responseCount(), 1 );
    QCOMPARE( server->envelopeCount(), 0 );
    QSimTerminalResponse resp2 = QSimTerminalResponse::fromPdu( server->lastResponse() );
    QVERIFY( resp2.result() == (QSimTerminalResponse::Result)resptype );
    QVERIFY( resp2.cause() == QSimTerminalResponse::NoSpecificCause );
}
Exemplo n.º 11
0
void SimApp::softKeysMenu(const QSimCommand& cmd)
{
    // Request icons from the SIM if the menu contains them.
    QList<QSimMenuItem> items = cmd.menuItems();
    QList<QSimMenuItem>::ConstIterator it;
    for (it = items.begin(); it != items.end(); ++it) {
        int iconId = (int)((*it).iconId());
        if ( iconId > 0 )
            createIconReader();
    }

    // Create the menu widgetry.
    SoftKeysMenu *menu = new SoftKeysMenu(cmd, iconReader, stack);

    // main menu send QSimEnvelope,sub menu sends QSimTerminalResponse
    if (cmd.type() == QSimCommand::SetupMenu) {
        connect(menu, SIGNAL(sendEnvelope(QSimEnvelope)),
                this, SLOT(sendEnvelope(QSimEnvelope)) );
    } else {
        connect(menu, SIGNAL(sendResponse(QSimTerminalResponse)),
                this, SLOT(sendResponse(QSimTerminalResponse)) );
    }
    setView(menu);
}
Exemplo n.º 12
0
void SimApp::simCommand(const QSimCommand &cmd)
{
    switch (cmd.type()) {
        case QSimCommand::SetupMenu: {
            // prevent No SIM message from appearing while fetching main menu
            if ( failLabel ) {
                stack->removeWidget( failLabel );
                delete failLabel;
                failLabel = 0;
            }
            QWidget *oldView = view;
            if (listViewPreferred(cmd))
                cmdMenu(cmd);
            else
                softKeysMenu(cmd);
            removeView(oldView);
            break;
        }
        case QSimCommand::DisplayText:
            cmdDisplayText(cmd);
            break;
        case QSimCommand::GetInkey:
            cmdInKey(cmd);
            break;
        case QSimCommand::GetInput:
            cmdInput(cmd);
            break;
        case QSimCommand::SetupCall:
            cmdSetupCall(cmd);
            break;
        case QSimCommand::PlayTone:
            cmdTone(cmd);
            break;
        case QSimCommand::SelectItem:
            if (listViewPreferred(cmd))
                cmdMenu(cmd);
            else
                softKeysMenu(cmd);
            break;
        case QSimCommand::Refresh:
            cmdRefresh(cmd);
            break;
        case QSimCommand::SendSS:
        case QSimCommand::SendSMS:
        case QSimCommand::SendUSSD:
        case QSimCommand::SendDTMF:
        case QSimCommand::RunATCommand:
        case QSimCommand::CloseChannel:
        case QSimCommand::ReceiveData:
        case QSimCommand::SendData:
            // Pop up a notification to the user if text is not empty.
            showNotification(cmd);
            break;
        case QSimCommand::Timeout:
            // Wavecom only - ignore this.
            break;
        case QSimCommand::EndSession:
            qApp->quit();
            break;
        case QSimCommand::LaunchBrowser:
            cmdLaunchBrowser(cmd);
            break;
        case QSimCommand::OpenChannel:
            cmdChannel(cmd);
            break;
        case QSimCommand::SetupIdleModeText:
            cmdIdleModeText(cmd);
            break;
        case QSimCommand::NoCommand:
        case QSimCommand::MoreTime:
        case QSimCommand::PollInterval:
        case QSimCommand::PollingOff:
        case QSimCommand::ProvideLocalInformation:
        case QSimCommand::PerformCardAPDU:
        case QSimCommand::PowerOffCard:
        case QSimCommand::PowerOnCard:
        case QSimCommand::GetReaderStatus:
        case QSimCommand::TimerManagement:
        case QSimCommand::GetChannelStatus:
        case QSimCommand::LanguageNotification:
            // Ignore these commands: they are handled by modem vendor plugins.
            break;
        case QSimCommand::SetupEventList:
            cmdSetupEventList(cmd);
            break;

        default: break;
    }
}
Exemplo n.º 13
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 );
}
Exemplo n.º 14
0
void tst_QSimToolkit::testDeliverSendSMS()
{
    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 );

    Q_UNUSED(html);

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

    // Clear the client/server state.
    server->clear();
    deliveredCommand = QSimCommand();

    // Compose and send the command.
    QSimCommand cmd;
    cmd.setType( QSimCommand::SendSMS );
    cmd.setDestinationDevice( QSimCommand::Network );
    cmd.setText( text );
    if ( text.isEmpty() && ( options & QSimCommand::EncodeEmptyStrings ) != 0 )
        cmd.setSuppressUserFeedback( true );
    cmd.setNumber( number );
    cmd.setSmsPacking( smsPacking );
    cmd.setIconId( (uint)iconId );
    cmd.setIconSelfExplanatory( iconSelfExplanatory );
    cmd.setTextAttribute( textAttribute );
    QByteArray newtpdu = tpdu;
    if ( smsPacking ) {
        // To prevent truncation of the 1.4.1 test data during 7-bit to 8-bit conversion,
        // we extract the TPDU from "data" rather than use "tpdu".
        newtpdu = QSimCommand::fromPdu( data ).extensionField(0x8B);
    }
    newtpdu[1] = (char)0;
    cmd.addExtensionField( 0x8B, newtpdu );
    server->emitCommand( cmd );

    // Wait for the command to arrive in the client.
    QVERIFY( QFutureSignal::wait( this, SIGNAL(commandSeen()), 100 ) );

    // Verify that the command was delivered exactly as we asked.
    QVERIFY( deliveredCommand.type() == cmd.type() );
    QVERIFY( deliveredCommand.text() == cmd.text() );
    QVERIFY( deliveredCommand.suppressUserFeedback() == cmd.suppressUserFeedback() );
    QVERIFY( deliveredCommand.number() == cmd.number() );
    QVERIFY( deliveredCommand.smsPacking() == cmd.smsPacking() );
    QVERIFY( deliveredCommand.iconId() == cmd.iconId() );
    QVERIFY( deliveredCommand.iconSelfExplanatory() == cmd.iconSelfExplanatory() );
    QVERIFY( deliveredCommand.extensionData() == cmd.extensionData() );
    QVERIFY( deliveredCommand.textAttribute() == cmd.textAttribute() );
    QCOMPARE( deliveredCommand.toPdu( (QSimCommand::ToPduOptions)options ), data );

    // The terminal response should have been sent immediately to ack reception of the command.
    QCOMPARE( server->responseCount(), 1 );
    QCOMPARE( server->envelopeCount(), 0 );
    if ( resptype != 0x0004 ) {
        QCOMPARE( server->lastResponse(), resp );
    } else {
        // We cannot test the "icon not displayed" case because the qtopiaphone
        // library will always respond with "command performed successfully".
        // Presumably the Qtopia user interface can always display icons.
        QByteArray resp2 = resp;
        resp2[resp2.size() - 1] = 0x00;
        QCOMPARE( server->lastResponse(), resp2 );
    }
}