Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entangled with Google test

Tags:

I am having trouble to get up and running with Google test. I have read the suggested steps from Google, I also looked a previous post, and read some other examples, but it doesn't clear much things up.

To keep things simple, I am trying the suggested example from Google test that is available from the directory in the Android ndk - sample1:

// main.cpp

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "gtest/gtest.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    testing::InitGoogleTest(&argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/factorial/main.qml"));
    viewer.showExpanded();

    return RUN_ALL_TESTS();
}

// sample1_unittest.cpp

#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"

// Tests factorial of 0.
TEST(FactorialTest, Zero) {
  EXPECT_EQ(1, Factorial(0));
}

The files sample1.h, sample1.cpp are also in the project, which contain the factorial function. Google test was equally informed to the project file - factorial.pro:

INCLUDEPATH += 
/opt/android-studio/ndk/sources/third_party/googletest/googletest/include

When I press [Build > Build Project "factorial"] it gets the following error:

main.cpp:8: error: undefined reference to 'testing::InitGoogleTest(int*, char**)'
sample1_unittest.cpp:17: error: undefined reference to 'testing::Test::Test()'

I am working with Ubuntu, QtCreator, Android and C++. Indeed I have spent already 3 days mocking around, but getting not much anywhere so far. Thus, I am posting here in hope some guru may give any hint on this. Any help will be mostly appreciated.