summaryrefslogtreecommitdiffstats
path: root/tdecore/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tdecore/tests')
-rw-r--r--tdecore/tests/KIDLTest.cpp33
-rw-r--r--tdecore/tests/KIDLTest.h16
-rw-r--r--tdecore/tests/KIDLTestClient.cpp17
-rw-r--r--tdecore/tests/Makefile.am86
-rw-r--r--tdecore/tests/cplusplustest.cpp44
-rw-r--r--tdecore/tests/dcopkonqtest.cpp36
-rw-r--r--tdecore/tests/kapptest.cpp40
-rw-r--r--tdecore/tests/kcalendartest.cpp152
-rw-r--r--tdecore/tests/kcharsetstest.cpp12
-rw-r--r--tdecore/tests/kcmdlineargstest.cpp91
-rw-r--r--tdecore/tests/kconfigtest.cpp162
-rw-r--r--tdecore/tests/kconfigtestgui.cpp200
-rw-r--r--tdecore/tests/kconfigtestgui.h72
-rw-r--r--tdecore/tests/kdebugtest.cpp98
-rw-r--r--tdecore/tests/kglobaltest.cpp64
-rw-r--r--tdecore/tests/kiconloadertest.cpp34
-rw-r--r--tdecore/tests/kipctest.cpp33
-rw-r--r--tdecore/tests/kipctest.h21
-rw-r--r--tdecore/tests/klocaletest.cpp199
-rw-r--r--tdecore/tests/klocaletest.h32
-rw-r--r--tdecore/tests/kmacroexpandertest.cpp137
-rw-r--r--tdecore/tests/kmdcodectest.cpp395
-rw-r--r--tdecore/tests/kmemtest.cpp248
-rw-r--r--tdecore/tests/knotifytest.cpp10
-rw-r--r--tdecore/tests/kprocesstest.cpp116
-rw-r--r--tdecore/tests/kprocesstest.h50
-rw-r--r--tdecore/tests/kprociotest.cpp65
-rw-r--r--tdecore/tests/kprociotest.h42
-rw-r--r--tdecore/tests/krandomsequencetest.cpp91
-rw-r--r--tdecore/tests/kresolvertest.cpp420
-rw-r--r--tdecore/tests/krfcdatetest.cpp81
-rw-r--r--tdecore/tests/kshelltest.cpp55
-rw-r--r--tdecore/tests/ksimpleconfigtest.cpp48
-rw-r--r--tdecore/tests/ksocktest.cpp109
-rw-r--r--tdecore/tests/ksortablevaluelisttest.cpp32
-rw-r--r--tdecore/tests/kstdacceltest.cpp39
-rw-r--r--tdecore/tests/kstddirstest.cpp52
-rw-r--r--tdecore/tests/kstringhandlertest.cpp97
-rw-r--r--tdecore/tests/ktempfiletest.cpp48
-rw-r--r--tdecore/tests/ktimezonestest.cpp62
-rw-r--r--tdecore/tests/kuniqueapptest.cpp59
-rw-r--r--tdecore/tests/kurltest.cpp1124
-rw-r--r--tdecore/tests/kxerrorhandlertest.cpp54
-rw-r--r--tdecore/tests/startserviceby.cpp41
-rw-r--r--tdecore/tests/testqtargs.cpp104
45 files changed, 5021 insertions, 0 deletions
diff --git a/tdecore/tests/KIDLTest.cpp b/tdecore/tests/KIDLTest.cpp
new file mode 100644
index 000000000..a763f85c8
--- /dev/null
+++ b/tdecore/tests/KIDLTest.cpp
@@ -0,0 +1,33 @@
+#include "KIDLTest.h"
+
+#include <kapplication.h>
+#include <dcopclient.h>
+
+KIDLTest::KIDLTest( const TQCString& id )
+ : DCOPObject( id )
+{
+}
+
+TQString KIDLTest::hello( const TQString& name )
+{
+ qDebug("Du heter %s", name.latin1() );
+ qDebug("Ha det %s", name.latin1() );
+
+ return TQString("Jeg heter KIDLTest");
+}
+
+int main( int argc, char** argv )
+{
+ KApplication app( argc, argv, "kidlservertest", false /* No GUI */ );
+
+ app.dcopClient()->attach();
+ app.dcopClient()->registerAs( "kidlservertest" );
+
+ qDebug("Server process started...");
+
+ (void) new KIDLTest( "Hello" );
+
+ qDebug("Server listening ...");
+
+ return app.exec();
+}
diff --git a/tdecore/tests/KIDLTest.h b/tdecore/tests/KIDLTest.h
new file mode 100644
index 000000000..6955bb6ca
--- /dev/null
+++ b/tdecore/tests/KIDLTest.h
@@ -0,0 +1,16 @@
+#ifndef KIDLTEST_H
+#define KIDLTEST_H
+
+#include <dcopobject.h>
+
+class KIDLTest : virtual public DCOPObject
+{
+ K_DCOP
+public:
+ KIDLTest( const TQCString& id );
+
+k_dcop:
+ virtual TQString hello( const TQString& name );
+};
+
+#endif
diff --git a/tdecore/tests/KIDLTestClient.cpp b/tdecore/tests/KIDLTestClient.cpp
new file mode 100644
index 000000000..21125bff5
--- /dev/null
+++ b/tdecore/tests/KIDLTestClient.cpp
@@ -0,0 +1,17 @@
+#include <kapplication.h>
+#include <dcopclient.h>
+
+#include "KIDLTest_stub.h"
+
+int main( int argc, char** argv )
+{
+ KApplication app( argc, argv, "KIDLTestClient", false /* No GUI */ );
+
+ kapp->dcopClient()->attach();
+ // kapp->dcopClient()->registerAs( "kidlclienttest" );
+
+ KIDLTest_stub* t = new KIDLTest_stub( "kidlservertest", "Hello" );
+
+ TQString ret = t->hello("Torben");
+ qDebug("Server says: %s", ret.latin1() );
+}
diff --git a/tdecore/tests/Makefile.am b/tdecore/tests/Makefile.am
new file mode 100644
index 000000000..e35ae68a4
--- /dev/null
+++ b/tdecore/tests/Makefile.am
@@ -0,0 +1,86 @@
+# This file is part of the KDE libraries
+# Copyright (C) 1996-1997 Matthias Kalle Dalheimer (kalle@kde.org)
+# (C) 1997-1998 Stephan Kulow (coolo@kde.org)
+
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public License
+# along with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+INCLUDES = -I$(top_srcdir)/tdecore $(all_includes)
+
+AM_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS) $(KDE_RPATH)
+
+check_PROGRAMS = kconfigtestgui klocaletest kprocesstest ksimpleconfigtest \
+ kstddirstest kurltest kuniqueapptest ktempfiletest krandomsequencetest \
+ kdebugtest ksocktest kstringhandlertest kcmdlineargstest kapptest \
+ kmemtest kidlservertest kidlclienttest dcopkonqtest kipctest \
+ cplusplustest kiconloadertest kresolvertest kmdcodectest knotifytest \
+ ksortablevaluelisttest krfcdatetest testqtargs kprociotest \
+ kcharsetstest kcalendartest kmacroexpandertest kshelltest \
+ kxerrorhandlertest startserviceby kstdacceltest kglobaltest ktimezonestest
+
+TESTS = kurltest kstdacceltest
+
+noinst_HEADERS = klocaletest.h kprocesstest.h KIDLTest.h \
+ kipctest.h kprociotest.h
+
+METASOURCES = AUTO
+
+LDADD = ../libtdecore.la
+kconfigtestgui_SOURCES = kconfigtestgui.cpp
+kdebugtest_SOURCES = kdebugtest.cpp
+klocaletest_SOURCES = klocaletest.cpp
+#klocaletest2_SOURCES = klocaletest2.cpp klocale.cpp libintl.cpp kcatalogue.cpp
+#kcatalogue_SOURCES = kcatalogue.cpp libintl.cpp
+ksimpleconfigtest_SOURCES = ksimpleconfigtest.cpp
+kurltest_SOURCES = kurltest.cpp
+kstddirstest_SOURCES = kstddirstest.cpp
+kprocesstest_SOURCES = kprocesstest.cpp
+kuniqueapptest_SOURCES = kuniqueapptest.cpp
+kapptest_SOURCES = kapptest.cpp
+ksocktest_SOURCES = ksocktest.cpp
+ktempfiletest_SOURCES = ktempfiletest.cpp
+krandomsequencetest_SOURCES = krandomsequencetest.cpp
+kstringhandlertest_SOURCES = kstringhandlertest.cpp
+kcmdlineargstest_SOURCES = kcmdlineargstest.cpp
+dcopkonqtest_SOURCES = dcopkonqtest.cpp
+kmemtest_SOURCES = kmemtest.cpp
+kidlservertest_SOURCES = KIDLTest.cpp KIDLTest.skel
+kidlclienttest_SOURCES = KIDLTestClient.cpp KIDLTest.stub
+$(srcdir)/KIDLTestClient.cpp: KIDLTest_stub.h
+kipctest_SOURCES = kipctest.cpp
+cplusplustest_SOURCES = cplusplustest.cpp
+kiconloadertest_SOURCES = kiconloadertest.cpp
+kresolvertest_SOURCES = kresolvertest.cpp
+kmdcodectest_SOURCES = kmdcodectest.cpp
+knotifytest_SOURCES = knotifytest.cpp
+ksortablevaluelisttest_SOURCES = ksortablevaluelisttest.cpp
+krfcdatetest_SOURCES = krfcdatetest.cpp
+testqtargs_SOURCES = testqtargs.cpp
+kprociotest_SOURCES = kprociotest.cpp
+kcharsetstest_SOURCES = kcharsetstest.cpp
+kcalendartest_SOURCES = kcalendartest.cpp
+kmacroexpandertest_SOURCES = kmacroexpandertest.cpp
+kshelltest_SOURCES = kshelltest.cpp
+kxerrorhandlertest_SOURCES = kxerrorhandlertest.cpp
+startserviceby_SOURCES = startserviceby.cpp
+kstdacceltest_SOURCES = kstdacceltest.cpp
+kglobaltest_SOURCES = kglobaltest.cpp
+ktimezonestest_SOURCES = ktimezonestest.cpp
+
+check_LTLIBRARIES = kunittest_kconfig.la
+
+kunittest_kconfig_la_SOURCES = kconfigtest.cpp
+kunittest_kconfig_la_LIBADD = $(LIB_KUNITTEST)
+kunittest_kconfig_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN)
diff --git a/tdecore/tests/cplusplustest.cpp b/tdecore/tests/cplusplustest.cpp
new file mode 100644
index 000000000..1f789fea7
--- /dev/null
+++ b/tdecore/tests/cplusplustest.cpp
@@ -0,0 +1,44 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <tqstring.h>
+#include <tqdict.h>
+
+class A { int foo; };
+class B { int bar; };
+class C : public A, public B { int foobar; };
+
+TQDict<A> dictA;
+TQDict<B> dictB;
+
+int main(int , char *[])
+{
+ C obj;
+ A *pA = &obj;
+ B *pB = &obj;
+ C *pC = &obj;
+qWarning("pA = %p, pB = %p, pC = %p", pA, pB, pC);
+ if (pA == pC) qWarning("pA == pC");
+ if (pB == pC) qWarning("pB == pC");
+
+ dictA.insert("hello", pC);
+ dictB.insert("hello", pC);
+
+ if (dictA["hello"] == pC) qWarning("dictA['hello'] == pC");
+ if (dictB["hello"] == pC) qWarning("dictB['hello'] == pC");
+}
diff --git a/tdecore/tests/dcopkonqtest.cpp b/tdecore/tests/dcopkonqtest.cpp
new file mode 100644
index 000000000..8830d34c7
--- /dev/null
+++ b/tdecore/tests/dcopkonqtest.cpp
@@ -0,0 +1,36 @@
+#include <kapplication.h>
+#include <kdebug.h>
+#include <dcopclient.h>
+
+int main( int argc, char** argv )
+{
+ KApplication app( argc, argv, "KIDLTestClient", false );
+
+ kapp->dcopClient()->attach();
+ // kapp->dcopClient()->registerAs( "kidlclienttest" );
+
+ TQByteArray data;
+
+ kdDebug() << "sending reparseConfiguration to object KonquerorIface in konqueror" << endl;
+ TQByteArray snd;
+ TQByteArray rcv;
+ TQCString _type_;
+ kapp->dcopClient()->call( "konqueror", "KonquerorIface", "reparseConfiguration()", snd, _type_, rcv );
+ kdDebug() << _type_ << endl;
+ if( _type_ != "void" ) kdDebug() << "void expected, " << _type_.data() << " returned" << endl;
+
+/*
+debug("sending configure to object KonquerorIface in konqueror");
+ if (kapp->dcopClient()->send( "konqueror", "KonquerorIface", "configure()", data ))
+ debug("ok");
+ else
+ debug("ko");
+
+/// BROADCAST
+debug("sending databaseChanged to object ksycoca in all apps");
+ if (kapp->dcopClient()->send( "*", "ksycoca", "databaseChanged()", data ))
+ debug("ok");
+ else
+ debug("ko");
+*/
+}
diff --git a/tdecore/tests/kapptest.cpp b/tdecore/tests/kapptest.cpp
new file mode 100644
index 000000000..4a6465099
--- /dev/null
+++ b/tdecore/tests/kapptest.cpp
@@ -0,0 +1,40 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#define private public
+#include "kapplication.h"
+#include <stdio.h>
+
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <kglobalsettings.h>
+#include <ksycoca.h>
+
+int
+main(int argc, char *argv[])
+{
+ KAboutData about("kapptest", "kapptest", "version");
+ KCmdLineArgs::init(argc, argv, &about);
+
+ KApplication a;
+
+ KSycoca *s = KSycoca::self();
+
+ qWarning("s->language() %s", s->language().latin1());
+ qWarning("Offset of aIconName: %ld", (long) &(static_cast<KApplication *>(0)->aIconName));
+}
diff --git a/tdecore/tests/kcalendartest.cpp b/tdecore/tests/kcalendartest.cpp
new file mode 100644
index 000000000..8b6e8eea4
--- /dev/null
+++ b/tdecore/tests/kcalendartest.cpp
@@ -0,0 +1,152 @@
+// Simplest example using two kde calendar systems (gregorian and hijri)
+// Carlos Moro <cfmoro@correo.uniovi.es>
+// GNU-GPL v.2
+
+#include "kcalendarsystemfactory.h"
+#include "kcalendarsystem.h"
+
+#include <tqstringlist.h>
+
+#include <kapplication.h>
+#include <kaboutdata.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+
+class KLocale;
+
+void test(TQDate & date);
+
+static const char description[] = "KCalendarTest";
+
+static KCmdLineOptions options[] =
+{
+ { "help", I18N_NOOP("Prints this help"), 0 },
+ { "type hijri|gregorian|jalali|hebrew", I18N_NOOP("Supported calendar types"), 0 },
+ { "date <date>", I18N_NOOP("Show day info"), 0 },
+};
+
+int main(int argc, char **argv) {
+
+ TQDate date;
+ TQString calType, option;
+
+ KAboutData aboutData( "kcalendartest", "KCalendarTest" ,
+ "0.1", description, KAboutData::License_GPL,
+ "(c) 2002, Carlos Moro", 0, 0,
+ "cfmoro@correo.uniovi.es");
+ aboutData.addAuthor("Carlos Moro",0, "cfmoro@correo.uniovi.es");
+
+
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ KApplication app(false, false);
+
+ TQStringList lst = KCalendarSystemFactory::calendarSystems();
+ kdDebug() << "Supported calendar types: " << endl;
+ for (TQStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
+ kdDebug() << *it << endl;
+ kdDebug() << endl;
+
+
+ if ( args->isSet("type") )
+ calType = args->getOption("type");
+
+
+ KGlobal::locale()->setCalendar(calType);
+
+ /*
+ * If we like to see some date
+ *
+ */
+ if ( args->isSet("date") ) {
+ option = args->getOption("date");
+ date = KGlobal::locale()->readDate(option);
+ } else
+ date = TQDate::tqcurrentDate();
+
+ args->clear(); // Free up some memory.
+
+ test(date);
+
+ return 0;
+
+
+
+}
+
+void test(TQDate & date) {
+
+ kdDebug() << "(KLocale) readDate" << endl;
+
+ kdDebug() << "Created calendar: " << KGlobal::locale()->calendar()->calendarName() << endl;
+
+ kdDebug() << "Day name for first day of week is " << KGlobal::locale()->calendar()->weekDayName(1) << endl;
+ kdDebug() << "Short month name for second month is " << KGlobal::locale()->calendar()->weekDayName(1, true) << endl;
+
+ kdDebug() << "Month name for second month is " << KGlobal::locale()->calendar()->monthName(2, KGlobal::locale()->calendar()->year(date)) << endl;
+ kdDebug() << "Short month name for second month is " << KGlobal::locale()->calendar()->monthName(2, KGlobal::locale()->calendar()->year(date), true) << endl;
+ kdDebug() << "Month name possessive for second month is " << KGlobal::locale()->calendar()->monthNamePossessive(2, KGlobal::locale()->calendar()->year(date)) << endl;
+ kdDebug() << "Short month name possessive for second month is " << KGlobal::locale()->calendar()->monthNamePossessive(2, KGlobal::locale()->calendar()->year(date), true) << endl;
+ kdDebug() << "Month name for fifth month is " << KGlobal::locale()->calendar()->monthName(5, KGlobal::locale()->calendar()->year(date)) << endl;
+ kdDebug() << "Short month name for fifth month is " << KGlobal::locale()->calendar()->monthName(5, KGlobal::locale()->calendar()->year(date), true) << endl;
+ kdDebug() << "Month name possessive for fifth month is " << KGlobal::locale()->calendar()->monthNamePossessive(5, KGlobal::locale()->calendar()->year(date)) << endl;
+ kdDebug() << "Short month name possessive for fifth month is " << KGlobal::locale()->calendar()->monthNamePossessive(5, KGlobal::locale()->calendar()->year(date), true) << endl;
+
+ kdDebug() << "Day for date " << date.toString() << " is " << KGlobal::locale()->calendar()->day(date) << endl;
+ kdDebug() << "Month for date " << date.toString() << " is " << KGlobal::locale()->calendar()->month(date) << endl;
+ kdDebug() << "Year for date " << date.toString() << " is " << KGlobal::locale()->calendar()->year(date) << endl;
+
+ kdDebug() << "Day for date " << date.toString() << " as a string is " << KGlobal::locale()->calendar()->dayString(date, true) << endl;
+ kdDebug() << "Month for date " << date.toString() << " as a string is " << KGlobal::locale()->calendar()->monthString(date, true) << endl;
+ kdDebug() << "Year for date " << date.toString() << " as a string is " << KGlobal::locale()->calendar()->yearString(date, true) << endl;
+
+ kdDebug() << "Day of week for date " << date.toString() << " is number " << KGlobal::locale()->calendar()->dayOfWeek(date) << endl;
+ kdDebug() << "Week name for date " << date.toString() << " is " << KGlobal::locale()->calendar()->weekDayName(date) << endl;
+ kdDebug() << "Short week name for date " << date.toString() << " is " << KGlobal::locale()->calendar()->weekDayName(date, true) << endl;
+
+ kdDebug() << "Month name for date " << date.toString() << " is " << KGlobal::locale()->calendar()->monthName(date) << endl;
+ kdDebug() << "Short month name for date " << date.toString() << " is " << KGlobal::locale()->calendar()->monthName(date, true) << endl;
+ kdDebug() << "Month name possessive for date " << date.toString() << " is " << KGlobal::locale()->calendar()->monthNamePossessive(date) << endl;
+ kdDebug() << "Short month name possessive for date " << date.toString() << " is " << KGlobal::locale()->calendar()->monthNamePossessive(date, true) << endl;
+
+ kdDebug() << "It's week number " << KGlobal::locale()->calendar()->weekNumber(date) << endl;
+
+
+ kdDebug() << "(KLocale) Formatted date: " << KGlobal::locale()->formatDate(date) << endl;
+ kdDebug() << "(KLocale) Short formatted date: " << KGlobal::locale()->formatDate(date, true) << endl;
+
+ kdDebug() << "That month have : " << KGlobal::locale()->calendar()->daysInMonth(date) << " days" << endl;
+
+ kdDebug() << "That year has " << KGlobal::locale()->calendar()->monthsInYear(date) << " months" << endl;
+ kdDebug() << "There are " << KGlobal::locale()->calendar()->weeksInYear(KGlobal::locale()->calendar()->year(date)) << " weeks that year" << endl;
+ kdDebug() << "There are " << KGlobal::locale()->calendar()->daysInYear(date) << " days that year" << endl;
+
+ kdDebug() << "The day of pray is number " << KGlobal::locale()->calendar()->weekDayOfPray() << endl;
+
+ kdDebug() << "Max valid year supported is " << KGlobal::locale()->calendar()->maxValidYear() << endl;
+ kdDebug() << "Min valid year supported is " << KGlobal::locale()->calendar()->minValidYear() << endl;
+
+ kdDebug() << "It's the day number " << KGlobal::locale()->calendar()->dayOfYear(date) << " of year" << endl;
+
+ kdDebug() << "Add 3 days" << endl;
+ date = KGlobal::locale()->calendar()->addDays(date, 3);
+ kdDebug() << "It's " << KGlobal::locale()->formatDate(date) << endl;
+
+ kdDebug() << "Then add 3 months" << endl;
+ date = KGlobal::locale()->calendar()->addMonths(date, 3);
+ kdDebug() << "It's " << KGlobal::locale()->formatDate(date) << endl;
+
+ kdDebug() << "And last, add -3 years" << endl;
+ date = KGlobal::locale()->calendar()->addYears(date, -3);
+ kdDebug() << "It's " << KGlobal::locale()->formatDate(date) << endl;
+
+ kdDebug() << "Is lunar based: " << KGlobal::locale()->calendar()->isLunar() << endl;
+ kdDebug() << "Is lunisolar based: " << KGlobal::locale()->calendar()->isLunisolar() << endl;
+ kdDebug() << "Is solar based: " << KGlobal::locale()->calendar()->isSolar() << endl;
+
+}
diff --git a/tdecore/tests/kcharsetstest.cpp b/tdecore/tests/kcharsetstest.cpp
new file mode 100644
index 000000000..09b9486c0
--- /dev/null
+++ b/tdecore/tests/kcharsetstest.cpp
@@ -0,0 +1,12 @@
+
+#include <kcharsets.h>
+
+#include <assert.h>
+
+int main()
+{
+ TQString input( "&lt;Hello &amp;World&gt;" );
+ TQString output = KCharsets::resolveEntities( input );
+ assert( output == "<Hello &World>" );
+ return 0;
+}
diff --git a/tdecore/tests/kcmdlineargstest.cpp b/tdecore/tests/kcmdlineargstest.cpp
new file mode 100644
index 000000000..0ad9807c9
--- /dev/null
+++ b/tdecore/tests/kcmdlineargstest.cpp
@@ -0,0 +1,91 @@
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#include <kapplication.h>
+
+#include <stdio.h>
+
+// we use our own macro to not bother translators
+// but still demonstrate the use. You would use I18N_NOOP
+#define I18N_NOP(x) x
+
+static const char version[] = "v0.0.2 1999 (c) Waldo Bastian";
+static const char description[] = I18N_NOP("This is a test program.");
+
+static KCmdLineOptions options[] =
+{
+ { "test", I18N_NOP("do a short test only, note that\n"
+ "this is rather long comment"), 0 },
+ { "baud <baudrate>", I18N_NOP("set baudrate"), "9600" },
+ { "+file(s)", I18N_NOP("Files to load"), 0 },
+ KCmdLineLastOption
+};
+
+#if 1
+int
+main(int argc, char *argv[])
+{
+ KLocale::setMainCatalogue("kdelibs");
+ KCmdLineArgs::init( argc, argv, "testapp", description, version);
+
+ KCmdLineArgs::addCmdLineOptions( options ); // Add my own options.
+
+ // MyWidget::addCmdLineOptions();
+
+ KApplication k( false, false /*true, true*/ );
+
+ // Get application specific arguments
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ // Check if an option is set
+ if (args->isSet("test"))
+ {
+ // Do stuff
+ printf("Option 'test' is set.\n");
+ }
+
+ if (args->isSet("baud"))
+ {
+ // Do stuff
+ printf("Option 'baud' is set.\n");
+ }
+
+ // Read the value of an option.
+ TQCString baudrate = args->getOption("baud"); // 9600 is the default value.
+
+ printf("Baudrate = %s\n", baudrate.data());
+
+ printf("Full list of baudrates:\n");
+ QCStringList result = args->getOptionList("baud");
+ for(QCStringList::ConstIterator it=result.begin();
+ it != result.end();
+ ++it)
+ {
+ printf("Baudrate = %s\n", (*it).data());
+ }
+ printf("End of list\n");
+
+ for(int i = 0; i < args->count(); i++)
+ {
+ printf("%d: %s\n", i, args->arg(i));
+ printf("%d: %s\n", i, args->url(i).url().ascii());
+ }
+
+ args->clear(); // Free up memory.
+
+
+// k.exec();
+ return 0;
+}
+#else
+int
+main(int argc, char *argv[])
+{
+ KCmdLineArgs::init( argc, argv, "testapp", description, version);
+
+ KApplication k( true, true );
+
+ k.exec();
+ return 0;
+}
+#endif
+
+
diff --git a/tdecore/tests/kconfigtest.cpp b/tdecore/tests/kconfigtest.cpp
new file mode 100644
index 000000000..1842b5036
--- /dev/null
+++ b/tdecore/tests/kconfigtest.cpp
@@ -0,0 +1,162 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kunittest/tester.h>
+#include <kunittest/module.h>
+
+#include <kconfig.h>
+
+class KConfigTest : public KUnitTest::Tester
+{
+public:
+ void allTests();
+private:
+ void writeConfigFile();
+ void revertEntries();
+};
+
+KUNITTEST_MODULE( kunittest_kconfig, "KConfigTest" )
+KUNITTEST_MODULE_REGISTER_TESTER( KConfigTest )
+
+// test data
+#define BOOLENTRY1 true
+#define BOOLENTRY2 false
+#define STRINGENTRY1 "hello"
+#define STRINGENTRY2 " hello"
+#define STRINGENTRY3 "hello "
+#define STRINGENTRY4 " hello "
+#define STRINGENTRY5 " "
+#define STRINGENTRY6 ""
+#define LOCAL8BITENTRY "Hello äöü"
+#define POINTENTRY TQPoint( 4351, 1235 )
+#define SIZEENTRY TQSize( 10, 20 )
+#define RECTENTRY TQRect( 10, 23, 5321, 13 )
+#define DATETIMEENTRY TQDateTime( TQDate( 2002, 06, 23 ), TQTime( 12, 55, 40 ) )
+#define STRINGLISTENTRY TQStringList( "Hello," )
+
+void KConfigTest::writeConfigFile()
+{
+ KConfig sc( "kconfigtest" );
+
+ sc.setGroup("AAA");
+ sc.writeEntry("stringEntry1", STRINGENTRY1, true, true);
+ sc.deleteEntry("stringEntry2", false, true);
+
+ sc.setGroup("Hello");
+ sc.writeEntry( "boolEntry1", BOOLENTRY1 );
+ sc.writeEntry( "boolEntry2", BOOLENTRY2 );
+
+ sc.writeEntry( "Test", TQString::fromLocal8Bit( LOCAL8BITENTRY ) );
+ sc.writeEntry( "Test2", "");
+ sc.writeEntry( "stringEntry1", STRINGENTRY1 );
+ sc.writeEntry( "stringEntry2", STRINGENTRY2 );
+ sc.writeEntry( "stringEntry3", STRINGENTRY3 );
+ sc.writeEntry( "stringEntry4", STRINGENTRY4 );
+ sc.writeEntry( "stringEntry5", STRINGENTRY5 );
+// sc.writeEntry( "stringEntry6", STRINGENTRY6 );
+ sc.writeEntry( "keywith=equalsign", STRINGENTRY1 );
+ sc.deleteEntry( "stringEntry5" );
+ sc.deleteEntry( "stringEntry6" );
+
+ sc.deleteGroup("deleteMe", true);
+
+ sc.setGroup("Bye");
+ sc.writeEntry( "rectEntry", RECTENTRY );
+ sc.writeEntry( "pointEntry", POINTENTRY );
+ sc.writeEntry( "sizeEntry", SIZEENTRY );
+ sc.writeEntry( "dateTimeEntry", DATETIMEENTRY );
+ sc.writeEntry( "stringListEntry", STRINGLISTENTRY );
+ sc.sync();
+}
+
+// ### TODO: call this, and test the state of things afterwards
+void KConfigTest::revertEntries()
+{
+ qWarning("Reverting entries");
+ KConfig sc( "kconfigtest" );
+
+ sc.setGroup("Hello");
+ sc.revertToDefault( "boolEntry1");
+ sc.revertToDefault( "boolEntry2");
+
+ sc.revertToDefault( "Test" );
+ sc.revertToDefault( "Test2" );
+ sc.revertToDefault( "stringEntry1" );
+ sc.revertToDefault( "stringEntry2" );
+ sc.revertToDefault( "stringEntry3" );
+ sc.revertToDefault( "stringEntry4" );
+ sc.revertToDefault( "stringEntry5" );
+ sc.sync();
+}
+
+void KConfigTest::allTests()
+{
+ writeConfigFile();
+
+ KConfig sc2( "kconfigtest" );
+
+ KConfigGroup sc3( &sc2, "AAA");
+ bool bImmutable = sc3.entryIsImmutable("stringEntry1");
+
+ CHECK( bImmutable, false );
+ //qWarning("sc3.entryIsImmutable() 1: %s", bImmutable ? "true" : "false");
+
+ sc2.setGroup("AAA");
+ CHECK( sc2.hasKey( "stringEntry1" ), true );
+ CHECK( sc2.readEntry( "stringEntry1" ), TQString( STRINGENTRY1 ) );
+ CHECK( sc2.entryIsImmutable("stringEntry1"), bImmutable );
+ CHECK( sc2.hasKey( "stringEntry2" ), false );
+ CHECK( sc2.readEntry( "stringEntry2", "bla" ), TQString( "bla" ) );
+
+ CHECK( sc2.hasDefault( "stringEntry1" ), false );
+
+ sc2.setGroup("Hello");
+ CHECK( sc2.readEntry( "Test" ), TQString::fromLocal8Bit( LOCAL8BITENTRY ) );
+ CHECK( sc2.readEntry("Test2", "Fietsbel").isEmpty(), true );
+ CHECK( sc2.readEntry( "stringEntry1" ), TQString( STRINGENTRY1 ) );
+ CHECK( sc2.readEntry( "stringEntry2" ), TQString( STRINGENTRY2 ) );
+ CHECK( sc2.readEntry( "stringEntry3" ), TQString( STRINGENTRY3 ) );
+ CHECK( sc2.readEntry( "stringEntry4" ), TQString( STRINGENTRY4 ) );
+ CHECK( sc2.hasKey( "stringEntry5" ), false);
+ CHECK( sc2.readEntry( "stringEntry5", "test" ), TQString( "test" ) );
+ CHECK( sc2.hasKey( "stringEntry6" ), false);
+ CHECK( sc2.readEntry( "stringEntry6", "foo" ), TQString( "foo" ) );
+ CHECK( sc2.readBoolEntry( "boolEntry1" ), BOOLENTRY1 );
+ CHECK( sc2.readBoolEntry( "boolEntry2" ), BOOLENTRY2 );
+
+#if 0
+ TQString s;
+ s = sc2.readEntry( "keywith=equalsign" );
+ fprintf(stderr, "comparing keywith=equalsign %s with %s -> ", STRINGENTRY1, s.latin1());
+ if (s == STRINGENTRY1)
+ fprintf(stderr, "OK\n");
+ else {
+ fprintf(stderr, "not OK\n");
+ exit(-1);
+ }
+#endif
+
+ sc2.setGroup("Bye");
+
+ CHECK( sc2.readPointEntry( "pointEntry" ), POINTENTRY );
+ CHECK( sc2.readSizeEntry( "sizeEntry" ), SIZEENTRY);
+ CHECK( sc2.readRectEntry( "rectEntry" ), RECTENTRY );
+ CHECK( sc2.readDateTimeEntry( "dateTimeEntry" ).toString(), DATETIMEENTRY.toString() );
+ CHECK( sc2.readListEntry( "stringListEntry").join( "," ), STRINGLISTENTRY.join( "," ) );
+}
diff --git a/tdecore/tests/kconfigtestgui.cpp b/tdecore/tests/kconfigtestgui.cpp
new file mode 100644
index 000000000..af560b496
--- /dev/null
+++ b/tdecore/tests/kconfigtestgui.cpp
@@ -0,0 +1,200 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kconfigtestgui.h"
+#include "kconfigtestgui.moc"
+
+//
+// configtest.cpp: libKDEcore example
+//
+// demonstrates use of KConfig class
+//
+// adapted from Qt widgets demo
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <kapplication.h>
+#include <tqdialog.h>
+#include <tqfile.h>
+#include <tqfileinfo.h>
+#include <tqdatetime.h>
+#include <kdebug.h>
+#include <ksimpleconfig.h>
+#include <config.h>
+
+// Standard Qt widgets
+
+#include <tqlabel.h>
+#include <tqlineedit.h>
+#include <tqpushbutton.h>
+
+// KDE includes
+#include <kconfig.h>
+
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif
+
+#ifndef _PATH_TMP
+#define _PATH_TMP "/tmp/"
+#endif
+
+//
+// Construct the KConfigTestView with buttons
+//
+
+KConfigTestView::KConfigTestView( TQWidget *parent, const char *name )
+ : TQDialog( parent, name ),
+ pConfig( 0L ),
+ pFile( 0L ),
+ pStream( 0L )
+{
+ // Set the window caption/title
+
+ setCaption( "KConfig test" );
+
+ // Label and edit for the app config file
+ pAppFileLabel = new TQLabel( this, "appconfiglabel" );
+ pAppFileLabel->setText( "Application config file:" );
+ pAppFileLabel->setGeometry( 20, 20, 200, 20 );
+
+ pAppFileEdit = new TQLineEdit( this, "appconfigedit" );
+ pAppFileEdit->setGeometry( 240, 20, 160, 20 );
+ connect( pAppFileEdit, TQT_SIGNAL(returnPressed()),
+ TQT_SLOT(appConfigEditReturnPressed()));
+
+ // Label and edit for the group
+ pGroupLabel = new TQLabel( this, "grouplabel" );
+ pGroupLabel->setText( "Group:" );
+ pGroupLabel->setGeometry( 20, 60, 80, 20 );
+
+ pGroupEdit = new TQLineEdit( this, "groupedit" );
+ pGroupEdit->setGeometry( 120, 60, 100, 20 );
+ connect( pGroupEdit, TQT_SIGNAL(returnPressed()),
+ TQT_SLOT(groupEditReturnPressed()));
+
+ // Edit and label for the key/value pair
+ pKeyEdit = new TQLineEdit( this, "keyedit" );
+ pKeyEdit->setGeometry( 20, 100, 80, 20 );
+ connect( pKeyEdit, TQT_SIGNAL( returnPressed()),
+ TQT_SLOT(keyEditReturnPressed()));
+
+ pEqualsLabel = new TQLabel( this, "equalslabel" );
+ pEqualsLabel->setGeometry( 105, 100, 20, 20 );
+ pEqualsLabel->setText( "=" );
+
+ pValueEdit = new TQLineEdit( this, "valueedit" );
+ pValueEdit->setGeometry( 120, 100, 100, 20 );
+ pValueEdit->setText( "---" );
+
+ pWriteButton = new TQPushButton( this, "writebutton" );
+ pWriteButton->setGeometry( 20,140, 80, 20 );
+ pWriteButton->setText( "Write entry" );
+ connect( pWriteButton, TQT_SIGNAL(clicked()), TQT_SLOT( writeButtonClicked() ) );
+
+ // Labels for the info line
+ pInfoLabel1 = new TQLabel( this, "infolabel1" );
+ pInfoLabel1->setGeometry( 20, 200, 60, 20 );
+ pInfoLabel1->setText( "Info:" );
+
+ pInfoLabel2 = new TQLabel( this, "infolabel2" );
+ pInfoLabel2->setGeometry( 100, 200, 300, 20 );
+ pInfoLabel2->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
+
+ // Quit button
+ pQuitButton = new TQPushButton( this, "quitbutton" );
+ pQuitButton->setText( "Quit" );
+ pQuitButton->setGeometry( 340, 60, 60, 60 );
+ connect( pQuitButton, TQT_SIGNAL(clicked()), tqApp, TQT_SLOT(quit()) );
+
+ // create a default KConfig object in order to be able to start right away
+ pConfig = new KConfig( TQString::null );
+}
+
+KConfigTestView::~KConfigTestView()
+{
+ delete pConfig;
+ delete pFile;
+ delete pStream;
+}
+
+void KConfigTestView::appConfigEditReturnPressed()
+{
+ // if there already was a config object, delete it and its associated data
+ delete pConfig;
+ pConfig = 0L;
+ delete pFile;
+ pFile = 0L;
+ delete pStream;
+ pStream = 0L;
+
+ // create a new config object
+ if( !pAppFileEdit->text().isEmpty() )
+ pConfig = new KConfig( pAppFileEdit->text() );
+
+ pInfoLabel2->setText( "New config object created." );
+}
+
+void KConfigTestView::groupEditReturnPressed()
+{
+ pConfig->setGroup( pGroupEdit->text() );
+ // according to the Qt doc, this is begging for trouble, but for a
+ // test program this will do
+ TQString aText;
+ aText.sprintf( "Group set to %s", TQString( pConfig->group() ).isEmpty() ?
+ TQString("<default>").ascii() : pConfig->group().ascii() );
+ pInfoLabel2->setText( aText );
+}
+
+void KConfigTestView::keyEditReturnPressed()
+{
+ TQString aValue = pConfig->readEntry( pKeyEdit->text() );
+ // just checking aValue.isNull() would be easier here, but this is
+ // to demonstrate the HasKey()-method. Besides, it is better data
+ // encapsulation because we do not make any assumption about coding
+ // non-values here.
+ if( !pConfig->hasKey( pKeyEdit->text() ) )
+ {
+ pInfoLabel2->setText( "Key not found!" );
+ pValueEdit->setText( "---" );
+ }
+ else
+ {
+ pInfoLabel2->setText( "Key found!" );
+ pValueEdit->setText( aValue );
+ }
+}
+
+void KConfigTestView::writeButtonClicked()
+{
+ pConfig->writeEntry( pKeyEdit->text(), TQString( pValueEdit->text() ) );
+ pInfoLabel2->setText( "Entry written" );
+
+ kdDebug() << "Entry written: " << 27 << endl;
+}
+
+
+int main( int argc, char **argv )
+{
+ KApplication a( argc, argv, "bla" );
+
+ KConfigTestView *w = new KConfigTestView();
+ a.setMainWidget( w );
+ return w->exec();
+}
diff --git a/tdecore/tests/kconfigtestgui.h b/tdecore/tests/kconfigtestgui.h
new file mode 100644
index 000000000..7655c8142
--- /dev/null
+++ b/tdecore/tests/kconfigtestgui.h
@@ -0,0 +1,72 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef _KCONFIG_TEST_H
+#define _KCONFIG_TEST_H
+
+#include <kapplication.h>
+#include <tqdialog.h>
+#include <tqfile.h>
+#include <tqfileinfo.h>
+#include <kdebug.h>
+#include <ksimpleconfig.h>
+#include <tqtextstream.h>
+
+// Standard Qt widgets
+
+#include <tqlabel.h>
+#include <tqlineedit.h>
+#include <tqpushbutton.h>
+
+#include <kconfig.h>
+
+//
+// KConfigTestView contains lots of Qt widgets.
+//
+
+class KConfigTestView : public TQDialog
+{
+ Q_OBJECT
+public:
+ KConfigTestView( TQWidget *parent=0, const char *name=0 );
+ ~KConfigTestView();
+
+private slots:
+ void appConfigEditReturnPressed();
+ void groupEditReturnPressed();
+ void keyEditReturnPressed();
+ void writeButtonClicked();
+
+private:
+ TQLabel* pAppFileLabel;
+ TQLineEdit* pAppFileEdit;
+ TQLabel* pGroupLabel;
+ TQLineEdit* pGroupEdit;
+ TQLineEdit* pKeyEdit;
+ TQLabel* pEqualsLabel;
+ TQLineEdit* pValueEdit;
+ TQPushButton* pWriteButton;
+ TQLabel* pInfoLabel1, *pInfoLabel2;
+ TQPushButton* pQuitButton;
+
+ KConfig* pConfig;
+ TQFile* pFile;
+ TQTextStream* pStream;
+};
+
+#endif
diff --git a/tdecore/tests/kdebugtest.cpp b/tdecore/tests/kdebugtest.cpp
new file mode 100644
index 000000000..ee49127ea
--- /dev/null
+++ b/tdecore/tests/kdebugtest.cpp
@@ -0,0 +1,98 @@
+#include "kdebug.h"
+#include <tqwidget.h>
+#include <kinstance.h>
+#include <iostream>
+#include <tqapplication.h>
+#include <tqpen.h>
+#include <tqvariant.h>
+
+class TestWidget : public QWidget
+{
+
+public:
+ TestWidget(TQWidget* parent, const char* name)
+ : TQWidget(parent, name)
+ {
+ kdDebug().form("mytest %s", "hello") << endl;
+ TQString test = "%20C this is a string";
+ kdDebug(150) << test << endl;
+ TQCString cstr = test.latin1();
+ kdDebug(150) << test << endl;
+ TQChar ch = 'a';
+ kdDebug() << "TQChar a: " << ch << endl;
+ ch = '\r';
+ kdDebug() << "TQChar \\r: " << ch << endl;
+ kdDebug() << k_lineinfo << "error on this line" << endl;
+ kdDebug(2 == 2) << "this is right " << perror << endl;
+ kdDebug() << "Before instance creation" << endl;
+ kdDebug(1202) << "Before instance creation" << endl;
+ KInstance i("kdebugtest");
+ kdDebug(1) << "kDebugInfo with inexisting area number" << endl;
+ kdDebug(1202) << "This number has a value of " << 5 << endl;
+ // kdDebug() << "This number should come out as appname " << 5 << " " << "test" << endl;
+ kdWarning() << "1+1 = " << 1+1+1 << endl;
+ kdError(1+1 != 2) << "there is something really odd!" << endl;
+ TQString s = "mystring";
+ kdDebug() << s << endl;
+ kdError(1202) << "Error !!!" << endl;
+ kdError() << "Error with no area" << endl;
+
+ kdDebug() << "Printing a null TQWidget pointer: " << (TQWidget*)0 << endl;
+
+ kdDebug() << "char " << '^' << " " << char(26) << endl;
+ TQPoint p(0,9);
+ kdDebug() << p << endl;
+
+ TQRect r(9,12,58,234);
+ kdDebug() << r << endl;
+
+ TQRegion reg(r);
+ reg += TQRect(1,60,200,59);
+ kdDebug() << reg << endl;
+
+ TQStringList sl;
+ sl << "hi" << "this" << "list" << "is" << "short";
+ kdDebug() << sl << endl;
+
+ TQValueList<int> il;
+ kdDebug() << "Empty TQValueList<int>: " << il << endl;
+ il << 1 << 2 << 3 << 4 << 5;
+ kdDebug() << "TQValueList<int> filled: " << il << endl;
+
+ Q_LLONG big = 65536LL*65536*500;
+ kdDebug() << big << endl;
+
+ TQVariant v( 0.12345 );
+ kdDebug() << "Variant: " << v << endl;
+ v = TQPen( Qt::red );
+ kdDebug() << "Variant: " << v << endl;
+
+ TQByteArray data( 6 );
+ data[0] = 42;
+ data[1] = 'H';
+ data[2] = 'e';
+ data[3] = 'l';
+ data[4] = 'l';
+ data[5] = 'o';
+ kdDebug() << data << endl;
+ data.resize( 80 );
+ data.fill( 42 );
+ kdDebug() << data << endl;
+ }
+ void resizeEvent(TQResizeEvent*)
+ {
+ kdDebug() << this << endl;
+ }
+};
+
+int main(int argc, char** argv)
+{
+ TQApplication app(argc, argv);
+ TestWidget widget(0, "NoNameWidget");
+ widget.setGeometry(45, 54, 120, 80);
+ widget.show();
+ app.setMainWidget(&widget);
+ app.exec();
+ return 0;
+}
+
diff --git a/tdecore/tests/kglobaltest.cpp b/tdecore/tests/kglobaltest.cpp
new file mode 100644
index 000000000..d03be209e
--- /dev/null
+++ b/tdecore/tests/kglobaltest.cpp
@@ -0,0 +1,64 @@
+#include <config.h>
+
+#include <kglobal.h>
+#include <stdio.h>
+#include <kapplication.h>
+#include <stdlib.h>
+#include <kdebug.h>
+#include <assert.h>
+#include <kcmdlineargs.h>
+
+static bool check(const TQString& txt, TQString a, TQString b)
+{
+ if (a.isEmpty())
+ a = TQString::null;
+ if (b.isEmpty())
+ b = TQString::null;
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+void testkasciistricmp()
+{
+ assert( kasciistricmp( "test", "test" ) == 0 );
+ assert( kasciistricmp( "test", "Test" ) == 0 );
+ assert( kasciistricmp( "TeSt", "tEst" ) == 0 );
+
+ assert( kasciistricmp( 0, 0 ) == 0 );
+ assert( kasciistricmp( "", "" ) == 0 );
+ assert( kasciistricmp( 0, "" ) < 0 );
+ assert( kasciistricmp( "", 0 ) > 0 );
+
+ assert( kasciistricmp( "", "foo" ) < 0 );
+ assert( kasciistricmp( "foo", "" ) > 0 );
+
+ assert( kasciistricmp( "test", "testtest" ) < 0 );
+ assert( kasciistricmp( "testtest", "test" ) > 0 );
+
+ assert( kasciistricmp( "a", "b" ) < 0 );
+ assert( kasciistricmp( "b", "a" ) > 0 );
+ assert( kasciistricmp( "A", "b" ) < 0 );
+ assert( kasciistricmp( "b", "A" ) > 0 );
+ assert( kasciistricmp( "a", "B" ) < 0 );
+ assert( kasciistricmp( "B", "a" ) > 0 );
+ assert( kasciistricmp( "A", "B" ) < 0 );
+ assert( kasciistricmp( "B", "A" ) > 0 );
+}
+
+int main(int argc, char *argv[])
+{
+ KApplication::disableAutoDcopRegistration();
+ KCmdLineArgs::init( argc, argv, "kglobaltest", 0, 0, 0, 0 );
+ KApplication app( false, false );
+
+ testkasciistricmp();
+
+ printf("\nTest OK !\n");
+}
+
diff --git a/tdecore/tests/kiconloadertest.cpp b/tdecore/tests/kiconloadertest.cpp
new file mode 100644
index 000000000..96a7a6813
--- /dev/null
+++ b/tdecore/tests/kiconloadertest.cpp
@@ -0,0 +1,34 @@
+#include <kiconloader.h>
+#include <tqdatetime.h>
+#include <stdio.h>
+#include <kapplication.h>
+#include <stdlib.h>
+#include <kdebug.h>
+
+int main(int argc, char *argv[])
+{
+ KApplication app(argc,argv,"kiconloadertest"/*,false,false*/);
+
+ KIconLoader * mpLoader = KGlobal::iconLoader();
+ KIcon::Context mContext = KIcon::Application;
+ TQTime dt;
+ dt.start();
+ int count = 0;
+ for ( int mGroup = 0; mGroup < KIcon::LastGroup ; ++mGroup )
+ {
+ kdDebug() << "queryIcons " << mGroup << "," << mContext << endl;
+ TQStringList filelist=mpLoader->queryIcons(mGroup, mContext);
+ kdDebug() << " -> found " << filelist.count() << " icons." << endl;
+ int i=0;
+ for(TQStringList::Iterator it = filelist.begin();
+ it != filelist.end() /*&& i<10*/;
+ ++it, ++i )
+ {
+ //kdDebug() << ( i==9 ? "..." : (*it) ) << endl;
+ mpLoader->loadIcon( (*it), (KIcon::Group)mGroup );
+ ++count;
+ }
+ }
+ kdDebug() << "Loading " << count << " icons took " << (float)(dt.elapsed()) / 1000 << " seconds" << endl;
+}
+
diff --git a/tdecore/tests/kipctest.cpp b/tdecore/tests/kipctest.cpp
new file mode 100644
index 000000000..136aa6d70
--- /dev/null
+++ b/tdecore/tests/kipctest.cpp
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <tqobject.h>
+#include <kapplication.h>
+#include <kipc.h>
+#include "kipctest.h"
+
+MyObject::MyObject()
+ : TQObject(0L, "testobj")
+{
+ connect(kapp, TQT_SIGNAL(kdisplayPaletteChanged()), TQT_SLOT(slotPaletteChanged()));
+ connect(kapp, TQT_SIGNAL(kdisplayFontChanged()), TQT_SLOT(slotFontChanged()));
+ connect(kapp, TQT_SIGNAL(kdisplayStyleChanged()), TQT_SLOT(slotStyleChanged()));
+ connect(kapp, TQT_SIGNAL(backgroundChanged(int)), TQT_SLOT(slotBackgroundChanged(int)));
+ connect(kapp, TQT_SIGNAL(appearanceChanged()), TQT_SLOT(slotAppearanceChanged()));
+ connect(kapp, TQT_SIGNAL(kipcMessage(int,int)), TQT_SLOT(slotMessage(int,int)));
+}
+
+int main(int argc, char **argv)
+{
+ KApplication app(argc, argv, "kipc");
+
+ if (argc == 3)
+ {
+ KIPC::sendMessageAll((KIPC::Message) atoi(argv[1]), atoi(argv[2]));
+ return 0;
+ }
+
+ MyObject obj;
+ return app.exec();
+}
+
+#include "kipctest.moc"
diff --git a/tdecore/tests/kipctest.h b/tdecore/tests/kipctest.h
new file mode 100644
index 000000000..17122fbd8
--- /dev/null
+++ b/tdecore/tests/kipctest.h
@@ -0,0 +1,21 @@
+#ifndef __blah__h__
+#define __blah__h__
+
+#include <tqobject.h>
+
+class MyObject: public TQObject
+{
+ Q_OBJECT
+public:
+ MyObject();
+
+public slots:
+ void slotPaletteChanged() { printf("SIGNAL: Palette changed\n"); }
+ void slotStyleChanged() { printf("SIGNAL: Style changed\n"); }
+ void slotFontChanged() { printf("SIGNAL: Font changed\n"); }
+ void slotBackgroundChanged(int i) { printf("SIGNAL: Background %d changed\n", i); }
+ void slotAppearanceChanged() { printf("SIGNAL: Appearance changed\n"); }
+ void slotMessage(int id, int arg) { printf("SIGNAL: user message: %d,%d\n", id, arg); }
+};
+
+#endif
diff --git a/tdecore/tests/klocaletest.cpp b/tdecore/tests/klocaletest.cpp
new file mode 100644
index 000000000..39bef8dde
--- /dev/null
+++ b/tdecore/tests/klocaletest.cpp
@@ -0,0 +1,199 @@
+// klocaletest.cpp -*- C++ -*-
+//
+// $Id$
+//
+// Author: Jacek Konieczny <jajcus@zeus.polsl.gliwice.pl>
+//
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <tqdatetime.h>
+#include <tqlabel.h>
+
+#include <kglobal.h>
+#include <kglobalsettings.h>
+#include "klocale.h"
+#include <kapplication.h>
+#include <kcharsets.h>
+#include <kdebug.h>
+
+#include "klocaletest.h"
+
+bool check(TQString txt, TQString a, TQString b)
+{
+ if (a.isEmpty())
+ a = TQString::null;
+ if (b.isEmpty())
+ b = TQString::null;
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+bool checkDate(TQString txt, TQDate a, TQDate b)
+{
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a.toString() << "' against expected value '" << b.toString() << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a.toString() << "' against expected value '" << b.toString() << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+Test::Test( TQWidget *parent, const char *name )
+ : TQWidget( parent, name )
+{
+ setCaption("Testing KLocale");
+
+ TQWidget *d = tqApp->desktop();
+ setGeometry((d->width()-320)>>1, (d->height()-160)>>1, 420, 420);
+
+ createFields();
+ show();
+}
+
+Test::~Test()
+{
+ ;
+}
+
+void Test::createFields()
+{
+ TQString string;
+
+ string+="Selected languages: ";
+ string+=KGlobal::locale()->languages()+"\n";
+
+ // This will show nothing, as there is no klocaletest.mo
+ // but you can copy other *.mo file
+ string+="Used language: ";
+ string+=KGlobal::locale()->language()+"\n";
+ string+="Locale encoding: ";
+ string+=TQString::tqfromLatin1(KGlobal::locale()->encoding())+"\n";
+
+ string+="Localized date and time: ";
+ string+=KGlobal::locale()->formatDateTime(TQDateTime::tqcurrentDateTime());
+ string+="\nLocalized monetary numbers: ";
+ string+=KGlobal::locale()->formatMoney(1234567.89) + " / \n" +KGlobal::locale()->formatMoney(-1234567.89);
+ // This will not work
+ // but you can copy other *.mo file
+ string+="\nSome localized strings:\n";
+ string+=TQString::tqfromLatin1("Yes = ")+i18n("Yes")+"\n";
+ string+=TQString::tqfromLatin1("No = ")+i18n("No")+"\n";
+ string+=TQString::tqfromLatin1("Help = ")+i18n("Help")+"\n";
+ string+=TQString::tqfromLatin1("Cancel = ")+i18n("Cancel")+"\n";
+
+ label=new TQLabel(string,this,"Label");
+ label->setGeometry(10,10,400,400);
+ label->setFont(KGlobalSettings::generalFont());
+ label->show();
+}
+
+int main( int argc, char ** argv )
+{
+ KLocale::setMainCatalogue("kdelibs");
+ KApplication a( argc, argv, "klocaletest" );
+
+ KGlobal::locale()->setLanguage(TQString::tqfromLatin1("en_US"));
+ KGlobal::locale()->setCountry(TQString::tqfromLatin1("C"));
+ KGlobal::locale()->setThousandsSeparator(TQString::tqfromLatin1(","));
+
+ TQString formatted;
+ formatted = KGlobal::locale()->formatNumber( 70 ); check("formatNumber(70)",formatted,"70.00");
+ formatted = KGlobal::locale()->formatNumber( 70, 0 ); check("formatNumber(70, 0)",formatted,"70");
+ formatted = KGlobal::locale()->formatNumber( 70.2 ); check("formatNumber(70.2)",formatted,"70.20");
+ formatted = KGlobal::locale()->formatNumber( 70.24 ); check("formatNumber(70.24)",formatted,"70.24");
+ formatted = KGlobal::locale()->formatNumber( 70.245 ); check("formatNumber(70.245)",formatted,"70.25"); /*rounded*/
+ formatted = KGlobal::locale()->formatNumber(1234567.89123456789,8); check("formatNumber(1234567.89123456789,8)",formatted,"1,234,567.89123457");
+
+ formatted = KGlobal::locale()->formatNumber("70"); check("formatNumber(\"70\")",formatted,"70.00");
+ formatted = KGlobal::locale()->formatNumber("70", true, 2); check("formatNumber(\"70\", true, 2)",formatted,"70.00");
+ formatted = KGlobal::locale()->formatNumber("70", true, 0); check("formatNumber(\"70\", true, 0)",formatted,"70");
+ formatted = KGlobal::locale()->formatNumber("70.9123", true, 0); check("formatNumber(\"70.9123\", true, 0)",formatted,"71"); /* rounded */
+ formatted = KGlobal::locale()->formatNumber("-70.2", true, 2); check("formatNumber(\"-70.2\", true, 2)",formatted,"-70.20");
+ formatted = KGlobal::locale()->formatNumber("+70.24", true, 2); check("formatNumber(\"+70.24\", true, 2)",formatted,"70.24");
+ formatted = KGlobal::locale()->formatNumber("70.245", true, 2); check("formatNumber(\"70.245\", true, 2)",formatted,"70.25"); /*rounded*/
+ formatted = KGlobal::locale()->formatNumber("99.996", true, 2); check("formatNumber(\"99.996\", true, 2)",formatted,"100.00"); /*rounded*/
+ formatted = KGlobal::locale()->formatNumber("12345678901234567.89123456789", false, 0); check("formatNumber(\"12345678901234567.89123456789\", false, 0)",formatted,"12,345,678,901,234,567.89123456789");
+
+
+
+ double num;
+ bool ok;
+ num = KGlobal::locale()->readNumber( "12,1", &ok ); check("readNumber(12,1)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,100", &ok ); check("readNumber(12,100)",ok?"yes":"no","yes");
+ num = KGlobal::locale()->readNumber( "12,100000,000", &ok ); check("readNumber(12,100000,000)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,100000000", &ok ); check("readNumber(12,100000000)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,100000,000", &ok ); check("readNumber(12,100000,000)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,,100,000", &ok ); check("readNumber(12,,100,000)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,1000,000", &ok ); check("readNumber(12,1000,000)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,0000000,000", &ok ); check("readNumber(12,0000000,000)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,0000000", &ok ); check("readNumber(12,0000000)",ok?"yes":"no","no");
+ num = KGlobal::locale()->readNumber( "12,146,131.12", &ok ); check("readNumber(12,146,131.12)",ok?"yes":"no","yes");
+ num = KGlobal::locale()->readNumber( "1.12345678912", &ok );
+ qDebug( "%s", TQString::number( num, 'g', 12 ).latin1() ); // warning this is the only way to see all decimals
+ check("readNumber(1.12345678912)",ok && num==1.12345678912?"yes":"no","yes");
+ // bug 95511
+ KLocale locale(*KGlobal::locale());
+ locale.setCurrencySymbol("$$");
+ num = locale.readMoney("1,234,567.89$$", &ok);
+ check("readMoney(1,234,567.89$$)",ok?"yes":"no","yes");
+ num = locale.readMoney("-1,234,567.89$$", &ok);
+ check("readMoney(-1,234,567.89$$)",ok?"yes":"no","yes");
+
+ TQDate date;
+ date.setYMD( 2002, 5, 3 );
+ checkDate("readDate( 3, 5, 2002 )",date,KGlobal::locale()->readDate( KGlobal::locale()->formatDate( date ) ) );
+ date = TQDate::tqcurrentDate();
+ checkDate("readDate( TQDate::tqcurrentDate() )",date,KGlobal::locale()->readDate( KGlobal::locale()->formatDate( date ) ) );
+
+ TQTime time;
+ time = KGlobal::locale()->readTime( "11:22:33", &ok );
+ check("readTime(\"11:22:33\")", (ok && time == TQTime(11, 22, 33)) ?
+ "yes" : "no", "yes");
+ time = KGlobal::locale()->readTime( "11:22", &ok );
+ check("readTime(\"11:22\")", (ok && time == TQTime(11, 22, 0)) ?
+ "yes" : "no", "yes");
+ time = KGlobal::locale()->readTime( "foo", &ok );
+ check("readTime(\"foo\")", (!ok && !time.isValid()) ?
+ "invalid" : "valid", "invalid");
+
+ time = KGlobal::locale()->readTime( "11:22:33", KLocale::WithoutSeconds, &ok );
+ check("readTime(\"11:22:33\", WithoutSeconds)", (!ok && !time.isValid()) ?
+ "invalid" : "valid", "invalid");
+ time = KGlobal::locale()->readTime( "11:22", KLocale::WithoutSeconds, &ok );
+ check("readTime(\"11:22\", WithoutSeconds)", (ok && time == TQTime(11, 22, 0)) ?
+ "yes" : "no", "yes");
+
+ KGlobal::locale()->setTimeFormat( "%H:%M %p" );
+ time = TQTime( 0, 22, 33 );
+ TQString timeStr = KGlobal::locale()->formatTime( time, true /*seconds*/, false /*duration*/ );
+ check("formatTime(\"0:22\", as time)", timeStr, "00:22 am" );
+ timeStr = KGlobal::locale()->formatTime( time, true /*seconds*/, true /*duration*/ );
+ check("formatTime(\"0:22\", as duration)", timeStr, "00:22" );
+
+ kdDebug() << "setLanguage C\n";
+ KGlobal::locale()->setLanguage(TQString::tqfromLatin1("C"));
+ kdDebug() << "C: " << i18n("yes") << " " << i18n(TQACCEL_OBJECT_NAME_STRING, "Space") << endl;
+
+ kdDebug() << "setLanguage de\n";
+ KGlobal::locale()->setLanguage(TQString::tqfromLatin1("de"));
+ kdDebug() << "de: " << i18n("yes") << " " << i18n(TQACCEL_OBJECT_NAME_STRING, "Space") << endl;
+
+
+ Test m;
+ a.setMainWidget( &m );
+ m.show();
+
+ return a.exec();
+}
+
+#include "klocaletest.moc"
diff --git a/tdecore/tests/klocaletest.h b/tdecore/tests/klocaletest.h
new file mode 100644
index 000000000..83f4f5cef
--- /dev/null
+++ b/tdecore/tests/klocaletest.h
@@ -0,0 +1,32 @@
+// $Id$
+
+#ifndef KLOCALETEST_H
+#define KLOCALETEST_H
+
+#include <tqwidget.h>
+
+class TQLabel;
+
+/** test: a small test program for KLocale
+ */
+class Test : public TQWidget
+{
+ Q_OBJECT
+
+public:
+ /**@name methods */
+ //@{
+ /** Constructor
+ */
+ Test( TQWidget *parent=0, const char *name=0 );
+ /** Destructor
+ */
+ ~Test();
+
+private:
+ TQString showLocale(TQString cat);
+ void createFields();
+
+ TQLabel *label;
+};
+#endif // TEST_H
diff --git a/tdecore/tests/kmacroexpandertest.cpp b/tdecore/tests/kmacroexpandertest.cpp
new file mode 100644
index 000000000..0c41a309b
--- /dev/null
+++ b/tdecore/tests/kmacroexpandertest.cpp
@@ -0,0 +1,137 @@
+#include <kmacroexpander.h>
+
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kdebug.h>
+
+#include <stdlib.h>
+
+bool check(TQString txt, TQString s, TQString a, TQString b)
+{
+ if (a.isEmpty())
+ a = TQString::null;
+ if (b.isEmpty())
+ b = TQString::null;
+ if (a == b)
+ kdDebug() << txt << " (" << s << ") : '" << a << "' - ok" << endl;
+ else {
+ kdDebug() << txt << " (" << s << ") : got '" << a << "' but expected '" << b << "' - KO!" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+class MyCExpander : public KCharMacroExpander {
+public:
+ MyCExpander() : KCharMacroExpander() {}
+protected:
+ bool expandMacro(TQChar chr, TQStringList &ret)
+ {
+ if (chr == 'm') {
+ ret = TQString("expanded");
+ return true;
+ }
+ return false;
+ }
+};
+
+class MyWExpander : public KWordMacroExpander {
+public:
+ MyWExpander() : KWordMacroExpander() {}
+protected:
+ bool expandMacro(const TQString &str, TQStringList &ret)
+ {
+ if (str == "macro") {
+ ret = TQString("expanded");
+ return true;
+ }
+ return false;
+ }
+};
+
+int main(int argc, char *argv[])
+{
+ KCmdLineArgs::init(argc, argv, ":", "", "", "");
+ KApplication app(false,false);
+ TQString s, s2;
+
+ TQMap<TQChar,TQStringList> map1;
+ map1.insert('n', "Restaurant \"Chew It\"");
+ TQStringList li;
+ li << "element1" << "'element2'";
+ map1.insert('l', li);
+
+ s = "text %l %n text";
+ check( "KMacroExpander::expandMacros", s, KMacroExpander::expandMacros(s, map1), "text element1 'element2' Restaurant \"Chew It\" text");
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map1), "text 'element1' ''\\''element2'\\''' 'Restaurant \"Chew It\"' text");
+ s = "text \"%l %n\" text";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map1), "text \"element1 'element2' Restaurant \\\"Chew It\\\"\" text");
+
+ TQMap<TQChar,TQString> map;
+ map.insert('a', "%n");
+ map.insert('f', "filename.txt");
+ map.insert('u', "http://www.kde.org/index.html");
+ map.insert('n', "Restaurant \"Chew It\"");
+
+ s = "Title: %a - %f - %u - %n - %%";
+ check( "KMacroExpander::expandMacros", s, KMacroExpander::expandMacros(s, map), "Title: %n - filename.txt - http://www.kde.org/index.html - Restaurant \"Chew It\" - %");
+
+ s = "kedit --caption %n %f";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map), "kedit --caption 'Restaurant \"Chew It\"' 'filename.txt'");
+
+ map.replace('n', "Restaurant 'Chew It'");
+ s = "kedit --caption %n %f";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map), "kedit --caption 'Restaurant '\\''Chew It'\\''' 'filename.txt'");
+
+ s = "kedit --caption \"%n\" %f";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map), "kedit --caption \"Restaurant 'Chew It'\" 'filename.txt'");
+
+ map.replace('n', "Restaurant \"Chew It\"");
+ s = "kedit --caption \"%n\" %f";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map), "kedit --caption \"Restaurant \\\"Chew It\\\"\" 'filename.txt'");
+
+ map.replace('n', "Restaurant $HOME");
+ s = "kedit --caption \"%n\" %f";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map), "kedit --caption \"Restaurant \\$HOME\" 'filename.txt'");
+
+ map.replace('n', "Restaurant `echo hello`");
+ s = "kedit --caption \"%n\" %f";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map), "kedit --caption \"Restaurant \\`echo hello\\`\" 'filename.txt'");
+
+ map.replace('n', "Restaurant `echo hello`");
+ s = "kedit --caption \"`echo %n`\" %f";
+ check( "KMacroExpander::expandMacrosShellQuote", s, KMacroExpander::expandMacrosShellQuote(s, map), "kedit --caption \"$( echo 'Restaurant `echo hello`')\" 'filename.txt'");
+
+ TQMap<TQString,TQString> smap;
+ smap.insert("foo", "%n");
+ smap.insert("file", "filename.txt");
+ smap.insert("url", "http://www.kde.org/index.html");
+ smap.insert("name", "Restaurant \"Chew It\"");
+
+ s = "Title: %foo - %file - %url - %name - %";
+ check( "KMacroExpander::expandMacros", s, KMacroExpander::expandMacros(s, smap), "Title: %n - filename.txt - http://www.kde.org/index.html - Restaurant \"Chew It\" - %");
+
+ s = "Title: %{foo} - %{file} - %{url} - %{name} - %";
+ check( "KMacroExpander::expandMacros", s, KMacroExpander::expandMacros(s, smap), "Title: %n - filename.txt - http://www.kde.org/index.html - Restaurant \"Chew It\" - %");
+
+ s = "Title: %foo-%file-%url-%name-%";
+ check( "KMacroExpander::expandMacros", s, KMacroExpander::expandMacros(s, smap), "Title: %n-filename.txt-http://www.kde.org/index.html-Restaurant \"Chew It\"-%");
+
+ s = "Title: %{file} %{url";
+ check( "KMacroExpander::expandMacros", s, KMacroExpander::expandMacros(s, smap), "Title: filename.txt %{url");
+
+ MyCExpander mx1;
+ s = "subst %m but not %n equ %%";
+ s2 = s;
+ mx1.expandMacros(s2);
+ check( "MyCExpander::expandMacros", s, s2, "subst expanded but not %n equ %");
+
+ MyWExpander mx2;
+ s = "subst %macro but not %not equ %%";
+ s2 = s;
+ mx2.expandMacros(s2);
+ check( "MyWExpander::expandMacros", s, s2, "subst expanded but not %not equ %");
+
+ kdDebug() << endl << "Test OK!" << endl;
+}
+
diff --git a/tdecore/tests/kmdcodectest.cpp b/tdecore/tests/kmdcodectest.cpp
new file mode 100644
index 000000000..e74d6f4b4
--- /dev/null
+++ b/tdecore/tests/kmdcodectest.cpp
@@ -0,0 +1,395 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000,2001 Dawit Alemayehu <adawit@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <config.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <iostream>
+
+#include <tqbuffer.h>
+#include <tqfile.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+
+#include <kmdcodec.h>
+
+using namespace std;
+
+#define TEST_BLOCK_LEN 1000 // Length of test blocks.
+#define TEST_BLOCK_COUNT 10000 // Number of test blocks.
+#define MAX_READ_BUF_SIZE 8192
+
+enum Codec
+{
+ Unspecified=0,
+ Base64Encode,
+ Base64Decode,
+ UUEncode,
+ UUDecode,
+ QPEncode,
+ QPDecode
+};
+
+void MD5_timeTrial ();
+void MD5_testSuite ();
+void testCodec (const char*, Codec, bool);
+void MD5_verify (const char*, const char*, bool);
+void MD5_file (const char * , bool rawOutput = false);
+void MD5_string (const char *, const char *expected = 0, bool rawOutput = false);
+
+long readContent (const TQFile& f, long count, TQByteArray& buf)
+{
+ long result;
+ int old_size;
+
+ old_size = buf.size();
+ buf.resize(old_size+count);
+
+ result = read (f.handle (), buf.data()+old_size, count);
+
+ if ( result > 0 && result < count )
+ {
+ buf.resize( old_size + result );
+ }
+ else if ( result == 0 )
+ {
+ buf.resize( old_size );
+ }
+ else if ( result == -1 )
+ {
+ kdError() << "Could not read the file!" << endl;
+ }
+
+ return result;
+}
+
+void testCodec (const char* msg, Codec type, bool isFile)
+{
+ TQByteArray output;
+
+ if ( isFile )
+ {
+ int count;
+ TQByteArray data;
+
+ TQFile f (TQFile::encodeName(msg));
+
+ if (!f.exists())
+ {
+ kdError() << "Could not find: " << f.name () << endl;
+ return;
+ }
+
+ if (!f.open(IO_ReadOnly))
+ {
+ f.close ();
+ kdError() << "Could not open: " << f.name() << endl;
+ return;
+ }
+
+ // Read contents of file...
+ count = 0;
+
+ while ((count= readContent(f, MAX_READ_BUF_SIZE, data)) > 0);
+
+ // Error! Exit!
+ if ( count == -1 )
+ {
+ kdError () << "Error reading from: " << f.name() << endl;
+ f.close ();
+ return;
+ }
+
+ f.close ();
+
+ // Perform the requested encoding or decoding...
+ switch (type)
+ {
+ case Base64Encode:
+ KCodecs::base64Encode(data, output, true);
+ break;
+ case Base64Decode:
+ KCodecs::base64Decode(data, output);
+ break;
+ case UUEncode:
+ KCodecs::uuencode(data, output);
+ break;
+ case UUDecode:
+ KCodecs::uudecode(data, output);
+ break;
+ case QPEncode:
+ KCodecs::quotedPrintableEncode(data, output, true);
+ break;
+ case QPDecode:
+ KCodecs::quotedPrintableDecode(data, output);
+ break;
+ default:
+ break;
+ }
+
+ TQCString result (output.data(), output.size()+1);
+ cout << "Result: " << endl << result << endl;
+ }
+ else
+ {
+ TQCString result;
+
+ const size_t len = strlen(msg);
+ output.resize(len);
+ memcpy (output.data(), msg, len);
+
+ switch (type)
+ {
+ case Base64Encode:
+ result = KCodecs::base64Encode(output);
+ break;
+ case Base64Decode:
+ result = KCodecs::base64Decode(output);
+ break;
+ case UUEncode:
+ result = KCodecs::uuencode(output);
+ break;
+ case UUDecode:
+ result = KCodecs::uudecode(output);
+ break;
+ case QPEncode:
+ result = KCodecs::quotedPrintableEncode(output);
+ break;
+ case QPDecode:
+ result = KCodecs::quotedPrintableDecode(output);
+ break;
+ default:
+ break;
+ }
+ cout << result << endl;
+ }
+}
+
+void MD5_timeTrial ()
+{
+ KMD5 context;
+
+ time_t endTime;
+ time_t startTime;
+
+ TQ_UINT8 block[TEST_BLOCK_LEN];
+ TQ_UINT32 i;
+
+ cout << "Timing test. Digesting " << TEST_BLOCK_COUNT << " blocks of "
+ << TEST_BLOCK_LEN << "-byte..." << endl;
+
+ // Initialize block
+ for (i = 0; i < TEST_BLOCK_LEN; i++)
+ block[i] = (TQ_UINT8)(i & 0xff);
+
+ // Start timer
+ time (&startTime);
+
+ // Digest blocks
+ for (i = 0; i < TEST_BLOCK_COUNT; i++)
+ context.update (block, TEST_BLOCK_LEN);
+
+ // Stop timer
+ time (&endTime);
+
+ long duration = endTime - startTime;
+ long speed;
+ if (duration)
+ speed = (TEST_BLOCK_LEN * (TEST_BLOCK_COUNT/duration));
+ else
+ speed = TEST_BLOCK_COUNT;
+
+ cout << "Result: " << endl;
+ cout << " Time = " << duration << " seconds" << endl;
+ cout << " Speed = " << speed << " bytes/second" << endl;
+ cout << " Digest = " << context.hexDigest() << endl;
+}
+
+void MD5_testSuite ()
+{
+ cout << "MD5 preset test suite as defined in RFC 1321:" << endl;
+ MD5_string ( "", "d41d8cd98f00b204e9800998ecf8427e" );
+ MD5_string ( "a", "0cc175b9c0f1b6a831c399e269772661" );
+ MD5_string ( "abc", "900150983cd24fb0d6963f7d28e17f72" );
+ MD5_string ( "message digest", "f96b697d7cb7938d525a2f31aaf161d0" );
+ MD5_string ( "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" );
+ MD5_string ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "d174ab98d277d9f5a5611c2c9f419d9f" );
+ MD5_string ( "12345678901234567890123456789012345678901234567890123456789012"
+ "345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" );
+}
+
+void MD5_verify( const char *input, const char *digest, bool isFile )
+{
+ bool result;
+ KMD5 context;
+
+ if ( !isFile )
+ {
+ context.update (TQCString(input));
+ result = context.verify( digest );
+ cout << "Input string: " << input << endl;
+ }
+ else
+ {
+ TQFile f (input);
+
+ if (!f.open (IO_ReadOnly))
+ {
+ f.close ();
+ kdFatal() << "Cannot open file for reading!" << endl;
+ }
+
+ result = context.verify (digest);
+ f.close ();
+
+ cout << "Input filename: " << input << endl;
+ }
+
+ cout << "Calculated Digest = " << context.hexDigest() << endl;
+ cout << "Supplied Digest = " << digest << endl;
+ cout << "Matches: " << (result ? "TRUE":"FALSE") << endl;
+}
+
+void MD5_file (const char *filename, bool rawOutput )
+{
+ TQFile f (TQFile::encodeName(filename));
+
+ if (!f.open(IO_ReadOnly))
+ {
+ f.close();
+ kdError() << "(" << filename << ") cannot be opened!" << endl;
+ return;
+ }
+
+ KMD5 context;
+ context.update( f );
+
+ if ( rawOutput )
+ cout << "MD5 (" << filename << ") = " << context.rawDigest() << endl;
+ else
+ cout << "MD5 (" << filename << ") = " << context.hexDigest() << endl;
+
+ f.close ();
+}
+
+void MD5_string (const char *input, const char* expected, bool rawOutput )
+{
+ KMD5 context;
+ context.update (TQCString(input));
+
+ cout << "Checking MD5 for: " << input << endl;
+
+ if ( rawOutput )
+ cout << "Result: " << context.rawDigest() << endl;
+ else
+ cout << "Result: " << context.hexDigest() << endl;
+
+ if ( expected )
+ {
+ cout << "Expected: " << expected << endl;
+ cout << "Status: " << context.verify (expected) << endl;
+ }
+}
+
+int main (int argc, char *argv[])
+{
+ const char *version = "1.0";
+ const char *description = "Unit test for md5, base64 encode/decode and uuencode/decode facilities";
+ KCmdLineOptions options[] =
+ {
+ { "c <digest>", "compare <digest> with the calculated digest for a string or file.", 0 },
+ { "d", "decode the given string or file using base64", 0 },
+ { "e", "encode the given string or file using base64", 0 },
+ { "f", "the filename to be used as input", "default" },
+ { "p", "encode the given string or file using quoted-printable", 0},
+ { "q", "decode the given string or file using quoted-printable", 0},
+ { "r", "calculate the raw md5 for the given string or file", 0 },
+ { "s", "the string to be used as input", 0 },
+ { "t", "perform a timed message-digest test", 0 },
+ { "u", "uuencode the given string or file", 0 },
+ { "x", "uudecode the given string or file", 0 },
+ { "z", "run a preset message-digest test", 0 },
+ { "+command", "[input1, input2,...]", 0 },
+ KCmdLineLastOption
+ };
+
+ KCmdLineArgs::init( argc, argv, "kmdcodectest", description, version );
+ KCmdLineArgs::addCmdLineOptions( options );
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ int count = args->count();
+
+ KApplication app;
+
+ if (!count)
+ {
+ if ( args->isSet("t") )
+ MD5_timeTrial ();
+ else if ( args->isSet("z") )
+ MD5_testSuite ();
+ else
+ args->usage();
+ }
+ else
+ {
+ bool isVerify = args->isSet("c");
+ bool isString = args->isSet("s");
+ bool isFile = args->isSet( "f" );
+ Codec type = Unspecified;
+ if ( args->isSet("d") )
+ type = Base64Decode;
+ else if ( args->isSet("e") )
+ type = Base64Encode;
+ else if ( args->isSet("u") )
+ type = UUEncode;
+ else if ( args->isSet("x") )
+ type = UUDecode;
+ else if ( args->isSet("p") )
+ type = QPEncode;
+ else if ( args->isSet("q") )
+ type = QPDecode;
+ if ( isVerify )
+ {
+ const char* opt = args->getOption( "c" ).data();
+ for ( int i=0 ; i < count; i++ )
+ MD5_verify ( TQCString(args->arg(i)), opt, (isString || !isFile) );
+ }
+ else
+ {
+ for ( int i=0 ; i < count; i++ )
+ {
+ if ( type != Unspecified )
+ testCodec( args->arg(i), type, isFile );
+ else
+ {
+ if ( isString )
+ MD5_string( args->arg( i ), 0, args->isSet("r") );
+ else
+ MD5_file( args->arg( i ), args->isSet("r") );
+ }
+ }
+ }
+ }
+ args->clear();
+ return (0);
+}
diff --git a/tdecore/tests/kmemtest.cpp b/tdecore/tests/kmemtest.cpp
new file mode 100644
index 000000000..83c452e50
--- /dev/null
+++ b/tdecore/tests/kmemtest.cpp
@@ -0,0 +1,248 @@
+#include <stdio.h>
+#include <kapplication.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+void showMem()
+{
+ char buf[257];
+
+ printf("Reported Memory Usage Of This Process:\n");
+
+ FILE *fs = fopen("/proc/self/status", "r");
+ bool done = false;
+ while (!done)
+ {
+ fgets(buf, 256, fs);
+ buf[256] = 0;
+ if ((strncmp(buf, "VmLib", 5)==0) ||
+ (strncmp(buf, "VmData", 6)==0) ||
+ (strncmp(buf, "VmSize", 6)==0) ||
+ (strncmp(buf, "VmExe", 5)==0) ||
+ (strncmp(buf, "VmRSS", 5)==0) ||
+ (strncmp(buf, "VmLck", 5)==0))
+ printf("%s", buf);
+ done = (strncmp(buf, "VmLib", 5) == 0);
+ }
+ fclose(fs);
+}
+
+long showTotalMem()
+{
+ long realMem = 0;
+ char buf[257];
+
+ FILE *fs = fopen("/proc/meminfo", "r");
+ bool done = false;
+ while (!done)
+ {
+ fgets(buf, 256, fs);
+ buf[256] = 0;
+ if (strlen(buf)==0) done = true;
+ if (strncmp(buf, "Mem:", 4)==0)
+ {
+ long total = 0;
+ long used = 0;
+ long free = 0;
+ long shared = 0;
+ long buffers = 0;
+ long cached = 0;
+ sscanf(buf, "Mem: %ld %ld %ld %ld %ld %ld",
+ &total, &used, &free, &shared, &buffers, &cached);
+ realMem = used-buffers-cached;
+ printf("Actual Total Memory Usage: %0.1fKb\n", realMem/1024.0);
+ done = true;
+ }
+ }
+ fclose(fs);
+ return realMem;
+}
+
+long memSize()
+{
+ long realMem = 0;
+ char buf[257];
+
+ FILE *fs = fopen("/proc/meminfo", "r");
+ bool done = false;
+ while (!done)
+ {
+ fgets(buf, 256, fs);
+ buf[256] = 0;
+ if (strlen(buf)==0) done = true;
+ if (strncmp(buf, "Mem:", 4)==0)
+ {
+ long total = 0;
+ long used = 0;
+ long free = 0;
+ long shared = 0;
+ long buffers = 0;
+ long cached = 0;
+ sscanf(buf, "Mem: %ld %ld %ld %ld %ld %ld",
+ &total, &used, &free, &shared, &buffers, &cached);
+ realMem = total;
+ done = true;
+ }
+ }
+ fclose(fs);
+ return realMem;
+}
+
+void *mmapFile(const char *file)
+{
+ int fd = open(file, O_RDONLY);
+ if (fd == 0)
+ {
+ printf("open: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ struct stat stat_s;
+ int result = fstat(fd, &stat_s);
+ if (result)
+ {
+ printf("stat: %s\n", strerror(errno));
+ exit(-1);
+ }
+
+ void *ptr = mmap(0, stat_s.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (ptr == 0)
+ {
+ printf("mmap: %s\n", strerror(errno));
+ exit(-1);
+ }
+ return ptr;
+}
+
+int main(int argc, char *argv[])
+{
+ if ((argc==2) && (strcmp(argv[1], "all")==0))
+ {
+ long mem_size = memSize();
+ mem_size += mem_size / 16;
+ printf("Malloc... %0.1fMb\n", mem_size/(1024.0*1024.0));
+ char *mem = (char *) malloc(mem_size);
+ for(long i=0; i < mem_size; i+=1024)
+ {
+ mem[i] = 99;
+ }
+ printf("Done!\n");
+ exit(1);
+ }
+
+ if ((argc==3) && (strcmp(argv[1], "calc")==0))
+ {
+ char buf[257];
+ int total = 0;
+ long val;
+ while(true)
+ {
+ buf[0] = 0;
+ fgets(buf, sizeof(buf), stdin);
+ if (!strlen(buf))
+ {
+ printf("%s total = %0.1fKb (%d bytes)\n", argv[2], total/1024.0, total);
+ exit(1);
+ }
+ sscanf(buf, "%lx", &val);
+ total += val;
+// printf("Val = %ld\n", val);
+ }
+ exit(1);
+ }
+
+
+ if ((argc>=2) && (strcmp(argv[1], "launch")==0))
+ {
+ showMem();
+
+ char buf[200];
+
+ if (argc >=3)
+ snprintf(buf, 200, "%s &", argv[2]);
+ else
+ snprintf(buf, 200, "%s &", argv[0]);
+
+ printf("Waiting for memory usage to settle down....\n");
+ long prev = showTotalMem();
+ long diff = 0;
+ do {
+ sleep(15);
+ long next = showTotalMem();
+ if (next > prev)
+ diff = next - prev;
+ else
+ diff = prev-next;
+ prev = next;
+ }
+ while (diff > 2*1024);
+
+ for(int i=0; i < 5; i++)
+ {
+ printf("Launching #%d\n", i);
+ system(buf);
+ sleep(2);
+ }
+
+ sleep(10);
+ printf("Waiting for memory usage to settle down....\n");
+ prev = showTotalMem();
+ diff = 0;
+ do {
+ sleep(15);
+ long next = showTotalMem();
+ if (next > prev)
+ diff = next - prev;
+ else
+ diff = prev-next;
+ prev = next;
+ }
+ while (diff > 2*1024);
+ long fiveMem = prev;
+
+ for(int i=5; i < 15; i++)
+ {
+ printf("Launching #%d\n", i);
+ system(buf);
+ sleep(2);
+ }
+
+ sleep(10);
+ printf("Waiting for memory usage to settle down....\n");
+ prev = showTotalMem();
+ diff = 0;
+ do {
+ sleep(15);
+ long next = showTotalMem();
+ if (next > prev)
+ diff = next - prev;
+ else
+ diff = prev-next;
+ prev = next;
+ }
+ while (diff > 2*1024);
+ long fifteenMem = prev;
+ showMem();
+
+ printf("Actual memory usage of 1 instance = %0.1f Kb\n",
+ (fifteenMem - fiveMem) /10240.0);
+ }
+// showMem("second");
+
+ KApplication app(argc,argv,"kurltest");
+
+// showMem("After KApplication constructor");
+
+// malloc(10*1024);
+
+// showMem("After 10K malloc");
+
+ printf("Sleeping...\n");
+ sleep(8000);
+}
diff --git a/tdecore/tests/knotifytest.cpp b/tdecore/tests/knotifytest.cpp
new file mode 100644
index 000000000..8eb0586c0
--- /dev/null
+++ b/tdecore/tests/knotifytest.cpp
@@ -0,0 +1,10 @@
+#include <knotifyclient.h>
+#include <kapplication.h>
+
+int main( int argc, char **argv )
+{
+ KApplication app( argc, argv, "knotifytest" );
+ KNotifyClient::userEvent( "This is a notification to notify you :)",
+ KNotifyClient::Messagebox,
+ KNotifyClient::Error );
+}
diff --git a/tdecore/tests/kprocesstest.cpp b/tdecore/tests/kprocesstest.cpp
new file mode 100644
index 000000000..af04cd421
--- /dev/null
+++ b/tdecore/tests/kprocesstest.cpp
@@ -0,0 +1,116 @@
+//
+// MAIN -- a little demo of the capabilities of the "KProcess" class
+//
+// version 0.2, Aug 2nd 1997
+// $Id$
+//
+// (C) Christian Czezatke
+// e9025461@student.tuwien.ac.at
+//
+
+
+#include "kprocess.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <kapplication.h>
+
+#include <signal.h>
+
+#include "kprocesstest.h"
+
+#define PROCNO 10
+
+
+//
+// A nice input for "sort"... ;- )
+//
+static const char txt[] = "hat\nder\nalte\nhexenmeister\nsich\ndoch\neinmal\nwegbegeben\n\
+und\nnun\nsollen\nseine\ngeister\nsich\nnach\nmeinem\nwillen\nregen\nseine\nwort\nund\n\
+werke\nmerkt\nich\nund\nden\nbrauch\nund\nmit\ngeistesstaerke\ntu\nich\nwunder\nauch\n";
+
+
+int main(int argc, char *argv[])
+{
+ KProcess p1, p2, p3, p4;
+ Dummy dummy;
+ KApplication app(argc, argv, "kprocesstest");
+
+
+ printf("Welcome to the KProcess Demo Application!\n");
+
+ //
+ // The kghostview demo -- Starts a kghostview instance blocking. -- After
+ // kghostview has exited, kghostview is restarted non-blocking. When the process exits,
+ // the signal "processExited" will be emitted.
+ //
+
+ p1 << "kghostview";
+ TQObject::connect(&p1, TQT_SIGNAL(processExited(KProcess *)), &dummy, TQT_SLOT(printMessage(KProcess *)));
+
+ printf("starting kghostview blocking (close to continue)\n");
+ p1.start(KProcess::Block);
+ printf("restarting kghostview non blocking\n");
+ p1.start();
+
+
+ //
+ // A konsole with tcsh to demonstrate how to pass command line options to a process
+ // with "KProcess" (is run blocking)
+ //
+
+ printf("Starting konsole with /bin/tcsh as shell (close to continue)\n");
+ p2 << "konsole" << "-e" << "/bin/tcsh";
+ p2.setWorkingDirectory("/tmp");
+ TQObject::connect(&p2, TQT_SIGNAL(processExited(KProcess *)), &dummy, TQT_SLOT(printMessage(KProcess *)));
+ p2.start(KProcess::Block);
+
+ //
+ // Getting the output from a process. "ls" with parameter "-l" is called and it output is captured
+ //
+
+ p3 << "ls" << "-l";
+ TQObject::connect(&p3, TQT_SIGNAL(processExited(KProcess *)),
+ &dummy, TQT_SLOT(printMessage(KProcess *)));
+
+ TQObject::connect(&p3, TQT_SIGNAL(receivedStdout(KProcess *, char *, int)),
+ &dummy, TQT_SLOT(gotOutput(KProcess *, char *, int)));
+ TQObject::connect(&p3, TQT_SIGNAL(receivedStderr(KProcess *, char *, int)),
+ &dummy, TQT_SLOT(gotOutput(KProcess *, char *, int)));
+
+ p3.start(KProcess::NotifyOnExit, KProcess::AllOutput);
+
+
+ //
+ // An even more advanced example of communicating with a child proces. -- A "sort" command
+ // is started. After it has been started a list of words (as stored in "txt") is written
+ // to its stdin. When the sort command has absorbed all its input it will emit the signal
+ // "inputSent". -- This signal is connected to "outputDone" in the Dummy object.
+ //
+ // "OutputDone" will do a "sendEof" to p4. -- This will cause "sort" to perform its task.
+ // The output of sort is then captured once more by connecting to the signal "outputWaiting"
+ //
+ //
+
+ p4 << "sort";
+ TQObject::connect(&p4, TQT_SIGNAL(processExited(KProcess *)),
+ &dummy, TQT_SLOT(printMessage(KProcess *)));
+
+ TQObject::connect(&p4, TQT_SIGNAL(receivedStdout(KProcess *, char *, int)),
+ &dummy, TQT_SLOT(gotOutput(KProcess *, char *, int)));
+ TQObject::connect(&p4, TQT_SIGNAL(receivedStderr(KProcess *, char *, int)),
+ &dummy, TQT_SLOT(gotOutput(KProcess *, char *, int)));
+
+ TQObject::connect(&p4, TQT_SIGNAL(wroteStdin(KProcess *)),
+ &dummy, TQT_SLOT(outputDone(KProcess *)));
+
+ p4.start(KProcess::NotifyOnExit, KProcess::All);
+ printf("after p4.start");
+ p4.writeStdin(txt, strlen(txt));
+
+ printf("Entering man Qt event loop -- press <CTRL><C> to abort\n");
+ app.exec();
+
+ return 0;
+}
+#include "kprocesstest.moc"
diff --git a/tdecore/tests/kprocesstest.h b/tdecore/tests/kprocesstest.h
new file mode 100644
index 000000000..23ac443dd
--- /dev/null
+++ b/tdecore/tests/kprocesstest.h
@@ -0,0 +1,50 @@
+//
+// DUMMY -- A dummy class with a slot to demonstrate KProcess signals
+//
+// version 0.2, Aug 2nd 1997
+//
+// (C) Christian Czezatke
+// e9025461@student.tuwien.ac.at
+//
+
+
+#ifndef __DUMMY_H__
+#define __DUMMY_H__
+
+#include <stdio.h>
+#include <tqobject.h>
+#include "kprocess.h"
+
+class Dummy : public TQObject
+{
+ Q_OBJECT
+
+ public slots:
+ void printMessage(KProcess *proc)
+ {
+ printf("Process %d exited!\n", (int)proc->getPid());
+ }
+
+ void gotOutput(KProcess*, char *buffer, int len)
+ {
+ char result[1025]; // this is ugly since it relys on the internal buffer size of KProcess,
+ memcpy(result, buffer, len); // NEVER do that in your own application... ;-)
+ result[len] = '\0';
+ printf("OUTPUT>>%s", result);
+ }
+
+ void outputDone(KProcess *proc)
+ /*
+ Slot Procedure for the "sort" example. -- If it is indicated that the "sort" command has
+ absorbed all its input, we send an "EOF" to it to indicate that there is no more
+ data to be processed.
+ */
+ {
+ proc->closeStdin();
+ }
+
+};
+
+#endif
+
+
diff --git a/tdecore/tests/kprociotest.cpp b/tdecore/tests/kprociotest.cpp
new file mode 100644
index 000000000..446dacb30
--- /dev/null
+++ b/tdecore/tests/kprociotest.cpp
@@ -0,0 +1,65 @@
+//
+// MAIN -- a little demo of the capabilities of the "KProcess" class
+//
+// version 0.2, Aug 2nd 1997
+// $Id$
+//
+// (C) Christian Czezatke
+// e9025461@student.tuwien.ac.at
+//
+
+
+#include "kprocess.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <kapplication.h>
+
+#include <signal.h>
+
+#include "kprociotest.h"
+
+
+
+//
+// A nice input for "sort"... ;- )
+//
+static const char txt[] = "hat\nder\nalte\nhexenmeister\nsich\ndoch\neinmal\nwegbegeben\n\
+und\nnun\nsollen\nseine\ngeister\nsich\nnach\nmeinem\nwillen\nregen\nseine\nwort\nund\n\
+werke\nmerkt\nich\nund\nden\nbrauch\nund\nmit\ngeistesstaerke\ntu\nich\nwunder\nauch\n";
+
+
+int main(int argc, char *argv[])
+{
+ Dummy dummy;
+ KApplication app(argc, argv, "kprociotest");
+
+ printf("Welcome to the KProcIO Demo Application!\n");
+
+
+ KProcIO p;
+
+ p << "rev";
+
+ p.connect(&p, TQT_SIGNAL(processExited(KProcess*)), &dummy, TQT_SLOT(printMessage(KProcess*)));
+ p.connect(&p, TQT_SIGNAL(readReady(KProcIO*)), &dummy, TQT_SLOT(gotOutput(KProcIO*)));
+
+ bool b;
+
+ b = p.start();
+ printf("Start returns %s\n", b ? "true" : "false");
+
+ b = p.fputs("Hello World!");
+ printf("fputs returns %s\n", b ? "true" : "false");
+
+ b = p.fputs("This is a test. It should come out in reverse (esrever)");
+ printf("fputs returns %s\n", b ? "true" : "false");
+
+ p.closeWhenDone();
+
+ printf("Entering man Qt event loop -- press <CTRL><C> to abort\n");
+ app.exec();
+
+ return 0;
+}
+#include "kprociotest.moc"
diff --git a/tdecore/tests/kprociotest.h b/tdecore/tests/kprociotest.h
new file mode 100644
index 000000000..9f948e644
--- /dev/null
+++ b/tdecore/tests/kprociotest.h
@@ -0,0 +1,42 @@
+//
+// DUMMY -- A dummy class with a slot to demonstrate KProcess signals
+//
+// version 0.2, Aug 2nd 1997
+//
+// (C) Christian Czezatke
+// e9025461@student.tuwien.ac.at
+//
+
+
+#ifndef __DUMMY_H__
+#define __DUMMY_H__
+
+#include <stdio.h>
+#include <tqobject.h>
+#include "kprocio.h"
+
+class Dummy : public TQObject
+{
+ Q_OBJECT
+
+ public slots:
+ void printMessage(KProcess *proc)
+ {
+ printf("Process %d exited!\n", (int)proc->getPid());
+ }
+
+ void gotOutput(KProcIO*proc)
+ {
+ TQString line;
+ while(true) {
+ int result = proc->readln(line);
+ if (result == -1) return;
+ printf("OUTPUT>> [%d] '%s'\n", result, line.latin1());
+ }
+ }
+
+};
+
+#endif
+
+
diff --git a/tdecore/tests/krandomsequencetest.cpp b/tdecore/tests/krandomsequencetest.cpp
new file mode 100644
index 000000000..8f337c2f1
--- /dev/null
+++ b/tdecore/tests/krandomsequencetest.cpp
@@ -0,0 +1,91 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <tqptrlist.h>
+
+#include "krandomsequence.h"
+#include "kapplication.h"
+
+#include <stdio.h>
+
+int
+main(int argc, char *argv[])
+{
+ KApplication a(argc, argv, "krandomsequencetest");
+
+ long seed;
+ KRandomSequence seq;
+
+ seed = 2;
+ seq.setSeed(seed);printf("Seed = %4ld :", seed);
+ for(int i = 0; i < 20; i++)
+ printf("%3ld ", seq.getLong(100));
+ printf("\n");
+
+ seed = 0;
+ seq.setSeed(seed);printf("Seed = %4ld :", seed);
+ for(int i = 0; i < 20; i++)
+ printf("%3ld ", seq.getLong(100));
+ printf("\n");
+
+ seed = 0;
+ seq.setSeed(seed);printf("Seed = %4ld :", seed);
+ for(int i = 0; i < 20; i++)
+ printf("%3ld ", seq.getLong(100));
+ printf("\n");
+
+ seed = 2;
+ seq.setSeed(seed);printf("Seed = %4ld :", seed);
+ for(int i = 0; i < 20; i++)
+ printf("%3ld ", seq.getLong(100));
+
+ seq.setSeed(kapp->random());
+
+ TQPtrList<TQString> list;
+ list.append(new TQString("A"));
+ list.append(new TQString("B"));
+ list.append(new TQString("C"));
+ list.append(new TQString("D"));
+ list.append(new TQString("E"));
+ list.append(new TQString("F"));
+ list.append(new TQString("G"));
+
+ for(TQString *str = list.first(); str; str = list.next())
+ printf("%s", str->latin1());
+ printf("\n\n");
+
+ seq.randomize(&list);
+
+ for(TQString *str = list.first(); str; str = list.next())
+ printf("%s", str->latin1());
+ printf("\n\n");
+
+ seq.randomize(&list);
+
+ for(TQString *str = list.first(); str; str = list.next())
+ printf("%s", str->latin1());
+ printf("\n\n");
+
+ seq.randomize(&list);
+
+ for(TQString *str = list.first(); str; str = list.next())
+ printf("%s", str->latin1());
+ printf("\n\n");
+
+ printf("\n");
+}
diff --git a/tdecore/tests/kresolvertest.cpp b/tdecore/tests/kresolvertest.cpp
new file mode 100644
index 000000000..1b2f5148d
--- /dev/null
+++ b/tdecore/tests/kresolvertest.cpp
@@ -0,0 +1,420 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (C) 2001 Thiago Macieira <thiago.macieira@kdemail.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include <tqptrlist.h>
+#include <tqstring.h>
+
+#include <kuniqueapplication.h>
+#include <ksocks.h>
+#include <ksockaddr.h>
+#include <kextsock.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+
+#include "netsupp.h"
+
+/*
+ * These constants tell the flags in KDE::resolverFlags
+ * This is copied from ../netsupp.cpp
+ */
+#define KRF_KNOWS_AF_INET6 0x01 /* if present, the code knows about AF_INET6 */
+#define KRF_USING_OWN_GETADDRINFO 0x02 /* if present, we are using our own getaddrinfo */
+#define KRF_USING_OWN_INET_NTOP 0x04 /* if present, we are using our own inet_ntop */
+#define KRF_USING_OWN_INET_PTON 0x08 /* if present, we are using our own inet_pton */
+#define KRF_CAN_RESOLVE_UNIX 0x100 /* if present, the resolver can resolve Unix sockets */
+#define KRF_CAN_RESOLVE_IPV4 0x200 /* if present, the resolver can resolve to IPv4 */
+#define KRF_CAN_RESOLVE_IPV6 0x400 /* if present, the resolver can resolve to IPv6 */
+
+namespace KDE
+{
+ extern const int resolverFlags;
+}
+
+class TestApp : public KUniqueApplication
+{
+public:
+ TestApp() :
+ KUniqueApplication()
+ { }
+
+ int newInstance(TQValueList<TQCString> params);
+};
+
+bool tryLookup(const char* node, const char *serv)
+{
+ int error;
+ TQString _node = TQString::tqfromLatin1(node);
+ TQString _serv = TQString::tqfromLatin1(serv);
+
+ printf("\tTrying to lookup %s|%s... ", node, serv);
+ TQPtrList<KAddressInfo> list = KExtendedSocket::lookup(_node, _serv, 0, &error);
+ list.setAutoDelete(true);
+ if (!list.isEmpty())
+ {
+ printf("worked\n");
+ return true;
+ }
+
+ printf("failed\n\tReason was: %s\n",
+ (const char*)KExtendedSocket::strError(IO_LookupError, error).local8Bit());
+ return false;
+}
+
+#ifdef AF_INET6
+bool try_ntop()
+{
+ char buf[50]; // 46 is enough
+ kde_in6_addr in;
+
+ memset(&in, 0, sizeof(in));
+ ((unsigned char*)&in)[15] = 1; // set this to be ::1
+
+ printf("\tTrying to convert ::1 into string...");
+ if (inet_ntop(AF_INET6, &in, buf, sizeof(buf)) == NULL)
+ {
+ printf("failed\n");
+ return false;
+ }
+
+ printf("suceeded\n\treturned '%s'\n", buf);
+ return strcmp(buf, "::1") == 0;
+}
+
+bool try_pton()
+{
+ const char *buf = "::1";
+ kde_in6_addr in;
+
+ printf("\tTrying to convert '::1' into binary form...");
+ if (inet_pton(AF_INET6, buf, &in) == 0)
+ {
+ printf("failed\n");
+ return false;
+ }
+
+ if (KDE_IN6_IS_ADDR_LOOPBACK(&in))
+ {
+ printf("succeeded\n");
+ return true;
+ }
+
+ printf("claims to have suceeded, but returned invalid value\n");
+ return false;
+}
+#endif
+
+bool tryLookup6(const char *node, const char *serv)
+{
+ int error;
+ TQString _node = TQString::tqfromLatin1(node);
+ TQString _serv = TQString::tqfromLatin1(serv);
+
+ printf("\tTrying to lookup IPv6 of %s|%s... ", node, serv);
+ TQPtrList<KAddressInfo> list = KExtendedSocket::lookup(_node, _serv, KExtendedSocket::ipv6Socket, &error);
+ list.setAutoDelete(true);
+ if (!list.isEmpty())
+ {
+ printf("worked\n");
+ return true;
+ }
+
+ printf("failed\n\tReason was: %s\n",
+ (const char*)KExtendedSocket::strError(IO_LookupError, error).local8Bit());
+ return false;
+}
+
+bool testKernel()
+{
+#ifndef AF_INET6
+ printf("\tAF_INET6 unknown. Can't test anything\n");
+ return false;
+
+#else
+ int sock;
+ kde_sockaddr_in6 sin6;
+ socklen_t len = sizeof(sin6);
+
+ printf("\tAF_INET6 == %d\n", AF_INET6);
+ printf("\tTrying to create an IPv6 socket...");
+ sock = socket(AF_INET6, SOCK_STREAM, 0);
+ if (sock == -1)
+ printf("failed\n\tReason was: %s", strerror(errno));
+ else
+ {
+ printf("succeeded\n");
+
+ if (getsockname(sock, (struct sockaddr*)&sin6, &len) == 0)
+ printf("\tSize of kernel's sockaddr_in6 is %d bytes\n", len);
+ else
+ printf("\tCould not get socket name\n");
+ }
+
+ printf("\tSize of KDE's internal sockaddr_in6 is %d bytes\n",
+ sizeof(kde_sockaddr_in6));
+
+# ifdef HAVE_SOCKADDR_IN6
+ printf("\tSize of system libraries' sockaddr_in6 is %d bytes\n",
+ sizeof(sockaddr_in6));
+# else
+ printf("\tSystem libraries don't define sockaddr_in6\n");
+# endif
+
+ if (sock == -1)
+ return false;
+
+ printf("\tTrying to bind the socket to an address...");
+ sin6.sin6_family = AF_INET6;
+# ifdef HAVE_SOCKADDR_SA_LEN
+ sin6.sin6_len = sizeof(sin6);
+# endif
+ sin6.sin6_flowinfo = 0;
+ sin6.sin6_scope_id = 0;
+ sin6.sin6_port = 0; // bind to any port
+ memset(&sin6.sin6_addr, 0, sizeof(sin6.sin6_addr)); // any address
+
+ if (bind(sock, (sockaddr*)&sin6, sizeof(sin6)) == -1)
+ {
+ printf("failed\n\tReason was: %s\n", strerror(errno));
+ close(sock);
+ return false;
+ }
+
+ printf("succeeded\n");
+
+ KSocketAddress *ksin = KExtendedSocket::localAddress(sock);
+ if (ksin != NULL)
+ {
+ printf("\tWe got socket %s\n", (const char*)ksin->pretty().latin1());
+ delete ksin;
+ }
+
+ close(sock);
+ return true;
+#endif // AF_INET6
+}
+
+bool tryConnectLocal()
+{
+ KExtendedSocket ks1("::", "0", KExtendedSocket::ipv6Socket | KExtendedSocket::passiveSocket),
+ ks2;
+ const KInetSocketAddress *ksin1, *ksin2;
+
+ printf("Attempting a loop-back connection\n\tTrying to listen on socket...");
+ if (ks1.listen() != 0)
+ {
+ printf("failed\n\tReason was: %s\n",
+ (const char*)KExtendedSocket::strError(ks1.status(), ks1.systemError()).local8Bit());
+ return false;
+ }
+
+ ks1.setBlockingMode(false);
+ ksin1 = (KInetSocketAddress*)ks1.localAddress();
+
+ printf("succeeded\n\tWe have socket %s listening\n",
+ (const char*)ksin1->pretty().local8Bit());
+
+ ks2.setAddress("::1", ksin1->port());
+ ks2.setSocketFlags(KExtendedSocket::ipv6Socket | KExtendedSocket::noResolve);
+
+ printf("\tTrying to connect to that socket...");
+ if (ks2.connect() != 0)
+ {
+ printf("failed\n\tReason was: %s\n",
+ (const char*)KExtendedSocket::strError(ks2.status(), ks2.systemError()).local8Bit());
+ return false;
+ }
+
+ printf("suceeded\n");
+
+ ksin2 = dynamic_cast<const KInetSocketAddress *>(ks2.localAddress());
+ printf("\tIf you may flip to another terminal/xterm and run netstat to see\n"
+ "\tthis connection. It should be a connection from %s to %s.\n"
+ "\tPress any key to continue\n",
+ (const char*)ksin2->pretty().local8Bit(), (const char*)ksin1->pretty().local8Bit());
+ getchar();
+ return true;
+}
+
+bool tryConnectRemote()
+{
+ KExtendedSocket ks("www.6bone.net", "80", KExtendedSocket::ipv6Socket);
+
+ printf("\nAttempting a remote connection to www.6bone.net|80\n");
+
+ if (ks.connect() != 0)
+ {
+ printf("\tConnection failed with error: %s\n",
+ (const char*)KExtendedSocket::strError(ks.status(), ks.systemError()).local8Bit());
+ return false;
+ }
+
+ printf("\tConnection succeeded\n");
+ return true;
+}
+
+void go()
+{
+ int rf = KDE::resolverFlags;
+ printf("The resolver claims to:\n");
+ if (rf & KRF_USING_OWN_GETADDRINFO)
+ {
+ printf(" - Be using its own version of getaddrinfo()\n");
+ if (rf & KRF_CAN_RESOLVE_UNIX)
+ printf(" - Be able to resolve Unix-domain sockets\n");
+ else
+ printf(" - Be unable to resolve Unix-domain sockets -- This shouldn't happen\n");
+ if (rf & KRF_CAN_RESOLVE_IPV4)
+ printf(" - Be able to resolve IPv4 Internet sockets\n");
+ else
+ printf(" - Be unable to resolve IPv4 Internet sockets -- This shouldn't happen\n");
+ if (rf & KRF_CAN_RESOLVE_IPV6)
+ printf(" - Be able to resolve IPv6 Internet sockets\n");
+ else
+ printf(" - Be unable to resolve IPv6 Internet sockets\n");
+ }
+ else
+ printf(" - Be using the system getaddrinfo()\n");
+
+ if (rf & KRF_USING_OWN_INET_NTOP)
+ printf(" - Be using its own inet_ntop()\n");
+ else
+ printf(" - Be using the system inet_ntop()\n");
+
+ if (rf & KRF_USING_OWN_INET_PTON)
+ printf(" - Be using its own inet_pton()\n");
+ else
+ printf(" - Be using the system inet_pton()\n");
+
+ if (rf & KRF_KNOWS_AF_INET6)
+ printf(" - To know the value of AF_INET6\n");
+ else
+ printf(" - Not to know the value of AF_INET6\n");
+
+ printf("\n\nGeneral conclusion is:\n");
+ if ((rf & KRF_USING_OWN_GETADDRINFO) == 0 &&
+ rf & KRF_KNOWS_AF_INET6)
+ printf(" Your system probably supports full IPv6 implementation.\n"
+ " This depends on whether your system's getaddrinfo() supports IPv6.\n"
+ " However, KDE Libraries were compiled to use the support whenever available.\n");
+ else if ((rf & (KRF_USING_OWN_GETADDRINFO|KRF_KNOWS_AF_INET6)) == 0)
+ printf(" Your system supports partial IPv6 implementation.\n"
+ " That is, your system has a getaddrinfo() implementation, but KDE Libraries\n"
+ " don't know how to detect an IPv6 socket. That means that only request to"
+ " any kind of socket will use IPv6, if your getaddrinfo() returns them.");
+ else if (rf & KRF_USING_OWN_GETADDRINFO)
+ {
+ if (rf & KRF_KNOWS_AF_INET6)
+ {
+ printf(" Your system supports partial IPv6 implementation.\n");
+ if (rf & KRF_CAN_RESOLVE_IPV6)
+ printf(" The KDE implementation of getaddrinfo() claims to be able to resolve\n"
+ " IPv6 lookups and the value of AF_INET6 is known.\n");
+ else
+ printf(" The KDE implementation of getaddrinfo() cannot resolve IPv6 lookups.\n"
+ " That means that IPv6 support is limited to two addresses (:: and ::1)\n");
+ }
+ else
+ printf(" Your system doesn't support IPv6\n");
+ }
+
+ /* Make sure KSocks doesn't interfere in testing */
+ KSocks::disable();
+
+ /* Begin testing */
+ printf("\nReady to start testing\nPress any key to continue...");
+ getchar();
+ printf("\n");
+
+ /* Start with simple lookups */
+ printf("Trying simple lookups\n"
+ "All of the following look ups should work\n\n");
+ tryLookup(NULL, "/tmp/something");
+ tryLookup("127.0.0.1", "80");
+ tryLookup("localhost", "http");
+
+#ifdef AF_INET6
+ printf("\nPress any key for next test");
+ getchar();
+
+ printf("\nThis test determines if the inet_ntop and inet_pton functions work\n");
+ try_ntop();
+ try_pton();
+#endif
+
+ printf("\nPress any key for next test");
+ getchar();
+
+ printf("\nThis test determines how far the IPv6 resolution can go\n");
+ if (!tryLookup6("::1", "80"))
+ printf("Your system can't resolve a numeric IPv6 address\n");
+ else if (!tryLookup6("localhost", "80"))
+ printf("Your system can resolve a numeric IPv6 address, but not localhost\n");
+ else if (!tryLookup6("www.6bone.net", "80"))
+ printf("Your system can resolve numeric IPv6 addresses and localhost, \n"
+ "but cannot resolve an external address to IPv6 (www.6bone.net)\n");
+ else
+ printf("Your system can resolve any kind of IPv6 addresses\n");
+
+ printf("\nPress any key for next test");
+ getchar();
+
+ printf("\nThis test determines how supported IPv6 is in your kernel\n");
+ testKernel();
+
+ printf("\nPress any key for next test");
+ getchar();
+
+ printf("\nThis test determines if you can connect to IPv6 addresses via TCP\n");
+ tryConnectLocal();
+ tryConnectRemote();
+
+ printf("\n\nTest finished\n");
+}
+
+int TestApp::newInstance(TQValueList<TQCString> /*params*/)
+{
+ go();
+}
+
+int main(int argc, char **argv)
+{
+ KAboutData about("socktest2", "SockTest", "1.0");
+ KCmdLineArgs::init(argc, argv, &about);
+ KUniqueApplication::addCmdLineOptions();
+
+ /* TestApp a;
+ a.exec();*/
+ go();
+}
diff --git a/tdecore/tests/krfcdatetest.cpp b/tdecore/tests/krfcdatetest.cpp
new file mode 100644
index 000000000..368a1106f
--- /dev/null
+++ b/tdecore/tests/krfcdatetest.cpp
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <kapplication.h>
+#include <stdlib.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kcharsets.h>
+#include <tqtextcodec.h>
+#include <krfcdate.h>
+
+bool check(TQString txt, time_t a, time_t b)
+{
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ KApplication app(argc,argv,"kurltest",false,false);
+
+ time_t a;
+ time_t b;
+
+ // From http://www.w3.org/TR/NOTE-datetime
+ b = KRFCDate::parseDateISO8601("1994-11-05T13:15:30Z");
+ a = KRFCDate::parseDateISO8601("1994-11-05T08:15:30-05:00");
+ check( "1994-11-05T08:15:30-05:00", a, b);
+
+ a = KRFCDate::parseDateISO8601("1994-11-05T18:15:30+05:00");
+ check( "1994-11-05T18:15:30+05:00", a, b);
+
+ a = KRFCDate::parseDate("Thu Nov 5 1994 18:15:30 GMT+0500");
+ check( "Thu Nov 5 1994 18:15:30 GMT+0500", a, b);
+
+ a = KRFCDate::parseDate("Thu Nov 5 1994 18:15:30 GMT+05:00");
+ check( "Thu Nov 5 1994 18:15:30 GMT+05:00", a, b);
+
+ a = KRFCDate::parseDate("Wednesday, 05-Nov-94 13:15:30 GMT");
+ check( "Wednesday, 05-Nov-94 13:15:30 GMT", a, b);
+
+ a = KRFCDate::parseDate("Wed, 05-Nov-1994 13:15:30 GMT");
+ check( "Wed, 05-Nov-1994 13:15:30 GMT", a, b);
+
+ a = KRFCDate::parseDate("Wed, 05-November-1994 13:15:30 GMT");
+ check( "Wed, 05-November-1994 13:15:30 GMT", a, b);
+
+ b = KRFCDate::parseDateISO8601("1994-01-01T12:00:00");
+ a = KRFCDate::parseDateISO8601("1994");
+ check( "1994", a, b );
+
+ a = KRFCDate::parseDateISO8601("1994-01");
+ check( "1994-01", a, b );
+
+ a = KRFCDate::parseDateISO8601("1994-01-01");
+ check( "1994-01-01", a, b );
+
+ b = 0;
+
+ // pass RFC date to ISO parser
+ a = KRFCDate::parseDateISO8601("Thu, 01 Jan 2004 19:48:21 GMT");
+ check("pass RFC date \"Thu, 01 Jan 2004 19:48:21 GMT\" to parseDateISO8601", a, b);
+
+ // pass ISO date to RFC parser
+ a = KRFCDate::parseDate("1994-01-01T12:00:00");
+ check("pass ISO date \"1994-01-01T12:00:00\" to parseDate()", a, b);
+
+ // empty/null strings
+
+ check("parseDateISO8601(TQString())", KRFCDate::parseDateISO8601(TQString()), b);
+ check("parseDateISO8601(\"\")", KRFCDate::parseDateISO8601(""), b);
+ check("parseDate(TQString())", KRFCDate::parseDate(TQString()), b);
+ check("parseDate(\"\")", KRFCDate::parseDate(""), b);
+
+ printf("\nTest OK !\n");
+}
+
diff --git a/tdecore/tests/kshelltest.cpp b/tdecore/tests/kshelltest.cpp
new file mode 100644
index 000000000..394394e28
--- /dev/null
+++ b/tdecore/tests/kshelltest.cpp
@@ -0,0 +1,55 @@
+#include <kshell.h>
+
+#include <iostream>
+
+static QCString
+ps(const TQString &s)
+{
+ if (s.isNull())
+ return "(null)";
+ else
+ return s.local8Bit();
+}
+
+static void
+tx(const char *t)
+{
+ std::cout << t << " -> " << ps(KShell::tildeExpand(t)) << std::endl;
+}
+
+static void
+sj(const char *t, int flg)
+{
+ int err;
+ std::cout << t << " (" << flg << ") -> " << ps(KShell::joinArgsDQ(KShell::splitArgs(t, flg, &err))) << " (" << err << ")" << std::endl;
+}
+
+int main()
+{
+#if 1
+ tx("~");
+ tx("~/sulli");
+ tx("~root");
+ tx("~root/sulli");
+ tx("~sulli");
+#endif
+#if 1
+ TQStringList lst;
+ lst << "this" << "is" << "text";
+ std::cout << KShell::joinArgs(lst).latin1() << std::endl;
+#endif
+#if 1
+ sj("\"~sulli\" 'text' 'jo'\"jo\" $'crap' $'\\\\\\'\\ca\\e\\x21' ha\\ lo ", KShell::NoOptions);
+ sj("\"~sulli\" 'text'", KShell::TildeExpand);
+ sj("~\"sulli\" 'text'", KShell::TildeExpand);
+ sj("~/\"sulli\" 'text'", KShell::TildeExpand);
+ sj("~ 'text' ~", KShell::TildeExpand);
+ sj("~sulli ~root", KShell::TildeExpand);
+#endif
+ sj("say \" error", KShell::NoOptions);
+ sj("say `echo no error`", KShell::NoOptions);
+ sj("say \" still error", KShell::AbortOnMeta);
+ sj("say `echo meta error`", KShell::AbortOnMeta);
+ sj("BLA=say echo meta", KShell::AbortOnMeta);
+ sj("B\"L\"A=say FOO=bar echo meta", KShell::AbortOnMeta);
+}
diff --git a/tdecore/tests/ksimpleconfigtest.cpp b/tdecore/tests/ksimpleconfigtest.cpp
new file mode 100644
index 000000000..6aa93c06d
--- /dev/null
+++ b/tdecore/tests/ksimpleconfigtest.cpp
@@ -0,0 +1,48 @@
+// $Id$
+
+//
+// configtest.cpp: libKDEcore example
+//
+// demonstrates use of KSimpleConfig class
+
+#include <ksimpleconfig.h>
+#include <kapplication.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif
+
+#ifndef _PATH_TMP
+#define _PATH_TMP "/tmp/"
+#endif
+
+int main( int argc, char **argv )
+{
+ KApplication a( argc, argv, "kconfigtest" );
+
+ KSimpleConfig aConfig( _PATH_TMP"/simpleconfig.cfg" );
+
+ aConfig.setGroup( "Test group" );
+ aConfig.writeEntry( "key1", "value1" );
+ aConfig.writeEntry( "key2", "value2" );
+
+ aConfig.setGroup( "Another Test group" );
+ aConfig.writeEntry( "akey1", "avalue1" );
+ aConfig.writeEntry( "akey2", "avalue2" );
+
+ fprintf( stderr, "entries written, sleeping for 10 seconds\n" );
+ aConfig.sync();
+ sleep( 10 );
+
+ aConfig.setGroup( "Test group" );
+ aConfig.deleteEntry( "key2", false );
+ fprintf( stderr, "Deleted on entry from Test group, sleeping\n" );
+ aConfig.sync();
+ sleep( 10 );
+
+ aConfig.deleteGroup( "Another Test group", true );
+ fprintf( stderr, "Deleted Another Test group\n" );
+}
+
diff --git a/tdecore/tests/ksocktest.cpp b/tdecore/tests/ksocktest.cpp
new file mode 100644
index 000000000..042701c93
--- /dev/null
+++ b/tdecore/tests/ksocktest.cpp
@@ -0,0 +1,109 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kuniqueapplication.h"
+#include "kglobal.h"
+#include "kdebug.h"
+#include "ksock.h"
+#include "ksockaddr.h"
+#include "kextsock.h"
+
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+bool check(TQString txt, TQString a, TQString b)
+{
+ if (a.isEmpty())
+ a = TQString::null;
+ if (b.isEmpty())
+ b = TQString::null;
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ KAboutData about("socktest", "SockTest", "version");
+ KCmdLineArgs::init(argc, argv, &about);
+ KApplication::addCmdLineOptions();
+
+ KApplication app;
+
+ TQString host, port;
+
+ KInetSocketAddress host_address("213.203.58.36", 80);
+
+ check("KInetSocketAddress(\"213.203.58.36\", 80)", host_address.pretty(), "213.203.58.36 port 80");
+
+ int result = KExtendedSocket::resolve(&host_address, host, port, NI_NAMEREQD);
+ printf( "resolve result: %d\n", result );
+ check("KExtendedSocket::resolve() host=", host, "www.kde.org");
+// check("KExtendedSocket::resolve() port=", port, "http");
+ TQPtrList<KAddressInfo> list;
+ list = KExtendedSocket::lookup("www.kde.org", "http", KExtendedSocket::inetSocket);
+ for(KAddressInfo *info = list.first(); info; info = list.next())
+ {
+ qWarning("Lookup: %s %s %s", info->address()->pretty().latin1(),
+ info->address()->isEqual(KInetSocketAddress("213.203.58.36", 80)) ?
+ "is equal to" : "is NOT equal to",
+ "213.203.58.36 port 80");
+ }
+ check("KExtendedSocket::lookup()", list.first()->address()->pretty(), "213.203.58.36 port 80");
+
+
+
+ int err;
+
+ TQPtrList<KAddressInfo> cns = KExtendedSocket::lookup("www.kde.org", 0, KExtendedSocket::canonName, &err);
+ for (KAddressInfo *x = cns.first(); x; x = cns.next()) {
+ const char *canon = x->canonname();
+ qWarning( "Lookup: %s", canon ? canon : "<Null>");
+ }
+ check("KExtendedSocket::lookup() canonical", cns.first()->canonname(), "www.kde.org");
+
+ KExtendedSocket * sock2 = new KExtendedSocket( "www.kde.org", 80 );
+ check( "KExtendedSocket ctor / connect", TQString::number( sock2->connect() ), "0" );
+
+ printf("FD %d\n", sock2->fd());
+
+ KSocketAddress* addr = KExtendedSocket::peerAddress( sock2->fd() );
+ check( "peerAddress:", addr->nodeName().latin1(), "213.203.58.36" );
+
+ check( "isEqual:", addr->isEqual(KInetSocketAddress("213.203.58.36", 80)) ? "TRUE" : "FALSE", "TRUE");
+ check( "isEqual:", addr->isEqual(KInetSocketAddress("213.203.58.36", 8080)) ? "TRUE" : "FALSE", "FALSE");
+ check( "isEqual:", addr->isCoreEqual(KInetSocketAddress("213.203.58.36", 8080)) ? "TRUE" : "FALSE", "TRUE");
+}
diff --git a/tdecore/tests/ksortablevaluelisttest.cpp b/tdecore/tests/ksortablevaluelisttest.cpp
new file mode 100644
index 000000000..301054045
--- /dev/null
+++ b/tdecore/tests/ksortablevaluelisttest.cpp
@@ -0,0 +1,32 @@
+#include <tqstring.h>
+#include <ksortablevaluelist.h>
+
+int main( int argc, char **argv )
+{
+ KSortableValueList<TQString> list;
+ list.insert( 1, "FOO (1)" );
+ list.insert( 2, "Test (2)" );
+ list.insert( 1, "Huba! (1)" );
+ list.insert( 5, "MAAOOAM! (5)" );
+ list.insert( 10, "Teeheeest (10)" );
+ list.insert( 2, "I was here :) (2)" );
+ list.insert( 4, "Yeehaa... (4)" );
+
+ TQValueListIterator<KSortableItem<TQString> > it = list.begin();
+
+ qDebug("Insertion order:");
+ qDebug("================");
+ for ( ; it != list.end(); ++it )
+ qDebug( "%i: %s", (*it).index(), (*it).value().latin1() );
+
+ list.sort();
+
+ qDebug("\nSorted:");
+ qDebug("=======");
+
+ it = list.begin();
+ for ( ; it != list.end(); ++it )
+ qDebug( "%i: %s", (*it).index(), (*it).value().latin1() );
+
+ return 0;
+}
diff --git a/tdecore/tests/kstdacceltest.cpp b/tdecore/tests/kstdacceltest.cpp
new file mode 100644
index 000000000..ff8842139
--- /dev/null
+++ b/tdecore/tests/kstdacceltest.cpp
@@ -0,0 +1,39 @@
+#include <config.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kstdaccel.h>
+#include <stdlib.h> // for exit
+
+static bool check(TQString txt, TQString a, TQString b)
+{
+ if (a.isEmpty())
+ a = TQString::null;
+ if (b.isEmpty())
+ b = TQString::null;
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ KApplication::disableAutoDcopRegistration();
+ KApplication app(argc,argv,"kstdacceltest",false,false);
+
+ check( "shortcutDefault FullScreen", KStdAccel::shortcutDefault( KStdAccel::FullScreen ).toString(), "Ctrl+Shift+F" );
+ check( "shortcutDefault BeginningOfLine", KStdAccel::shortcutDefault( KStdAccel::BeginningOfLine ).toString(), "Home" );
+ check( "shortcutDefault EndOfLine", KStdAccel::shortcutDefault( KStdAccel::EndOfLine ).toString(), "End" );
+
+ check( "name BeginningOfLine", KStdAccel::name( KStdAccel::BeginningOfLine ), "BeginningOfLine" );
+ check( "name EndOfLine", KStdAccel::name( KStdAccel::EndOfLine ), "EndOfLine" );
+
+ check( "shortcut method", KStdAccel::shortcut( KStdAccel::ZoomIn ).toString(), KStdAccel::zoomIn().toString() );
+
+ return 0;
+}
diff --git a/tdecore/tests/kstddirstest.cpp b/tdecore/tests/kstddirstest.cpp
new file mode 100644
index 000000000..fa797d665
--- /dev/null
+++ b/tdecore/tests/kstddirstest.cpp
@@ -0,0 +1,52 @@
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kinstance.h>
+#include <kstandarddirs.h>
+#include <kconfig.h>
+
+int main(int argc, char **argv)
+{
+ KApplication a(argc, argv, "whatever", false);
+ KStandardDirs t;
+ KConfig config; // to add custom entries - a bit tricky :/
+
+ TQStringList list;
+ TQString s;
+
+ t.saveLocation("icon");
+
+ s = t.findResource("icon", "xv.xpm");
+ if (!s.isNull()) kdDebug() << s << endl;
+
+ list = t.findAllResources("data", "kfind/toolbar", true);
+ for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+ kdDebug() << "data " << (*it).ascii() << endl;
+ }
+
+ list = t.findAllResources("config", "kcmdisplayrc");
+ for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+ kdDebug() << "config " << (*it).ascii() << endl;
+ }
+
+ list = t.findAllResources("config", "kcmdisplayrc", false, true);
+ for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+ kdDebug() << "config2 " << (*it).ascii() << endl;
+ }
+
+ list = t.findAllResources("html", "en/*/index.html", false);
+ for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+ kdDebug() << "docs " << (*it).ascii() << endl;
+ }
+
+ list = t.findAllResources("html", "*/*/*.html", false);
+ for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+ kdDebug() << "docs " << (*it).ascii() << endl;
+ }
+
+ list = t.findDirs("data", "kwin");
+ for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+ kdDebug() << "kwin dirs " << (*it).ascii() << endl;
+ }
+
+ kdDebug() << "hit " << t.findResourceDir("config", "kcmdisplayrc") << endl;
+}
diff --git a/tdecore/tests/kstringhandlertest.cpp b/tdecore/tests/kstringhandlertest.cpp
new file mode 100644
index 000000000..2efdc96fc
--- /dev/null
+++ b/tdecore/tests/kstringhandlertest.cpp
@@ -0,0 +1,97 @@
+#include "kstringhandler.h"
+#include <iostream>
+using std::cout;
+using std::endl;
+
+bool check(const TQString &txt, const TQString &a, const TQString &b)
+{
+ if ( a != b ) {
+ cout << "ERROR: Tested " << txt.latin1() << ", expected" << endl;
+ cout << "'" << b.latin1() << "' (" << b.length() << " chars)" << endl;
+ cout << "but got" << endl;
+ cout << "'" << a.latin1() << "' (" << a.length() << " chars)" << endl;
+ exit( 1 );
+ }
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ TQString test = "The quick brown fox jumped over the lazy bridge. ";
+
+ check("word(test, 3)",
+ KStringHandler::word(test, 2),
+ "brown");
+ check("word(test, \"3:5\")",
+ KStringHandler::word(test, "2:4"),
+ "brown fox jumped");
+ check("insword(test, \"very\", 1)",
+ KStringHandler::insword(test, "very", 1),
+ "The very quick brown fox jumped over the lazy bridge. ");
+ check("setword(test, \"very\", 1)",
+ KStringHandler::setword(test, "very", 1),
+ "The very brown fox jumped over the lazy bridge. ");
+ check("remrange(test, \"4:6\")",
+ KStringHandler::remrange(test, "4:6"),
+ "The quick brown fox lazy bridge. " );
+ check("remrange(test, \"4:8\")",
+ KStringHandler::remrange(test, "4:8"),
+ "The quick brown fox ");
+ check("remword(test, 4)",
+ KStringHandler::remword(test, 4),
+ "The quick brown fox over the lazy bridge. ");
+ check("remword(test, \"lazy\")",
+ KStringHandler::remword(test, "lazy"),
+ "The quick brown fox jumped over the bridge. ");
+ check("capwords(test)",
+ KStringHandler::capwords(test),
+ "The Quick Brown Fox Jumped Over The Lazy Bridge. ");
+ check("reverse(test)",
+ KStringHandler::reverse(test),
+ " bridge. lazy the over jumped fox brown quick The");
+ TQString result;
+ result = KStringHandler::ljust(test, 70);
+ if (result.length() != 70)
+ {
+ printf("Length = %d, expected 70.\n", result.length());
+ exit(1);
+ }
+ check("ljust(test, 70)",
+ result,
+ "The quick brown fox jumped over the lazy bridge. ");
+ result = KStringHandler::rjust(test, 70);
+ if (result.length() != 70)
+ {
+ printf("Length = %d, expected 70.\n", result.length());
+ exit(1);
+ }
+ check("rjust(test, 70)",
+ result,
+ " The quick brown fox jumped over the lazy bridge.");
+ result = KStringHandler::center(test, 70);
+ if (result.length() != 70)
+ {
+ printf("Length = %d, expected 70.\n", result.length());
+ exit(1);
+ }
+ check("center(test, 70)",
+ result,
+ " The quick brown fox jumped over the lazy bridge. ");
+
+ test = "Click on http://foo@bar:www.kde.org/yoyo/dyne.html#a1 for info.";
+ check( "tagURLs()", KStringHandler::tagURLs( test ),
+ "Click on <a href=\"http://foo@bar:www.kde.org/yoyo/dyne.html#a1\">http://foo@bar:www.kde.org/yoyo/dyne.html#a1</a> for info." );
+
+ test = "http://www.foo.org/story$806";
+ check( "tagURLs()", KStringHandler::tagURLs( test ),
+ "<a href=\"http://www.foo.org/story$806\">http://www.foo.org/story$806</a>" );
+
+#if 0
+ // XFAIL - i.e. this needs to be fixed, but has never been
+ test = "&lt;a href=www.foo.com&gt;";
+ check( "tagURLs()", KStringHandler::tagURLs( test ),
+ "&lt;a href=<a href=\"www.foo.com\">www.foo.com</a>&gt;" );
+#endif
+
+ cout << "All OK!" << endl;
+}
diff --git a/tdecore/tests/ktempfiletest.cpp b/tdecore/tests/ktempfiletest.cpp
new file mode 100644
index 000000000..60404f03a
--- /dev/null
+++ b/tdecore/tests/ktempfiletest.cpp
@@ -0,0 +1,48 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "ktempfile.h"
+#include "kapplication.h"
+#include "kstandarddirs.h"
+#include <tqstring.h>
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, char *argv[])
+{
+ KApplication a(argc, argv, "ktempfiletest");
+ printf("Making tempfile after KApplication constructor.\n");
+ KTempFile f4;
+ printf("Filename = %s\n", f4.name().ascii());
+
+ printf("Making tempfile with \".ps\" extension.\n");
+ KTempFile f2(TQString::null, ".ps");
+ printf("Filename = %s\n", f2.name().ascii());
+
+ printf("Making tempfile in home directory.\n");
+ KTempFile f3(TQString((const char *)getenv("HOME"))+"/testXXX", ".myEXT", 0666);
+ printf("Filename = %s\n", f3.name().ascii());
+
+ TQString name = locateLocal("socket", "test");
+ printf("Socket Filename = %s\n", name.ascii());
+
+ printf("Done.\n");
+}
diff --git a/tdecore/tests/ktimezonestest.cpp b/tdecore/tests/ktimezonestest.cpp
new file mode 100644
index 000000000..69ea7c8a1
--- /dev/null
+++ b/tdecore/tests/ktimezonestest.cpp
@@ -0,0 +1,62 @@
+#include "ktimezones.h"
+#include <kapplication.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+ KInstance instance("ktimezonestest");
+
+ if ((argc==2) && (strcmp(argv[1], "local")==0))
+ {
+ KTimezones timezones;
+
+ // Find the local timezone.
+ const KTimezone *timezone = timezones.local();
+ printf( "Local timezone: %s\n", timezone->name().latin1() );
+
+ // Find the current offset of the UTC timezone.
+ timezone = timezones.zone("UTC");
+ printf( "UTC timezone offset should be 0: %d\n", timezone->offset(TQDateTime::tqcurrentDateTime()) );
+
+ // Find some offsets for Europe/London.
+ char *london = "Europe/London";
+ timezone = timezones.zone(london);
+ TQDateTime winter(TQDateTime::fromString("2005-01-01T00:00:00", Qt::ISODate));
+ TQDateTime summer(TQDateTime::fromString("2005-06-01T00:00:00", Qt::ISODate));
+ printf( "%s winter timezone offset should be 0: %d\n", london, timezone->offset(winter) );
+ printf( "%s summer timezone offset should be 3600: %d\n", london, timezone->offset(summer) );
+
+ // Try timezone conversions.
+ const KTimezone *losAngeles = timezones.zone("America/Los_Angeles");
+ char *bstBeforePdt = "2005-03-28T00:00:00";
+ char *bstAfterPdt = "2005-05-01T00:00:00";
+ char *gmtBeforePst = "2005-10-30T01:00:00";
+ char *gmtAfterPst = "2005-12-01T00:00:00";
+ TQString result;
+ result = timezone->convert(losAngeles, TQDateTime::fromString(bstBeforePdt, Qt::ISODate)).toString(Qt::ISODate);
+ printf( "BST before PDT, %s should be 2005-03-27T15:00:00: %s\n", bstBeforePdt, result.latin1() );
+ result = timezone->convert(losAngeles, TQDateTime::fromString(bstAfterPdt, Qt::ISODate)).toString(Qt::ISODate);
+ printf( "BST and PDT, %s should be 2005-04-30T16:00:00: %s\n", bstAfterPdt, result.latin1() );
+ result = timezone->convert(losAngeles, TQDateTime::fromString(gmtBeforePst, Qt::ISODate)).toString(Qt::ISODate);
+ printf( "GMT before PST, %s should be 2005-10-29T17:00:00: %s\n", gmtBeforePst, result.latin1() );
+ result = timezone->convert(losAngeles, TQDateTime::fromString(gmtAfterPst, Qt::ISODate)).toString(Qt::ISODate);
+ printf( "GMT and PST, %s should be 2005-11-30T16:00:00: %s\n", gmtAfterPst, result.latin1() );
+ printf( "Latitude 89 should be valid: %svalid\n", KTimezone::isValidLatitude(89.0) ? "" : "in");
+ printf( "Latitude 91 should be invalid: %svalid\n", KTimezone::isValidLatitude(91.0) ? "" : "in");
+ printf( "Longitude 179 should be valid: %svalid\n", KTimezone::isValidLongitude(179.0) ? "" : "in");
+ printf( "Longitude 181 should be valid: %svalid\n", KTimezone::isValidLongitude(181.0) ? "" : "in");
+ return 0;
+ }
+
+ if ((argc==2) && (strcmp(argv[1], "all")==0))
+ {
+ KTimezones timezones;
+ KTimezones::ZoneMap allZones = timezones.allZones();
+ for ( KTimezones::ZoneMap::const_iterator it = allZones.begin(), end = allZones.end(); it != end; ++it )
+ printf( "%s\n", it.key().latin1() );
+ }
+
+ printf( "Usage: ktimezonestest [local|all]!\n" );
+ return 1;
+}
diff --git a/tdecore/tests/kuniqueapptest.cpp b/tdecore/tests/kuniqueapptest.cpp
new file mode 100644
index 000000000..699c99539
--- /dev/null
+++ b/tdecore/tests/kuniqueapptest.cpp
@@ -0,0 +1,59 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kuniqueapplication.h"
+#include "kglobalsettings.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+
+class TestApp : public KUniqueApplication
+{
+public:
+ TestApp() : KUniqueApplication("TestApp") { }
+ virtual int newInstance( );
+};
+
+
+int
+TestApp::newInstance( )
+{
+ qWarning("NewInstance");
+ return 0;
+}
+
+int
+main(int argc, char *argv[])
+{
+ KAboutData about("kuniqueapptest", "kuniqueapptest", "version");
+ KCmdLineArgs::init(argc, argv, &about);
+ KUniqueApplication::addCmdLineOptions();
+
+ if (!TestApp::start())
+ {
+ exit(0);
+ }
+ TestApp a;
+
+ printf("Running.\n");
+ kapp->exec();
+ printf("Terminating.\n");
+}
diff --git a/tdecore/tests/kurltest.cpp b/tdecore/tests/kurltest.cpp
new file mode 100644
index 000000000..c8e5bcced
--- /dev/null
+++ b/tdecore/tests/kurltest.cpp
@@ -0,0 +1,1124 @@
+#include <config.h>
+
+#include <kurl.h>
+#include <stdio.h>
+#include <kapplication.h>
+#include <stdlib.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kcharsets.h>
+#include <tqtextcodec.h>
+#include <tqdatastream.h>
+#include <assert.h>
+#include <kcmdlineargs.h>
+
+static bool check(TQString txt, TQString a, TQString b)
+{
+ if (a.isEmpty())
+ a = TQString::null;
+ if (b.isEmpty())
+ b = TQString::null;
+ if (a == b) {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
+ }
+ else {
+ kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
+ exit(1);
+ }
+ return true;
+}
+
+void testAdjustPath()
+{
+ KURL url1("file:///home/kde/");
+ url1.adjustPath(0);
+ check( "adjustPath(0)", url1.path(), "/home/kde/" );
+ url1.adjustPath(-1);
+ check( "adjustPath(-1) removes last slash", url1.path(), "/home/kde" );
+ url1.adjustPath(-1);
+ check( "adjustPath(-1) again", url1.path(), "/home/kde" );
+ url1.adjustPath(1);
+ check( "adjustPath(1)", url1.path(), "/home/kde/" );
+
+ KURL url2("file:///home/kde//");
+ url2.adjustPath(0);
+ check( "adjustPath(0)", url2.path(), "/home/kde//" );
+ url2.adjustPath(-1);
+ check( "adjustPath(-1) removes all trailing slashes", url2.path(), "/home/kde" );
+ url2.adjustPath(1);
+ check( "adjustPath(1)", url2.path(), "/home/kde/" );
+
+ KURL ftpurl1("ftp://ftp.kde.org/");
+ ftpurl1.adjustPath(0);
+ check( "adjustPath(0)", ftpurl1.path(), "/" );
+ ftpurl1.adjustPath(-1);
+ check( "adjustPath(-1) preserves last slash", ftpurl1.path(), "/" );
+
+ KURL ftpurl2("ftp://ftp.kde.org///");
+ ftpurl2.adjustPath(0);
+ check( "adjustPath(0)", ftpurl2.path(), "///" );
+ ftpurl2.adjustPath(-1);
+ check( "adjustPath(-1) removes all but last slash", ftpurl2.path(), "/" );
+ ftpurl2.adjustPath(1);
+ check( "adjustPath(1)", ftpurl2.path(), "/" );
+
+ // Equivalent tests written by the KDirLister maintainer :)
+
+ KURL u3( TQCString("ftp://brade@ftp.kde.org///") );
+ u3.adjustPath(-1);
+ check("KURL::adjustPath()", u3.url(), "ftp://brade@ftp.kde.org/");
+
+ KURL u4( TQCString("ftp://brade@ftp.kde.org/kde///") );
+ u4.adjustPath(-1);
+ check("KURL::adjustPath()", u4.url(), "ftp://brade@ftp.kde.org/kde");
+
+ // applying adjustPath(-1) twice should not yield two different urls
+ // (follows from the above test)
+ KURL u5 = u4;
+ u5.adjustPath(-1);
+ check("KURL::adjustPath()", u5.url(), u4.url());
+}
+
+int main(int argc, char *argv[])
+{
+ KApplication::disableAutoDcopRegistration();
+ KCmdLineArgs::init( argc, argv, "kurltest", 0, 0, 0, 0 );
+ KApplication app( false, false );
+
+ KURL::List lst;
+
+ KURL emptyURL;
+ check( "KURL::isMalformed()", emptyURL.isMalformed() ? "TRUE":"FALSE", "TRUE");
+ check( "KURL::isValid()", emptyURL.isValid() ? "TRUE":"FALSE", "FALSE");
+ check( "KURL::isEmpty()", emptyURL.isEmpty() ? "TRUE":"FALSE", "TRUE");
+ check( "prettyURL()", emptyURL.prettyURL(), "");
+ check( "isLocalFile()", emptyURL.isLocalFile()?"TRUE":"FALSE", "FALSE" );
+
+ emptyURL = "";
+ check( "KURL::isMalformed()", emptyURL.isMalformed() ? "TRUE":"FALSE", "TRUE");
+ check( "KURL::isValid()", emptyURL.isValid() ? "TRUE":"FALSE", "FALSE");
+ check( "KURL::isEmpty()", emptyURL.isEmpty() ? "TRUE":"FALSE", "TRUE");
+
+ KURL fileURL = "file:/";
+ check( "KURL::isEmpty()", fileURL.isEmpty() ? "TRUE":"FALSE", "FALSE");
+
+ fileURL = "file:///";
+ check( "KURL::isEmpty()", fileURL.isEmpty() ? "TRUE":"FALSE", "FALSE");
+
+ KURL baseURL ("hTTp://www.foo.bar:80" );
+ check( "KURL::isValid()", baseURL.isValid() ? "TRUE":"FALSE", "TRUE");
+ check( "KURL::protocol()", baseURL.protocol(), "http"); // lowercase
+ KURL url1 ( baseURL, "//www1.foo.bar" );
+ check( "KURL::host()", url1.host(), "www1.foo.bar");
+ check( "KURL::url()", url1.url(), "http://www1.foo.bar");
+
+ baseURL = "http://www.Abc.de";
+ check( "KURL::host() is lowercase", baseURL.host(), "www.abc.de");
+ baseURL = "donkey://Abc/DE";
+ check( "KURL::host() is lowercase", baseURL.host(), "abc");
+
+ baseURL = "http://www.foo.bar";
+ KURL rel_url( baseURL, "/top//test/../test1/file.html" );
+ check( "KURL::url()", rel_url.url(), "http://www.foo.bar/top//test1/file.html" );
+
+
+ baseURL = "http://www.foo.bar/top//test2/file2.html";
+ check( "KURL::url()", baseURL.url(), "http://www.foo.bar/top//test2/file2.html" );
+
+ baseURL = "file:/usr/local/src/kde2/////kdelibs/kio";
+ check( "KURL::url()", baseURL.url(), "file:///usr/local/src/kde2/////kdelibs/kio" );
+
+ baseURL = "http://www.foo.bar";
+ KURL rel_url2( baseURL, "mailto:bastian@kde.org" );
+ check( "KURL::url()", rel_url2.url(), "mailto:bastian@kde.org" );
+
+ baseURL = "mailto:bastian@kde.org?subject=hello";
+ check( "KURL::url()", baseURL.url(), "mailto:bastian@kde.org?subject=hello" );
+
+ baseURL = "file:/usr/local/src/kde2/kdelibs/kio/";
+ KURL url2( baseURL, "../../////kdebase/konqueror" );
+ check( "KURL::url()", url2.url(), "file:///usr/local/src/kde2/////kdebase/konqueror" );
+
+ TQString u1 = "file:/home/dfaure/my#myref";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my#myref");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
+ check("KURL::htmlRef()", url1.htmlRef(), "myref");
+ check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
+
+ u1 = "file:/home/dfaure/my#%2f";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my#%2f");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
+ check("KURL::encodedHtmlRef()", url1.ref(), "%2f");
+ check("KURL::htmlRef()", url1.htmlRef(), "/");
+
+ url1 = KURL(url1, "#%6a");
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my#%6a");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
+ check("KURL::encodedHtmlRef()", url1.ref(), "%6a");
+ check("KURL::htmlRef()", url1.htmlRef(), "j");
+
+ KURL dxOffEagle( KURL("http://something/other.html"), "newpage.html?[{\"foo: bar\"}]" );
+ check("isValid", dxOffEagle.isValid() ? "OK" : "KO", "OK");
+ check("url", dxOffEagle.url(), TQString("http://something/newpage.html?[{\"foo:%20bar\"}]") );
+
+ KURL javascript( KURL("javascript:window.location+\"__flashplugin_unique__\"") );
+ check("isValid", javascript.isValid() ? "OK" : "KO", "OK");
+ check("url", javascript.url(), TQString("javascript:window.location+\"__flashplugin_unique__\"") );
+
+
+ u1 = "file:///home/dfaure/my#myref";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my#myref");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
+ check("KURL::htmlRef()", url1.htmlRef(), "myref");
+ check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
+
+ url1 = "gg:www.kde.org";
+ check("KURL::isValid()", url1.isValid()?"TRUE":"FALSE", "TRUE" );
+
+ url1= "KDE";
+ check("KURL::isValid()", url1.isValid()?"TRUE":"FALSE", "FALSE" );
+
+ url1= "$HOME/.kde/share/config";
+ check("KURL::isValid()", url1.isValid()?"TRUE":"FALSE", "FALSE" );
+
+ u1 = "file:/opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::htmlRef()", url1.htmlRef(), "TQObject::connect");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
+ check("KURL::upURL()", url1.upURL().url(), "file:///opt/kde2/qt2/doc/html/");
+
+ url1 = KURL( TQCString( "http://www.kde.org/foo.cgi?foo=bar" ) );
+ check("query", url1.query(), "?foo=bar" );
+ url1.setQuery( "toto=titi&kde=rocks" );
+ check("query", url1.query(), "?toto=titi&kde=rocks" );
+ url1.setQuery( "?kde=rocks&a=b" );
+ check("query", url1.query(), "?kde=rocks&a=b" );
+ url1.setQuery( "?" );
+ check("setQuery(\"?\") -> query", url1.query(), "?" );
+ url1.setQuery( "" );
+ check("setQuery(\"\") -> query", url1.query(), "?" );
+ url1.setQuery( TQString::null );
+ check("setQuery(TQString::null) -> query", url1.query(), TQString::null );
+
+ u1 = "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::htmlRef()", url1.htmlRef(), "TQObject::connect");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
+ check("KURL::upURL()", url1.upURL().url(), "file:///opt/kde2/qt2/doc/html/");
+
+ u1 = "file:/opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject:connect";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject:connect");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::htmlRef()", url1.htmlRef(), "TQObject:connect");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
+ check("KURL::upURL()", url1.upURL().url(), "file:///opt/kde2/qt2/doc/html/");
+
+ u1 = "file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/#myref";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/#myref");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::isLocalFile()", url1.isLocalFile() ? "yes" : "no", "no"); // Not strictly local!
+ //check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
+ //check("KURL::htmlRef()", url1.htmlRef(), "myref");
+ check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
+
+ u1 = "error:/?error=14&errText=Unknown%20host%20asdfu.adgi.sdfgoi#http://asdfu.adgi.sdfgoi";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "error:/?error=14&errText=Unknown%20host%20asdfu.adgi.sdfgoi#http://asdfu.adgi.sdfgoi");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::isLocalFile()", url1.isLocalFile() ? "yes" : "no", "no");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
+ //check("KURL::htmlRef()", url1.htmlRef(), "myref");
+
+ u1 = "file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
+ check("KURL::htmlRef()", url1.htmlRef(), "");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
+ check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
+
+ u1 = "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
+ check("KURL::htmlRef()", url1.htmlRef(), "");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
+ check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
+
+#if 0
+// This URL is broken, '#' should be escaped.
+ u1 = "file:/home/dfaure/cdrdao-1.1.5/dao/#CdrDriver.cc#";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/cdrdao-1.1.5/dao/#CdrDriver.cc#");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "no");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
+ check("KURL::htmlRef()", url1.htmlRef(), "");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
+ check("KURL::prettyURL()", url1.upURL().url(), "file:///home/dfaure/cdrdao-1.1.5/dao/#CdrDriver.cc#");
+#endif
+
+ u1 = "file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/README";
+ url1 = u1;
+ check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/README");
+ check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
+ check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
+ check("KURL::htmlRef()", url1.htmlRef(), "");
+ check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
+ check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/");
+
+ KURL notPretty("http://ferret.lmh.ox.ac.uk/%7Ekdecvs/");
+ check("KURL::prettyURL()", notPretty.prettyURL(), "http://ferret.lmh.ox.ac.uk/~kdecvs/");
+ KURL notPretty2("file:/home/test/directory%20with%20spaces");
+ check("KURL::prettyURL()", notPretty2.prettyURL(), "file:///home/test/directory with spaces");
+ KURL notPretty3("fish://foo/%23README%23");
+ check("KURL::prettyURL()", notPretty3.prettyURL(), "fish://foo/%23README%23");
+ KURL url15581("http://alain.knaff.linux.lu/bug-reports/kde/spaces in url.html");
+ check("KURL::prettyURL()", url15581.prettyURL(), "http://alain.knaff.linux.lu/bug-reports/kde/spaces in url.html");
+ check("KURL::url()", url15581.url(), "http://alain.knaff.linux.lu/bug-reports/kde/spaces%20in%20url.html");
+ KURL url15582("http://alain.knaff.linux.lu/bug-reports/kde/percentage%in%url.html");
+ check("KURL::prettyURL()", url15582.prettyURL(), "http://alain.knaff.linux.lu/bug-reports/kde/percentage%in%url.html");
+ check("KURL::url()", url15582.url(), "http://alain.knaff.linux.lu/bug-reports/kde/percentage%25in%25url.html");
+
+ KURL longUserName("http://thisisaverylongusername@foobar.com/");
+ check("KURL::prettyURL()", longUserName.prettyURL(), "http://thisisaverylongusername@foobar.com/");
+ check("KURL(KURL::prettyURL())", KURL(longUserName.prettyURL()).url(), "http://thisisaverylongusername@foobar.com/");
+
+ KURL whitespaceInUser("http://google.com%20%20%20@foobar.com/");
+ check("KURL::prettyURL()", whitespaceInUser.prettyURL(), "http://google.com%20%20%20@foobar.com/");
+
+ KURL whitespaceInPath("http://www.google.com/foo%20bar/");
+ check("KURL::prettyURL()", whitespaceInPath.prettyURL(), "http://www.google.com/foo bar/");
+
+ KURL whitespaceInPath2("http://www.google.com/foo%20%20%20%20%20%20%20bar/");
+ check("KURL::prettyURL()", whitespaceInPath2.prettyURL(),
+ "http://www.google.com/foo%20%20%20%20%20%20 bar/");
+
+ KURL carsten;
+ carsten.setPath("/home/gis/src/kde/kdelibs/kfile/.#kfiledetailview.cpp.1.18");
+ check("KURL::path()", carsten.path(), "/home/gis/src/kde/kdelibs/kfile/.#kfiledetailview.cpp.1.18");
+
+ KURL charles;
+ charles.setPath( "/home/charles/foo%20moo" );
+ check("KURL::path()", charles.path(), "/home/charles/foo%20moo");
+ KURL charles2("file:/home/charles/foo%20moo");
+ check("KURL::path()", charles2.path(), "/home/charles/foo moo");
+
+ KURL udir;
+ printf("\n* Empty URL\n");
+ check("KURL::url()", udir.url(), TQString::null);
+ check("KURL::isEmpty()", udir.isEmpty() ? "ok" : "ko", "ok");
+ check("KURL::isValid()", udir.isValid() ? "ok" : "ko", "ko");
+ udir = udir.upURL();
+ check("KURL::upURL()", udir.upURL().isEmpty() ? "ok" : "ko", "ok");
+
+ udir.setPath("/home/dfaure/file.txt");
+ printf("\n* URL is %s\n",udir.url().ascii());
+ check("KURL::path()", udir.path(), "/home/dfaure/file.txt");
+ check("KURL::url()", udir.url(), "file:///home/dfaure/file.txt");
+ check("KURL::directory(false,false)", udir.directory(false,false), "/home/dfaure/");
+ check("KURL::directory(true,false)", udir.directory(true,false), "/home/dfaure");
+
+ KURL u2( TQCString("/home/dfaure/") );
+ printf("\n* URL is %s\n",u2.url().ascii());
+ // not ignoring trailing slash
+ check("KURL::directory(false,false)", u2.directory(false,false), "/home/dfaure/");
+ check("KURL::directory(true,false)", u2.directory(true,false), "/home/dfaure");
+ // ignoring trailing slash
+ check("KURL::directory(false,true)", u2.directory(false,true), "/home/");
+ check("KURL::directory(true,true)", u2.directory(true,true), "/home");
+
+ // cleanPath() tests (before cd() since cd uses that)
+ u2.cleanPath();
+ check("cleanPath(false)", u2.url(), "file:///home/dfaure/");
+ u2.addPath( "/..//foo" );
+ check("addPath", u2.url(), "file:///home/dfaure/..//foo");
+ u2.cleanPath(false);
+ check("cleanPath()", u2.url(), "file:///home//foo");
+ u2.cleanPath(true);
+ check("cleanPath()", u2.url(), "file:///home/foo");
+
+ u2.cd("..");
+ check("KURL::cd(\"..\")", u2.url(), "file:///home");
+ u2.cd("thomas");
+ check("KURL::cd(\"thomas\")", u2.url(), "file:///home/thomas");
+ u2.cd("../");
+ check("KURL::cd(\"../\")", u2.url(), "file:///home/");
+ u2.cd("/opt/kde/bin/");
+ check("KURL::cd(\"/opt/kde/bin/\")", u2.url(), "file:///opt/kde/bin/");
+ u2 = "ftp://ftp.kde.org/";
+ printf("\n* URL is %s\n",u2.url().ascii());
+ u2.cd("pub");
+ check("KURL::cd(\"pub\")", u2.url(), "ftp://ftp.kde.org/pub");
+ u2 = u2.upURL();
+ check("KURL::upURL()", u2.url(), "ftp://ftp.kde.org/");
+ u2 = u1;
+ printf("\n* URL is %s\n",u2.url().ascii());
+ // setFileName
+ u2.setFileName( "myfile.txt" );
+ check("KURL::setFileName()", u2.url(), "file:///home/dfaure/myfile.txt");
+ u2.setFileName( "myotherfile.txt" );
+ check("KURL::setFileName()", u2.url(), "file:///home/dfaure/myotherfile.txt");
+ // more tricky, renaming a directory (kpropsdlg.cc, line ~ 238)
+ TQString tmpurl = "file:/home/dfaure/myolddir/";
+ if ( tmpurl.tqat(tmpurl.length() - 1) == '/')
+ // It's a directory, so strip the trailing slash first
+ tmpurl.truncate( tmpurl.length() - 1);
+ KURL newUrl = tmpurl;
+ newUrl.setFileName( "mynewdir" );
+ check("KURL::setFileName() special", newUrl.url(), "file:///home/dfaure/mynewdir");
+ // addPath tests
+ newUrl.addPath( "subdir" );
+ check("KURL::addPath(\"subdir\")", newUrl.url(), "file:///home/dfaure/mynewdir/subdir");
+ newUrl.addPath( "/foo/" );
+ check("KURL::addPath(\"/foo/\")", newUrl.url(), "file:///home/dfaure/mynewdir/subdir/foo/");
+ u2 = "http://www.kde.org"; // no path
+ u2.addPath( "subdir" );
+ check("KURL::addPath(\"subdir\")", u2.url(), "http://www.kde.org/subdir");
+ u2.addPath( "" );
+ check("KURL::addPath(\"subdir\")", u2.url(), "http://www.kde.org/subdir"); // unchanged
+
+ // even more tricky
+ u2 = "print:/specials/Print%20To%20File%20(PDF%2FAcrobat)";
+ printf("\n* URL is %s\n",u2.url().ascii());
+ check("KURL::path()", u2.path(), "/specials/Print To File (PDF/Acrobat)");
+ check("KURL::fileName()", u2.fileName(), "Print To File (PDF/Acrobat)");
+ u2.setFileName( "" );
+ check("KURL::setFileName()", u2.url(), "print:/specials/");
+
+ u2 = "file:/specials/Print";
+ printf("\n* URL is %s\n",u2.url().ascii());
+ check("KURL::path()", u2.path(), "/specials/Print");
+ check("KURL::fileName()", u2.fileName(), "Print");
+ u2.setFileName( "" );
+ check("KURL::setFileName()", u2.url(), "file:///specials/");
+
+ const char * u6 = "ftp://host/dir1/dir2/myfile.txt";
+ printf("\n* URL is %s\n",u6);
+ check("KURL::hasSubURL()", KURL(u6).hasSubURL() ? "yes" : "no", "no");
+ lst.clear();
+ lst = KURL::split( KURL(u6) );
+ check("KURL::split()", lst.count()==1 ? "1" : "error", "1");
+ check("KURL::split()", lst.first().url(), "ftp://host/dir1/dir2/myfile.txt");
+ // cdUp code
+ KURL lastUrl = lst.last();
+ TQString dir = lastUrl.directory( true, true );
+ check( "KURL::directory(true,true)", dir, "/dir1/dir2");
+
+ /// Comparisons
+ TQString ucmp1 = "ftp://ftp.de.kde.org/dir";
+ TQString ucmp2 = "ftp://ftp.de.kde.org/dir/";
+ check("urlcmp(only slash difference)", urlcmp(ucmp1,ucmp2)?"ko":"ok","ok");
+ check("urlcmp(only slash difference, ignore_trailing)", urlcmp(ucmp1,ucmp2,true,false)?"ok":"ko","ok");
+ TQString ucmp3 = "ftp://ftp.de.kde.org/dir/#";
+ check("urlcmp(only hash difference)", urlcmp(ucmp2,ucmp3)?"ko":"ok","ok");
+ check("urlcmp(only hash difference, ignore_ref)", urlcmp(ucmp2,ucmp3,false,true)?"ok":"ko","ok");
+ check("urlcmp(slash and hash difference, ignore_trailing, ignore_ref)", urlcmp(ucmp2,ucmp3,true,true)?"ok":"ko","ok");
+ check("urlcmp(empty, empty)", urlcmp("","",false,true)?"ok":"ko","ok");
+ check("urlcmp(empty, empty)", urlcmp("","")?"ok":"ko","ok");
+ check("urlcmp(empty, not empty)", urlcmp("",ucmp1)?"ok":"ko","ko");
+ check("urlcmp(empty, not empty)", urlcmp("",ucmp1,false,true)?"ok":"ko","ko");
+ check("urlcmp(malformed, not empty)", urlcmp("file",ucmp1)?"ok":"ko","ko");
+ check("urlcmp(malformed, not empty)", urlcmp("file",ucmp1,false,true)?"ok":"ko","ko");
+
+ KURL ftpUrl ( "ftp://ftp.de.kde.org" );
+ printf("\n* URL is %s\n",ftpUrl.url().latin1());
+ check("KURL::path()", ftpUrl.path(), TQString::null);
+ ftpUrl = "ftp://ftp.de.kde.org/";
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp.de.kde.org/host/subdir/") ? "yes" : "no", "yes");
+ ftpUrl = "ftp://ftp/host/subdir/";
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/") ? "yes" : "no", "yes");
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir") ? "yes" : "no", "yes");
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdi") ? "yes" : "no", "no");
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/blah/") ? "yes" : "no", "yes");
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/blah/subdir") ? "yes" : "no", "no");
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "file:////ftp/host/subdir/") ? "yes" : "no", "no");
+ check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/subsub") ? "yes" : "no", "yes");
+
+ // WABA: The following tests are to test the handling of relative URLs as
+ // found on web-pages.
+
+ KURL waba1( "http://www.website.com/directory/?hello#ref" );
+ {
+ KURL waba2( waba1, "relative.html");
+ check("http: Relative URL, single file", waba2.url(), "http://www.website.com/directory/relative.html");
+ }
+ {
+ KURL waba2( waba1, "../relative.html");
+ check("http: Relative URL, single file, directory up", waba2.url(), "http://www.website.com/relative.html");
+ }
+ {
+ KURL waba2( waba1, "down/relative.html");
+ check("http: Relative URL, single file, directory down", waba2.url(), "http://www.website.com/directory/down/relative.html");
+ }
+ {
+ KURL waba2( waba1, "/down/relative.html");
+ check("http: Relative URL, full path", waba2.url(), "http://www.website.com/down/relative.html");
+ }
+ {
+ KURL waba2( waba1, "//www.kde.org/relative.html");
+ check("http: Relative URL, with host", waba2.url(), "http://www.kde.org/relative.html");
+ }
+ {
+ KURL waba2( waba1, "relative.html?query=test&name=harry");
+ check("http: Relative URL, with query", waba2.url(), "http://www.website.com/directory/relative.html?query=test&name=harry");
+ waba2.removeQueryItem("query");
+ check("http: Removing query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry");
+ waba2.addQueryItem("age", "18");
+ check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18");
+ waba2.addQueryItem("age", "21");
+ check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18&age=21");
+ waba2.addQueryItem("fullname", "Harry Potter");
+ check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18&age=21&fullname=Harry%20Potter");
+ }
+ {
+ KURL waba2( waba1, "?query=test&name=harry");
+ check("http: Relative URL, with query and no filename", waba2.url(), "http://www.website.com/directory/?query=test&name=harry");
+ }
+ {
+ KURL waba2( waba1, "relative.html#with_reference");
+ check("http: Relative URL, with reference", waba2.url(), "http://www.website.com/directory/relative.html#with_reference");
+ }
+ {
+ KURL waba2( waba1, "#");
+ check("http: Relative URL, with empty reference", waba2.url(), "http://www.website.com/directory/?hello#");
+ }
+ {
+ KURL waba2( waba1, "");
+ check("http: Empty relative URL", waba2.url(), "http://www.website.com/directory/?hello#ref");
+ }
+ {
+ KURL base( "http://faure@www.kde.org" ); // no path
+ KURL waba2( base, "filename.html");
+ check("http: Relative URL, orig URL had no path", waba2.url(), "http://faure@www.kde.org/filename.html");
+ }
+ {
+ KURL base( "http://faure:pass@www.kde.org:81?query" );
+ KURL rel1( base, "http://www.kde.org/bleh/"); // same host
+ check("http: Relative URL, orig URL had username", rel1.url(), "http://faure:pass@www.kde.org/bleh/");
+ KURL rel2( base, "http://www.yahoo.org"); // different host
+ check("http: Relative URL, orig URL had username", rel2.url(), "http://www.yahoo.org");
+ }
+
+ waba1 = "http://www.website.com/directory/filename?bla#blub";
+ {
+ KURL waba2( waba1, "relative.html");
+ check("http: Relative URL, single file", waba2.url(), "http://www.website.com/directory/relative.html");
+ }
+ {
+ KURL waba2( waba1, "../relative.html");
+ check("http: Relative URL, single file, directory up", waba2.url(), "http://www.website.com/relative.html");
+ }
+ {
+ KURL waba2( waba1, "down/relative.html");
+ check("http: Relative URL, single file, directory down", waba2.url(), "http://www.website.com/directory/down/relative.html");
+ }
+ {
+ KURL waba2( waba1, "/down/relative.html");
+ check("http: Relative URL, full path", waba2.url(), "http://www.website.com/down/relative.html");
+ }
+ {
+ KURL waba2( waba1, "relative.html?query=test&name=harry");
+ check("http: Relative URL, with query", waba2.url(), "http://www.website.com/directory/relative.html?query=test&name=harry");
+ }
+ {
+ KURL waba2( waba1, "?query=test&name=harry");
+ check("http: Relative URL, with query and no filename", waba2.url(), "http://www.website.com/directory/filename?query=test&name=harry");
+ }
+ {
+ KURL waba2( waba1, "relative.html#with_reference");
+ check("http: Relative URL, with reference", waba2.url(), "http://www.website.com/directory/relative.html#with_reference");
+ }
+ {
+ KURL waba2( waba1, "http:/relative.html"); // "rfc 1606 loophole"
+ check("http: Strange relative URL", waba2.url(), "http://www.website.com/relative.html");
+ }
+ waba1.setUser("waldo");
+ check("http: Set user", waba1.url(), "http://waldo@www.website.com/directory/filename?bla#blub");
+ waba1.setUser("waldo/bastian");
+ check("http: Set user with slash in it", waba1.url(), "http://waldo%2Fbastian@www.website.com/directory/filename?bla#blub");
+ waba1.setRef( TQString::null );
+ waba1.setPass( "pass" );
+ waba1.setDirectory( "/foo" );
+ waba1.setProtocol( "https" );
+ waba1.setHost( "web.com" );
+ waba1.setPort( 881 );
+ check("http: setRef/setPass/setDirectory/setHost/setPort", waba1.url(), "https://waldo%2Fbastian:pass@web.com:881/foo/?bla");
+ waba1.setDirectory( "/foo/" );
+ check("http: setDirectory #2", waba1.url(), "https://waldo%2Fbastian:pass@web.com:881/foo/?bla");
+
+ // Empty queries should be preserved!
+ waba1 = "http://www.kde.org/cgi/test.cgi?";
+ check("http: URL with empty query string", waba1.url(),
+ "http://www.kde.org/cgi/test.cgi?");
+
+ // Empty references should be preserved
+ waba1 = "http://www.kde.org/cgi/test.cgi#";
+ check("http: URL with empty reference string", waba1.url(),
+ "http://www.kde.org/cgi/test.cgi#");
+ check("hasRef()", waba1.hasRef()?"true":"false","true");
+ check("hasHTMLRef()", waba1.hasHTMLRef()?"true":"false","true");
+ check("encodedHtmlRef()", waba1.encodedHtmlRef(),TQString::null);
+
+ // URLs who forgot to encode spaces in the query.
+ waba1 = "http://www.kde.org/cgi/test.cgi?hello=My Value";
+ check("http: URL with incorrect encoded query", waba1.url(),
+ "http://www.kde.org/cgi/test.cgi?hello=My%20Value");
+
+ // URL with ':' in query (':' should NOT be encoded!)
+ waba1.setQuery("hello:My Value");
+ check("http: URL with ':' in query", waba1.url(),
+ "http://www.kde.org/cgi/test.cgi?hello:My%20Value");
+ check("upURL() removes query", waba1.upURL().url(),
+ "http://www.kde.org/cgi/test.cgi");
+
+ // URLs who forgot to encode spaces in the query.
+ waba1 = "http://www.kde.org/cgi/test.cgi?hello=My Value+20";
+ check("http: URL with incorrect encoded query", waba1.url(),
+ "http://www.kde.org/cgi/test.cgi?hello=My%20Value+20");
+
+ // Urls without path (BR21387)
+ waba1 = "http://meine.db24.de?link=home_c_login_login";
+ check("http: URL with empty path string", waba1.url(),
+ "http://meine.db24.de?link=home_c_login_login");
+ check("http: URL with empty path string path", waba1.path(),
+ "");
+ check("http: URL with empty path string query", waba1.query(),
+ "?link=home_c_login_login");
+
+ waba1 = "http://a:389?b=c";
+ check( "http: URL with port, query, and empty path; url", waba1.url(), "http://a:389?b=c" );
+ check( "http: URL with port, query, and empty path; host", waba1.host(), "a" );
+ check( "http: URL with port, query, and empty path; port", TQString::number( waba1.port() ), "389" );
+ check( "http: URL with port, query, and empty path; path", waba1.path(), "" );
+ check( "http: URL with port, query, and empty path; query", waba1.query(), "?b=c" );
+
+ // Urls without path (BR21387)
+ waba1 = "http://meine.db24.de#link=home_c_login_login";
+ check("http: URL with empty path string", waba1.url(),
+ "http://meine.db24.de#link=home_c_login_login");
+ check("http: URL with empty path string path", waba1.path(),
+ "");
+
+ waba1 = "http://www.meinestadt.de&url_plain=http";
+ check("http: URL with empty path string", waba1.host(),
+ "www.meinestadt.de&url_plain=http");
+ check("http: URL with empty path string", waba1.htmlURL(),
+ "http://www.meinestadt.de&amp;url_plain=http");
+
+ check("http: URL with empty path string", waba1.path(),
+ "");
+
+ waba1 = "http://a:389#b=c";
+ check( "http: URL with port, ref, and empty path; url", waba1.url(), "http://a:389#b=c" );
+ check( "http: URL with port, ref, and empty path; host", waba1.host(), "a" );
+ check( "http: URL with port, ref, and empty path; port", TQString::number( waba1.port() ), "389" );
+ check( "http: URL with port, ref, and empty path; path", waba1.path(), "" );
+ check( "http: URL with port, ref, and empty path; ref", waba1.ref(), "b=c" );
+ check( "http: URL with port, ref, and empty path; query", waba1.query(), "" );
+
+ // IPV6
+ waba1 = "http://[::FFFF:129.144.52.38]:81/index.html";
+ check("http: IPV6 host", waba1.host(),
+ "::ffff:129.144.52.38");
+ check("http: IPV6 port", TQString("%1").arg(waba1.port()),
+ "81");
+
+ // IPV6
+ waba1 = "http://waba:pass@[::FFFF:129.144.52.38]:81/index.html";
+ check("http: IPV6 host", waba1.host(),
+ "::ffff:129.144.52.38");
+ check("http: IPV6 host", waba1.user(),
+ "waba");
+ check("http: IPV6 host", waba1.pass(),
+ "pass");
+ check("http: IPV6 port", TQString("%1").arg(waba1.port()),
+ "81");
+
+ // IPV6
+ waba1 = "http://www.kde.org/cgi/test.cgi";
+ waba1.setHost("::ffff:129.144.52.38");
+ check("http: IPV6 host", waba1.url(),
+ "http://[::ffff:129.144.52.38]/cgi/test.cgi");
+ waba1 = "http://[::ffff:129.144.52.38]/cgi/test.cgi";
+ assert( waba1.isValid() );
+
+ // IPV6 without path
+ waba1 = "http://[::ffff:129.144.52.38]?query";
+ assert( waba1.isValid() );
+ check("http: IPV6 without path", waba1.url(),
+ "http://[::ffff:129.144.52.38]?query");
+ check("http: IPV6 without path; query", waba1.query(),
+ "?query");
+ waba1 = "http://[::ffff:129.144.52.38]#ref";
+ assert( waba1.isValid() );
+ check("http: IPV6 without path", waba1.url(),
+ "http://[::ffff:129.144.52.38]#ref");
+ check("http: IPV6 without path; ref", waba1.ref(),
+ "ref");
+ // IPV6 without path but with a port
+ waba1 = "http://[::ffff:129.144.52.38]:81?query";
+ assert( waba1.isValid() );
+ check("http: IPV6 without path", waba1.url(),
+ "http://[::ffff:129.144.52.38]:81?query");
+ check("http: IPV6 without path; port", TQString::number( waba1.port() ), "81" );
+ check("http: IPV6 without path; query", waba1.query(), "?query");
+ waba1 = "http://[::ffff:129.144.52.38]:81#ref";
+ assert( waba1.isValid() );
+ check("http: IPV6 without path", waba1.url(),
+ "http://[::ffff:129.144.52.38]:81#ref");
+ check("http: IPV6 without path; port", TQString::number( waba1.port() ), "81" );
+ check("http: IPV6 without path; ref", waba1.ref(), "ref");
+
+ // Streaming operators
+ KURL origURL( "http://www.website.com/directory/?#ref" );
+ waba1 = "http://[::ffff:129.144.52.38]:81?query";
+ TQByteArray buffer;
+ {
+ TQDataStream stream( buffer, IO_WriteOnly );
+ stream << origURL
+ << KURL( "file:" ) // an invalid one
+ << waba1; // the IPv6 one
+ }
+ {
+ TQDataStream stream( buffer, IO_ReadOnly );
+ KURL restoredURL;
+ stream >> restoredURL;
+ check( "Streaming valid URL", origURL.url(), restoredURL.url() );
+ stream >> restoredURL;
+ check( "Streaming invalid URL", restoredURL.isValid()?"valid":"malformed", "malformed" );
+ check( "Streaming invalid URL", restoredURL.url(), "file:" );
+ stream >> restoredURL;
+ check( "Streaming ipv6 URL with query", restoredURL.url(), waba1.url() );
+ }
+
+ // Broken stuff
+ waba1 = "file:a";
+ check("Broken stuff #1 path", waba1.path(), "a");
+ check("Broken stuff #1 fileName(false)", waba1.fileName(false), "a");
+ check("Broken stuff #1 fileName(true)", waba1.fileName(true), "a");
+ check("Broken stuff #1 directory(false, false)", waba1.directory(false, false), "");
+ check("Broken stuff #1 directory(true, false)", waba1.directory(true, false), "");
+ check("Broken stuff #1 directory(false, true)", waba1.directory(true, true), "");
+
+ waba1 = "file:a/";
+ check("Broken stuff #2 path", waba1.path(), "a/");
+ check("Broken stuff #2 fileName(false)", waba1.fileName(false), "");
+ check("Broken stuff #2 fileName(true)", waba1.fileName(true), "a");
+ check("Broken stuff #2 directory(false, false)", waba1.directory(false, false), "a/");
+ check("Broken stuff #2 directory(true, false)", waba1.directory(true, false), "a");
+ check("Broken stuff #2 directory(false, true)", waba1.directory(true, true), "");
+
+ waba1 = "file:";
+ check("Broken stuff #3 empty", waba1.isEmpty()?"EMPTY":"NOT", "NOT");
+ check("Broken stuff #3 valid", waba1.isValid()?"VALID":"MALFORMED", "MALFORMED");
+ check("Broken stuff #3 path", waba1.path(), "");
+ check("Broken stuff #3 fileName(false)", waba1.fileName(false), "");
+ check("Broken stuff #3 fileName(true)", waba1.fileName(true), "");
+ check("Broken stuff #3 directory(false, false)", waba1.directory(false, false), "");
+ check("Broken stuff #3 directory(true, false)", waba1.directory(true, false), "");
+ check("Broken stuff #3 directory(false, true)", waba1.directory(true, true), "");
+ KURL broken;
+ broken.setPath( TQString::null );
+ check("Broken stuff #4 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT");
+ // It's valid: because isValid refers to parsing, not to what happens afterwards.
+ check("Broken stuff #4 valid", broken.isValid()?"VALID":"MALFORMED", "VALID");
+ check("Broken stuff #4 path", broken.path(), "");
+ broken = "file://"; // just because coolo wondered
+ check("Broken stuff #5 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT");
+ check("Broken stuff #5 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED");
+ check("Broken stuff #5 path", broken.path(), "");
+ broken = "file";
+ check("Broken stuff #6 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED");
+ broken = "/";
+ check("Broken stuff #7 valid", broken.isValid()?"VALID":"MALFORMED", "VALID");
+ check("Broken stuff #7 path", broken.path(), "/" );
+ check("Broken stuff #7 url", broken.url(), "file:///" );
+ check("Broken stuff #7 file", broken.protocol(), "file" );
+
+ broken = "LABEL=USB_STICK"; // 71430, can we use KURL for this?
+ check("Broken stuff #6 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED");
+ check("Broken stuff #6 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT");
+ check("Broken stuff #6 path", broken.path(), "");
+
+#if 0 // BROKEN?
+ // UNC like names
+ KURL unc1("FILE://localhost/home/root");
+ check("UNC, with localhost", unc1.path(), "/home/root");
+ check("UNC, with localhost", unc1.url(), "file:///home/root");
+#endif
+ KURL unc2("file:///home/root");
+ check("UNC, with empty host", unc2.path(), "/home/root");
+ check("UNC, with empty host", unc2.url(), "file:///home/root");
+
+ {
+ KURL unc3("FILE://remotehost/home/root");
+#if 0 // BROKEN?
+ check("UNC, with remote host", unc3.path(), "//remotehost/home/root");
+#endif
+ check("UNC, with remote host", unc3.url(), "file://remotehost/home/root");
+ KURL url2("file://atlas/dfaure");
+ check("KURL::host()", url2.host(), "atlas");
+ check("KURL::path()", url2.path(), "/dfaure");
+ //check("KURL::path()", url3.path(), "//atlas/dfaure"); // says Waba
+ //KURL url3("file:////atlas/dfaure");
+ //check("KURL::path()", url3.path(), "//atlas/dfaure"); // says Waba
+
+ KURL url4(url2, "//remotehost/home/root");
+ check("KURL::host()", url4.host(), "remotehost");
+ check("KURL::path()", url4.path(), "/home/root");
+ }
+
+ KURL umail1 ( "mailto:faure@kde.org" );
+ check("mailto: URL, general form", umail1.protocol(), "mailto");
+ check("mailto: URL, general form", umail1.path(), "faure@kde.org");
+ check("mailto: URL, is relative", KURL::isRelativeURL("mailto:faure@kde.org") ? "true" : "false", "false");
+ KURL umail2 ( "mailto:Faure David <faure@kde.org>" );
+ check("mailto: URL, general form", umail2.protocol(), "mailto");
+ check("mailto: URL, general form", umail2.path(), "Faure David <faure@kde.org>");
+ check("isRelativeURL(\"mailto:faure@kde.org\")", KURL::isRelativeURL("mailto:faure@kde.org") ? "yes" : "no", "no");
+ KURL umail3 ( "mailto:" );
+ check("mailto: invalid URL", umail3.isValid()?"valid":"malformed", "malformed");
+
+ check("man: URL, is relative", KURL::isRelativeURL("man:mmap") ? "true" : "false", "false");
+ check("javascript: URL, is relative", KURL::isRelativeURL("javascript:doSomething()") ? "true" : "false", "false");
+ // more isRelative
+ check("file: URL, is relative", KURL::isRelativeURL("file:///blah") ? "true" : "false", "false");
+ check("/path, is relative", KURL::isRelativeURL("/path") ? "true" : "false", "true"); // arguable, but necessary for KURL( baseURL, "//www1.foo.bar" );
+ check("something, is relative", KURL::isRelativeURL("something") ? "true" : "false", "true");
+ KURL about("about:konqueror");
+ check("about:",about.path(),"konqueror");
+
+ KURL ulong("https://swww.gad.de:443/servlet/CookieAccepted?MAIL=s@gad.de&VER=25901");
+ check("host",ulong.host(),"swww.gad.de");
+ check("path",ulong.path(),"/servlet/CookieAccepted");
+
+#if QT_VERSION < 300
+ qt_set_locale_codec( KGlobal::charsets()->codecForName( "iso-8859-1" ) );
+#else
+ TQTextCodec::setCodecForLocale( KGlobal::charsets()->codecForName( "iso-8859-1" ) );
+#endif
+ TQString raw = "data:text/html,%00%2540%00";
+ check("data URL: encode-decode of %00", KURL(raw).url(), raw );
+
+ // UTF8 tests
+ KURL uloc("/home/dfaure/konqtests/Matériel");
+ check("url",uloc.url().latin1(),"file:///home/dfaure/konqtests/Mat%E9riel");
+ check("pretty",uloc.prettyURL(),"file:///home/dfaure/konqtests/Matériel"); // escaping the letter would be correct too
+ check("pretty + strip",uloc.prettyURL(0, KURL::StripFileProtocol),"/home/dfaure/konqtests/Matériel"); // escaping the letter would be correct too
+ // 106 is MIB for UTF-8
+ check("UTF8",uloc.url(0, 106),"file:///home/dfaure/konqtests/Mat%C3%A9riel");
+ uloc = KURL("file:///home/dfaure/konqtests/Mat%C3%A9riel", 106);
+ check("UTF8 path", uloc.path(), "/home/dfaure/konqtests/Matériel");
+ check("encodedPathAndQuery", uloc.encodedPathAndQuery(), "/home/dfaure/konqtests/Mat%E9riel");
+
+ // fromPathOrURL tests
+ uloc = KURL::fromPathOrURL( "/home/dfaure/konqtests/Mat%E9riel" );
+ check("fromPathOrURL path", uloc.path(), "/home/dfaure/konqtests/Mat%E9riel");
+ uloc = KURL::fromPathOrURL( "http://www.kde.org" );
+ check("pathOrURL url", uloc.pathOrURL(), uloc.url() );
+ uloc = KURL::fromPathOrURL( "www.kde.org" );
+ check("fromPathOrURL malformed", uloc.isValid()?"valid":"malformed", "malformed");
+ uloc = KURL::fromPathOrURL( "index.html" );
+ check("fromPathOrURL malformed", uloc.isValid()?"valid":"malformed", "malformed");
+ uloc = KURL::fromPathOrURL( "" );
+ check("fromPathOrURL malformed", uloc.isValid()?"valid":"malformed", "malformed");
+
+ // pathOrURL tests
+ uloc = KURL::fromPathOrURL( "/home/dfaure/konqtests/Mat%E9riel" );
+ check("pathOrURL path", uloc.pathOrURL(), uloc.path() );
+ uloc = "http://www.kde.org";
+ check("pathOrURL url", uloc.url(), "http://www.kde.org");
+ uloc = "file:///home/dfaure/konq%20tests/Mat%E9riel#ref";
+ check("pathOrURL local file with ref", uloc.pathOrURL(), "file:///home/dfaure/konq tests/Matériel#ref" );
+ uloc = "file:///home/dfaure/konq%20tests/Mat%E9riel?query";
+ check("pathOrURL local file with query", uloc.pathOrURL(), "file:///home/dfaure/konq tests/Matériel?query" );
+ uloc = KURL::fromPathOrURL( "/home/dfaure/file#with#hash" );
+ check("pathOrURL local path with #", uloc.pathOrURL(), "/home/dfaure/file#with#hash" );
+
+ testAdjustPath();
+
+#if QT_VERSION < 300
+ qt_set_locale_codec( KGlobal::charsets()->codecForName( "koi8-r" ) );
+#else
+ TQTextCodec::setCodecForLocale( KGlobal::charsets()->codecForName( "koi8-r" ) );
+#endif
+ baseURL = "file:/home/coolo";
+ KURL russian = baseURL.directory(false, true) + TQString::fromLocal8Bit( "ÆÇÎ7" );
+ check( "russian", russian.url(), "file:///home/%C6%C7%CE7" );
+
+ KURL tobi1("http://some.host.net/path/to/file#fragmentPrecedes?theQuery");
+ check("wrong order of query and hypertext reference #1", tobi1.ref(), "fragmentPrecedes");
+ check("wrong order of query and hypertext reference #2", tobi1.query(), "?theQuery");
+
+ tobi1 = "http://host.net/path/?#http://brokenäadsfküpoij31ü029muß2890zupycÜ*!*'O´+ß0i";
+ check("zero-length query",tobi1.query(),"?");
+
+ tobi1 = "http://host.net/path/#no-query";
+ check("no query", tobi1.query(),"");
+ check("encodedPathAndQuery", tobi1.encodedPathAndQuery(), "/path/");
+
+ tobi1 = "http://host.net/path?myfirstquery#andsomeReference";
+ tobi1.setEncodedPathAndQuery("another/path/?another&query");
+ check("setEncodedPathAndQuery test#1", tobi1.query(), "?another&query");
+ check("setEncodedPathAndQuery test#2", tobi1.path(), "another/path/"); // with trailing slash
+ check("encodedPathAndQuery", tobi1.encodedPathAndQuery(), "another/path/?another&query");
+ tobi1.setEncodedPathAndQuery("another/path?another&query");
+ check("setEncodedPathAndQuery test#1", tobi1.query(), "?another&query");
+ check("setEncodedPathAndQuery test#2", tobi1.path(), "another/path"); // without trailing slash
+ check("encodedPathAndQuery", tobi1.encodedPathAndQuery(), "another/path?another&query");
+
+ KURL theKow = "http://www.google.de/search?q=frerich&hlx=xx&hl=de&empty=&lr=lang+de&test=%2B%20%3A%25";
+ check("queryItem (first item)", theKow.queryItem("q"), "frerich");
+ check("queryItem (middle item)", theKow.queryItem("hl"), "de");
+ check("queryItem (last item)", theKow.queryItem("lr"), "lang de");
+ check("queryItem (invalid item)", theKow.queryItem("InterstellarCounselor"), TQString::null);
+ check("queryItem (empty item)", theKow.queryItem("empty"), "");
+ check("queryItem (item with encoded chars)", theKow.queryItem("test"), "+ :%");
+ check("encodedPathAndQuery", theKow.encodedPathAndQuery(), "/search?q=frerich&hlx=xx&hl=de&empty=&lr=lang+de&test=%2B%20%3A%25");
+
+ // checks for queryItems(), which returns a TQMap<TQString,TQString>:
+ KURL queryUrl( "mailto:Marc%20Mutz%20%3cmutz@kde.org%3E?"
+ "Subject=subscribe+me&"
+ "body=subscribe+mutz%40kde.org&"
+ "Cc=majordomo%40lists.kde.org" );
+ check("queryItems (c.s. keys)",
+ TQStringList(queryUrl.queryItems().keys()).join(", "),
+ "Cc, Subject, body" );
+ check("queryItems (c.i.s. keys)",
+ TQStringList(queryUrl.queryItems(KURL::CaseInsensitiveKeys).keys()).join(", "),
+ "body, cc, subject" );
+ check("queryItems (values; c.s. keys)",
+ TQStringList(queryUrl.queryItems().values()).join(", "),
+ "majordomo@lists.kde.org, subscribe me, subscribe mutz@kde.org" );
+ check("queryItems (values; c.i.s. keys)",
+ TQStringList(queryUrl.queryItems(KURL::CaseInsensitiveKeys).values()).join(", "),
+ "subscribe mutz@kde.org, majordomo@lists.kde.org, subscribe me" );
+
+ KURL umlaut1("http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel");
+ check("umlaut1.url()", umlaut1.url(), "http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel");
+
+ KURL umlaut2("http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel", 106);
+ check("umlaut2.url()", umlaut2.url(), "http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel");
+
+ // Needed for #49616
+ check( "encode_string('C++')", KURL::encode_string( "C++" ), "C%2B%2B" );
+ check( "decode_string('C%2B%2B')", KURL::decode_string( "C%2B%2B" ), "C++" );
+ check( "decode_string('C%00A')", KURL::decode_string( "C%00%A" ), "C" ); // we stop at %00
+
+ check( "encode_string('%')", KURL::encode_string( "%" ), "%25" );
+ check( "encode_string(':')", KURL::encode_string( ":" ), "%3A" );
+
+ KURL amantia( "http://%E1.foo.de" );
+ check("amantia.isValid()", amantia.isValid() ? "true" : "false", "true");
+#ifdef HAVE_IDNA_H
+ check("amantia.url()", amantia.url(), "http://xn--80a.foo.de"); // Non-ascii is allowed in IDN domain names.
+#else
+ check("amantia.url()", amantia.url(), "http://?.foo.de"); // why not
+#endif
+
+ KURL thiago( TQString::fromUtf8( "http://\303\244.de" ) ); // ä in utf8
+ check("thiago.isValid()", thiago.isValid() ? "true" : "false", "true");
+#ifdef HAVE_IDNA_H
+ check("thiago.url()", thiago.url(), "http://xn--4ca.de"); // Non-ascii is allowed in IDN domain names.
+#else
+ check("thiago.url()", thiago.url(), TQString::fromUtf8( "http://\303\244.de" ) );
+#endif
+
+
+ KURL smb("smb://domain;username:password@server/share");
+ check("smb.isValid()", smb.isValid() ? "true" : "false", "true");
+ check("smb.user()", smb.user(), "domain;username");
+ smb = "smb:/";
+ check("smb:/", smb.isValid()?"VALID":"MALFORMED", "VALID");
+ smb = "smb://"; // kurl.cpp rev 1.106
+ check("smb://", smb.isValid()?"VALID":"MALFORMED", "MALFORMED");
+ smb = "smb://host";
+ check("smb://host", smb.isValid()?"VALID":"MALFORMED", "VALID");
+ smb = "smb:///";
+ check("smb:///", smb.isValid()?"VALID":"MALFORMED", "VALID");
+
+ KURL weird;
+ weird = "http://strange<hostname>/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
+
+ weird = "http://strange<username>@strange<hostname>/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
+
+ weird = "http://strange<username>@ok_hostname/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
+ check("weird.host()", weird.host(), "ok_hostname");
+
+ weird = "http://strange;hostname/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
+
+ weird = "http://strange;username@strange;hostname/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
+
+ weird = "http://strange;username@ok_hostname/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
+ check("weird.host()", weird.host(), "ok_hostname");
+
+ weird = "http://strange;username:password@strange;hostname/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
+
+ weird = "http://strange;username:password@ok_hostname/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
+ check("weird.host()", weird.host(), "ok_hostname");
+
+ weird = "http://[strange;hostname]/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
+
+ weird = "http://[::fff:1:23]/";
+ check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
+ check("weird.host()", weird.host(), "::fff:1:23");
+
+ KURL com1("http://server.com/dir/", ".");
+ check("com1.url()", com1.url(), "http://server.com/dir/");
+
+ KURL com2("http://server.com/dir/blubb/", "blah/");
+ check("com2.url()", com2.url(), "http://server.com/dir/blubb/blah/");
+
+ KURL utf8_1("audiocd:/By%20Name/15%20Geantra%C3%AE.wav", 106);
+ check("utf8_1.fileName()", utf8_1.fileName(), TQString::fromLatin1("15 Geantraî.wav"));
+
+ KURL utf8_2("audiocd:/By%20Name/15%2fGeantra%C3%AE.wav", 106);
+ check("utf8_2.fileName()", utf8_2.fileName(), TQString::fromLatin1("15/Geantraî.wav"));
+
+ KURL url_newline_1("http://www.foo.bar/foo/bar\ngnork");
+ check("url_newline_1.url()", url_newline_1.url(), TQString::fromLatin1("http://www.foo.bar/foo/bar%0Agnork"));
+
+ KURL url_newline_2("http://www.foo.bar/foo?bar\ngnork");
+ check("url_newline_2.url()", url_newline_2.url(), TQString::fromLatin1("http://www.foo.bar/foo?bar%0Agnork"));
+
+ KURL local_file_1("file://localhost/my/file");
+ check("local_file_1.isLocalFile()", local_file_1.isLocalFile() ? "true" : "false", "true");
+
+ KURL local_file_2("file://www.kde.org/my/file");
+ check("local_file_2.isLocalFile()", local_file_2.isLocalFile() ? "true" : "false", "false");
+
+ KURL local_file_3;
+ local_file_3.setHost(getenv("HOSTNAME"));
+ local_file_3.setPath("/my/file");
+ printf("\nURL=%s\n", local_file_3.url().latin1());
+ check("local_file_3.isLocalFile()", local_file_3.isLocalFile() ? "true" : "false", "true");
+
+ KURL local_file_4("file:///my/file");
+ check("local_file_4.isLocalFile()", local_file_4.isLocalFile() ? "true" : "false", "true");
+
+ KURL local_file_5;
+ local_file_5.setPath("/foo?bar");
+ check("local_file_5.url()", local_file_5.url(), "file:///foo%3Fbar");
+
+ TQString basePath = "/home/bastian";
+
+ check("relativePath(\"/home/bastian\", \"/home/bastian\")", KURL::relativePath(basePath, "/home/bastian"), "./");
+ bool b;
+ check("relativePath(\"/home/bastian\", \"/home/bastian/src/plugins\")", KURL::relativePath(basePath, "/home/bastian/src/plugins", &b), "./src/plugins");
+ check("Is a subdirectory?", b ? "true" : "false", "true");
+ check("relativePath(\"/home/bastian\", \"./src/plugins\")", KURL::relativePath(basePath, "./src/plugins"), "./src/plugins");
+ check("relativePath(\"/home/bastian\", \"/home/waba/src/plugins\")", KURL::relativePath(basePath, "/home/waba/src/plugins", &b), "../waba/src/plugins");
+ check("Is a subdirectory?", b ? "true" : "false", "false");
+ check("relativePath(\"/home/bastian\", \"/\")", KURL::relativePath(basePath, "/"), "../../");
+
+ check("relativePath(\"/\", \"/\")", KURL::relativePath("/", "/"), "./");
+ check("relativePath(\"/\", \"/home/bastian\")", KURL::relativePath("/", "/home/bastian"), "./home/bastian");
+ check("relativePath(\"\", \"/home/bastian\")", KURL::relativePath("", "/home/bastian"), "/home/bastian");
+
+ baseURL = "http://www.kde.org/index.html";
+ check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html#help\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html#help"), "#help");
+ check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html?help=true\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html?help=true"), "index.html?help=true");
+ check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/contact.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/contact.html"), "contact.html");
+ check("relativeURL(\"http://www.kde.org/index.html\", \"ftp://ftp.kde.org/pub/kde\")", KURL::relativeURL(baseURL, "ftp://ftp.kde.org/pub/kde"), "ftp://ftp.kde.org/pub/kde");
+ check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html"), "./");
+
+ baseURL = "http://www.kde.org/info/index.html";
+ check("relativeURL(\"http://www.kde.org/info/index.html\", \"http://www.kde.org/bugs/contact.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/bugs/contact.html"), "../bugs/contact.html");
+
+ baseURL = "ptal://mlc:usb:PC_970";
+ check("isValid()?", baseURL.isValid() ? "true" : "false", "false");
+ check("url()", baseURL.url(), "ptal://mlc:usb:PC_970");
+
+ baseURL = "http://mlc:80/";
+ check("isValid()?", baseURL.isValid() ? "true" : "false", "true");
+ check("port()?", TQString::number(baseURL.port()), "80");
+ check("path()?", baseURL.path(), "/");
+
+ baseURL = "ptal://mlc:usb@PC_970"; // User=mlc, password=usb, host=PC_970
+ check("isValid()?", baseURL.isValid() ? "true" : "false", "true");
+ check("host()?", baseURL.host(), "pc_970");
+ check("user()?", baseURL.user(), "mlc");
+ check("pass()?", baseURL.pass(), "usb");
+
+ weird = "ftp://user%40host.com@ftp.host.com/var/www/";
+ check("user()?", weird.user(), "user@host.com" );
+ check("host()?", weird.host(), "ftp.host.com" );
+ KURL up = weird.upURL();
+ check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/var/");
+ up = up.upURL();
+ check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/");
+ up = up.upURL();
+ check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/"); // unchanged
+
+ KURL ldap = "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)";
+ check("host()?", ldap.host(), "host.com");
+ check("port()?", TQString("%1").arg(ldap.port()), "6666");
+ check("path()?", ldap.path(), "/o=University of Michigan,c=US");
+ check("query()?", ldap.query(), "??sub?(cn=Babs%20Jensen)");
+ check("url()?", ldap.url(), "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)");
+ ldap.setQuery("??sub?(cn=Karl%20Marx)");
+ check("query()?", ldap.query(), "??sub?(cn=Karl%20Marx)");
+ check("url()?", ldap.url(), "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Karl%20Marx)");
+
+ KURL leo = "data:text/html,http://www.invalid/";
+ check("data URL: isValid", leo.isValid()?"valid":"malformed", "valid" );
+ check("data URL: protocol", leo.protocol(), "data" );
+ check("data URL: url", leo.url(), "data:text/html,http://www.invalid/" );
+ check("data URL: path", leo.path(), "text/html,http://www.invalid/" );
+
+ // URI Mode tests
+ url1 = "http://www.foobar.com/";
+ check("KURL(\"http://www.foobar.com/\").uriMode()", TQString::number(url1.uriMode()), TQString::number(KURL::URL));
+ url1 = "mailto:user@host.com";
+ check("KURL(\"mailto:user@host.com\").uriMode()", TQString::number(url1.uriMode()), TQString::number(KURL::Mailto));
+ check("KURL(\"mailto:user@host.com\").url()", url1.url(), "mailto:user@host.com");
+ check("KURL(\"mailto:user@host.com\").url(0, 106)", url1.url(0, 106), "mailto:user@host.com");
+ url1 = "data:text/plain,foobar?gazonk=flarp";
+ check("KURL(\"data:text/plain,foobar?gazonk=flarp\").uriMode()", TQString::number(url1.uriMode()), TQString::number(KURL::RawURI));
+ check("KURL(\"data:text/plain,foobar?gazonk=flarp\").path()", url1.path(), "text/plain,foobar?gazonk=flarp");
+ url1 = "mailto:User@Host.COM?subject=Hello";
+ check("KURL(\"mailto:User@Host.COM?subject=Hello\").path()", url1.path(), "User@host.com");
+
+ KURL emptyUserTest1("http://www.foobar.com/");
+ KURL emptyUserTest2("http://www.foobar.com/");
+ emptyUserTest2.setUser("");
+ check("Empty vs. null fields: user", emptyUserTest1==emptyUserTest2?"TRUE":"FALSE","TRUE");
+ emptyUserTest2.setPass("");
+ check("Empty vs. null fields: password", emptyUserTest1==emptyUserTest2?"TRUE":"FALSE","TRUE");
+
+ printf("\nTest OK !\n");
+}
+
diff --git a/tdecore/tests/kxerrorhandlertest.cpp b/tdecore/tests/kxerrorhandlertest.cpp
new file mode 100644
index 000000000..c2efc7443
--- /dev/null
+++ b/tdecore/tests/kxerrorhandlertest.cpp
@@ -0,0 +1,54 @@
+#include <tqwidget.h>
+#include <X11/Xlib.h>
+#include <iostream>
+using namespace std;
+
+#include <kxerrorhandler.h>
+
+int handler1( Display*, XErrorEvent* e )
+ {
+ cout << "ERR1:" << e->resourceid << ":" << (int)e->error_code << ":" << (int)e->request_code << ":" << e->serial << endl;
+ return 1;
+ }
+
+bool handler3( int request, int error_code, unsigned long resourceid )
+ {
+ cout << "ERR3:" << resourceid << ":" << error_code << ":" << request << endl;
+ return true;
+ }
+
+int main()
+ {
+ Display* dpy = XOpenDisplay( NULL );
+ XSetWindowAttributes attrs;
+ Window w = XCreateWindow( dpy, DefaultRootWindow( dpy ), 0, 0, 100, 100, 0, CopyFromParent, CopyFromParent,
+ CopyFromParent, 0, &attrs );
+ cout << w << ":" << XNextRequest( dpy ) << endl;
+ XMapWindow( dpy, w );
+ ++w;
+// XSetInputFocus( dpy, w, RevertToParent, CurrentTime );
+ {
+ KXErrorHandler handle1( handler1, dpy );
+ cout << w << ":" << XNextRequest( dpy ) << endl;
+ XMapWindow( dpy, w );
+ XWindowAttributes attr;
+ {
+ KXErrorHandler handle2( dpy );
+ XGetWindowAttributes(dpy, w, &attr);
+ {
+ KXErrorHandler handle3( handler3, dpy );
+ XSetInputFocus( dpy, w, RevertToParent, CurrentTime );
+ cout << "WAS3:" << handle3.error( /*false*/ true ) << endl;
+ }
+ cout << "WAS2:" << handle2.error( false ) << endl;
+ }
+// XSync( dpy, False );
+ cout << "WAS1:" << handle1.error( false ) << endl;
+ }
+ for(;;)
+ {
+ XEvent ev;
+ XNextEvent( dpy, &ev );
+ }
+ XCloseDisplay( dpy );
+ }
diff --git a/tdecore/tests/startserviceby.cpp b/tdecore/tests/startserviceby.cpp
new file mode 100644
index 000000000..93e6716ef
--- /dev/null
+++ b/tdecore/tests/startserviceby.cpp
@@ -0,0 +1,41 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kapplication.h"
+#include <stdio.h>
+
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <kglobalsettings.h>
+#include <kdebug.h>
+
+int
+main(int argc, char *argv[])
+{
+ KAboutData about("kapptest", "kapptest", "version");
+ KCmdLineArgs::init(argc, argv, &about);
+
+ KApplication a;
+
+ TQString error;
+ TQCString dcopService;
+ int pid;
+ a.startServiceByDesktopName( "kaddressbook", TQString::null, &error, &dcopService, &pid );
+ kdDebug() << "Started. error=" << error << " dcopService=" << dcopService << " pid=" << pid << endl;
+ a.exec();
+}
diff --git a/tdecore/tests/testqtargs.cpp b/tdecore/tests/testqtargs.cpp
new file mode 100644
index 000000000..d1c8ff244
--- /dev/null
+++ b/tdecore/tests/testqtargs.cpp
@@ -0,0 +1,104 @@
+/*
+ testqtargs -- is there really a bug in KCmdLineArgs or am I on crack?
+
+ I used the following compile options:
+
+ g++ -g -Wall -o testqtargs testqtargs.cpp -I/usr/X11R6/include \
+ -I/opt/qt3/include -I/opt/trinity/include -L/usr/X11R6/lib -L/opt/qt3/lib \
+ -L/opt/trinity/lib -lqt -ltdecore
+
+ if invoked like this ./testqtargs --bg blue --caption something --hello hi
+
+ The program should list argv[] then produce output like this:
+
+ qt arg[0] = background
+ qt arg[1] = blue
+ arg bg = blue
+ arg caption = something
+ arg hello = hi
+
+ Instead for me it prints:
+
+ qt arg[0] = -background
+ qt arg[1] = blue
+ arg caption = something
+ arg hello = hi
+
+ See the extra dash in qt arg[0]? I believe that is the cause of the problem.
+ --bg is aliased to --background but If you try it with --background or
+ -background, you get the same thing.
+
+ in tdecore/kapplication.cpp, KCmdLineOption qt_options is defined and used
+ by the static method Kapplication::addCmdLineOptions to add the Qt options
+ but its' entries look like this:
+
+ { "background <color>", I18N_NOOP("sets the default background color and an\n
+application palette (light and dark shades are\ncalculated)."), 0},
+
+ it looks for "background" instead of "-background" so never find the arg.
+
+ Software: g++ 2.95, kdelibs from CVS Jan 28, Qt 3.01
+ OS: Debian GNU/Linux 3.0 (sid)
+
+
+*/
+
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <klocale.h>
+
+static const KCmdLineOptions options[] =
+{
+ { "hello ", I18N_NOOP("Says hello"), 0 },
+ KCmdLineLastOption
+};
+
+int main(int argc, char *argv[])
+{
+ for (int i = 0; i < argc; i++)
+ {
+ qDebug("argv[%d] = %s", i, argv[i]);
+ }
+ KAboutData aboutData( "testqtargs", I18N_NOOP("testqtargs"),
+ "1.0", I18N_NOOP("testqtargs"), KAboutData::License_GPL,
+ "", "", "", "");
+
+ KCmdLineArgs::init(argc, argv, &aboutData);
+ KCmdLineArgs::addCmdLineOptions(options);
+
+ KCmdLineArgs *qtargs = KCmdLineArgs::parsedArgs("qt");
+ for (int i = 0; i < qtargs->count(); i++)
+ {
+ qDebug("qt arg[%d] = %s", i, qtargs->arg(i));
+ }
+
+ KApplication app;
+
+ KCmdLineArgs *kdeargs = KCmdLineArgs::parsedArgs("kde");
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ // An arg set by Qt
+ if(qtargs->isSet("background"))
+ {
+ qDebug("arg bg = %s", (const char*)qtargs->getOption("background"));
+ }
+ // An arg set by KDE
+ if(kdeargs->isSet("caption"))
+ {
+ qDebug("arg caption = %s", (const char*)kdeargs->getOption("caption"));
+ }
+ // An arg set by us.
+ if(args->isSet("hello"))
+ {
+ qDebug("arg hello = %s", (const char*)args->getOption("hello"));
+ }
+ args->clear();
+
+ TQWidget *w = new TQWidget();
+ app.setMainWidget(w);
+ w->show();
+
+ return app.exec();
+}
+