Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unit testing of shared library

Unit testing of shared library

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on 17 Jun 2014, 22:46 last edited by
    #1

    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 .pro

    TEMPLATE = subdirs

    SUBDIRS +=
    tests
    dynamicui
    @

    @
    #-------------------------------------------------

    Project created by QtCreator 2014-06-17T14:48:09

    #-------------------------------------------------

    #dynamicui .pro

    QT += widgets

    QT -= core gui

    TARGET = dynamicui
    TEMPLATE = lib

    DEFINES += DYNAMICUI_LIBRARY

    SOURCES += dynamicui.cpp

    HEADERS += dynamicui.hpp
    dynamicui_global.hpp

    unix {
    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_bundle

    TEMPLATE = app

    SOURCES += dynamicuitest.cpp
    main.cpp
    ../dynamicui/dynamicui.cpp
    DEFINES += SRCDIR=\"$$PWD/\"

    HEADERS +=
    dynamicuitest.hpp
    ../dynamicui/dynamicui.hpp

    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/ -ldynamicui

    INCLUDEPATH += $$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_H

    define DYNAMICUITEST_H

    #include <QString>
    #include <QtTest>
    #include "dynamicui.hpp"

    class DynamicUiTest : public QObject
    {
    Q_OBJECT

    public:
    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();
    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 18 Jun 2014, 01:22 last edited by
      #2

      Where is the library located?
      Are you sure that it is in $$OUT_PWD/../dynamicui/ ?

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Exotic_Devel
        wrote on 18 Jun 2014, 23:34 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on 19 Jun 2014, 02:21 last edited by
          #4

          In the main pro file you listed test subdir first.
          Try to put dynamicui first and add ordered to CONFIG

          @
          SUBDIRS +=
          dynamicui \
          tests

          CONFIG += ordered
          @

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Exotic_Devel
            wrote on 19 Jun 2014, 13:56 last edited by
            #5

            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/ -ldynamicui

            INCLUDEPATH += $$PWD/../dynamicui
            DEPENDPATH += $$PWD/../dynamicui
            @

            Read the documentation on creating libraries, but it was unclear.

            1 Reply Last reply
            0

            1/5

            17 Jun 2014, 22:46

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved