summaryrefslogtreecommitdiffstats
path: root/kdemm/test
diff options
context:
space:
mode:
Diffstat (limited to 'kdemm/test')
-rw-r--r--kdemm/test/Makefile.am30
-rw-r--r--kdemm/test/main.cpp38
-rw-r--r--kdemm/test/statetest.cpp299
-rw-r--r--kdemm/test/statetest.h57
-rw-r--r--kdemm/test/testwidget.cpp194
-rw-r--r--kdemm/test/testwidget.h64
6 files changed, 682 insertions, 0 deletions
diff --git a/kdemm/test/Makefile.am b/kdemm/test/Makefile.am
new file mode 100644
index 000000000..d488da365
--- /dev/null
+++ b/kdemm/test/Makefile.am
@@ -0,0 +1,30 @@
+# This file is part of the KDE libraries
+# Copyright (C) 2004 Matthias Kretz <kretz@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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+INCLUDES = -I$(top_srcdir)/kdemm $(all_includes)
+
+METASOURCES = AUTO
+
+check_PROGRAMS = guitest statetest
+
+guitest_SOURCES = main.cpp testwidget.cpp
+guitest_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+guitest_LDADD = $(LIB_KPARTS) $(top_builddir)/kdemm/libkdemm.la
+
+statetest_SOURCES = statetest.cpp
+statetest_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+statetest_LDADD = $(top_builddir)/kdemm/libkdemm.la
diff --git a/kdemm/test/main.cpp b/kdemm/test/main.cpp
new file mode 100644
index 000000000..eb42dc1ec
--- /dev/null
+++ b/kdemm/test/main.cpp
@@ -0,0 +1,38 @@
+/* This file is part of the KDE project
+ Copyright (C) 2004 Matthias Kretz <kretz@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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+#include "testwidget.h"
+
+int main( int argc, char ** argv )
+{
+ KAboutData about( "kdemmtest", "KDE Multimedia Test",
+ "0.1", "Testprogram",
+ KAboutData::License_LGPL, 0 );
+ about.addAuthor( "Matthias Kretz", 0, "kretz@kde.org" );
+ KCmdLineArgs::init( argc, argv, &about );
+ KApplication app;
+ TestWidget foo;
+ app.setMainWidget( &foo );
+ return app.exec();
+}
+
+// vim: sw=4 ts=4 noet
diff --git a/kdemm/test/statetest.cpp b/kdemm/test/statetest.cpp
new file mode 100644
index 000000000..48ae444ee
--- /dev/null
+++ b/kdemm/test/statetest.cpp
@@ -0,0 +1,299 @@
+/* This file is part of the KDE project
+ Copyright (C) 2004 Matthias Kretz <kretz@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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "statetest.h"
+
+#include <kdemm/factory.h>
+#include <kdemm/channel.h>
+#include <kdemm/player.h>
+
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kurl.h>
+#include <cstdlib>
+
+using namespace KDE::Multimedia;
+
+kdbgstream& operator<<( kdbgstream & stream, const Player::State state )
+{
+ switch( state )
+ {
+ case Player::NoMedia:
+ stream << "NoMedia";
+ break;
+ case Player::Loading:
+ stream << "Loading";
+ break;
+ case Player::Stopped:
+ stream << "Stopped";
+ break;
+ case Player::Playing:
+ stream << "Playing";
+ break;
+ case Player::Buffering:
+ stream << "Buffering";
+ break;
+ case Player::Paused:
+ stream << "Paused";
+ break;
+ }
+
+ return stream;
+}
+
+void StateTester::run( const KURL & url )
+{
+ /*
+ check for correct states:
+
+ - after construction:
+ NoMedia
+
+ - load()
+ NoMedia -> NoMedia, (only? for remote files: Loading -> NoMedia, Stopped ), Stopped
+
+ - play()
+ Stopped, Paused -> Playing (except: Stopped -> Stopped)
+
+ - when playing:
+ Playing -> Buffering -> Playing
+
+ - pause()
+ Playing -> Paused
+
+ - stop()
+ Playing, Paused -> Stopped
+ */
+
+ f = Factory::self();
+ kdDebug() << "using backend: " << f->backendName() <<
+ "\n Comment: " << f->backendComment() <<
+ "\n Version: " << f->backendVersion() << endl;
+
+ c = f->createChannel( "teststates" );
+ p = f->createPlayer();
+ p->setOutputChannel( c );
+ connect( p, TQT_SIGNAL( stateChanged( KDE::Multimedia::Player::State, KDE::Multimedia::Player::State ) ),
+ TQT_SLOT( stateChanged( KDE::Multimedia::Player::State, KDE::Multimedia::Player::State ) ) );
+ connect( p, TQT_SIGNAL( finished() ), kapp, TQT_SLOT( quit() ) );
+
+ if( p->state() != Player::NoMedia )
+ kdDebug() << p->state() << " should be NoMedia" << endl;
+
+ kdDebug() << "loading " << url << endl;
+
+ if( ! p->load( url ) )
+ kdDebug() << "load failed" << endl;
+ if( p->state() == Player::Loading )
+ kdDebug() << "wait until Player finished Loading" << endl;
+ else if( p->state() == Player::Stopped )
+ testplaying();
+ else if( p->state() == Player::NoMedia )
+ {
+ kdDebug() << "could not load media. exiting." << endl;
+ exit( 0 );
+ }
+}
+
+void StateTester::stateChanged( Player::State newstate, Player::State oldstate )
+{
+ kdDebug() << "stateChanged( new = " << newstate << ", old = " << oldstate << " )" << endl;
+ switch( oldstate )
+ {
+ case Player::NoMedia:
+ switch( newstate )
+ {
+ case Player::NoMedia:
+ case Player::Loading:
+ case Player::Stopped:
+ return;
+ default:
+ break;
+ }
+ case Player::Loading:
+ switch( newstate )
+ {
+ case Player::NoMedia:
+ return;
+ case Player::Stopped:
+ testplaying();
+ return;
+ default:
+ break;
+ }
+ case Player::Stopped:
+ switch( newstate )
+ {
+ case Player::Playing:
+ case Player::Stopped:
+ return;
+ default:
+ break;
+ }
+ case Player::Playing:
+ switch( newstate )
+ {
+ case Player::Buffering:
+ //testbuffering();
+ case Player::Paused:
+ case Player::Stopped:
+ return;
+ default:
+ break;
+ }
+ case Player::Buffering:
+ switch( newstate )
+ {
+ case Player::Playing:
+ case Player::Stopped:
+ case Player::Paused:
+ return;
+ default:
+ break;
+ }
+ case Player::Paused:
+ switch( newstate )
+ {
+ case Player::Playing:
+ case Player::Stopped:
+ case Player::Buffering:
+ return;
+ default:
+ break;
+ }
+ }
+
+ wrongStateChange();
+}
+
+void StateTester::testplaying()
+{
+ if( ! p->play() )
+ kdDebug() << "play failed" << endl;
+ if( p->state() == Player::Stopped )
+ {
+ kdDebug() << "could not play media. exiting." << endl;
+ exit( 0 );
+ }
+ else if( p->state() == Player::Playing )
+ {
+ if( ! p->pause() )
+ {
+ kdDebug() << "pause failed" << endl;
+ if( p->state() != Player::Playing )
+ wrongStateChange();
+ }
+ else
+ {
+ if( p->state() != Player::Paused )
+ wrongStateChange();
+ if( ! p->play() )
+ {
+ kdDebug() << "play failed" << endl;
+ if( p->state() != Player::Paused )
+ wrongStateChange();
+ kdError() << "what now? play shouldn't fail here" << endl;
+ exit( 1 );
+ }
+ if( p->state() != Player::Playing )
+ wrongStateChange();
+ }
+ // it's playing now
+ if( ! p->stop() )
+ {
+ kdDebug() << "stop failed" << endl;
+ if( p->state() != Player::Playing )
+ wrongStateChange();
+ }
+ else
+ {
+ if( p->state() != Player::Stopped )
+ wrongStateChange();
+ if( ! p->play() )
+ {
+ kdDebug() << "play failed" << endl;
+ if( p->state() != Player::Stopped )
+ wrongStateChange();
+ kdError() << "play shouldn't fail after it worked before. exiting." << endl;
+ exit( 1 );
+ }
+ }
+ // it's playing again
+ if( ! p->pause() )
+ {
+ kdDebug() << "pause failed. exiting." << endl;
+ exit( 1 );
+ }
+ if( p->state() != Player::Paused )
+ wrongStateChange();
+ if( ! p->stop() )
+ {
+ kdDebug() << "stop failed" << endl;
+ if( p->state() != Player::Paused )
+ wrongStateChange();
+ exit( 1 );
+ }
+ if( p->state() != Player::Stopped )
+ wrongStateChange();
+ // do further checking, calling load again
+ kdDebug() << "success! playing the last 1/5 of the file now and quit on the finished signal" << endl;
+ p->play();
+ p->seek( p->totalTime() * 4 / 5 );
+ }
+}
+
+void StateTester::wrongStateChange()
+{
+ kdError() << "wrong state change in backend!" << endl;
+ exit( 1 );
+}
+
+static const KCmdLineOptions options[] =
+{
+ { "+url", I18N_NOOP( "media file to play" ), 0 },
+ KCmdLineLastOption // End of options.
+};
+
+int main( int argc, char ** argv )
+{
+ KAboutData about( "kdemmtest", "KDE Multimedia Test",
+ "0.1", "Testprogram",
+ KAboutData::License_LGPL, 0 );
+ about.addAuthor( "Matthias Kretz", 0, "kretz@kde.org" );
+ KCmdLineArgs::init( argc, argv, &about );
+ KCmdLineArgs::addCmdLineOptions( options );
+ KApplication app; // we need it for KTrader
+
+ StateTester tester;
+ if( KCmdLineArgs::parsedArgs()->count() > 0 )
+ tester.run( KCmdLineArgs::parsedArgs()->url( 0 ) );
+ else
+ {
+ KCmdLineArgs::usage();
+ exit( 2 );
+ }
+
+ return app.exec();
+}
+
+#include "statetest.moc"
+
+// vim: sw=4 ts=4 noet
diff --git a/kdemm/test/statetest.h b/kdemm/test/statetest.h
new file mode 100644
index 000000000..cf912ac56
--- /dev/null
+++ b/kdemm/test/statetest.h
@@ -0,0 +1,57 @@
+/* This file is part of the KDE project
+ Copyright (C) 2004 Matthias Kretz <kretz@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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef STATETEST_H
+#define STATETEST_H
+
+#include <tqobject.h>
+
+#include <kdemm/player.h>
+
+class KURL;
+
+namespace KDE
+{
+ namespace Multimedia
+ {
+ class Factory;
+ class Channel;
+ }
+}
+
+class StateTester : public QObject
+{
+ Q_OBJECT
+ public:
+ void run( const KURL & );
+
+ private slots:
+ void stateChanged( KDE::Multimedia::Player::State, KDE::Multimedia::Player::State );
+
+ private:
+ void testplaying();
+ void wrongStateChange();
+
+ KDE::Multimedia::Factory * f;
+ KDE::Multimedia::Channel * c;
+ KDE::Multimedia::Player * p;
+};
+
+#endif // STATETEST_H
+// vim: sw=4 ts=4 noet
diff --git a/kdemm/test/testwidget.cpp b/kdemm/test/testwidget.cpp
new file mode 100644
index 000000000..a9a579cd1
--- /dev/null
+++ b/kdemm/test/testwidget.cpp
@@ -0,0 +1,194 @@
+/* This file is part of the KDE project
+ Copyright (C) 2004 Matthias Kretz <kretz@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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "testwidget.h"
+
+#include <kdemm/factory.h>
+#include <kdemm/player.h>
+#include <kdemm/channel.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+#include <kurl.h>
+#include <tqslider.h>
+#include <tqlayout.h>
+#include <tqapplication.h>
+#include <tqpushbutton.h>
+#include <tqlabel.h>
+#include <klineedit.h>
+#include <kurlcompletion.h>
+
+using namespace KDE::Multimedia;
+
+TestWidget::TestWidget()
+ : TQWidget( 0, 0 )
+ , m_ticking( false )
+{
+ c = Factory::self()->createChannel( i18n( "KDE Multimedia testprogram" ) );
+ if( ! c )
+ kdFatal() << "couldn't create outputdevice" << endl;
+ po = Factory::self()->createPlayer();
+ if( ! po )
+ kdFatal() << "couldn't create Player" << endl;
+
+ if( ! po->setOutputChannel( c ) )
+ kdFatal() << "PlayObject::setOutputChannel failed" << endl;
+
+ if( ! po->state() == Player::NoMedia )
+ kdFatal() << "PlayObject in wrong state 1" << endl;
+
+ ( new TQHBoxLayout( this ) )->setAutoAdd( true );
+
+ m_v1slider = new TQSlider( this );
+ m_v1slider->setRange( 0, 150 );
+ m_v1slider->setValue( ( int )( 100 * po->volume() ) );
+ connect( m_v1slider, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( v1changed( int ) ) );
+
+ m_v2slider = new TQSlider( this );
+ m_v2slider->setRange( 0, 150 );
+ m_v2slider->setValue( ( int )( 100 * c->volume() ) );
+ connect( m_v2slider, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( v2changed( int ) ) );
+
+ TQFrame * frame = new TQFrame( this );
+ ( new TQVBoxLayout( frame ) )->setAutoAdd( true );
+
+ m_seekslider = new TQSlider( frame );
+ m_seekslider->setOrientation( Qt::Horizontal );
+ connect( m_seekslider, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( seek( int ) ) );
+ po->setTickInterval( 100 );
+ connect( po, TQT_SIGNAL( tick( long ) ), TQT_SLOT( tick( long ) ) );
+ connect( po, TQT_SIGNAL( length( long ) ), TQT_SLOT( length( long ) ) );
+
+ m_statelabel = new TQLabel( frame );
+ connect( po, TQT_SIGNAL( stateChanged( KDE::Multimedia::Player::State, KDE::Multimedia::Player::State ) ),
+ TQT_SLOT( stateChanged( KDE::Multimedia::Player::State ) ) );
+ stateChanged( po->state() );
+
+ TQPushButton * pause = new TQPushButton( frame );
+ pause->setText( "pause" );
+ connect( pause, TQT_SIGNAL( clicked() ), po, TQT_SLOT( pause() ) );
+
+ TQPushButton * play = new TQPushButton( frame );
+ play->setText( "play" );
+ connect( play, TQT_SIGNAL( clicked() ), po, TQT_SLOT( play() ) );
+
+ TQPushButton * stop = new TQPushButton( frame );
+ stop->setText( "stop" );
+ connect( stop, TQT_SIGNAL( clicked() ), po, TQT_SLOT( stop() ) );
+
+ KLineEdit * file = new KLineEdit( frame );
+ file->setCompletionObject( new KURLCompletion( KURLCompletion::FileCompletion ) );
+ connect( file, TQT_SIGNAL( returnPressed( const TQString & ) ), TQT_SLOT( loadFile( const TQString & ) ) );
+
+ TQFrame * frame2 = new TQFrame( this );
+ ( new TQVBoxLayout( frame2 ) )->setAutoAdd( true );
+
+ m_volumelabel1 = new TQLabel( frame2 );
+ m_volumelabel1->setText( TQString::number( po->volume() ) );
+
+ m_volumelabel2 = new TQLabel( frame2 );
+ m_volumelabel2->setText( TQString::number( c->volume() ) );
+
+ m_totaltime = new TQLabel( frame2 );
+ m_totaltime->setText( TQString::number( po->totalTime() ) );
+
+ m_currenttime = new TQLabel( frame2 );
+ m_currenttime->setText( TQString::number( po->currentTime() ) );
+
+ m_remainingtime = new TQLabel( frame2 );
+ m_remainingtime->setText( TQString::number( po->remainingTime() ) );
+
+ show();
+
+ if( ! po->load( KURL( "/home/mkretz/Musik/qt23.mp3" ) ) )
+ kdFatal() << "PlayObject::load failed" << endl;
+
+ connect( po, TQT_SIGNAL( finished() ), qApp, TQT_SLOT( quit() ) );
+
+}
+
+void TestWidget::v1changed( int v )
+{
+ if( ! po->setVolume( ( ( float )v ) / 100 ) )
+ kdDebug() << "setVolume1 failed" << endl;
+ m_volumelabel1->setText( TQString::number( po->volume() ) );
+}
+
+void TestWidget::v2changed( int v )
+{
+ if( ! c->setVolume( ( ( float )v ) / 100 ) )
+ kdDebug() << "setVolume2 failed" << endl;
+ m_volumelabel2->setText( TQString::number( c->volume() ) );
+}
+
+void TestWidget::tick( long t )
+{
+ m_ticking = true;
+ m_seekslider->setValue( t );
+ m_currenttime->setText( TQString::number( po->currentTime() ) );
+ m_remainingtime->setText( TQString::number( po->remainingTime() ) );
+ m_ticking = false;
+}
+
+void TestWidget::stateChanged( Player::State newstate )
+{
+ switch( newstate )
+ {
+ case Player::NoMedia:
+ m_statelabel->setText( "NoMedia" );
+ break;
+ case Player::Loading:
+ m_statelabel->setText( "Loading" );
+ break;
+ case Player::Stopped:
+ m_statelabel->setText( "Stopped" );
+ break;
+ case Player::Paused:
+ m_statelabel->setText( "Paused" );
+ break;
+ case Player::Buffering:
+ m_statelabel->setText( "Buffering" );
+ break;
+ case Player::Playing:
+ m_statelabel->setText( "Playing" );
+ break;
+ }
+}
+
+void TestWidget::seek( int ms )
+{
+ if( ! m_ticking )
+ po->seek( ms );
+}
+
+void TestWidget::length( long ms )
+{
+ m_seekslider->setRange( 0, ms );
+ m_totaltime->setText( TQString::number( po->totalTime() ) );
+ m_currenttime->setText( TQString::number( po->currentTime() ) );
+ m_remainingtime->setText( TQString::number( po->remainingTime() ) );
+}
+
+void TestWidget::loadFile( const TQString & file )
+{
+ po->load( KURL( file ) );
+}
+
+#include "testwidget.moc"
+// vim: sw=4 ts=4 noet
diff --git a/kdemm/test/testwidget.h b/kdemm/test/testwidget.h
new file mode 100644
index 000000000..7a9d0df72
--- /dev/null
+++ b/kdemm/test/testwidget.h
@@ -0,0 +1,64 @@
+/* This file is part of the KDE project
+ Copyright (C) 2004 Matthias Kretz <kretz@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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef TESTWIDGET_H
+#define TESTWIDGET_H
+
+#include <tqwidget.h>
+
+#include <kdemm/player.h>
+
+class TQSlider;
+class TQLabel;
+class TQString;
+
+namespace KDE
+{
+ namespace Multimedia
+ {
+ class Channel;
+ }
+}
+
+using namespace KDE::Multimedia;
+
+class TestWidget : public QWidget
+{
+ Q_OBJECT
+ public:
+ TestWidget();
+ private slots:
+ void v1changed( int );
+ void v2changed( int );
+ void tick( long );
+ void stateChanged( KDE::Multimedia::Player::State );
+ void seek( int );
+ void length( long );
+ void loadFile( const TQString & );
+
+ private:
+ TQSlider *m_v1slider, *m_v2slider, *m_seekslider;
+ TQLabel *m_statelabel, *m_volumelabel1, *m_volumelabel2, *m_totaltime, *m_currenttime, *m_remainingtime;
+ Channel * c;
+ Player * po;
+ bool m_ticking;
+};
+
+#endif // TESTWIDGET_H
+// vim: sw=4 ts=4 noet