From kde-commits Wed Feb 25 11:09:25 2015 From: Adriaan de Groot Date: Wed, 25 Feb 2015 11:09:25 +0000 To: kde-commits Subject: [krecipes] src/tests/database: Add test that shows that non-Latin1 properties, at least, are mangled Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=142486257402658 Git commit 86e6954c3fe1529c317fd669222ab1e825145125 by Adriaan de Groot. Committed on 25/02/2015 at 11:08. Pushed by adridg into branch 'master'. Add test that shows that non-Latin1 properties, at least, are mangled by th= e addProperty() / propertyName() API M +53 -3 src/tests/database/encoding.cpp M +2 -0 src/tests/database/encoding.h http://commits.kde.org/krecipes/86e6954c3fe1529c317fd669222ab1e825145125 diff --git a/src/tests/database/encoding.cpp b/src/tests/database/encoding.= cpp index e81165c..b96367d 100644 --- a/src/tests/database/encoding.cpp +++ b/src/tests/database/encoding.cpp @@ -49,8 +49,6 @@ void TestDatabaseEncoding::testSourceEncoding() QCOMPARE( moose0.at(0), QChar(0xb5) ); // "micro" symbol QCOMPARE( moose0, moose1 ); QCOMPARE( moose0, moose2 ); // This is the important bit: the string is = representable in latin1 - = - qDebug() << "ORG" << moose0; } = void TestDatabaseEncoding::testInsertPropertyLatin1() @@ -79,8 +77,60 @@ void TestDatabaseEncoding::testRetrievePropertyLatin1() IngredientProperty p =3D m_sqliteDatabase->propertyName( i ); QCOMPARE( p.units, QString("g") ); QCOMPARE( p.name, moose1 ); + + if ( i > 0 ) { + m_sqliteDatabase->removeProperty( i ); + } + +} + +void TestDatabaseEncoding::testInsertPropertyUTF8() +{ + QString moose1 =3D QString::fromUtf8("=C2=B5=C3=B8=C3=B8se"); // That's = a string that fix in latin1 + QString moose2 =3D QString::fromUtf8("=E1=88=90=E1=88=A8=E1=88=AD =E1=89= =A2=E1=88=AB"); // Harar Beer, from Ethiopia, does not fit in latin1 + QString moose3 =3D QString::fromUtf8("=CE=BC=C3=B8=C3=B8se"); // That's = a mu-oose, not a micro-oose + QVERIFY( m_sqliteDatabase->ok() ); + + QTextCodec *codec =3D QTextCodec::codecForName("latin-1"); + QVERIFY2( codec, "No codec" ); + QVERIFY2( codec->canEncode(moose1), "Can't encode micro-oose" ); + QVERIFY2( !codec->canEncode(moose2), "Can encode harar beer (unexpected)"= ); + QVERIFY2( !codec->canEncode(moose3), "Can encode mu-oose (unexpected)" ); + = + QVERIFY( moose1 =3D=3D QString::fromLatin1(moose1.toLatin1()) ); // Conv= erts OK + QVERIFY( moose2 !=3D QString::fromLatin1(moose2.toLatin1()) ); // Lossy = conversion + QVERIFY( moose3 !=3D QString::fromLatin1(moose3.toLatin1()) ); // Lossy = conversion + = + // Both of the non-latin1 properties can be added + RecipeDB::IdType i =3D m_sqliteDatabase->addProperty( moose2, QString("mL= ")); + QVERIFY( i > 0 ); + if ( i > 0 ) { + m_sqliteDatabase->removeProperty( i ); + } + + i =3D m_sqliteDatabase->addProperty( moose3, QString("g")); + QVERIFY( i > 0 ); + if ( i > 0 ) { + m_sqliteDatabase->removeProperty( i ); + } +} + +void TestDatabaseEncoding::testRetrievePropertyUTF8() +{ + QString moose2 =3D QString::fromUtf8("=E1=88=90=E1=88=A8=E1=88=AD =E1=89= =A2=E1=88=AB"); // Harar Beer, from Ethiopia, does not fit in latin1 + QVERIFY( m_sqliteDatabase->ok() ); + RecipeDB::IdType i =3D m_sqliteDatabase->addProperty( moose2, QString("mL= ")); + + QVERIFY( i > 0 ); = - qDebug() << "ORG" << moose1 << "GOT" << p.units; + IngredientProperty p =3D m_sqliteDatabase->propertyName( i ); + QVERIFY2( p.units =3D=3D QString("mL"), "Units have changed." ); + QVERIFY2( p.name =3D=3D moose2, "Property name has been mangled." ); + + if ( i > 0 ) { + m_sqliteDatabase->removeProperty( i ); + } + } = = diff --git a/src/tests/database/encoding.h b/src/tests/database/encoding.h index 7f7f042..316c2a3 100644 --- a/src/tests/database/encoding.h +++ b/src/tests/database/encoding.h @@ -25,6 +25,8 @@ private slots: void testSourceEncoding(); void testInsertPropertyLatin1(); void testRetrievePropertyLatin1(); + void testInsertPropertyUTF8(); + void testRetrievePropertyUTF8(); private: RecipeDB * createDatabase( const QString & configFilename ); RecipeDB * m_sqliteDatabase;