tests/auto/qtextstream/tst_qtextstream.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   219     void numeralCase_data();
   219     void numeralCase_data();
   220     void numeralCase();
   220     void numeralCase();
   221     void nanInf();
   221     void nanInf();
   222     void utf8IncompleteAtBufferBoundary_data();
   222     void utf8IncompleteAtBufferBoundary_data();
   223     void utf8IncompleteAtBufferBoundary();
   223     void utf8IncompleteAtBufferBoundary();
       
   224     void writeSeekWriteNoBOM();
   224 
   225 
   225     // status
   226     // status
   226     void status_real_read_data();
   227     void status_real_read_data();
   227     void status_real_read();
   228     void status_real_read();
   228     void status_integer_read();
   229     void status_integer_read();
  1843         QString line = in.readLine().trimmed();
  1844         QString line = in.readLine().trimmed();
  1844         ++i;
  1845         ++i;
  1845         QVERIFY2(line.endsWith(lineContents), QString("Line %1: %2").arg(i).arg(line).toLocal8Bit());
  1846         QVERIFY2(line.endsWith(lineContents), QString("Line %1: %2").arg(i).arg(line).toLocal8Bit());
  1846     } while (!in.atEnd());
  1847     } while (!in.atEnd());
  1847 }
  1848 }
       
  1849 
       
  1850 // ------------------------------------------------------------------------------
       
  1851 
       
  1852 // Make sure we don't write a BOM after seek()ing
       
  1853 
       
  1854 void tst_QTextStream::writeSeekWriteNoBOM()
       
  1855 {
       
  1856 
       
  1857     //First with the default codec (normally either latin-1 or UTF-8)
       
  1858 
       
  1859     QBuffer out;
       
  1860     out.open(QIODevice::WriteOnly);
       
  1861     QTextStream stream(&out);
       
  1862 
       
  1863     int number = 0;
       
  1864     QString sizeStr = QLatin1String("Size=")
       
  1865         + QString::number(number).rightJustified(10, QLatin1Char('0'));
       
  1866     stream << sizeStr << endl;
       
  1867     stream << "Version=" << QString::number(14) << endl;
       
  1868     stream << "blah blah blah" << endl;
       
  1869     stream.flush();
       
  1870 
       
  1871     QCOMPARE(out.buffer().constData(), "Size=0000000000\nVersion=14\nblah blah blah\n");
       
  1872 
       
  1873     // Now overwrite the size header item
       
  1874     number = 42;
       
  1875     stream.seek(0);
       
  1876     sizeStr = QLatin1String("Size=")
       
  1877         + QString::number(number).rightJustified(10, QLatin1Char('0'));
       
  1878     stream << sizeStr << endl;
       
  1879     stream.flush();
       
  1880 
       
  1881     // Check buffer is still OK
       
  1882     QCOMPARE(out.buffer().constData(), "Size=0000000042\nVersion=14\nblah blah blah\n");
       
  1883 
       
  1884 
       
  1885     //Then UTF-16
       
  1886 
       
  1887     QBuffer out16;
       
  1888     out16.open(QIODevice::WriteOnly);
       
  1889     QTextStream stream16(&out16);
       
  1890     stream16.setCodec("UTF-16");
       
  1891 
       
  1892     stream16 << "one" << "two" << QLatin1String("three");
       
  1893     stream16.flush();
       
  1894 
       
  1895     // save that output
       
  1896     QByteArray first = out16.buffer();
       
  1897 
       
  1898     stream16.seek(0);
       
  1899     stream16 << "one";
       
  1900     stream16.flush();
       
  1901 
       
  1902     QCOMPARE(out16.buffer(), first);
       
  1903 }
       
  1904 
       
  1905 
  1848 
  1906 
  1849 // ------------------------------------------------------------------------------
  1907 // ------------------------------------------------------------------------------
  1850 void tst_QTextStream::generateOperatorCharData(bool for_QString)
  1908 void tst_QTextStream::generateOperatorCharData(bool for_QString)
  1851 {
  1909 {
  1852     QTest::addColumn<QByteArray>("input");
  1910     QTest::addColumn<QByteArray>("input");