/*  This file is part of the KDE project
    Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/

#include <QtCore/QList>
#include <QtCore/QObject>

#include <Phonon/AudioOutputDevice>
#include <Phonon/BackendCapabilities>

#include <qtest_kde.h>

#include "../mixer.h"
#include "../mixerlist.h"
#include "../mixercontrol.h"
#include "../mixercontrolset.h"

using Phonon::Mixer::Mixer;
using Phonon::Mixer::MixerList;
using Phonon::Mixer::MixerControl;
using Phonon::Mixer::MixerControlSet;

class MixerTest : public QObject
{
    Q_OBJECT
    private slots:
        void initTestCase();
        void mixerListing();
        void listControls();
        void waitForEvents();
        void cleanupTestCase();

    private:
        QList<Phonon::AudioOutputDevice> m_deviceList;
};

void MixerTest::initTestCase()
{
    QCoreApplication::setApplicationName("mixertest");
    m_deviceList = Phonon::BackendCapabilities::availableAudioOutputDevices();
}

void MixerTest::mixerListing()
{
    QList<Mixer> mixerList;
    foreach (const Phonon::AudioOutputDevice &dev, m_deviceList) {
        Mixer m(dev);
        if (m.isValid()) {
            mixerList << m;
        }
    }
    QVERIFY(!mixerList.isEmpty());
    QList<Mixer> l = MixerList::availableMixers();
    foreach (const Mixer &m, mixerList) {
        QVERIFY(l.contains(m));
    }
}

void MixerTest::listControls()
{
    foreach (Mixer m, MixerList::availableMixers()) {
        QVERIFY(m.isValid());
        QList<MixerControlSet> l = m.controlSets();
        foreach (const MixerControlSet &c, l) {
            QVERIFY(c.isValid());

//X             if (c.type() == MixerControl::Enum) {
//X                 qDebug() << c.name() << c.value(0) << c.enumStrings();
//X             } else {
//X                 qDebug() << c.name() << c.value(0);
//X             }
        }
    }
}

void MixerTest::waitForEvents()
{
    QList<Mixer> l = MixerList::availableMixers();
    QTest::kWaitForSignal(this, SIGNAL(destroyed()), 60000);
}

void MixerTest::cleanupTestCase()
{
}

QTEST_MAIN(MixerTest)

#include "mixertest.moc"
