diff options
Diffstat (limited to 'tests/auto/qtextstream/tst_qtextstream.cpp')
-rw-r--r-- | tests/auto/qtextstream/tst_qtextstream.cpp | 1542 |
1 files changed, 1 insertions, 1541 deletions
diff --git a/tests/auto/qtextstream/tst_qtextstream.cpp b/tests/auto/qtextstream/tst_qtextstream.cpp index 2d7c24d238..b086a213c8 100644 --- a/tests/auto/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/qtextstream/tst_qtextstream.cpp @@ -243,45 +243,6 @@ private slots: void generateBOM(); void readBomSeekBackReadBomAgain(); - // old tests -#ifdef QT3_SUPPORT - void qt3_operator_shiftleft_data(); - void qt3_operator_shiftleft(); - void qt3_operator_shiftright_data(); - void qt3_operator_shiftright(); - void qt3_operator_shift_QChar_data(); - void qt3_operator_shift_QChar(); - void qt3_operator_shift_char_data(); - void qt3_operator_shift_char(); - void qt3_operator_shift_short_data(); - void qt3_operator_shift_short(); - void qt3_operator_shift_ushort_data(); - void qt3_operator_shift_ushort(); - void qt3_operator_shift_int_data(); - void qt3_operator_shift_int(); - void qt3_operator_shift_uint_data(); - void qt3_operator_shift_uint(); - void qt3_operator_shift_long_data(); - void qt3_operator_shift_long(); - void qt3_operator_shift_ulong_data(); - void qt3_operator_shift_ulong(); - void qt3_operator_shift_float_data(); - void qt3_operator_shift_float(); - void qt3_operator_shift_double_data(); - void qt3_operator_shift_double(); - void qt3_operator_shift_QString_data(); - void qt3_operator_shift_QString(); - void qt3_operator_shift_QByteArray_data(); - void qt3_operator_shift_QByteArray(); - - void qt3_writeDataToFileReadAsLines_data(); - void qt3_writeDataToFileReadAsLines(); - void qt3_writeDataToQStringReadAsLines_data(); - void qt3_writeDataToQStringReadAsLines(); - - void qt3_readLineFromString(); -#endif - // task-specific tests void task180679_alignAccountingStyle(); void task178772_setCodec(); @@ -294,54 +255,6 @@ private: void generateRealNumbersData(bool for_QString); void generateStringData(bool for_QString); void generateRealNumbersDataWrite(); - - // Qt 3 privates -#ifdef QT3_SUPPORT - void qt3_createWriteStream( QTextStream *&os ); - void qt3_closeWriteStream( QTextStream *os ); - void qt3_createReadStream( QTextStream *&is ); - void qt3_closeReadStream( QTextStream *is ); - void qt3_read_QChar( QTextStream *s ); - void qt3_write_QChar( QTextStream *s ); - void qt3_read_char( QTextStream *s ); - void qt3_write_char( QTextStream *s ); - void qt3_read_short( QTextStream *s ); - void qt3_write_short( QTextStream *s ); - void qt3_read_ushort( QTextStream *s ); - void qt3_write_ushort( QTextStream *s ); - void qt3_read_int( QTextStream *s ); - void qt3_write_int( QTextStream *s ); - void qt3_read_uint( QTextStream *s ); - void qt3_write_uint( QTextStream *s ); - void qt3_read_long( QTextStream *s ); - void qt3_write_long( QTextStream *s ); - void qt3_read_ulong( QTextStream *s ); - void qt3_write_ulong( QTextStream *s ); - void qt3_read_float( QTextStream *s ); - void qt3_write_float( QTextStream *s ); - void qt3_read_double( QTextStream *s ); - void qt3_write_double( QTextStream *s ); - void qt3_read_QString( QTextStream *s ); - void qt3_write_QString( QTextStream *s ); - void qt3_read_QByteArray( QTextStream *s ); - void qt3_write_QByteArray( QTextStream *s ); - void qt3_operatorShift_data( QIODevice::OpenMode ); - void qt3_do_shiftleft( QTextStream *ts ); - QTextStream::Encoding qt3_toEncoding( const QString& ); - QString qt3_decodeString( QByteArray array, const QString& encoding ); -#endif - - // Qt 3 data - QTextStream *os; - QTextStream *is; - QTextStream *ts; - QFile *inFile; - QFile *inResource; - QFile *outFile; - QByteArray *inArray; - QBuffer *inBuffer; - QString *inString; - bool file_is_empty; }; // Testing get/set functions @@ -465,18 +378,6 @@ void tst_QTextStream::getSetCheck() tst_QTextStream::tst_QTextStream() { - // Initialize Qt 3 data - ts = 0; - os = 0; - is = 0; - outFile = 0; - inFile = 0; - inResource = 0; - inArray = 0; - inBuffer = 0; - inString = 0; - file_is_empty = FALSE; - Q_SET_DEFAULT_IAP } @@ -486,41 +387,10 @@ tst_QTextStream::~tst_QTextStream() void tst_QTextStream::init() { - // Initialize Qt 3 data - ts = 0; - os = 0; - is = 0; - inFile = 0; - inResource = 0; - outFile = 0; - inArray = 0; - inBuffer = 0; - inString = 0; - file_is_empty = FALSE; } void tst_QTextStream::cleanup() { - // Clean up Qt 3 data - delete ts; - ts = 0; - delete os; - os = 0; - delete is; - is = 0; - delete inResource; - inResource = 0; - delete inFile; - inFile = 0; - delete outFile; - outFile = 0; - delete inArray; - inArray = 0; - delete inBuffer; - inBuffer = 0; - delete inString; - inString = 0; - QCoreApplication::instance()->processEvents(); } @@ -2710,7 +2580,7 @@ void tst_QTextStream::readBomSeekBackReadBomAgain() QFile::remove("utf8bom"); QFile file("utf8bom"); QVERIFY(file.open(QFile::ReadWrite)); - file.write("\xef\xbb\xbf""Andreas"); + file.write("\xef\xbb\xbf" "Andreas"); file.seek(0); QCOMPARE(file.pos(), qint64(0)); @@ -2725,1416 +2595,6 @@ void tst_QTextStream::readBomSeekBackReadBomAgain() } // ------------------------------------------------------------------------------ -// QT 3 tests -// ------------------------------------------------------------------------------ -#ifdef QT3_SUPPORT - -void tst_QTextStream::qt3_readLineFromString() -{ - QString data = "line 1e\nline 2e\nline 3e"; - QStringList list; - QTextStream stream(&data, QIODevice::ReadOnly); - stream.setCodec(QTextCodec::codecForName("ISO-8859-1")); - stream.setAutoDetectUnicode(true); - - while (!stream.atEnd()) { - QString line = stream.readLine(); - QCOMPARE(QChar(line[line.size()-1]), QChar('e')); - list << line; - } - QVERIFY(list.count() == 3); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shiftright_data() -{ - qt3_operatorShift_data( QIODevice::ReadOnly ); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shiftleft_data() -{ - qt3_operatorShift_data( QIODevice::WriteOnly ); -} - -static const double doubleDummy = 567.89; -static const int intDummy = 1234; -static const QString stringDummy = "ABCD"; - -struct tst_IODevice { - char *n; - QIODevice::OpenModeFlag modes; - QString name() const { return QString::fromLatin1(n); } -} devices[] = { - { "file", QIODevice::ReadWrite }, - { "bytearray", QIODevice::ReadWrite }, - { "buffer", QIODevice::ReadWrite }, - { "string", QIODevice::ReadWrite }, - { "resource", QIODevice::ReadOnly }, //See discussion (resources) below - { 0, (QIODevice::OpenModeFlag)0 } -}; - -/* Resources: - - This will test QTextStream's ability to interact with resources, - however the trouble is the resources must be created correctly and - built into the executable (but this executable also creates the - resource files). So there is a chicken and egg problem, to create - resources (if the file formats change at all): - - 1) p4 edit resources/... - - 2) Change QIODevice::ReadOnly above in the devices[] for "resource" - to QIODevice::WriteOnly - - 3) run the test - - 4) revert this file, qmake, make, and run again. - - 5) Enjoy. -*/ - -static inline QString resourceDir() -{ - QString ret = "resources/"; - if(QSysInfo::ByteOrder == QSysInfo::BigEndian) - ret += "big_endian/"; - else - ret += "little_endian/"; - return ret; -} - -static const char *const encodings[] = { - "Locale", - "Latin1", - "Unicode", - "UnicodeNetworkOrder", - "UnicodeReverse", - "RawUnicode", - "UnicodeUTF8", - 0 -}; - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operatorShift_data( QIODevice::OpenMode mode ) -{ - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<QString>("type"); - QTest::addColumn<double>("doubleVal"); - QTest::addColumn<int>("intVal"); - QTest::addColumn<QString>("stringVal"); - QTest::addColumn<QByteArray>("encoded"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - if(!(device->modes & mode)) - continue; - - /* - We first test each type at least once. - */ - QTest::newRow( device->name() + "0" ) << device->name() << QString("UnicodeUTF8") << QString("QChar") - << doubleDummy << (int) 'Z' << stringDummy - << QByteArray( QByteArray("Z") ); - QTest::newRow( device->name() + "1" ) << device->name() << QString("UnicodeUTF8") << QString("char") - << doubleDummy << (int) 'Z' << stringDummy - << QByteArray( QByteArray("Z") ); - QTest::newRow( device->name() + "2" ) << device->name() << QString("UnicodeUTF8") << QString("signed short") - << doubleDummy << 12345 << stringDummy - << QByteArray( QByteArray("12345") ); - QTest::newRow( device->name() + "3" ) << device->name() << QString("UnicodeUTF8") << QString("unsigned short") - << doubleDummy << 12345 << stringDummy - << QByteArray( QByteArray("12345") ); - QTest::newRow( device->name() + "4" ) << device->name() << QString("UnicodeUTF8") << QString("signed int") - << doubleDummy << 12345 << stringDummy - << QByteArray( QByteArray("12345") ); - QTest::newRow( device->name() + "5" ) << device->name() << QString("UnicodeUTF8") << QString("unsigned int") - << doubleDummy << 12345 << stringDummy - << QByteArray( QByteArray("12345") ); - QTest::newRow( device->name() + "6" ) << device->name() << QString("UnicodeUTF8") << QString("signed long") - << doubleDummy << 12345 << stringDummy - << QByteArray( QByteArray("12345") ); - QTest::newRow( device->name() + "7" ) << device->name() << QString("UnicodeUTF8") << QString("unsigned long") - << doubleDummy << 12345 << stringDummy - << QByteArray( QByteArray("12345") ); - QTest::newRow( device->name() + "8" ) << device->name() << QString("UnicodeUTF8") << QString("float") - << (double)3.1415f << intDummy << stringDummy - << QByteArray( QByteArray("3.1415") ); - QTest::newRow( device->name() + "9" ) << device->name() << QString("UnicodeUTF8") << QString("double") - << 3.1415 << intDummy << stringDummy - << QByteArray( QByteArray("3.1415") ); - QTest::newRow( device->name() + "10" ) << device->name() << QString("UnicodeUTF8") << QString("char *") - << doubleDummy << intDummy << QString("I-am-a-string") - << QByteArray( QByteArray("I-am-a-string") ); - QTest::newRow( device->name() + "11" ) << device->name() << QString("UnicodeUTF8") << QString("QString") - << doubleDummy << intDummy << QString("I-am-a-string") - << QByteArray( QByteArray("I-am-a-string") ); - QTest::newRow( device->name() + "12" ) << device->name() << QString("UnicodeUTF8") << QString("QByteArray") - << doubleDummy << intDummy << QString("I-am-a-string") - << QByteArray( QByteArray("I-am-a-string") ); - - /* - Then we test some special cases that have caused problems in the past. - */ - QTest::newRow( device->name() + "20" ) << device->name() << QString("UnicodeUTF8") << QString("QChar") - << doubleDummy << 0xff8c << stringDummy - << QByteArray( QByteArray("\xef\xbe\x8c") ); - QTest::newRow( device->name() + "21" ) << device->name() << QString("UnicodeUTF8") << QString("QChar") - << doubleDummy << 0x8cff << stringDummy - << QByteArray( QByteArray("\xe8\xb3\xbf") ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_do_shiftleft( QTextStream *ts ) -{ - QFETCH( QString, encoding ); - QFETCH( QString, type ); - QFETCH( double, doubleVal ); - QFETCH( int, intVal ); - QFETCH( QString, stringVal ); - - ts->setEncoding( qt3_toEncoding(encoding) ); - - if ( type == "QChar" ) { - if ( intVal >= 0 && intVal <= 0xffff ) - *ts << QChar( intVal ); - } else if ( type == "char" ) { - *ts << (char) intVal; - } else if ( type == "signed short" ) { - *ts << (signed short) intVal; - } else if ( type == "unsigned short" ) { - *ts << (unsigned short) intVal; - } else if ( type == "signed int" ) { - *ts << (signed int) intVal; - } else if ( type == "unsigned int" ) { - *ts << (unsigned int) intVal; - } else if ( type == "signed long" ) { - *ts << (signed long) intVal; - } else if ( type == "unsigned long" ) { - *ts << (unsigned long) intVal; - } else if ( type == "float" ) { - *ts << (float) doubleVal; - } else if ( type == "double" ) { - *ts << (double) doubleVal; - } else if ( type == "char *" ) { - *ts << stringVal.latin1(); - } else if ( type == "QString" ) { - *ts << stringVal; - } else if ( type == "QByteArray" ) { - *ts << QByteArray( stringVal.latin1() ); - } else { - QWARN( "Unknown type: %s" + type ); - } - - ts->flush(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shiftleft() -{ - QFETCH( QString, device ); - QFETCH( QString, encoding ); - QFETCH( QByteArray, encoded ); - - if ( device == "file" ) { - QFile outFile( "qtextstream.out" ); - QVERIFY( outFile.open( QIODevice::WriteOnly ) ); - QTextStream ts( &outFile ); - - qt3_do_shiftleft( &ts ); - outFile.close(); - - QFile inFile( "qtextstream.out" ); - QVERIFY( inFile.open( QIODevice::ReadOnly ) ); - QCOMPARE( inFile.readAll().constData(), encoded.constData() ); - } else if(device == "resource" ) { //ONLY TO CREATE THE RESOURCE!! NOT A TEST! - QFile outFile( resourceDir() + "operator_shiftright_" + QTest::currentDataTag() + ".data" ); - QVERIFY( outFile.open( QIODevice::WriteOnly ) ); - QTextStream ts( &outFile ); - qt3_do_shiftleft( &ts ); - outFile.close(); - } else if ( device == "bytearray" ) { - QByteArray outArray; - QTextStream ts(&outArray, QIODevice::WriteOnly ); - - qt3_do_shiftleft( &ts ); - - QVERIFY( outArray == encoded ); - } else if ( device == "buffer" ) { - QByteArray outArray; - QBuffer outBuffer(&outArray); - QVERIFY( outBuffer.open(QIODevice::WriteOnly) ); - QTextStream ts( &outBuffer ); - - qt3_do_shiftleft( &ts ); - - QCOMPARE( outArray, encoded ); - } else if ( device == "string" ) { - QString outString; - QTextStream ts( &outString, QIODevice::WriteOnly ); - - qt3_do_shiftleft( &ts ); - - QString decodedString = qt3_decodeString( encoded, encoding ); - QCOMPARE( outString, decodedString ); - } else { - QWARN( "Unknown device type: " + device ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shiftright() -{ - QFETCH( QString, device ); - QFETCH( QString, encoding ); - QFETCH( QString, type ); - QFETCH( double, doubleVal ); - QFETCH( int, intVal ); - QFETCH( QString, stringVal ); - QFETCH( QByteArray, encoded ); - - if ( device == "file" ) { - QFile outFile( "qtextstream.out" ); - QVERIFY( outFile.open( QIODevice::WriteOnly ) ); - QVERIFY( (int) outFile.write(encoded) == (int) encoded.size() ); - outFile.close(); - - inFile = new QFile( "qtextstream.out" ); - QVERIFY( inFile->open( QIODevice::ReadOnly ) ); - ts = new QTextStream( inFile ); - } else if(device == "resource" ) { - inResource = new QFile( ":/tst_textstream/" + resourceDir() + "operator_shiftright_" + QTest::currentDataTag() + ".data" ); - QVERIFY( inResource->open( QIODevice::ReadOnly ) ); - ts = new QTextStream( inResource ); - } else if ( device == "bytearray" ) { - ts = new QTextStream(&encoded, QIODevice::ReadOnly); - } else if ( device == "buffer" ) { - inBuffer = new QBuffer(&encoded); - QVERIFY( inBuffer->open(QIODevice::ReadOnly) ); - ts = new QTextStream( inBuffer ); - } else if ( device == "string" ) { - inString = new QString( qt3_decodeString(encoded, encoding) ); - ts = new QTextStream(inString, QIODevice::ReadOnly); - } else { - QWARN( "Unknown device type: " + device ); - } - - ts->setEncoding( qt3_toEncoding(encoding) ); - - if ( type == "QChar" ) { - QChar c; - if ( intVal >= 0 && intVal <= 0xffff ) - *ts >> c; - QCOMPARE( c.toLatin1(), QChar(intVal).toLatin1() ); - } else if ( type == "char" ) { - char c; - *ts >> c; - QCOMPARE( c, (char) intVal ); - } else if ( type == "signed short" ) { - signed short h; - *ts >> h; - QCOMPARE( h, (signed short) intVal ); - } else if ( type == "unsigned short" ) { - unsigned short h; - *ts >> h; - QCOMPARE( h, (unsigned short) intVal ); - } else if ( type == "signed int" ) { - signed int i; - *ts >> i; - QCOMPARE( i, (signed int) intVal ); - } else if ( type == "unsigned int" ) { - unsigned int i; - *ts >> i; - QCOMPARE( i, (unsigned int) intVal ); - } else if ( type == "signed long" ) { - signed long ell; - *ts >> ell; - QCOMPARE( ell, (signed long) intVal ); - } else if ( type == "unsigned long" ) { - unsigned long ell; - *ts >> ell; - QCOMPARE( ell, (unsigned long) intVal ); - } else if ( type == "float" ) { - float f; - *ts >> f; - QCOMPARE( f, (float) doubleVal ); - } else if ( type == "double" ) { - double d; - *ts >> d; - QCOMPARE( d, (double) doubleVal ); - } else if ( type == "char *" ) { - char *cp = new char[2048]; - *ts >> cp; - QVERIFY( qstrcmp(cp, stringVal.latin1()) == 0 ); - delete[] cp; - } else if ( type == "QString" ) { - QString s; - *ts >> s; - QCOMPARE( s, stringVal ); - } else if ( type == "QByteArray" ) { - QByteArray s; - *ts >> s; - QCOMPARE( QString::fromLatin1(s), stringVal ); - } else { - QWARN( "Unknown type: %s" + type ); - } -} - -// ------------------------------------------------------------------------------ -QTextStream::Encoding tst_QTextStream::qt3_toEncoding( const QString &str ) -{ - if ( str == "Locale" ) - return QTextStream::Locale; - else if ( str == "Latin1" ) - return QTextStream::Latin1; - else if ( str == "Unicode" ) - return QTextStream::Unicode; - else if ( str == "UnicodeNetworkOrder" ) - return QTextStream::UnicodeNetworkOrder; - else if ( str == "UnicodeReverse" ) - return QTextStream::UnicodeReverse; - else if ( str == "RawUnicode" ) - return QTextStream::RawUnicode; - else if ( str == "UnicodeUTF8" ) - return QTextStream::UnicodeUTF8; - - QWARN( "No such encoding " + str ); - return QTextStream::Latin1; -} - -// ------------------------------------------------------------------------------ -QString tst_QTextStream::qt3_decodeString( QByteArray array, const QString& encoding ) -{ - switch ( qt3_toEncoding(encoding) ) { - case QTextStream::Locale: - return QString::fromLocal8Bit( array.data(), array.size() ); - case QTextStream::Latin1: - return QString::fromLatin1( array.data(), array.size() ); - case QTextStream::Unicode: - case QTextStream::UnicodeNetworkOrder: - case QTextStream::UnicodeReverse: - case QTextStream::RawUnicode: - QWARN( "Unicode not implemented ###" ); - return QString(); - case QTextStream::UnicodeUTF8: - return QString::fromUtf8( array.data(), array.size() ); - default: - QWARN( "Unhandled encoding" ); - return QString(); - } -} - -// ************************************************ - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_createWriteStream( QTextStream *&os ) -{ - QFETCH( QString, device ); - - if ( device == "file" ) { - outFile = new QFile( "qtextstream.out" ); - QVERIFY( outFile->open( QIODevice::WriteOnly ) ); - os = new QTextStream( outFile ); - os->setCodec(QTextCodec::codecForName("ISO-8859-1")); - os->setAutoDetectUnicode(true); - } else if(device == "resource" ) { //ONLY TO CREATE THE RESOURCE!! NOT A TEST! - outFile = new QFile( resourceDir() + - QTest::currentTestFunction() + - "_" + QTest::currentDataTag() + ".data" ); - QVERIFY( outFile->open( QIODevice::WriteOnly ) ); - os = new QTextStream( outFile ); - os->setCodec(QTextCodec::codecForName("ISO-8859-1")); - os->setAutoDetectUnicode(true); - } else if ( device == "bytearray" ) { - inArray = new QByteArray; - os = new QTextStream(inArray, QIODevice::WriteOnly); - os->setCodec(QTextCodec::codecForName("ISO-8859-1")); - os->setAutoDetectUnicode(true); - } else if ( device == "buffer" ) { - inBuffer = new QBuffer; - QVERIFY( inBuffer->open(QIODevice::WriteOnly) ); - os = new QTextStream( inBuffer ); - os->setCodec(QTextCodec::codecForName("ISO-8859-1")); - os->setAutoDetectUnicode(true); - } else if ( device == "string" ) { - inString = new QString; - os = new QTextStream( inString, QIODevice::WriteOnly ); - os->setCodec(QTextCodec::codecForName("ISO-8859-1")); - os->setAutoDetectUnicode(true); - } else { - QWARN( "Error creating write stream: Unknown device type '" + device + "'" ); - } - - QFETCH( QString, encoding ); - os->setEncoding( qt3_toEncoding( encoding )); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_closeWriteStream( QTextStream *os ) -{ - QFETCH( QString, device ); - - os->flush(); - if ( os->device() ) - os->device()->close(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_createReadStream( QTextStream *&is ) -{ - QFETCH( QString, device ); - - if ( device == "file" ) { - inFile = new QFile( "qtextstream.out" ); - is = new QTextStream( inFile ); - is->setCodec(QTextCodec::codecForName("ISO-8859-1")); - is->setAutoDetectUnicode(true); - QVERIFY( inFile->open( QIODevice::ReadOnly ) ); - } else if(device == "resource") { - inResource = new QFile( ":/tst_textstream/" + resourceDir() + - QTest::currentTestFunction() + - "_" + QTest::currentDataTag() + ".data" ); - is = new QTextStream( inResource ); - is->setCodec(QTextCodec::codecForName("ISO-8859-1")); - is->setAutoDetectUnicode(true); - QVERIFY( inResource->open( QIODevice::ReadOnly ) ); - } else if ( device == "bytearray" ) { - is = new QTextStream(inArray, QIODevice::ReadOnly); - is->setCodec(QTextCodec::codecForName("ISO-8859-1")); - is->setAutoDetectUnicode(true); - } else if ( device == "buffer" ) { - QVERIFY( inBuffer->open(QIODevice::ReadOnly) ); - is = new QTextStream( inBuffer ); - is->setCodec(QTextCodec::codecForName("ISO-8859-1")); - is->setAutoDetectUnicode(true); - } else if ( device == "string" ) { - is = new QTextStream( inString, QIODevice::ReadOnly ); - is->setCodec(QTextCodec::codecForName("ISO-8859-1")); - is->setAutoDetectUnicode(true); - } else { - QWARN( "Error creating read stream: Unknown device type '" + device + "'" ); - } - - QFETCH( QString, encoding ); - is->setEncoding( qt3_toEncoding( encoding )); - - if (!file_is_empty) { - QVERIFY( !is->atEnd() ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_closeReadStream( QTextStream *is ) -{ - QVERIFY( is->atEnd() ); - - if ( is->device() ) - is->device()->close(); -} - -// **************** QChar **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_QChar_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<ushort>("qchar"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << QChar( 'A' ).unicode(); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << QChar( 'B' ).unicode(); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << QChar( 'Z' ).unicode(); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << QChar( 'z' ).unicode(); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << QChar( '@' ).unicode(); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_QChar() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_QChar( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_QChar( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_QChar( QTextStream *s ) -{ - QFETCH( ushort, qchar ); - QChar expected( qchar ); - QChar actual; - *s >> actual; - QCOMPARE( actual, expected ); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_QChar( QTextStream *s ) -{ - QFETCH( ushort, qchar ); - QChar actual( qchar ); - *s << actual; -} - -// **************** char **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_char_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<int>("ch"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << int('A'); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << int('B'); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << int('Z'); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << int(14); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << int('0'); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_char() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_char( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_char( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_char( QTextStream *s ) -{ - QFETCH( int, ch ); - char c(ch); - char exp; - *s >> exp; - QCOMPARE( exp, c ); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_char( QTextStream *s ) -{ - QFETCH( int, ch ); - char c(ch); - *s << c; -} - -// **************** short **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_short_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<short>("ss"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << short(0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << short(-1); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << short(1); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << short(255); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << short(-254); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_short() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_short( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_short( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_short( QTextStream *s ) -{ - QFETCH( short, ss ); - short exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, ss ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_short( QTextStream *s ) -{ - QFETCH( short, ss ); - *s << " A " << ss << " B "; -} - -// **************** ushort **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_ushort_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<ushort>("us"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << ushort(0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << ushort(1); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << ushort(10); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << ushort(255); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << ushort(512); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_ushort() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_ushort( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_ushort( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_ushort( QTextStream *s ) -{ - QFETCH( ushort, us ); - ushort exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, us ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_ushort( QTextStream *s ) -{ - QFETCH( ushort, us ); - *s << " A " << us << " B "; -} - -// **************** int **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_int_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<int>("si"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << int(0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << int(1); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << int(10); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << int(255); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << int(512); - QTest::newRow( tag + "5" ) << device->modes << device->name() << encoding << int(-1); - QTest::newRow( tag + "6" ) << device->modes << device->name() << encoding << int(-10); - QTest::newRow( tag + "7" ) << device->modes << device->name() << encoding << int(-255); - QTest::newRow( tag + "8" ) << device->modes << device->name() << encoding << int(-512); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_int() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_int( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_int( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_int( QTextStream *s ) -{ - QFETCH( int, si ); - int exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, si ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_int( QTextStream *s ) -{ - QFETCH( int, si ); - *s << " A " << si << " B "; -} - -// **************** uint **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_uint_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<uint>("ui"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << uint(0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << uint(1); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << uint(10); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << uint(255); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << uint(512); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_uint() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_uint( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_uint( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_uint( QTextStream *s ) -{ - QFETCH( uint, ui ); - uint exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, ui ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_uint( QTextStream *s ) -{ - QFETCH( uint, ui ); - *s << " A " << ui << " B "; -} - -// **************** long **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_long_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<long>("sl"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << long(0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << long(1); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << long(10); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << long(255); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << long(65535); - QTest::newRow( tag + "5" ) << device->modes << device->name() << encoding << long(-1); - QTest::newRow( tag + "6" ) << device->modes << device->name() << encoding << long(-10); - QTest::newRow( tag + "7" ) << device->modes << device->name() << encoding << long(-255); - QTest::newRow( tag + "8" ) << device->modes << device->name() << encoding << long(-65534); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_long() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_long( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_long( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_long( QTextStream *s ) -{ - QFETCH( long, sl ); - long exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, sl ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_long( QTextStream *s ) -{ - QFETCH( long, sl ); - *s << " A " << sl << " B "; -} - -// **************** long **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_ulong_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<ulong>("ul"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << ulong(0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << ulong(1); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << ulong(10); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << ulong(255); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << ulong(65535); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_ulong() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_ulong( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_ulong( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_ulong( QTextStream *s ) -{ - QFETCH( ulong, ul ); - ulong exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, ul ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_ulong( QTextStream *s ) -{ - QFETCH( ulong, ul ); - *s << " A " << ul << " B "; -} - -// **************** float **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_float_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<float>("f"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << float(0.0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << float(0.0001); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << float(-0.0001); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << float(3.45678); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << float(-3.45678); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_float() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_float( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_float( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_float( QTextStream *s ) -{ - QFETCH( float, f ); - float exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, f ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_float( QTextStream *s ) -{ - QFETCH( float, f ); - *s << " A " << f << " B "; -} - -// **************** double **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_double_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<double>("d"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << double(0.0); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << double(0.0001); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << double(-0.0001); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << double(3.45678); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << double(-3.45678); - QTest::newRow( tag + "5" ) << device->modes << device->name() << encoding << double(1.23456789); - QTest::newRow( tag + "6" ) << device->modes << device->name() << encoding << double(-1.23456789); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_double() -{ - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - os->precision( 10 ); - qt3_write_double( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - is->precision( 10 ); - qt3_read_double( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_double( QTextStream *s ) -{ - QFETCH( double, d ); - double exp; - QString A, B; - *s >> A >> exp >> B; - QCOMPARE( A, QString("A") ); - QCOMPARE( B, QString("B") ); - QCOMPARE( exp, d ); - s->skipWhiteSpace(); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_double( QTextStream *s ) -{ - QFETCH( double, d ); - *s << " A " << d << " B "; -} - -// **************** QString **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_QString_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<QString>("str"); - QTest::addColumn<bool>("multi_str"); - QTest::addColumn<bool>("zero_length"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << QString("") << bool(FALSE) << bool(TRUE); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << QString() << bool(FALSE) << bool(TRUE); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << QString("foo") << bool(FALSE) << bool(FALSE); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << QString("foo\nbar") << bool(TRUE) << bool(FALSE); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << QString("cjacka ckha cka ckah ckac kahckadhcbkgdk vkzdfbvajef vkahv") << bool(TRUE) << bool(FALSE); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_QString() -{ - QFETCH( bool, zero_length ); - file_is_empty = zero_length; - - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_QString( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_QString( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_QString( QTextStream *s ) -{ - QString exp; - QFETCH( QString, str ); - if (str.isNull()) - str = ""; - - QFETCH( bool, multi_str ); - if (!multi_str) { - *s >> exp; - QCOMPARE( exp, str ); - } else { - QStringList l; - l = QStringList::split( " ", str ); - if (l.count() < 2) - l = QStringList::split( "\n", str ); - for (int i=0; i<l.count(); i++) { - *s >> exp; - QCOMPARE( exp, l[i] ); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_QString( QTextStream *s ) -{ - QFETCH( QString, str ); - *s << str; -} - -// **************** QByteArray **************** - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_QByteArray_data() -{ - QTest::addColumn<int>("modes"); - QTest::addColumn<QString>("device"); - QTest::addColumn<QString>("encoding"); - QTest::addColumn<QByteArray>("cs"); - QTest::addColumn<bool>("multi_str"); - QTest::addColumn<bool>("zero_length"); - - for ( int i=0; !devices[i].name().isNull(); i++ ) { - tst_IODevice *device = devices+i; - for ( int e=0; encodings[e] != 0; e++ ) { - QString encoding = encodings[e]; - - QString tag = device->name() + "_" + encoding + "_"; - QTest::newRow( tag + "0" ) << device->modes << device->name() << encoding << QByteArray("") << bool(FALSE) << bool(TRUE); - QTest::newRow( tag + "1" ) << device->modes << device->name() << encoding << QByteArray(0) << bool(FALSE) << bool(TRUE); - QTest::newRow( tag + "2" ) << device->modes << device->name() << encoding << QByteArray("foo") << bool(FALSE) << bool(FALSE); - QTest::newRow( tag + "3" ) << device->modes << device->name() << encoding << QByteArray("foo\nbar") << bool(TRUE) << bool(FALSE); - QTest::newRow( tag + "4" ) << device->modes << device->name() << encoding << QByteArray("cjacka ckha cka ckah ckac kahckadhcbkgdk vkzdfbvajef vkahv") << bool(TRUE) << bool(FALSE); - } - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_operator_shift_QByteArray() -{ - QFETCH( bool, zero_length ); - file_is_empty = zero_length; - - QFETCH( int, modes ); - if(modes & QIODevice::WriteOnly) { - qt3_createWriteStream( os ); - qt3_write_QByteArray( os ); - qt3_closeWriteStream( os ); - } - if(modes & QIODevice::ReadOnly) { - qt3_createReadStream( is ); - qt3_read_QByteArray( is ); - qt3_closeReadStream( is ); - } -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_read_QByteArray( QTextStream *s ) -{ -/* - QFETCH( QByteArray, cs ); - QByteArray exp; - *s >> exp; - QCOMPARE( exp, cs ); -*/ - QByteArray exp; - QFETCH( QByteArray, cs ); - if (cs.isNull()) - cs = ""; - - QFETCH( bool, multi_str ); - if (!multi_str) { - *s >> exp; - QCOMPARE( exp.constData(), cs.constData() ); - } else { - QStringList l; - l = QStringList::split( " ", cs ); - if (l.count() < 2) - l = QStringList::split( "\n", cs ); - for (int i=0; i<l.count(); i++) { - *s >> exp; - QCOMPARE( exp, QByteArray(l[i].toAscii()) ); - } - } -} - -// ------------------------------------------------------------------------------ -static void qt3_generateLineData( bool for_QString ) -{ - QTest::addColumn<QByteArray>("input"); - QTest::addColumn<QStringList>("output"); - - QTest::newRow("emptyer") << QByteArray() << QStringList(); - QTest::newRow("lf") << QByteArray("\n") << (QStringList() << ""); - QTest::newRow("crlf") << QByteArray("\r\n") << (QStringList() << ""); - QTest::newRow("oneline/nothing") << QByteArray("ole") << (QStringList() << "ole"); - QTest::newRow("oneline/lf") << QByteArray("ole\n") << (QStringList() << "ole"); - QTest::newRow("oneline/crlf") << QByteArray("ole\r\n") << (QStringList() << "ole"); - QTest::newRow("twolines/lf/lf") << QByteArray("ole\ndole\n") << (QStringList() << "ole" << "dole"); - QTest::newRow("twolines/crlf/crlf") << QByteArray("ole\r\ndole\r\n") << (QStringList() << "ole" << "dole"); - QTest::newRow("twolines/lf/crlf") << QByteArray("ole\ndole\r\n") << (QStringList() << "ole" << "dole"); - QTest::newRow("twolines/lf/nothing") << QByteArray("ole\ndole") << (QStringList() << "ole" << "dole"); - QTest::newRow("twolines/crlf/nothing") << QByteArray("ole\r\ndole") << (QStringList() << "ole" << "dole"); - QTest::newRow("threelines/lf/lf/lf") << QByteArray("ole\ndole\ndoffen\n") << (QStringList() << "ole" << "dole" << "doffen"); - QTest::newRow("threelines/crlf/crlf/crlf") << QByteArray("ole\r\ndole\r\ndoffen\r\n") << (QStringList() << "ole" << "dole" << "doffen"); - QTest::newRow("threelines/crlf/crlf/nothing") << QByteArray("ole\r\ndole\r\ndoffen") << (QStringList() << "ole" << "dole" << "doffen"); - - if (!for_QString) { - QTest::newRow("unicode/nothing") << QByteArray("\xfe\xff\x00\xe5\x00\x67\x00\x65", 8) << (QStringList() << "\345ge"); - QTest::newRow("unicode-little/nothing") << QByteArray("\xff\xfe\xe5\x00\x67\x00\x65\x00", 8) << (QStringList() << "\345ge"); - QTest::newRow("unicode/lf") << QByteArray("\xfe\xff\x00\xe5\x00\x67\x00\x65\x00\x0a", 10) << (QStringList() << "\345ge"); - QTest::newRow("unicode-little/lf") << QByteArray("\xff\xfe\xe5\x00\x67\x00\x65\x00\x0a\x00", 10) << (QStringList() << "\345ge"); - - QTest::newRow("unicode/twolines") << QByteArray("\xfe\xff\x00\xe5\x00\x67\x00\x65\x00\x0a\x00\xe5\x00\x67\x00\x65\x00\x0a", 18) << (QStringList() << "\345ge" << "\345ge"); - QTest::newRow("unicode-little/twolines") << QByteArray("\xff\xfe\xe5\x00\x67\x00\x65\x00\x0a\x00\xe5\x00\x67\x00\x65\x00\x0a\x00", 18) << (QStringList() << "\345ge" << "\345ge"); - - QTest::newRow("unicode/threelines") - << QByteArray("\xfe\xff" - "\x00\xe5\x00\x67\x00\x65\x00\x0a" - "\x00\xe5\x00\x67\x00\x65\x00\x0a" - "\x00\xe5\x00\x67\x00\x65\x00\x0a", 26) - << (QStringList() << "\345ge" << "\345ge" << "\345ge"); - QTest::newRow("unicode-little/threelines") - << QByteArray("\xff\xfe" - "\xe5\x00\x67\x00\x65\x00\x0a\x00" - "\xe5\x00\x67\x00\x65\x00\x0a\x00" - "\xe5\x00\x67\x00\x65\x00\x0a\x00", 26) - << (QStringList() << "\345ge" << "\345ge" << "\345ge"); - } - - // partials - QTest::newRow("cr") << QByteArray("\r") << (QStringList() << ""); - QTest::newRow("oneline/cr") << QByteArray("ole\r") << (QStringList() << "ole"); - if (!for_QString) - QTest::newRow("unicode/cr") << QByteArray("\xfe\xff\x00\xe5\x00\x67\x00\x65\x00\x0d", 10) << (QStringList() << "\345ge"); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_writeDataToFileReadAsLines_data() -{ - qt3_generateLineData(false); -} - -// ------------------------------------------------------------------------------ -QByteArray pretty(const QString &input) -{ - QByteArray data; - - QByteArray arr = input.toLatin1(); - for (int i = 0; i < arr.size(); ++i) { - char buf[64]; - memset(buf, 0, sizeof(buf)); - char ch = arr.at(i); - sprintf(buf, "\\%2hhx", ch); - data += buf; - } - - return data; -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_writeDataToFileReadAsLines() -{ - QFETCH(QByteArray, input); - QFETCH(QStringList, output); - - QFile::remove("eoltest"); - - // Create the file - QFile writer("eoltest"); - QVERIFY2(writer.open(QFile::WriteOnly | QFile::Truncate), ("When creating a file: " + writer.errorString()).latin1()); - QCOMPARE(writer.write(input), qlonglong(input.size())); - writer.close(); - - // Read from it using QTextStream - QVERIFY2(writer.open(QFile::ReadOnly), ("When reading a file: " + writer.errorString()).latin1()); - QTextStream stream(&writer); - QStringList tmp; - - while (!stream.atEnd()) - tmp << stream.readLine(); - - QCOMPARE(tmp, output); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_writeDataToQStringReadAsLines_data() -{ - qt3_generateLineData(true); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_writeDataToQStringReadAsLines() -{ - QFETCH(QByteArray, input); - QFETCH(QStringList, output); - - QString s = input; - QTextStream stream(&s, QIODevice::ReadOnly); - - QStringList tmp; - while (!stream.atEnd()) - tmp << stream.readLine(); - - QCOMPARE(tmp, output); -} - -// ------------------------------------------------------------------------------ -void tst_QTextStream::qt3_write_QByteArray( QTextStream *s ) -{ - QFETCH( QByteArray, cs ); - *s << cs; -} -#endif - -// ------------------------------------------------------------------------------ void tst_QTextStream::status_real_read_data() { QTest::addColumn<QString>("input"); |