mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-09-02 02:12:47 +02:00
Fix tests for Qt5
Conflicts: tests/CMakeLists.txt
This commit is contained in:
committed by
Uwe L. Korn
parent
0558b2396f
commit
fc0fec1fdc
13
src/tests/CMakeLists.txt
Normal file
13
src/tests/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
if( BUILD_TESTS )
|
||||
setup_qt()
|
||||
|
||||
enable_testing()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/../src/tomahawk ${CMAKE_CURRENT_LIST_DIR}/../src/libtomahawk)
|
||||
include(tomahawk_add_test.cmake)
|
||||
|
||||
tomahawk_add_test(Result)
|
||||
tomahawk_add_test(Query)
|
||||
tomahawk_add_test(Database)
|
||||
|
||||
endif()
|
69
src/tests/TestDatabase.h
Normal file
69
src/tests/TestDatabase.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TOMAHAWK_TESTDATABASE_H
|
||||
#define TOMAHAWK_TESTDATABASE_H
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "database/Database.h"
|
||||
#include "database/DatabaseCommand_LogPlayback.h"
|
||||
|
||||
|
||||
class TestDatabaseCommand : public Tomahawk::DatabaseCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
virtual QString commandname() const { return "TestCommand"; }
|
||||
};
|
||||
|
||||
class TestDatabase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testFactories()
|
||||
{
|
||||
Tomahawk::Database* db = new Tomahawk::Database("test");
|
||||
Tomahawk::dbcmd_ptr command;
|
||||
|
||||
// can we check that his ASSERTs?, it's a build in type, one must not register it again
|
||||
// db->registerCommand<DatabaseCommand_LogPlayback>();
|
||||
|
||||
// check that if we request a factory for LogPlayback it really creates a LogPlayback object
|
||||
command = db->commandFactory<Tomahawk::DatabaseCommand_LogPlayback>()->newInstance();
|
||||
Tomahawk::DatabaseCommand_LogPlayback* lpCmd = qobject_cast< Tomahawk::DatabaseCommand_LogPlayback* >( command.data() );
|
||||
QVERIFY( lpCmd );
|
||||
|
||||
// try to handle a third party database command
|
||||
|
||||
// test no command factory is available until now
|
||||
QVERIFY( !db->commandFactory<TestDatabaseCommand>() );
|
||||
|
||||
// register it
|
||||
db->registerCommand<TestDatabaseCommand>();
|
||||
|
||||
// make sure it's available now
|
||||
command = db->commandFactory<TestDatabaseCommand>()->newInstance();
|
||||
TestDatabaseCommand* tCmd = qobject_cast< TestDatabaseCommand* >( command.data() );
|
||||
QVERIFY( tCmd );
|
||||
|
||||
delete db;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TOMAHAWK_TESTDATABASE_H
|
37
src/tests/TestQuery.h
Normal file
37
src/tests/TestQuery.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TOMAHAWK_TESTQUERY_H
|
||||
#define TOMAHAWK_TESTQUERY_H
|
||||
|
||||
#include "libtomahawk/Query.h"
|
||||
#include "libtomahawk/Source.h"
|
||||
|
||||
class TestQuery : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testGet()
|
||||
{
|
||||
Tomahawk::query_ptr q = Tomahawk::Query::get( "", "", "" );
|
||||
QVERIFY( !q );
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
51
src/tests/TestResult.h
Normal file
51
src/tests/TestResult.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TOMAHAWK_TESTRESULT_H
|
||||
#define TOMAHAWK_TESTRESULT_H
|
||||
|
||||
#include "libtomahawk/Result.h"
|
||||
#include "libtomahawk/Track.h"
|
||||
#include "libtomahawk/Source.h"
|
||||
|
||||
class TestResult : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testIsValid()
|
||||
{
|
||||
Tomahawk::result_ptr r = Tomahawk::Result::get( "/tmp/test.mp3" );
|
||||
QVERIFY( !r->isValid() );
|
||||
|
||||
Tomahawk::track_ptr t = Tomahawk::Track::get( "Artist", "Track" );
|
||||
r->setTrack( t );
|
||||
QVERIFY( r->isValid() );
|
||||
}
|
||||
|
||||
void testGet()
|
||||
{
|
||||
Tomahawk::result_ptr r = Tomahawk::Result::get( "" );
|
||||
QVERIFY( !r );
|
||||
|
||||
Tomahawk::result_ptr vr = Tomahawk::Result::get( "/tmp/test.mp3" );
|
||||
QVERIFY( vr );
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
35
src/tests/main.cpp.in
Normal file
35
src/tests/main.cpp.in
Normal file
@@ -0,0 +1,35 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest>
|
||||
#include <QtCore>
|
||||
|
||||
#include "Test@TOMAHAWK_TEST_CLASS@.h"
|
||||
#include "moc_Test@TOMAHAWK_TEST_CLASS@.cpp"
|
||||
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
QCoreApplication app( argc, argv );
|
||||
|
||||
#define TEST( Type ) { \
|
||||
Type o; \
|
||||
if (int r = QTest::qExec( &o, argc, argv ) != 0) return r; }
|
||||
|
||||
TEST( Test@TOMAHAWK_TEST_CLASS@ );
|
||||
return 0;
|
||||
}
|
23
src/tests/tomahawk_add_test.cmake
Normal file
23
src/tests/tomahawk_add_test.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
macro(tomahawk_add_test test_class)
|
||||
include_directories(${QT_INCLUDES} "${PROJECT_SOURCE_DIR}/src" ${CMAKE_CURRENT_BINARY_DIR} ${QJSON_INCLUDE_DIR})
|
||||
|
||||
set(TOMAHAWK_TEST_CLASS ${test_class})
|
||||
set(TOMAHAWK_TEST_TARGET ${TOMAHAWK_TEST_CLASS}Test)
|
||||
configure_file(main.cpp.in Test${TOMAHAWK_TEST_CLASS}.cpp)
|
||||
configure_file(Test${TOMAHAWK_TEST_CLASS}.h Test${TOMAHAWK_TEST_CLASS}.h)
|
||||
|
||||
add_executable(${TOMAHAWK_TEST_CLASS}Test Test${TOMAHAWK_TEST_CLASS}.cpp)
|
||||
|
||||
set_target_properties(${TOMAHAWK_TEST_TARGET} PROPERTIES AUTOMOC ON)
|
||||
|
||||
target_link_libraries(${TOMAHAWK_TEST_TARGET}
|
||||
${TOMAHAWK_LIBRARIES}
|
||||
${QT_QTTEST_LIBRARY}
|
||||
${QT_QTCORE_LIBRARY}
|
||||
)
|
||||
|
||||
add_test(NAME ${TOMAHAWK_TEST_TARGET} COMMAND ${TOMAHAWK_TEST_TARGET})
|
||||
|
||||
qt5_use_modules(${TOMAHAWK_TEST_TARGET} Core Network Widgets Sql Xml Test)
|
||||
|
||||
endmacro()
|
Reference in New Issue
Block a user