Unit testing of shared library
-
wrote on 17 Jun 2014, 22:46 last edited by
I'm trying to create a test for shared library that I am creating. But without success.
I'm getting the error: /usr/bin/ld: cannot find -ldynamicui
I know that is probably a problem with the project files, but do not know what is.@
#main .proTEMPLATE = subdirs
SUBDIRS +=
tests
dynamicui
@@
#-------------------------------------------------Project created by QtCreator 2014-06-17T14:48:09
#-------------------------------------------------
#dynamicui .pro
QT += widgets
QT -= core gui
TARGET = dynamicui
TEMPLATE = libDEFINES += DYNAMICUI_LIBRARY
SOURCES += dynamicui.cpp
HEADERS += dynamicui.hpp
dynamicui_global.hppunix {
target.path = /usr/lib
INSTALLS += target
}
@@
#-------------------------------------------------Project created by QtCreator 2014-06-17T14:31:36
#-------------------------------------------------
#tests .pro
QT += widgets testlib
QT -= gui
TARGET = dynamicuitest
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += dynamicuitest.cpp
main.cpp
../dynamicui/dynamicui.cpp
DEFINES += SRCDIR=\"$$PWD/\"HEADERS +=
dynamicuitest.hpp
../dynamicui/dynamicui.hppwin32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../dynamicui/release/ -ldynamicui
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../dynamicui/debug/ -ldynamicui
else:unix:!macx: LIBS += -L$$OUT_PWD/../dynamicui/ -ldynamicuiINCLUDEPATH += $$PWD/../dynamicui
DEPENDPATH += $$PWD/../dynamicui
@@
// dynamicui_global.hpp
#ifndef DYNAMICUI_GLOBAL_HPP
#define DYNAMICUI_GLOBAL_HPP#include <QtCore/qglobal.h>
#if defined(DYNAMICUI_LIBRARY)
define DYNAMICUISHARED_EXPORT Q_DECL_EXPORT
#else
define DYNAMICUISHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // DYNAMICUI_GLOBAL_HPP
@@
// dynamicui.hpp#ifndef DYNAMICUI_HPP
#define DYNAMICUI_HPP#include "dynamicui_global.hpp"
#include <QtWidgets/QWidget>
#include <QtUiTools/QUiLoader>
#include <QString>
#include <QFile>class DYNAMICUISHARED_EXPORT DynamicUi
{
public:
explicit DynamicUi();
~DynamicUi();
QWidget* createUi(const QString, QWidget* = 0);
};#endif // DYNAMICUI_HPP
@@
#include "dynamicui.hpp"DynamicUi::DynamicUi() // Constructor
{
}DynamicUi::~DynamicUi() // Destructor
{
}
QWidget* DynamicUi::createUi(const QString url, QWidget *parent)
{
QUiLoader loader;
QFile ui_file(url);ui_file.open(QFile::ReadOnly);
QWidget* widget = loader.load(&ui_file, parent); // Load .ui file and return pointer for object created
ui_file.close();return widget;
}
@@
#ifndef DYNAMICUITEST_Hdefine DYNAMICUITEST_H
#include <QString>
#include <QtTest>
#include "dynamicui.hpp"class DynamicUiTest : public QObject
{
Q_OBJECTpublic:
DynamicUiTest();private Q_SLOTS:
void testCreateUi();
//void testCreateUi_data();
};
#endif
@@
#include "dynamicuitest.hpp"DynamicUiTest::DynamicUiTest()
{
}void DynamicUiTest::testCreateUi()
{
DynamicUi lui;
QString url = "/home/matheus/Dropbox/Projetos/C++/TecTracker/TecTrackerApp/Tests/gui/test.ui";
QCOMPARE(true, lui.createUi(url)->isWidgetType());//QFETCH(QString, data);
}/void LoadUiTest::testCreateForm_data()
{
QTest::addColumn<QString>("data");
QTest::newRow("0") << QString();
}/
@@
#include "dynamicuitest.hpp"
#include <QtWidgets/QApplication>int main(int argc, char *argv[])
{
QApplication app(argc, argv);DynamicUiTest tests;
QTest::qExec(&tests, argc, argv);return app.exec();
}
@ -
wrote on 18 Jun 2014, 01:22 last edited by
Where is the library located?
Are you sure that it is in $$OUT_PWD/../dynamicui/ ? -
wrote on 18 Jun 2014, 23:34 last edited by
I used the Add Library function of Qt Creator, this project file was automatically generated.
The project is divided into subdir, DynamicUi.pro, dynamicui.pro and tests.pro.
The test project is a unit test that tests the library. I believe we should first compile the library and then compile the test. The project file of test must point to the folder where it is the compiled binary library. But do not know how to get the pro. -
wrote on 19 Jun 2014, 02:21 last edited by
In the main pro file you listed test subdir first.
Try to put dynamicui first and add ordered to CONFIG@
SUBDIRS +=
dynamicui \
testsCONFIG += ordered
@ -
wrote on 19 Jun 2014, 13:56 last edited by
ok, it worked
finally, explain to me these lines of tests.pro:
@
DEFINES += SRCDIR=\"$$PWD/\"win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../dynamicui/release/ -ldynamicui
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../dynamicui/debug/ -ldynamicui
else:unix:!macx: LIBS += -L$$OUT_PWD/../dynamicui/ -ldynamicuiINCLUDEPATH += $$PWD/../dynamicui
DEPENDPATH += $$PWD/../dynamicui
@Read the documentation on creating libraries, but it was unclear.
1/5