File indexing completed on 2024-05-12 05:10:03
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 "lccntest.h" 0028 0029 #include "../utils/lccnvalidator.h" 0030 0031 #include <QTest> 0032 0033 // see http://www.loc.gov/marc/lccn_structure.html 0034 // see http://www.loc.gov/marc/lccn-namespace.html 0035 // see http://catalog.loc.gov/help/number.htm 0036 0037 QTEST_APPLESS_MAIN( LccnTest ) 0038 0039 Q_DECLARE_METATYPE(QValidator::State) 0040 0041 #define QL1(x) QStringLiteral(x) 0042 0043 void LccnTest::initTestCase() { 0044 qRegisterMetaType<QValidator::State>(); 0045 } 0046 0047 void LccnTest::testValidation() { 0048 QFETCH(QString, string); 0049 QFETCH(QValidator::State, state); 0050 0051 Tellico::LCCNValidator val; 0052 int pos = 0; 0053 0054 QCOMPARE(val.validate(string, pos), state); 0055 } 0056 0057 void LccnTest::testValidation_data() { 0058 QTest::addColumn<QString>("string"); 0059 QTest::addColumn<QValidator::State>("state"); 0060 0061 QTest::newRow("89-456") << QL1("89-456") << QValidator::Acceptable; 0062 QTest::newRow("2001-1114") << QL1("2001-1114") << QValidator::Acceptable; 0063 QTest::newRow("gm 71-2450") << QL1("gm 71-2450") << QValidator::Acceptable; 0064 } 0065 0066 void LccnTest::testFormalization() { 0067 QFETCH(QString, string); 0068 QFETCH(QString, result); 0069 0070 QCOMPARE(Tellico::LCCNValidator::formalize(string), result); 0071 } 0072 0073 void LccnTest::testFormalization_data() { 0074 QTest::addColumn<QString>("string"); 0075 QTest::addColumn<QString>("result"); 0076 0077 QTest::newRow("89-456") << QL1("89-456") << QL1("89000456"); 0078 QTest::newRow("2001-1114") << QL1("2001-1114") << QL1("2001001114"); 0079 QTest::newRow("gm 71-2450 ") << QL1("gm 71-2450 ") << QL1("gm71002450"); 0080 QTest::newRow("n78-890351 ") << QL1("n78-890351 ") << QL1("n78890351"); 0081 QTest::newRow("n78-89035") << QL1("n78-89035") << QL1("n78089035"); 0082 QTest::newRow("n 78890351") << QL1("n 78890351") << QL1("n78890351"); 0083 QTest::newRow("85-2") << QL1("85-2") << QL1("85000002"); 0084 QTest::newRow("75-425165//r75") << QL1("75-425165//r75") << QL1("75425165"); 0085 QTest::newRow(" 79139101 /AC/r932") << QL1(" 79139101 /AC/r932") << QL1("79139101"); 0086 }