// Version: $Id: 35945ae1823e3e8d4a34c3e8d4dc6df502a81260 $
//
//

// Commentary:
//
//

// Change Log:
//
//

// Code:

#include "dtkCorePluginFactoryTest.h"
#include "dtkCorePluginFactoryTestConcept.h"

#include <QtTest>

// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////

class dtkCorePluginFactoryTestConceptPlugin : public dtkCorePluginFactoryTestConcept
{
public:
    ~dtkCorePluginFactoryTestConceptPlugin(void) {}

public:
    QString name(void) const { return "dtkCorePluginFactoryTestConceptPlugin"; }
};

// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////

class dtkCorePluginFactoryTestCasePrivate
{
public:
    dtkCorePluginFactoryTestConceptPluginFactory factory;
};

dtkCorePluginFactoryTestConcept *dtkCorePluginFactoryTestConceptPluginCreator(void)
{
    return new dtkCorePluginFactoryTestConceptPlugin;
}

// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////

dtkCorePluginFactoryTestCase::dtkCorePluginFactoryTestCase(void) : d(new dtkCorePluginFactoryTestCasePrivate)
{

}

dtkCorePluginFactoryTestCase::~dtkCorePluginFactoryTestCase(void)
{
    delete d;
}

void dtkCorePluginFactoryTestCase::initTestCase(void)
{
    d->factory.record("dtkCorePluginFactoryTestConceptPlugin", dtkCorePluginFactoryTestConceptPluginCreator);
}

void dtkCorePluginFactoryTestCase::init(void)
{

}

void dtkCorePluginFactoryTestCase::testBasic(void)
{
    dtkCorePluginFactoryTestConcept *concept = d->factory.create("dtkCorePluginFactoryTestConceptPlugin");
    QVERIFY(concept);
    QCOMPARE(QString("dtkCorePluginFactoryTestConceptPlugin"), concept->name());
    d->factory.clear();
    concept = d->factory.create("dtkCorePluginFactoryTestConceptPlugin");
    QCOMPARE(nullptr, concept);
    QCOMPARE(0, d->factory.keys().count());
}

void dtkCorePluginFactoryTestCase::cleanup(void)
{

}

void dtkCorePluginFactoryTestCase::cleanupTestCase(void)
{

}

DTKTEST_MAIN_NOGUI(dtkCorePluginFactoryTest, dtkCorePluginFactoryTestCase)

//
// dtkCorePluginFactoryTest.cpp ends here
