[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krecipes] src/tests/database: Add test that shows that non-Latin1 properties, at least, are mangled
From: Adriaan de Groot <groot () kde ! org>
Date: 2015-02-25 11:09:25
Message-ID: E1YQZqH-0003xw-44 () scm ! kde ! org
[Download RAW message or body]
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 the \
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 = 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 = QString::fromUtf8(" øøse"); // That's a string that fix in \
latin1 + QString moose2 = QString::fromUtf8("ሐረር ቢራ"); // Harar Beer, from \
Ethiopia, does not fit in latin1 + QString moose3 = QString::fromUtf8("μøøse"); \
// That's a mu-oose, not a micro-oose + QVERIFY( m_sqliteDatabase->ok() );
+
+ QTextCodec *codec = 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 == QString::fromLatin1(moose1.toLatin1()) ); // Converts OK
+ QVERIFY( moose2 != QString::fromLatin1(moose2.toLatin1()) ); // Lossy conversion
+ QVERIFY( moose3 != QString::fromLatin1(moose3.toLatin1()) ); // Lossy conversion
+
+ // Both of the non-latin1 properties can be added
+ RecipeDB::IdType i = m_sqliteDatabase->addProperty( moose2, QString("mL"));
+ QVERIFY( i > 0 );
+ if ( i > 0 ) {
+ m_sqliteDatabase->removeProperty( i );
+ }
+
+ i = m_sqliteDatabase->addProperty( moose3, QString("g"));
+ QVERIFY( i > 0 );
+ if ( i > 0 ) {
+ m_sqliteDatabase->removeProperty( i );
+ }
+}
+
+void TestDatabaseEncoding::testRetrievePropertyUTF8()
+{
+ QString moose2 = QString::fromUtf8("ሐረር ቢራ"); // Harar Beer, from \
Ethiopia, does not fit in latin1 + QVERIFY( m_sqliteDatabase->ok() );
+ RecipeDB::IdType i = m_sqliteDatabase->addProperty( moose2, QString("mL"));
+
+ QVERIFY( i > 0 );
- qDebug() << "ORG" << moose1 << "GOT" << p.units;
+ IngredientProperty p = m_sqliteDatabase->propertyName( i );
+ QVERIFY2( p.units == QString("mL"), "Units have changed." );
+ QVERIFY2( p.name == 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;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic