Qt : Unit Test with Visual Studio - c++

I have a Visual Studio Project and want to write some Unit Test for it.
I tried doing that by using a "Native Unit Test Project".
The Problem is, that when I use a QString in the Test, the Test fails with following message:
Message: Failed to set up the execution context to run the test
Any suggestions how I can write Unit Test using Qt?
#include "stdafx.h"
#include "CppUnitTest.h"
#include <QtCore/QCoreApplication>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Test
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
QString a = "Test";
Assert::IsTrue(true);
}
};
}

I have tried with the above example of yours and i am able to compile the unit test. These are the following changes I've done apart from copying your code.
Check if your QT is built with 32 bit or 64 bit compiler.
You need to set the same in Solution Platforms.
You need to add include directory path and the lib file path(Qt5Cored.lib(for
debug)/Qt5Core.lib(for release)) in the Project properties.
To run the unit test you need to copy the
Qt5Cored.dll/Qt5Core.dll file in the folder where your unit test dll file is generated(After compilation).
PS:- I am using VS 2015 but this doesn't matter.

I have also ran into this issue with Qt6 with a project created using the Qt Visual Studio Tools extension for Visual Studio 2019.
QString was one of the things popping up as an error during the build process, but there was various more errors. My solution was as follows:
Gone to the Microsoft Unit Testing Framework for C++ project's Properties (right-click on solution, bottom option of the menu "Properties")
As mentioned in #sonulohani's response, I had it running in x64 by default.
Under Configuration Properties > Linker > General Additional Library Directories I added the path to my QT installation location libs folder (for me this was C:\Qt\6.1.2\msvc2019_64\lib) at the top of the list.
Under Configuration Properties > Linker > Input Additional Dependencies I added a link to all the "*.lib" files from that very same QT installation (for me, this was C:\Qt\6.1.2\msvc2019_64\lib\*.lib) AND a link to the build output .obj files for the Qt project ($(SolutionDir)<MY PROJECT NAME>\$(IntDir)*.obj where <MY PROJECT NAME> was my project name). This second part may not necessarily be needed.
Copying just the Qt6Core.dll/Qt6Cored.dll as suggested by #sonulohani did not work. It was still missing stuff. So in the properties, under Configuration Properties > Build Events > Post-Build Event Command Line I added this script to copy all the Qt6 dll files to the test project .dll output directory:
for %%f in (C:\Qt\6.1.2\msvc2019_64\bin\Qt6*.dll) do #copy /y %%f $(SolutionDir)$(Platform)\$(Configuration)\Tests\
Now at that point I had another issue, since both my test project and my actual Qt project was dumping its files into the same output directory, and the Qt project did not like having all those dlls in there and did not run anymore. So I created the $(SolutionDir)$(Platform)\$(Configuration)\Tests\ directory within the regular output directory, and also made this \Tests\ subdirectory the output directory for the test project (Configuration Properties > General Output Directory).

Related

Add OpenSSL static lib to Visual Studio 2017 project

Do NuGets modify the include and linking paths when added to a project?
My background is with CMake where this stuff was trivial, but I'm now at a company that builds solution files from the ground up and I'm unsure how to properly add the static OpenSSL libs to my project. I'm posting the question to make sure I don't duplicate something or otherwise mess it up.
When I add the openssl-vc141-static-x86_64 to my project, it builds the .lib files and everything, but does not modify the include or linker paths.
I can manually add the linker paths, but because the project I was given doesn't have the typical Release/Debug configurations, I can't use the $(Configuration) macro to point at the target libs - so I end of just pointing at Release. The build works though.
I see there is a .targets file, but it doesn't seem to do anything.
(update)
To be specific, I'm basically building boost's http_server_async.cpp. The linker errors I'm getting are:
Error LNK2019 unresolved external symbol _BIO_free referenced in function "public: __thiscall boost::asio::ssl::context::bio_cleanup::~bio_cleanup(void)" (??1bio_cleanup#context#ssl#asio#boost##QAE#XZ) ESOIPDataScope C:\gitrepo\ALIDB\ESOIPDataScope\DataHandler.obj
Error LNK2001 unresolved external symbol _BIO_free ESOIPDataScope C:\gitrepo\ALIDB\ESOIPDataScope\Listener.obj
... (48 more like this)
When I manually add $(SolutionDir)packages\openssl-vc141-static-x86_64.1.1.0\build\native\lib\Win32\static\Release\libcrypto.lib and
$(SolutionDir)packages\openssl-vc141-static-x86_64.1.1.0\build\native\lib\Win32\static\Release\libssl.lib to be additional dependencies the project compiles.
(/update)
Just for contrast, I added a freeglut NuGet, and noticed that gave my more configuration options (Configuration Properties → Referenced Projects), also, boost seems to have added its linker directories to my project (though I only see that in MSBuild output, not in Configuration Properties->Linker->Command Line)
Is there a proper way to add these projects that I'm missing? Or a proper way to use the targets file? Or maybe the OpenSSL static NuGet just missing something? Or maybe I should just look into vcpkg?
Do NuGets modify the include and linking paths when added to a
project?
Sure. I can tell you explicitly that the nuget imports additional properties into the project through <package_id>.targets or <package_id>.props file, instead of manually adding include path again.
This is a mechanism for nuget packaging to add additional project properties such as library path directly to the project during the installation of the nuget package. More info you can refer to this link.
The <package_id>.targets was created during the process of packing the nuget package.
In other words, this method was designed by the author of the nuget package. And in my side, the file openssl-vc141-static-x86_64.targets exists in this path:
C:\Users\Admin\source\repos\ConsoleApplication25\packages\openssl-vc141-static-x86_64.1.1.0\build\native
also, boost seems to have added its linker directories to my project
(though I only see that in MSBuild output, not in Configuration
Properties->Linker->Command Line)
l think the issue is related to the difference between <package_id>.targets and <package_id>.props. Although using <package_id>.targets does not appear on the property UI, it still works for the whole project.
In more detail
When you install the nuget package into the project, these files are automatically executed. <target_id>.props file is added at the top of the file while .targets is added at the bottom.
When initializing the xxx.vcxproj file, because <package_id> .props is at the head of the file, the property UI can capture the properties in the file, and <package_id> .targets is at the end, so the initialization cannot be captured but still In the project. For the nuget, it uses openssl-vc141-static-x86_64.targets.
In openssl-vc141-static-x86_64.targets file, you can see this:
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)include\;%
(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>HAS_LIBTHRIFT;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
</ClCompile>
And l have set the output log to Diagnostic and build the project and found this:
The library path has been added into AdditionalIncludeDirectories by the openssl-vc141-static-x86_64.targets file automatically. So you do not have to worry about it.
Is there a proper way to add these projects that I'm missing? Or a
proper way to use the targets file? Or maybe the OpenSSL static NuGet
just missing something? Or maybe I should just look into vcpkg?
You do not need to worry about it and do not add the include path into project property. This is superfluous and when you have finished installing this nuget package, use it in cpp files directly.
In addition,
For c++ packages installed by nuget, you don't need to add any paths to the project property.
Update 1
The issue is related to your project rather than the nuget package. Exactly because your current project does not have $(Configuration), so in openssl-vc141-static-x86_64.targets, you can see these:
<ItemDefinitionGroup Label="Win32 and vc141 and Debug" Condition="'$(Platform)' == 'Win32' And ( $(PlatformToolset.IndexOf('v141')) > -1 Or '$(PlatformToolset)' == 'WindowsKernelModeDriver8.0' Or '$(PlatformToolset)' == 'WindowsApplicationForDrivers8.0' Or '$(PlatformToolset)' == 'WindowsUserModeDriver8.0' ) And '$(Configuration)' == 'Debug'">
<Link>
<AdditionalLibraryDirectories>$(MSBuildThisFileDirectory)lib\Win32\static\Debug\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libssl.lib;libcrypto.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>xcopy /Y "$(MSBuildThisFileDirectory)\lib\Win32\dynamic\*-1_1.dll" "$(OutDir)"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
This is the operation to import specific libssl.lib and libcrypto.Lib into the AdditionalDependencies node. But you can find out that there is a judge condition And '$(Configuration)' == 'Debug', since you do not have $(Configuration),therefore, it always returns false and these libs cannot be automatically imported into AdditionalDependencies.
As a workaround, you should add these lib path manually just as you said.
And l am sure that if you use a project which contains $(Configuration)(Debug or Release), you will not encouter this issue. And most of the C++ nuget packages can be used directly in the project which contains the Configuration node.
l am sure that if you use the $(Configuration) into your project and then reinstall this package(please clean the nuget cache before doing it), you will not face this error.
Also, your screen shot, where did you get that? I don't see anything
like that in the VS output console, or when I run msbuild on the
command line. Is there some way I might have accidentally broken the
default behaviour?
You can set MSBuild project build output verbosity to Diagnostic by Tools-->Options-->Projects and Solutions-->Build and Run.
When you build your project,the Output Window shows thw whole build process and records all the information and then you can search the key fields by the search box on the Output Window.

std::bad_alloc using Botan for PKCS#11

I'm new in C++ and I really stuck using Botan to connect to a hardware cryptography token. I don't know If I missed any setups for libs or dlls.
I built Botan library based on Building Botan library in Windows 10. botan.lib and botan.dll is created in lib folder after building.
Then I create a consoleApplication in Visual Studio 2019 with this simple code:
#include <iostream>
#include <botan/botan.h>
#include <botan/p11.h>
#include <botan/p11_slot.h>
#include <botan/p11_session.h>
#include <botan/p11_module.h>
#include <botan/p11_object.h>
#include <botan/p11_randomgenerator.h>
#include <botan/p11_x509.h>
#include <botan/x509_dn.h>
using namespace Botan;
using namespace PKCS11;
int main()
{
Botan::PKCS11::Module module("C:\\Windows\\System32\\ShuttleCsp11_3003.dll");
// Sometimes useful if a newly connected token is not detected by the PKCS#11 module
module.reload();
Botan::PKCS11::Info info = module.get_info();
// print library version
std::cout << std::to_string(info.libraryVersion.major) << "."
<< std::to_string(info.libraryVersion.minor) << std::endl;
}
This is the settings I prepared to run:
Configuration Properties→VC++ Directories:
Include Directories → add C:\Botan\include\botan-2;
Executable Directories → add C:\Botan\bin;
Library Directory → add C:\Botan\lib;
Source Directory → add C:\Botan\src;
Additional Include Library → add C:\Botan\include\botan-2
Linker
Additional Library Directory → add C:\Botan\lib;
Input → Additional Dependencies → add C:\Botan\lib\botan.lib
Also I installed token driver which dll is in System32 folder;
As I build the Botan Library with x86 so I debug the project with this config:
The error which I need your help to solve is:
Unhandled exception at 0x74CD2CF2 in ConsoleApplication1.exe: Microsoft C++ exception:
std::bad_alloc at memory location 0x004FF1AC.
This error occurred in this line of Code:
Botan::PKCS11::Module module("C:\\Windows\\System32\\ShuttleCsp11_3003.dll");
And this is the call stack
Note that I copied botan.dll and ShuttleCsp11_3003.dll in debug folder.
Somebody please help, thanks
Use Vcpkg, which is a tool created by Microsoft that helps acquire and build open source C and C++ libraries, to install botan automatically using a one liner shell command line and integrate to your VS 2019 project.
After installing vcpkg from GitHub, type the following command from a PowerShell prompt to download and install the library including all the dependencies:
.\vcpkg install botan:x86-windows
Use this to automatically (or you can do it manually) integrate the library to your VS project.
.\vcpkg integrate install
This is serious error here, which is the reason why the namespace and include files are not recognized by your project, Include Directories → add C:\Botan\include\botan-2 is incorrect Check the directory/file name botan-2, it should not exist.
should be C:\Botan\include; as your program includes botan in the folder path (eg #include "botan/botan.h")
Copy the dll files to your project directory( for debug testing) and to your application folder (debug or release version) and don't forget to correct the dll folder path while loading PKCS#11 shared library.

Xcode External Build System Project Can't Find wchar.h

I'm trying to figure out how to use Xcode's "External Build System" project template to do some C++ coding. I've set it up with a very simple test project, just to make sure that I understand the configuration. I'm using make to build the project. When I try to run it, the build fails with the error message 'wchar.h' file not found.
Here are the steps I took to set up the project:
Create a new Project, using the Other -> External Build System template.
Set the Build Tool option to /usr/bin/make.
Copy my source file, ex_3_4.cpp to the directory where the Xcode project is located, and add it to the project using the Add files to "TestProject"... menu option.
Copy the makefile to the directory where the Xcode project is located.
Everything works if I run make from the terminal - I get an executable that runs fine, and there is no trouble finding wchar.h or any other headers. So I know that this is a problem with something in the project settings.
Here is the code in the source file:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
}
And here is my makefile:
all:
clang++ ex_3_4.cpp -o ex_3_4
clean:
rm ex_3_4
I can't find any place in the project settings where I can specify a search path for the wchar.h file (or any other header files for that matter), so I'm not sure how to fix this. I feel like it must be something simple.
If it makes any difference, I've been using Xcode 7.3, but I've also tried it with the new Xcode 8.0. I get the same error message using either version.
Perhaps you want to add a library target to your project, add it as a dependency on your project and then, your .h into the Headers section

CMake : Executable crashes when running ctest

I am configuring CMake build project on Windows for MSVC++ project.It build ok the executable,then installs it into a defined directory.In my cases that's:
${CMAKE_SOURCE_DIR}/x64/${CMAKE_BUILD_TYPE}/
The executable has got a folder in the same directory with files which it loads upon the launch.If I launch the .exe manually it opens up and runs ok.But I want to do it via ctest.
I defined ctest like this:
add_test(ENGINE_TEST1 ${CMAKE_SOURCE_DIR}/x64/${CMAKE_BUILD_TYPE}/MyApp.exe
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/x64/${CMAKE_BUILD_TYPE})
When I call from the cmd:
ctest
The executable is starting up but crashes immediately with the error:
Debug Error!
Program:../..../.../MyApp.exe
R6010 -abort() has
been called.
Indeed,when checking the CMake's Last Test.log file it shows that it runs the test not in "WORKING_DIRECTORY but in the directory where the MyApp.exe has been built by CMake.How do I change that?
As I am not CMake pro I am sure the following answer is not the optimal way to do it,but at least it works for me.
Again,I was trying to run ctest on an executable from within the directory into which cmake had installed it.The exe on the startup was trying to load dependent files which were in the same directory.But it was crashing because it couldn't fin the files.
It appears that the cmake default workspace directory is the directory where the cmake files and projects are generated.That's 'build' directory.So when the executable is launched via ctest it search the paths of the files to load relative to the build directory.
Now,CMAKE has 2 variations of add_test() method.One is simple with arguments:
add_test([test_name] [test exe path])
It doesn't take care of the working directory.
And another one which is explained here does include an argument for explicit setup of the working directory.
Frankly speaking,I wasn't able to get this advanced function working as it was demanding to supply some test .config which I didn't understand how to setup.So what I did,I used the simple add_test function.
And then I set the working directory to the location of my executable using this:
set_tests_properties(mytest PROPERTIES WORKING_DIRECTORY "${TEST_WOKRING_DIR}")
And it fixed the problem.

using googletest in eclipse: how?

I've downloaded google test, but now I've no idea on how to link it to my project in eclipse.
Should I add it as a source folder? Should include it as g++ included library? And how can I run test then?
Using Riga's excellent answer, here is a summary of how I got it to work:
Created a new C++ project in Eclipse (I chose Executable > Empty Project)
Downloaded googletest 1.5.0, untarred, and ran ./scripts/fuse_gtest_files.py . <project-dir>/contrib
Back in Eclipse, excluded the contrib directory from the Release build configuration, and added <project-dir>/contrib to the include directories (odd, I know)
Added a src directory and added a class named Foo (see below for the contents of Foo.h--I left Foo.cpp empty for now)
Added a test directory in Eclipse, excluded it from the Release build configuration, added <project-dir>/contrib to the include directories, and added new source files FooTest.cpp and AllTests.cpp (see below for contents)
Built and ran the project!
Foo.h:
#ifndef FOO_H_
#define FOO_H_
class Foo {
public:
virtual ~Foo();
Foo();
bool foo(void) { return true; }
};
#endif /* FOO_H_ */
FooTest.cpp:
#include "gtest/gtest.h"
#include "Foo.h"
namespace {
class FooTest : public ::testing::Test {
protected:
Foo foo;
};
TEST_F(FooTest, Foo) {
ASSERT_TRUE(foo.foo());
}
}
AllTests.cpp:
#include "gtest/gtest.h"
#include "FooTest.cpp"
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Here are the detailed steps:
In Eclipse, open the File menu and select New > C++ Project
Project Type: Executable > Empty Project
Toolchain: Linux GCC
Click Finish
Open a terminal and cd /tmp
wget http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2
cd gtest-1.5.0/
./scripts/fuse_gtest_files.py . <project-dir>/contrib
Back in Eclipse, right-click on the project folder in the Project Explorer pane, then select Refresh
In the Project Explorer pane, right-click on the contrib folder, select Exclude from build...*, untick only the **Release box, and click OK
Right-click on the contrib folder and select Properties > C/C++ Build > Settings > Tool Settings tab > GCC C++ Compiler > Directories
Click on the Add... button, then the Workspace... button, then select <project-name>/contrib and click OK to add the directory
Click OK once more to accept your changes to the build settings
Right-click on the project in the Project Explorer pane and select New > Folder, enter src as its name, and click OK
Right-click on the src folder in the Project Explorer pane and select New > Class, name it Foo, then click OK (see above for contents of Foo.h; Foo.cpp can be left as is)
Right-click on the project in the Project Explorer pane and select New > Folder, enter test as its name, and click OK
Follow the steps above to add <project-name>/contrib and <project-name>/src as include directories to the test directory
Right-click on the test folder, then select New > Source File to add AllTests.cpp to the test folder, then repeat the same steps to add FooTest.cpp (see above for contents)
Right-click on FooTest.cpp and select Exclude from build..., click the Select All button, then OK
Right-click on the project in the Project Explorer pane, and select Properties > C/C++ Build > Settings > Tool Settings tab > GCC C++ Linker > Libraries, then click the Add... button, enter pthread (required by googletest), click OK to add the library, then OK once more to accept the changes
Hit Ctrl-b to build the project
Hit Ctrl-F11 to run the project
Victory!
Step 1 Install Eclipse
If Eclipse is not already installed on the machine, then get the latest version of the Eclipse IDE for C/C++ Developers from the Eclipse downloads page (http://www.eclipse.org/downloads/).
If Eclipse is already installed but only for Java, download the C++ plug-in following these instructions.
a. Open Eclipse and click on Help->Install New Software
b. In the Work with: box, type in http://download.eclipse.org/tools/cdt/releases/kepler. After a few moments, the Name box will populate. Select the following components:
CDT Main Features -> C/C++ Development Tools
CDT Main Features -> C/C++ Development Tools SDK
CDT Optional Features -> C/C++ Unit Testing Support
CDT Optional Features -> C/C++ Unit Testing Support Source
CDT Optional Features -> C/C++ Visual C++ Support
c. Click on Next, agree to the statements, and then Finish.
Step 2 Download Cygwin
Install Cygwin by clicking on the setup-x86_64.exe link on the Cygwin install page (http://www.cygwin.com/install.html). After running, click Next through the defaults until you get to the Select Packages window.
You will need to search for and install two packages: gcc and make.
The first search term is gcc. Search for gcc and then open the Devel folder. Mark the following packages for install by clicking on the word Skip (it will then change to the build number, which may by higher than the one depicted here): gcc-core, gcc-g++, and libgcc1.
The second search term is make. Here, we will only need the Devel package make.
Once these have been selected, click Next to install.
Step 3 Download and build Google Test project
Download the latest release of GoogleTest from https://code.google.com/p/googletest/downloads/list, and extract the zip file contents into a common directory. It is important that all users are able to access this directory.
(Note: the following commands use make -- the last revision of GoogleTest that uses make is https://github.com/google/googletest/releases/tag/release-1.8.1. For future revisions of GoogleTest use cmake instead.)
To build the Google Test project:
Open Cygwin (find the install directory for Cygwin and double-click
on Cygwin.bat).
Change the current working directory to the unzipped
GoogleTest make directory: cd c:/<<yourpath>>/gtest-1.7.0/make/
Build the project: make
Create an archived library out of the
gtest-all.o file: ar -rv libgtest.a gtest-all.o
Step 4 Add the Cygwin bin directory to the computers PATH variable
Follow the instructions on this page for your version of Windows: http://www.java.com/en/download/help/path.xml, to add Cygwins bin directory to the computers PATH environment variable. (typically by adding ;C:\cygwin64\bin to the end of the current value).
Step 5 Create a new project that uses GoogleTest
Start Eclipse and select File->New->C++ Project. Enter the values below and click Finish.
In the Project Explore, right-click the name of the project and select Properties. Under C/C++ Build, change the Builder type to Internal Builder.
Under C/C++ Build, select Settings, then click on the Includes folder under Cygwin C++ Compiler. Click on the Add button in the top box and then browse to the GoogleTest include folder.
Lastly, under the Cygwin C++ Linker folder, select Miscellaneous and then click the Add icon under Other objects. Find the libgtest.a file that you built back in step 3 (it should be in the make directory of the unzipped gtest folder).
Thats it! Now you're ready to try it out.
Step 6 Write some code that uses GoogleTest
Add a source folder by clicking File->New->Source folder. Call it
src.
Add a header file by right-clicking on the src folder and select New->Header File. Call this file Counter.h.
Add a source file by right-clicking on the src folder and select New->Source File. Call
this file Counter.cpp.
Add another source file and call it Counter_Tests.cpp.
Copy and paste the code below into the appropriate files:
Counter.h
class Counter {
private:
int mCounter;
public:
Counter() : mCounter(0) {}
int Increment();
};
Counter.cpp
#include <stdio.h>
#include "Counter.h"
int Counter::Increment() {
return mCounter++;
}
Counter_Tests.cpp
#include "gtest/gtest.h"
#include "Counter.h"
TEST(Counter, Increment) {
Counter c;
EXPECT_EQ(0, c.Increment());
EXPECT_EQ(1, c.Increment());
EXPECT_EQ(2, c.Increment());
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
In the Project menu select Build All. Now, to connect up the GoogleTest unit testing framework, select Run Configurations from the Run menu. From this dialog, select C/C++ Unit and click the New button.
It should fill in this project name automatically under C/C++ Application, if not click on Search Project to select this project. Next, click on the C/C++ Testing tab. In the Tests Runner drop-down, choose Google Tests Runner, and then click Run to watch the magic!
Below is a snapshot of the result. After writing more code/tests, you can click on the button highlighted in red to quickly recompile and re-run all of the tests.
You should not add it to your source folder, make separate folder instead. This is for avoidance of dependency of your production code from testing project. Do it like this
../ #your project folder
Makefile
src/
module1 #some module
module2 #another module
build #tmp for build
dist #binaries
contrib/
gtest
...
test/ #your test project folder
Makefile
src/
module1 #correspondent to main project's one
module2 #correspondent to main project's one
build
dist
...
I usually use google test as two files, this is very handy. Use scripts/fuse_gtest_files.py from gtest distribution to extract them. Having only two files you can include their compilation in your test project compilation and have simple project structure.
In your test projectspecify include directories ../contrib:../src:src.
Thus you can include headers like this
test/src/module1/class1Test.h:
#include "gtest/gtest.h"
#include "module1/class1.h"
// test class1 here
// ...
test/src/mainTest.cpp:
#include "gtest/gtest.h"
#include "module1/class1Test.h"
#include "module2/class2Test.h"
// include other tests you have
// ...
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Here is my solution for Eclipse 4.3 and CDT 8.2
I felt this was somewhat easier then described above.
Download gtest and install it as described in the readme.txt (using cmake and make in linux)
Go to "YourProject-> Properties-> C/C++ Build-> Settings-> GCC C++ Compiler-> Includes-> Include paths" and add the include folder in gtest
Go to "YourProject-> Properties-> C/C++ Build-> Settings-> GCC C++ Linker-> Libraries", add the gtest folder as search path and add libraries "gtest" and "pthread"
(4. If you have tests in the same project as sources exclude tests from release build)
Go to "Run-> Run Configurations..." and Create a new C/C++ Unit run configuration
Set project to your project and C/C++ Application to your Application in main tab. Set Tests Runner to Google Test Runner in C/C++ Testing tab.
(7. Error notifications may stick around in the eclipse gui, if this is the case re-indexing the project might help)
I've tray your solution and it runs well. I can say that for compile gtest is not very clear in the README. txt.
I've run the makefile in the /make directory through a cygwin console.
In my case the compiler advise me that don't findt the pthread library. So I modified the line
CXXFLAGS += -g -Wall -Wextra -pthread
and changed it to
CXXFLAGS += -g -Wall -Wextra -lpthread
The output I get is gtest_main.a. Then I have rename this file into libgtest.a and copy it to C:\cygwin\lib directory.
Then i've configure my eclipse project to use cygwin and added gtest and pthread as you say... and it works!
I hope it can help someone