summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am28
-rw-r--r--src/tests/entitytest.cpp19
-rw-r--r--src/tests/isbntest.cpp73
-rw-r--r--src/tests/latin1test.cpp25
4 files changed, 145 insertions, 0 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
new file mode 100644
index 0000000..75c0313
--- /dev/null
+++ b/src/tests/Makefile.am
@@ -0,0 +1,28 @@
+AM_CPPFLAGS = -I$(srcdir)/.. $(all_includes)
+
+KDE_OPTIONS = noautodist
+
+AM_LDFLAGS = $(QT_LDFLAGS) $(KDE_LDFLAGS) $(X_LDFLAGS)
+
+check_PROGRAMS = isbntest latin1test entitytest
+
+check: isbntest latin1test entitytest
+ ./isbntest
+ ./latin1test
+ ./entitytest
+
+METASOURCES = AUTO
+
+DISTCLEANFILES = *~ *.Po $(CLEANFILES)
+
+isbntest_SOURCES = isbntest.cpp
+isbntest_LDADD = ../isbnvalidator.o $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI)
+
+latin1test_SOURCES = latin1test.cpp
+latin1test_LDADD = $(LIB_QT) $(LIB_KDECORE)
+
+entitytest_SOURCES = entitytest.cpp
+entitytest_LDADD = ../tellico_utils.o $(LIB_QT) $(LIB_KDECORE)
+
+#formattest_SOURCES = formattest.cpp
+#formattest_LDADD = ../core/tellico_config.o ../core/tellico_config_addons.o ../field.o ../tellico_utils.o $(LIB_QT) $(LIB_KDECORE)
diff --git a/src/tests/entitytest.cpp b/src/tests/entitytest.cpp
new file mode 100644
index 0000000..215c377
--- /dev/null
+++ b/src/tests/entitytest.cpp
@@ -0,0 +1,19 @@
+#ifdef QT_NO_CAST_ASCII
+#undef QT_NO_CAST_ASCII
+#endif
+
+#include "tellico_utils.h"
+#include <kdebug.h>
+#include <assert.h>
+
+int main(int, char**) {
+ kdDebug() << "\n*****************************************************" << endl;
+
+ assert(Tellico::decodeHTML("robby") == "robby");
+ assert(Tellico::decodeHTML("&fake;") == "&fake;");
+ assert(Tellico::decodeHTML("&#48;") == "0");
+ assert(Tellico::decodeHTML("robby&#48;robby") == "robby0robby");
+
+ kdDebug() << "\ndecodeHTML Test OK !" << endl;
+ kdDebug() << "\n*****************************************************" << endl;
+}
diff --git a/src/tests/isbntest.cpp b/src/tests/isbntest.cpp
new file mode 100644
index 0000000..b4c5fee
--- /dev/null
+++ b/src/tests/isbntest.cpp
@@ -0,0 +1,73 @@
+#ifdef QT_NO_CAST_ASCII
+#undef QT_NO_CAST_ASCII
+#endif
+
+#include "isbnvalidator.h"
+
+#include <kdebug.h>
+
+#include <stdlib.h>
+
+bool check(QString a, QString b) {
+ static const Tellico::ISBNValidator val(0);
+ val.fixup(a);
+ if(a == b) {
+ kdDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ } else {
+ kdDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "KO!" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+int main(int, char**) {
+ kdDebug() << "\n*****************************************************" << endl;
+
+ // initial checks
+ check("0-446-60098-9", "0-446-60098-9");
+ // check sum value
+ check("0-446-60098", "0-446-60098-9");
+
+ check(Tellico::ISBNValidator::isbn10("978-0-06-087298-4"), "0-06-087298-5");
+ check(Tellico::ISBNValidator::isbn13("0-06-087298-5"), "978-0-06-087298-4");
+
+ // check EAN-13
+ check("9780940016750", "978-0-940016-75-0");
+ check("978-0940016750", "978-0-940016-75-0");
+ check("978-0-940016-75-0", "978-0-940016-75-0");
+ check("978286274486", "978-2-86274-486-5");
+ check("9788186119130", "978-81-86-11913-6");
+ check("9788186119137", "978-81-86-11913-6");
+ check("97881-8611-9-13-0", "978-81-86-11913-6");
+ check("97881-8611-9-13-7", "978-81-86-11913-6");
+
+ // don't add checksum for EAN that start with 978 or 979 and are less than 13 in length
+ check("978059600", "978-059600");
+ check("978-0596000", "978-059600-0");
+
+ // normal english-language hyphenation
+ check("0-596-00053", "0-596-00053-7");
+ check("044660098", "0-446-60098-9");
+ check("0446600989", "0-446-60098-9");
+
+ // check french hyphenation
+ check("2862744867", "2-86274-486-7");
+
+ // check german hyphenation
+ check("3423071516", "3-423-07151-6");
+
+ // check dutch hyphenation
+ check("9065442979", "90-6544-297-9");
+
+ // check keeping middle hyphens
+ check("6-18611913-0", "6-18611913-0");
+ check("6-186119-13-0", "6-186119-13-0");
+ check("6-18611-9-13-0", "6-18611-913-0");
+
+ // check garbage
+ check("My name is robby", "");
+ check("http://www.abclinuxu.cz/clanky/show/63080", "6-3080");
+
+ kdDebug() << "\n ISBN Validator Test OK !" << endl;
+ kdDebug() << "\n*****************************************************" << endl;
+}
diff --git a/src/tests/latin1test.cpp b/src/tests/latin1test.cpp
new file mode 100644
index 0000000..636c33f
--- /dev/null
+++ b/src/tests/latin1test.cpp
@@ -0,0 +1,25 @@
+#ifdef QT_NO_CAST_ASCII
+#undef QT_NO_CAST_ASCII
+#endif
+
+#include "latin1literal.h"
+#include <qstring.h>
+#include <kdebug.h>
+#include <assert.h>
+
+int main(int, char**) {
+ kdDebug() << "\n*****************************************************" << endl;
+
+ assert(QString::null == Latin1Literal(0));
+ assert(QString::null != Latin1Literal(""));
+ assert(QString::fromLatin1("") == Latin1Literal(""));
+ assert(QString::fromLatin1("") != Latin1Literal(0));
+ assert(QString::fromLatin1("x") != Latin1Literal(""));
+ assert(QString::fromLatin1("a") == Latin1Literal("a"));
+ assert(QString::fromLatin1("a") != Latin1Literal("b"));
+ assert(QString::fromLatin1("\xe4") == Latin1Literal("\xe4"));
+ assert(QString::fromUtf8("\xe2\x82\xac") != Latin1Literal("?"));
+
+ kdDebug() << "\nLatin1Literal Test OK !" << endl;
+ kdDebug() << "\n*****************************************************" << endl;
+}