qtmobility/tests/auto/qversitreader/tst_qversitreader.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    67 #endif
    67 #endif
    68 
    68 
    69 // This says "NOKIA" in Katakana encoded with UTF-8
    69 // This says "NOKIA" in Katakana encoded with UTF-8
    70 const QByteArray KATAKANA_NOKIA("\xe3\x83\x8e\xe3\x82\xad\xe3\x82\xa2");
    70 const QByteArray KATAKANA_NOKIA("\xe3\x83\x8e\xe3\x82\xad\xe3\x82\xa2");
    71 
    71 
       
    72 const static QByteArray SAMPLE_GIF_BASE64(QByteArray(
       
    73         "R0lGODlhEgASAIAAAAAAAP///yH5BAEAAAEALAAAAAASABIAAAIdjI+py+0G"
       
    74         "wEtxUmlPzRDnzYGfN3KBaKGT6rDmGxQAOw=="));
       
    75 
       
    76 const static QByteArray SAMPLE_GIF(QByteArray::fromBase64(SAMPLE_GIF_BASE64));
       
    77 
    72 Q_DECLARE_METATYPE(QVersitDocument::VersitType);
    78 Q_DECLARE_METATYPE(QVersitDocument::VersitType);
    73 Q_DECLARE_METATYPE(QVersitProperty);
    79 Q_DECLARE_METATYPE(QVersitProperty);
    74 
    80 
    75 QTM_USE_NAMESPACE
    81 QTM_USE_NAMESPACE
    76 
    82 
   554             << expectedProperty;
   560             << expectedProperty;
   555     }
   561     }
   556 
   562 
   557     {
   563     {
   558         QVersitProperty expectedProperty;
   564         QVersitProperty expectedProperty;
       
   565         expectedProperty.setName(QLatin1String("ORG"));
       
   566         expectedProperty.setValue(QString::fromUtf8(KATAKANA_NOKIA));
       
   567         expectedProperty.setValueType(QVersitProperty::CompoundType);
       
   568         QTest::newRow("vcard21 org utf8 qp")
       
   569             << QVersitDocument::VCard21Type
       
   570             << QByteArray("ORG;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E3=83=8E=E3=82=AD=E3=82=A2\r\n")
       
   571             << expectedProperty;
       
   572         QTest::newRow("vcard30 org utf8 qp")
       
   573             << QVersitDocument::VCard30Type
       
   574             << QByteArray("ORG;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E3=83=8E=E3=82=AD=E3=82=A2\r\n")
       
   575             << expectedProperty;
       
   576     }
       
   577 
       
   578     {
       
   579         QVersitProperty expectedProperty;
   559         expectedProperty.setName(QLatin1String("PHOTO"));
   580         expectedProperty.setName(QLatin1String("PHOTO"));
   560         expectedProperty.setValue(QLatin1String("Qt is great!"));
   581         expectedProperty.setValue(SAMPLE_GIF);
   561         expectedProperty.setValueType(QVersitProperty::BinaryType);
   582         expectedProperty.setValueType(QVersitProperty::BinaryType);
   562         QTest::newRow("vcard21 photo1")
   583         QTest::newRow("vcard21 photo1")
   563             << QVersitDocument::VCard21Type
   584             << QVersitDocument::VCard21Type
   564             << QByteArray("PHOTO;ENCODING=BASE64: U\t XQgaX MgZ\t3Jl YXQh\r\n\r\n")
   585             << QByteArray("PHOTO;ENCODING=BASE64:") + SAMPLE_GIF_BASE64 + QByteArray("\r\n\r\n")
   565             << expectedProperty;
   586             << expectedProperty;
   566 
   587 
   567         QTest::newRow("vcard30 photo1")
   588         QTest::newRow("vcard30 photo1")
   568             << QVersitDocument::VCard30Type
   589             << QVersitDocument::VCard30Type
   569             << QByteArray("PHOTO;ENCODING=B: U\t XQgaX MgZ\t3Jl YXQh\r\n\r\n")
   590             << QByteArray("PHOTO;ENCODING=B:") + SAMPLE_GIF_BASE64 + QByteArray("\r\n\r\n")
   570             << expectedProperty;
   591             << expectedProperty;
   571     }
       
   572 
   592 
   573     // Again, but without the explicit "ENCODING" parameter
   593     // Again, but without the explicit "ENCODING" parameter
   574     {
   594         QTest::newRow("vcard21 photo2")
   575         QVersitProperty expectedProperty;
       
   576         expectedProperty.setName(QLatin1String("PHOTO"));
       
   577         expectedProperty.setValue(QLatin1String("Qt is great!"));
       
   578         expectedProperty.setValueType(QVersitProperty::BinaryType);
       
   579         QTest::newRow("photo2")
       
   580             << QVersitDocument::VCard21Type
   595             << QVersitDocument::VCard21Type
   581             << QByteArray("PHOTO;BASE64: U\t XQgaX MgZ\t3Jl YXQh\r\n\r\n")
   596             << QByteArray("PHOTO;BASE64:") + SAMPLE_GIF_BASE64 + QByteArray("\r\n\r\n")
   582             << expectedProperty;
   597             << expectedProperty;
   583 
   598 
   584         QTest::newRow("photo2")
   599         QTest::newRow("vcard30 photo2")
   585             << QVersitDocument::VCard30Type
   600             << QVersitDocument::VCard30Type
   586             << QByteArray("PHOTO;B: U\t XQgaX MgZ\t3Jl YXQh\r\n\r\n")
   601             << QByteArray("PHOTO;B:") + SAMPLE_GIF_BASE64 + QByteArray("\r\n\r\n")
   587             << expectedProperty;
   602             << expectedProperty;
   588     }
   603     }
   589 
   604 
   590     {
   605     {
   591         QVersitProperty expectedProperty;
   606         QVersitProperty expectedProperty;
   594         expectedProperty.setValue(QLatin1String("john.citizen@example.com"));
   609         expectedProperty.setValue(QLatin1String("john.citizen@example.com"));
   595         expectedProperty.setValueType(QVersitProperty::PlainType);
   610         expectedProperty.setValueType(QVersitProperty::PlainType);
   596         QTest::newRow("email qp")
   611         QTest::newRow("email qp")
   597             << QVersitDocument::VCard21Type
   612             << QVersitDocument::VCard21Type
   598             << QByteArray("HOME.Springfield.EMAIL;Encoding=Quoted-Printable:john.citizen=40exam=\r\nple.com\r\n")
   613             << QByteArray("HOME.Springfield.EMAIL;Encoding=Quoted-Printable:john.citizen=40exam=\r\nple.com\r\n")
   599             << expectedProperty;
       
   600     }
       
   601 
       
   602     {
       
   603         QVersitProperty expectedProperty;
       
   604         expectedProperty.setName(QLatin1String("EMAIL"));
       
   605         expectedProperty.setValue(QLatin1String("john.citizen@example.com"));
       
   606         expectedProperty.setValueType(QVersitProperty::PlainType);
       
   607         QTest::newRow("email qp utf16")
       
   608             << QVersitDocument::VCard21Type
       
   609             << QByteArray("EMAIL;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-16BE:" + QTextCodec::codecForName("UTF-16BE")->fromUnicode(QLatin1String("john.citizen=40exam=\r\nple.com")) + "\r\n")
       
   610             << expectedProperty;
   614             << expectedProperty;
   611     }
   615     }
   612 
   616 
   613     {
   617     {
   614         QVersitDocument subDocument;
   618         QVersitDocument subDocument;
   755 void tst_QVersitReader::testDecodeQuotedPrintable()
   759 void tst_QVersitReader::testDecodeQuotedPrintable()
   756 {
   760 {
   757 #ifndef QT_BUILD_INTERNAL
   761 #ifndef QT_BUILD_INTERNAL
   758     QSKIP("Testing private API", SkipSingle);
   762     QSKIP("Testing private API", SkipSingle);
   759 #else
   763 #else
   760     QFETCH(QString, encoded);
   764     QFETCH(QByteArray, encoded);
   761 
   765 
   762     QFETCH(QString, decoded);
   766     QFETCH(QByteArray, decoded);
   763     mReaderPrivate->decodeQuotedPrintable(encoded);
   767     mReaderPrivate->decodeQuotedPrintable(encoded);
   764     QCOMPARE(encoded, decoded);
   768     QCOMPARE(encoded, decoded);
   765 #endif
   769 #endif
   766 }
   770 }
   767 
   771 
   768 void tst_QVersitReader::testDecodeQuotedPrintable_data()
   772 void tst_QVersitReader::testDecodeQuotedPrintable_data()
   769 {
   773 {
   770 #ifdef QT_BUILD_INTERNAL
   774 #ifdef QT_BUILD_INTERNAL
   771     QTest::addColumn<QString>("encoded");
   775     QTest::addColumn<QByteArray>("encoded");
   772     QTest::addColumn<QString>("decoded");
   776     QTest::addColumn<QByteArray>("decoded");
   773 
   777 
   774 
   778 
   775     QTest::newRow("Soft line breaks")
   779     QTest::newRow("Soft line breaks")
   776             << QString::fromLatin1("This=\r\n is =\r\none line.")
   780             << QByteArray("This=\r\n is =\r\none line.")
   777             << QString::fromLatin1("This is one line.");
   781             << QByteArray("This is one line.");
   778 
   782 
   779     QTest::newRow("Characters recommended to be encoded according to RFC 1521")
   783     QTest::newRow("Characters recommended to be encoded according to RFC 1521")
   780             << QString::fromLatin1("To be decoded: =0A=0D=21=22=23=24=3D=40=5B=5C=5D=5E=60=7B=7C=7D=7E")
   784             << QByteArray("To be decoded: =0A=0D=21=22=23=24=3D=40=5B=5C=5D=5E=60=7B=7C=7D=7E")
   781             << QString::fromLatin1("To be decoded: \n\r!\"#$=@[\\]^`{|}~");
   785             << QByteArray("To be decoded: \n\r!\"#$=@[\\]^`{|}~");
   782 
   786 
   783     QTest::newRow("Characters recommended to be encoded according to RFC 1521(lower case)")
   787     QTest::newRow("Characters recommended to be encoded according to RFC 1521(lower case)")
   784             << QString::fromLatin1("To be decoded: =0a=0d=21=22=23=24=3d=40=5b=5c=5d=5e=60=7b=7c=7d=7e")
   788             << QByteArray("To be decoded: =0a=0d=21=22=23=24=3d=40=5b=5c=5d=5e=60=7b=7c=7d=7e")
   785             << QString::fromLatin1("To be decoded: \n\r!\"#$=@[\\]^`{|}~");
   789             << QByteArray("To be decoded: \n\r!\"#$=@[\\]^`{|}~");
   786 
   790 
   787     QTest::newRow("random characters encoded")
   791     QTest::newRow("random characters encoded")
   788             << QString::fromLatin1("=45=6E=63=6F=64=65=64 =64=61=74=61")
   792             << QByteArray("=45=6E=63=6F=64=65=64 =64=61=74=61")
   789             << QString::fromLatin1("Encoded data");
   793             << QByteArray("Encoded data");
   790 
   794 
   791     QTest::newRow("short string1")
   795     QTest::newRow("short string1")
   792             << QString::fromLatin1("-=_")
   796             << QByteArray("-=_")
   793             << QString::fromLatin1("-=_");
   797             << QByteArray("-=_");
   794 
   798 
   795     QTest::newRow("short string2")
   799     QTest::newRow("short string2")
   796             << QString::fromLatin1("=0")
   800             << QByteArray("=0")
   797             << QString::fromLatin1("=0");
   801             << QByteArray("=0");
   798 
   802 
   799     QTest::newRow("short string2")
   803     QTest::newRow("short string2")
   800             << QString::fromLatin1("\r")
   804             << QByteArray("\r")
   801             << QString::fromLatin1("\r");
   805             << QByteArray("\r");
   802 
   806 
   803     QTest::newRow("short string2")
   807     QTest::newRow("short string2")
   804             << QString::fromLatin1("\n")
   808             << QByteArray("\n")
   805             << QString::fromLatin1("\n");
   809             << QByteArray("\n");
   806 
   810 
   807     QTest::newRow("short string2")
   811     QTest::newRow("short string2")
   808             << QString::fromLatin1("\n\r")
   812             << QByteArray("\n\r")
   809             << QString::fromLatin1("\n\r");
   813             << QByteArray("\n\r");
   810 
   814 
   811     QTest::newRow("White spaces")
   815     QTest::newRow("White spaces")
   812             << QString::fromLatin1("=09=20")
   816             << QByteArray("=09=20")
   813             << QString::fromLatin1("\t ");
   817             << QByteArray("\t ");
   814 #endif
   818 #endif
   815 }
   819 }
   816 void tst_QVersitReader::testParamName()
   820 void tst_QVersitReader::testParamName()
   817 {
   821 {
   818 #ifndef QT_BUILD_INTERNAL
   822 #ifndef QT_BUILD_INTERNAL