I figure out the google test platform. I hope perhaps this Gtest platform is able to help my current project.
So, I didn't see any tutorial from Gtest team in order to guide that How to create a new project and compile the project while including both libs "gmock/gmork" and "gtest/gtest.h".
I downloaded the Gtest project from repo: google/googletest
Do some steps to be able to use Gtest framework:
Intall gtest platform:
$ sudo apt-get install libgtest-dev #gtest
$ sudo apt-get install google-mock #gmock
Then, install Cmake:
$ sudo apt-get install cmake
and build 2 projects (gtest and gmock)
$ cd /usr/src/gtest
$ sudo cmake CMakeLists.txt
$ cd /usr/src/gmock
$ sudo cmake CMakeLists.txt
$ sudo make
Finally, copy all *.a files to /usr/lib
$ cp *.a /usr/lib
Consist of: libgtest.a , libgtest_main.a , libgmock.a , libgmock_main.a
I created an new project via Eclipse C, in Ubuntu 14.04 LTS. When I included gtest.h into my project, the program was built successfully and worked well
g++ -o "myGtest" ./myGtest.o ./src_code.o -lgtest -lpthread
but, if included more gmock.h, the program was failed to build. Compiler genereted too many errors
g++ -o "myGtest" ./myGtest.o ./src_code.o -lgtest -lgmock -lpthread
Please help me solve this problem.
By the way, I have one more question:
Assume that I have a simple module C src_code.c, for example:
I am testing function, in function invokes test , I would like to re-route the program to not execute this test, and it will jump to my self-defined test for instance, in myGtest.cpp, I write:
int test(int a) {
printf("overridden successful !\n");
return a;
}
This technique is a mock or stub or dummy function.
Please give me detail infor HOW can I mock a internal function in a module under test via Gtest framework ? Kindly give me an example.
I have tried to find solution at previous post at this site.
But, I didn't figure out my answer.