Started adding cppunit tests

This commit is contained in:
Michaël Lemaire 2013-10-31 22:53:22 +01:00
parent 5dfa34dd56
commit ca0f87b419
8 changed files with 193 additions and 1 deletions

View file

@ -28,6 +28,9 @@ public:
inline const QString& getName() {return name;}
void setName(QString name);
inline const BaseDefinition* getParent() {return parent;}
inline const BaseDefinition* getRoot() {return root;}
protected:
void addChild(BaseDefinition* child);
void removeChild(BaseDefinition* child);

View file

@ -10,7 +10,7 @@ SUBDIRS = \
editing \
controlling
unix:SUBDIRS += testing
unix:SUBDIRS += testing tests
basics.depends = system
definition.depends = basics
@ -19,3 +19,4 @@ exploring.depends = rendering
editing.depends = exploring rendering
controlling.depends = rendering
unix:testing.depends = rendering
unix:tests.depends = rendering

View file

@ -0,0 +1,5 @@
#include "BaseTestCase.h"
BaseTestCase::BaseTestCase()
{
}

16
src/tests/BaseTestCase.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef BASETESTCASE_H
#define BASETESTCASE_H
#include <cppunit/TestFixture.h>
#include <cppunit/TestSuite.h>
#include <cppunit/TestCaller.h>
#include <cppunit/extensions/HelperMacros.h>
using namespace CppUnit;
class BaseTestCase: public TestFixture
{
public:
BaseTestCase();
};
#endif // BASETESTCASE_H

81
src/tests/Layers_Test.cpp Normal file
View file

@ -0,0 +1,81 @@
#include "Layers_Test.h"
#include "Layers.h"
BaseDefinition* _construc1(Layers*)
{
return new BaseDefinition(NULL);
}
BaseDefinition* _construc2(Layers* parent)
{
BaseDefinition* result = new BaseDefinition(parent);
result->setName("test");
return result;
}
void Layers_Test::testConstructor()
{
Layers layers1(NULL, _construc1);
CPPUNIT_ASSERT_EQUAL(0, layers1.count());
}
void Layers_Test::testNullLayer()
{
Layers layers1(NULL, _construc1);
for (int i = -2; i < 5; i++)
{
BaseDefinition* layer = layers1.getLayer(0);
CPPUNIT_ASSERT(layer != NULL);
CPPUNIT_ASSERT(NULL == layer->getParent());
CPPUNIT_ASSERT(layer == layer->getRoot());
CPPUNIT_ASSERT(QString() == layer->getName());
}
CPPUNIT_ASSERT_EQUAL(0, layers1.count());
}
void Layers_Test::testCopy()
{
Layers layers1(NULL, _construc2);
layers1.addLayer();
CPPUNIT_ASSERT_EQUAL(1, layers1.count());
// Copy with the same constructor
Layers layers2(NULL, _construc2);
CPPUNIT_ASSERT_EQUAL(0, layers2.count());
layers1.copy(&layers2);
CPPUNIT_ASSERT_EQUAL(1, layers2.count());
CPPUNIT_ASSERT(QString("test") == layers1.getLayer(0)->getName());
CPPUNIT_ASSERT(&layers1 == layers1.getLayer(0)->getParent());
CPPUNIT_ASSERT(QString("test") == layers2.getLayer(0)->getName());
CPPUNIT_ASSERT(&layers2 == layers2.getLayer(0)->getParent());
CPPUNIT_ASSERT(layers1.getLayer(0) != layers2.getLayer(0));
}
void Layers_Test::testMaxLayerCount()
{
Layers layers1(NULL, _construc1);
layers1.setMaxLayerCount(2);
CPPUNIT_ASSERT_EQUAL(0, layers1.count());
layers1.addLayer();
CPPUNIT_ASSERT_EQUAL(1, layers1.count());
layers1.addLayer();
CPPUNIT_ASSERT_EQUAL(2, layers1.count());
layers1.addLayer();
CPPUNIT_ASSERT_EQUAL(2, layers1.count());
layers1.addLayer();
CPPUNIT_ASSERT_EQUAL(2, layers1.count());
layers1.removeLayer(0);
CPPUNIT_ASSERT_EQUAL(1, layers1.count());
layers1.addLayer();
CPPUNIT_ASSERT_EQUAL(2, layers1.count());
layers1.addLayer();
CPPUNIT_ASSERT_EQUAL(2, layers1.count());
}
CPPUNIT_TEST_SUITE_REGISTRATION(Layers_Test);

22
src/tests/Layers_Test.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef LAYERS_TEST_H
#define LAYERS_TEST_H
#include "BaseTestCase.h"
class Layers_Test: public BaseTestCase
{
public:
CPPUNIT_TEST_SUITE(Layers_Test);
CPPUNIT_TEST(testConstructor);
CPPUNIT_TEST(testNullLayer);
CPPUNIT_TEST(testCopy);
CPPUNIT_TEST(testMaxLayerCount);
CPPUNIT_TEST_SUITE_END();
void testConstructor();
void testNullLayer();
void testCopy();
void testMaxLayerCount();
};
#endif // LAYERS_TEST_H

22
src/tests/main.cpp Normal file
View file

@ -0,0 +1,22 @@
#include <cppunit/TextTestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <QtCore/QDebug>
using namespace CppUnit;
void noMessageOutput(QtMsgType, const QMessageLogContext&, const QString&)
{
}
int main()
{
qInstallMessageHandler(noMessageOutput);
TextTestRunner runner;
TestFactoryRegistry &registry = TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
return runner.run() ? 1 : 0;
}

42
src/tests/tests.pro Normal file
View file

@ -0,0 +1,42 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
TARGET = paysages-tests2
unix {
CONFIG += link_pkgconfig
PKGCONFIG += cppunit
}
SOURCES += main.cpp \
Layers_Test.cpp \
BaseTestCase.cpp
HEADERS += \
Layers_Test.h \
BaseTestCase.h
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system
else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system
INCLUDEPATH += $$PWD/../system
DEPENDPATH += $$PWD/../system
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../basics/release/ -lpaysages_basics
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../basics/debug/ -lpaysages_basics
else:unix: LIBS += -L$$OUT_PWD/../basics/ -lpaysages_basics
INCLUDEPATH += $$PWD/../basics
DEPENDPATH += $$PWD/../basics
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../definition/release/ -lpaysages_definition
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../definition/debug/ -lpaysages_definition
else:unix: LIBS += -L$$OUT_PWD/../definition/ -lpaysages_definition
INCLUDEPATH += $$PWD/../definition
DEPENDPATH += $$PWD/../definition
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../rendering/release/ -lpaysages_rendering
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ -lpaysages_rendering
else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering
INCLUDEPATH += $$PWD/../rendering
DEPENDPATH += $$PWD/../rendering