From 0603238d2b0356d63ebb45c1bdd856a7ddc54744 Mon Sep 17 00:00:00 2001 From: Dan Dennedy Date: Tue, 30 Apr 2013 21:45:31 -0700 Subject: [PATCH] Add the start of a unit test suite using QtTest. --- src/tests/common.pri | 16 +++++ src/tests/test_properties/test_properties.cpp | 58 +++++++++++++++++++ src/tests/test_properties/test_properties.pro | 4 ++ src/tests/test_repository/test_repository.cpp | 56 ++++++++++++++++++ src/tests/test_repository/test_repository.pro | 4 ++ src/tests/tests.pro | 3 + 6 files changed, 141 insertions(+) create mode 100644 src/tests/common.pri create mode 100644 src/tests/test_properties/test_properties.cpp create mode 100644 src/tests/test_properties/test_properties.pro create mode 100644 src/tests/test_repository/test_repository.cpp create mode 100644 src/tests/test_repository/test_repository.pro create mode 100644 src/tests/tests.pro diff --git a/src/tests/common.pri b/src/tests/common.pri new file mode 100644 index 00000000..85e978da --- /dev/null +++ b/src/tests/common.pri @@ -0,0 +1,16 @@ +QT += testlib +QT -= gui + +CONFIG += console +CONFIG -= app_bundle +CONFIG += testcase +TEMPLATE = app +DEFINES += SRCDIR=\\\"$$PWD/\\\" + +win32 { + INCLUDEPATH += include/mlt++ include/mlt + LIBS += -Llib -lmlt++ -lmlt +} else { + CONFIG += link_pkgconfig + PKGCONFIG += mlt++ +} diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp new file mode 100644 index 00000000..06dd8f24 --- /dev/null +++ b/src/tests/test_properties/test_properties.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2013 Dan Dennedy + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with consumer library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include +using namespace Mlt; + +class TestProperties: public QObject +{ + Q_OBJECT + +public: + TestProperties() {} + +private Q_SLOTS: + void InstantiationIsAReference() + { + Properties p; + QCOMPARE(p.ref_count(), 1); + } + + void CopyAddsReference() + { + Properties p; + Properties q = p; + QCOMPARE(p.ref_count(), 2); + } + + void DestructionRemovesReference() + { + Properties p; + Properties* q = new Properties(p); + QCOMPARE(p.ref_count(), 2); + delete q; + QCOMPARE(p.ref_count(), 1); + } +}; + +QTEST_APPLESS_MAIN(TestProperties) + +#include "test_properties.moc" diff --git a/src/tests/test_properties/test_properties.pro b/src/tests/test_properties/test_properties.pro new file mode 100644 index 00000000..0846b085 --- /dev/null +++ b/src/tests/test_properties/test_properties.pro @@ -0,0 +1,4 @@ +include (../common.pri) +TARGET = test_properties +SOURCES = test_properties.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/src/tests/test_repository/test_repository.cpp b/src/tests/test_repository/test_repository.cpp new file mode 100644 index 00000000..8cd8d4fb --- /dev/null +++ b/src/tests/test_repository/test_repository.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2013 Dan Dennedy + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with consumer library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include +using namespace Mlt; + +class TestRepository : public QObject +{ + Q_OBJECT + +public: + TestRepository() {} + +private Q_SLOTS: + void ThereAreProducers() + { + Repository* r = Factory::init(); + Properties* producers = r->producers(); + QVERIFY(producers->is_valid()); + if (producers->is_valid()) + QVERIFY(producers->count() > 0); + delete producers; + } + + void ThereAreConsumers() + { + Repository* r = Factory::init(); + Properties* consumers = r->consumers(); + QVERIFY(consumers->is_valid()); + if (consumers->is_valid()) + QVERIFY(consumers->count() > 0); + delete consumers; + } +}; + +QTEST_APPLESS_MAIN(TestRepository) + +#include "test_repository.moc" diff --git a/src/tests/test_repository/test_repository.pro b/src/tests/test_repository/test_repository.pro new file mode 100644 index 00000000..e9c36906 --- /dev/null +++ b/src/tests/test_repository/test_repository.pro @@ -0,0 +1,4 @@ +include(../common.pri) +TARGET = test_repository +SOURCES += test_repository.cpp + diff --git a/src/tests/tests.pro b/src/tests/tests.pro new file mode 100644 index 00000000..4a022769 --- /dev/null +++ b/src/tests/tests.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = test_properties \ + test_repository -- 2.39.2