File indexing completed on 2024-05-12 05:09:56
0001 /*************************************************************************** 0002 Copyright (C) 2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #undef QT_NO_CAST_FROM_ASCII 0026 0027 #include "cuecattest.h" 0028 0029 #include "../utils/upcvalidator.h" 0030 0031 #include <QTest> 0032 0033 QTEST_APPLESS_MAIN( CueCatTest ) 0034 0035 Q_DECLARE_METATYPE(QValidator::State) 0036 0037 #define QL1(x) QStringLiteral(x) 0038 0039 void CueCatTest::initTestCase() { 0040 qRegisterMetaType<QValidator::State>(); 0041 } 0042 0043 void CueCatTest::testDecode() { 0044 QFETCH(QString, string); 0045 QFETCH(QString, expectedString); 0046 QFETCH(QValidator::State, state); 0047 0048 QString originalString = string; 0049 QCOMPARE(Tellico::CueCat::decode(string), state); 0050 QCOMPARE(string, expectedString); 0051 Tellico::UPCValidator v(this); 0052 int pos = 0; 0053 QCOMPARE(v.validate(originalString, pos), state); 0054 } 0055 0056 void CueCatTest::testDecode_data() { 0057 QTest::addColumn<QString>("string"); 0058 QTest::addColumn<QString>("expectedString"); 0059 QTest::addColumn<QValidator::State>("state"); 0060 0061 QTest::newRow("My name is robby") << QL1("My name is robby") 0062 << QL1("My name is robby") 0063 << QValidator::Invalid; 0064 QTest::newRow(".C3nZC3nZC3nYCxP2Dxb1CNnY") << QL1(".C3nZC3nZC3nYCxP2Dxb1CNnY") 0065 << QL1(".C3nZC3nZC3nYCxP2Dxb1CNnY") 0066 << QValidator::Intermediate; 0067 QTest::newRow(".C3nZC3nZC3nYCxP2Dxb1CNnY.cGen.ENr7C3fZCNT7ENz3Ca.") 0068 << QL1(".C3nZC3nZC3nYCxP2Dxb1CNnY.cGen.ENr7C3fZCNT7ENz3Ca.") 0069 << QL1("9780201889543") 0070 << QValidator::Acceptable; 0071 } 0072 0073 void CueCatTest::testUpcValidate() { 0074 QFETCH(QString, string); 0075 QFETCH(QString, expectedString); 0076 QFETCH(QValidator::State, state); 0077 QFETCH(bool, isbn); 0078 0079 Tellico::UPCValidator v(this); 0080 int pos = 0; 0081 v.setCheckISBN(isbn); 0082 QCOMPARE(v.validate(string, pos), state); 0083 v.fixup(string); 0084 QCOMPARE(string, expectedString); 0085 } 0086 0087 void CueCatTest::testUpcValidate_data() { 0088 QTest::addColumn<QString>("string"); 0089 QTest::addColumn<QString>("expectedString"); 0090 QTest::addColumn<QValidator::State>("state"); 0091 QTest::addColumn<bool>("isbn"); 0092 0093 // TODO: return QValidator::Acceptable if check sum is correct 0094 QTest::newRow("Acceptable") << QL1("796030114977") << QL1("796030114977") << QValidator::Intermediate << false; 0095 QTest::newRow("Intermediate") << QL1("79603011497") << QL1("79603011497") << QValidator::Intermediate << false; 0096 QTest::newRow("Intermediate space") << QL1("79603011497 ") << QL1("79603011497") << QValidator::Invalid << false; 0097 QTest::newRow("Intermediate space number") << QL1("79603011497 7") << QL1("79603011497") << QValidator::Invalid << false; 0098 QTest::newRow("ISBN invalid") << QL1("9780940016750") << QL1("9780940016750") << QValidator::Intermediate << false; 0099 QTest::newRow("ISBN1") << QL1("9780940016750") << QL1("978-0-940016-75-0") << QValidator::Acceptable << true; 0100 QTest::newRow("ISBN2") << QL1("978-0940016750") << QL1("978-0-940016-75-0") << QValidator::Acceptable << true; 0101 }