diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 015c63703..43832d632 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,3 +3,4 @@ include(tomahawk_add_test.cmake) tomahawk_add_test(Result) tomahawk_add_test(Query) +tomahawk_add_test(Database) diff --git a/tests/TestDatabase.h b/tests/TestDatabase.h new file mode 100644 index 000000000..fcc31fe8a --- /dev/null +++ b/tests/TestDatabase.h @@ -0,0 +1,62 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef TOMAHAWK_TESTDATABASE_H +#define TOMAHAWK_TESTDATABASE_H + +#include + +#include "database/Database.h" +#include "database/DatabaseCommand_LogPlayback.h" + + +class TestDatabaseCommand : public DatabaseCommand +{ +Q_OBJECT + virtual QString commandname() const { return "TestCommand"; } +}; + +class TestDatabase : public QObject +{ + Q_OBJECT + +private slots: + void testFactories() + { + Database* db = new Database("test"); + DatabaseCommand* command = 0; + + // can we check that his ASSERTs?, it's a build in type, one must not register it again + // db->registerCommand(); + + // check that if we request a factory for LogPlayback it really creates a LogPlayback object + command = db->commandFactory()->newInstance(); + DatabaseCommand_LogPlayback* lpCmd = qobject_cast< DatabaseCommand_LogPlayback* >( command ); + QVERIFY( lpCmd ); + + // try to handle a third party database command + db->registerCommand(); + command = db->commandFactory()->newInstance(); + TestDatabaseCommand* tCmd = qobject_cast< TestDatabaseCommand* >( command ); + QVERIFY( tCmd ); + + delete db; + } +}; + +#endif // TOMAHAWK_TESTDATABASE_H