Permalink
Browse files

Add simple script + template to create a unit test.

  • Loading branch information...
daniel-kristjansson committed Jun 8, 2013
1 parent 318454d commit 10e47a46ea7095714856121cc29ee3e8928ca553
@@ -0,0 +1,31 @@
#!/bin/bash -e
print_help() {
echo "Enter name of component to test (no spaces)"
}
if [[ "$1" == "" ]] ; then
print_help
exit 1
fi
echo "Creating test_$1"
mkdir test_$1
for EXT in pro cpp h ; do
echo "Creating test_$1/test_$1.$EXT"
cp test_template/test_template.$EXT test_$1/test_$1.$EXT
sed -i test_$1/test_$1.$EXT -e "s/test_template/test_$1/g"
sed -i test_$1/test_$1.$EXT -e "s/TestTemplate/Test$1/g"
git add test_$1/test_$1.$EXT
done
cat > test_$1/.gitignore <<EOF
test_$1
*.gcda
*.gcno
*.gcov
EOF
git add test_$1/.gitignore
echo git commit -m "Add test template for $1"
@@ -0,0 +1,5 @@
test_template
*.gcda
*.gcno
*.gcov
@@ -0,0 +1,3 @@
#include "test_template.h"
QTEST_APPLESS_MAIN(TestTemplate)
@@ -0,0 +1,77 @@
/*
* Class TestTemplate
*
* Copyright (C) AUTHOR_GOES_HERE 2013
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <QtTest/QtTest>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#define MSKIP(MSG) QSKIP(MSG, SkipSingle)
#else
#define MSKIP(MSG) QSKIP(MSG)
#endif
class TestTemplate: public QObject
{
Q_OBJECT
private slots:
// called at the beginning of these sets of tests
void initTestCase(void)
{
}
// called at the end of these sets of tests
void cleanupTestCase(void)
{
}
// called before each test case
void init(void)
{
}
// called after each test case
void cleanup(void)
{
}
// example passing test
void example_passing_unit_test(void)
{
QVERIFY(true);
}
// example benchmark test
void example_benchmark_test(void)
{
QBENCHMARK
{
int sum = 0;
for (int i = 0; i < 999; i++)
sum += i;
}
}
// example skipped test
void example_skipped_test(void)
{
MSKIP("this test should pass, but doesn't yet");
QVERIFY(true); // yes this really would pass, but this is an example
}
};
@@ -0,0 +1,44 @@
include ( ../../../../settings.pro )
QT += xml sql network
contains(QT_VERSION, ^4\\.[0-9]\\..*) {
CONFIG += qtestlib
}
contains(QT_VERSION, ^5\\.[0-9]\\..*) {
QT += testlib
}
TEMPLATE = app
TARGET = test_template
DEPENDPATH += . ../..
INCLUDEPATH += . ../..
LIBS += -L../.. -lmythbase-$$LIBVERSION
contains(QMAKE_CXX, "g++") {
QMAKE_CXXFLAGS += -O0 -fprofile-arcs -ftest-coverage
QMAKE_LFLAGS += -fprofile-arcs
}
macx {
QMAKE_LFLAGS += -Wl,-rpath,$(PWD)/../../../../external/zeromq/src/.libs/
QMAKE_LFLAGS += -Wl,-rpath,$(PWD)/../../../../external/nzmqt/src/
QMAKE_LFLAGS += -Wl,-rpath,$(PWD)/../../../../external/qjson/lib/
QMAKE_LFLAGS += -Wl,-rpath,$(PWD)/../..
}
linux | freebsd {
QMAKE_LFLAGS += -Wl,-rpath=$(PWD)/../../../../external/zeromq/src/.libs/
QMAKE_LFLAGS += -Wl,-rpath=$(PWD)/../../../../external/nzmqt/src/
QMAKE_LFLAGS += -Wl,-rpath=$(PWD)/../../../../external/qjson/lib/
QMAKE_LFLAGS += -Wl,-rpath=$(PWD)/../..
}
# Input
HEADERS += test_template.h
SOURCES += test_template.cpp
QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2)
QMAKE_CLEAN += ; rm -f *.gcov *.gcda *.gcno
LIBS += $$EXTRA_LIBS $$LATE_LIBS

0 comments on commit 10e47a4

Please sign in to comment.