tests/auto/qiodevice/tst_qiodevice.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    75     void getch();
    75     void getch();
    76     void putch();
    76     void putch();
    77 
    77 
    78     void readLine_data();
    78     void readLine_data();
    79     void readLine();
    79     void readLine();
       
    80 
       
    81     void readLine2_data();
       
    82     void readLine2();
    80 };
    83 };
    81 
    84 
    82 // Testing get/set functions
    85 // Testing get/set functions
    83 void tst_QIODevice::getSetCheck()
    86 void tst_QIODevice::getSetCheck()
    84 {
    87 {
   451     QVERIFY(buffer.seek(0));
   454     QVERIFY(buffer.seek(0));
   452     line = buffer.readLine();
   455     line = buffer.readLine();
   453     QCOMPARE(line.size(), linelen);
   456     QCOMPARE(line.size(), linelen);
   454 }
   457 }
   455 
   458 
       
   459 void tst_QIODevice::readLine2_data()
       
   460 {
       
   461     QTest::addColumn<QByteArray>("line");
       
   462 
       
   463     QTest::newRow("1024 - 4") << QByteArray(1024 - 4, 'x');
       
   464     QTest::newRow("1024 - 3") << QByteArray(1024 - 3, 'x');
       
   465     QTest::newRow("1024 - 2") << QByteArray(1024 - 2, 'x');
       
   466     QTest::newRow("1024 - 1") << QByteArray(1024 - 1, 'x');
       
   467     QTest::newRow("1024"    ) << QByteArray(1024    , 'x');
       
   468     QTest::newRow("1024 + 1") << QByteArray(1024 + 1, 'x');
       
   469     QTest::newRow("1024 + 2") << QByteArray(1024 + 2, 'x');
       
   470 
       
   471     QTest::newRow("4096 - 4") << QByteArray(4096 - 4, 'x');
       
   472     QTest::newRow("4096 - 3") << QByteArray(4096 - 3, 'x');
       
   473     QTest::newRow("4096 - 2") << QByteArray(4096 - 2, 'x');
       
   474     QTest::newRow("4096 - 1") << QByteArray(4096 - 1, 'x');
       
   475     QTest::newRow("4096"    ) << QByteArray(4096    , 'x');
       
   476     QTest::newRow("4096 + 1") << QByteArray(4096 + 1, 'x');
       
   477     QTest::newRow("4096 + 2") << QByteArray(4096 + 2, 'x');
       
   478 
       
   479     QTest::newRow("8192 - 4") << QByteArray(8192 - 4, 'x');
       
   480     QTest::newRow("8192 - 3") << QByteArray(8192 - 3, 'x');
       
   481     QTest::newRow("8192 - 2") << QByteArray(8192 - 2, 'x');
       
   482     QTest::newRow("8192 - 1") << QByteArray(8192 - 1, 'x');
       
   483     QTest::newRow("8192"    ) << QByteArray(8192    , 'x');
       
   484     QTest::newRow("8192 + 1") << QByteArray(8192 + 1, 'x');
       
   485     QTest::newRow("8192 + 2") << QByteArray(8192 + 2, 'x');
       
   486 
       
   487     QTest::newRow("16384 - 4") << QByteArray(16384 - 4, 'x');
       
   488     QTest::newRow("16384 - 3") << QByteArray(16384 - 3, 'x');
       
   489     QTest::newRow("16384 - 2") << QByteArray(16384 - 2, 'x');
       
   490     QTest::newRow("16384 - 1") << QByteArray(16384 - 1, 'x');
       
   491     QTest::newRow("16384"    ) << QByteArray(16384    , 'x');
       
   492     QTest::newRow("16384 + 1") << QByteArray(16384 + 1, 'x');
       
   493     QTest::newRow("16384 + 2") << QByteArray(16384 + 2, 'x');
       
   494 
       
   495     QTest::newRow("20000") << QByteArray(20000, 'x');
       
   496 
       
   497     QTest::newRow("32768 - 4") << QByteArray(32768 - 4, 'x');
       
   498     QTest::newRow("32768 - 3") << QByteArray(32768 - 3, 'x');
       
   499     QTest::newRow("32768 - 2") << QByteArray(32768 - 2, 'x');
       
   500     QTest::newRow("32768 - 1") << QByteArray(32768 - 1, 'x');
       
   501     QTest::newRow("32768"    ) << QByteArray(32768    , 'x');
       
   502     QTest::newRow("32768 + 1") << QByteArray(32768 + 1, 'x');
       
   503     QTest::newRow("32768 + 2") << QByteArray(32768 + 2, 'x');
       
   504 
       
   505     QTest::newRow("40000") << QByteArray(40000, 'x');
       
   506 }
       
   507 
       
   508 void tst_QIODevice::readLine2()
       
   509 {
       
   510     QFETCH(QByteArray, line);
       
   511 
       
   512     int length = line.size();
       
   513 
       
   514     QByteArray data("First line.\r\n");
       
   515     data.append(line);
       
   516     data.append("\r\n");
       
   517     data.append(line);
       
   518     data.append("\r\n");
       
   519     data.append("\r\n0123456789");
       
   520 
       
   521     {
       
   522         QBuffer buffer(&data);
       
   523         buffer.open(QIODevice::ReadOnly);
       
   524 
       
   525         buffer.seek(0);
       
   526         QByteArray temp;
       
   527         temp.resize(64536);
       
   528         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(13));
       
   529         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 2));
       
   530         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 2));
       
   531         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(2));
       
   532         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(10));
       
   533         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(-1));
       
   534 
       
   535         buffer.seek(0);
       
   536         QCOMPARE(buffer.readLine().size(), 13);
       
   537         QCOMPARE(buffer.readLine().size(), length + 2);
       
   538         QCOMPARE(buffer.readLine().size(), length + 2);
       
   539         QCOMPARE(buffer.readLine().size(), 2);
       
   540         QCOMPARE(buffer.readLine().size(), 10);
       
   541         QVERIFY(buffer.readLine().isNull());
       
   542     }
       
   543 
       
   544     {
       
   545         QBuffer buffer(&data);
       
   546         buffer.open(QIODevice::ReadOnly | QIODevice::Text);
       
   547 
       
   548         buffer.seek(0);
       
   549         QByteArray temp;
       
   550         temp.resize(64536);
       
   551         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(12));
       
   552         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 1));
       
   553         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 1));
       
   554         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(1));
       
   555         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(10));
       
   556         QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(-1));
       
   557 
       
   558         buffer.seek(0);
       
   559         QCOMPARE(buffer.readLine().size(), 12);
       
   560         QCOMPARE(buffer.readLine().size(), length + 1);
       
   561         QCOMPARE(buffer.readLine().size(), length + 1);
       
   562         QCOMPARE(buffer.readLine().size(), 1);
       
   563         QCOMPARE(buffer.readLine().size(), 10);
       
   564         QVERIFY(buffer.readLine().isNull());
       
   565     }
       
   566 }
       
   567 
   456 QTEST_MAIN(tst_QIODevice)
   568 QTEST_MAIN(tst_QIODevice)
   457 #include "tst_qiodevice.moc"
   569 #include "tst_qiodevice.moc"