Getting started with Google Test (GTest) on Ubuntu
Google test is a framework for writing C++ unit tests. In this short post, I explain how to set it up in Ubuntu.
Start by installing the gtest development package:
sudo apt-get install libgtest-dev
Note that this package only install source files. You have to compile the code yourself to create the necessary library files. These source files should be located at /usr/src/gtest. Browse to this folder and use cmake to compile the library:
sudo apt-get install cmake # install cmake cd /usr/src/gtest sudo cmake CMakeLists.txt sudo make # copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder sudo cp *.a /usr/lib
Lets say we now want to test the following simple squareRoot function:
// whattotest.cpp #include <math.h> double squareRoot(const double a) { double b = sqrt(a); if(b != b) { // nan check return -1.0; }else{ return sqrt(a); } }
In the following code, we create two tests that test the function using a simple assertion. There exists many other assertion macros in the framework (see http://code.google.com/p/googletest/wiki/Primer#Assertions). The code contains a small main function that will run all of the tests automatically. Nice and simple!
// tests.cpp #include "whattotest.cpp" #include <gtest/gtest.h> TEST(SquareRootTest, PositiveNos) { ASSERT_EQ(6, squareRoot(36.0)); ASSERT_EQ(18.0, squareRoot(324.0)); ASSERT_EQ(25.4, squareRoot(645.16)); ASSERT_EQ(0, squareRoot(0.0)); } TEST(SquareRootTest, NegativeNos) { ASSERT_EQ(-1.0, squareRoot(-15.0)); ASSERT_EQ(-1.0, squareRoot(-0.2)); } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
The next step is to compile the code. I’ve set up a small CMakeLists.txt file below to compile the tests. This file locates the google test library and links it with the test application. Note that we also have to link to the pthread library or the application won’t compile.
cmake_minimum_required(VERSION 2.6) # Locate GTest find_package(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIRS}) # Link runTests with what we want to test and the GTest and pthread library add_executable(runTests tests.cpp) target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)
Compile and run the tests:
cmake CMakeLists.txt make ./runTests
Have fun testing! You can download all of the code above at my Github page: https://github.com/smistad/GTest
References
http://code.google.com/p/googletest/wiki/Documentation
http://www.ibm.com/developerworks/aix/library/au-googletestingframework.html
This entry was posted by Erik Smistad on July 5, 2012 at 15:44, and is filed under General. Follow any responses to this post through RSS 2.0.You can leave a response or trackback from your own site.
-
Very helpful! I used to install the libgtest-dev package and then to compile the libraries from the tarball downloaded from the google-test webpage. I didn’t know that the ubuntu package install those src files.
I would like to suggest to compile the libraries as shared ones using the following command for configuring the project:
sudo cmake -D BUILD_SHARED_LIBS=ON ..
I commonly prefer to use shared libraries in front of static ones.
Regards!
-
#6 written by shantanu 2 months ago
i am trying to compile the demo program but am getting following error while executing “make”
In file included from /usr/include/c++/4.7/vector:70:0,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/vector.tcc: At global scope:
/usr/include/c++/4.7/bits/vector.tcc:67:13: error: variable or field ‘reserve’ declared void
/usr/include/c++/4.7/bits/vector.tcc:67:13: error: ‘size_type’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘std::vector::iterator std::vector::insert(std::vector::iterator, const value_type&)’:
/usr/include/c++/4.7/bits/vector.tcc:111:13: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:130:48: error: ‘__n’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘std::vector& std::vector::operator=(const std::vector&)’:
/usr/include/c++/4.7/bits/vector.tcc:182:10: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:183:8: error: ‘__xlen’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:183:26: error: there are no arguments to ‘capacity’ that depend on a template parameter, so a declaration of ‘capacity’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:195:18: error: there are no arguments to ‘size’ that depend on a template parameter, so a declaration of ‘size’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:202:68: error: there are no arguments to ‘size’ that depend on a template parameter, so a declaration of ‘size’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:204:64: error: there are no arguments to ‘size’ that depend on a template parameter, so a declaration of ‘size’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:209:55: error: ‘__xlen’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc: At global scope:
/usr/include/c++/4.7/bits/vector.tcc:217:20: error: variable or field ‘_M_fill_assign’ declared void
/usr/include/c++/4.7/bits/vector.tcc:217:20: error: ‘size_t’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:217:32: error: expected primary-expression before ‘const’
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘void std::vector::_M_assign_aux(_ForwardIterator, _ForwardIterator, std::forward_iterator_tag)’:
/usr/include/c++/4.7/bits/vector.tcc:260:8: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:262:6: error: ‘__len’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:262:23: error: there are no arguments to ‘capacity’ that depend on a template parameter, so a declaration of ‘capacity’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:274:16: error: there are no arguments to ‘size’ that depend on a template parameter, so a declaration of ‘size’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:279:31: error: there are no arguments to ‘size’ that depend on a template parameter, so a declaration of ‘size’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘void std::vector::_M_insert_aux(std::vector::iterator, const _Tp&)’:
/usr/include/c++/4.7/bits/vector.tcc:340:10: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:342:10: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:343:42: error: ‘__len’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:352:40: error: ‘__elems_before’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:376:40: error: ‘__elems_before’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc: At global scope:
/usr/include/c++/4.7/bits/vector.tcc:440:41: error: ‘size_type’ has not been declared
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘void std::vector::_M_fill_insert(std::vector::iterator, int, const value_type&)’:
/usr/include/c++/4.7/bits/vector.tcc:448:14: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:450:12: error: ‘__elems_after’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:478:14: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:480:14: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:481:46: error: ‘__len’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:486:49: error: ‘__elems_before’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:506:35: error: ‘__elems_before’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘void std::vector::_M_range_insert(std::vector::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag)’:
/usr/include/c++/4.7/bits/vector.tcc:612:12: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:614:36: error: ‘__n’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:616:9: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:618:7: error: ‘__elems_after’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:647:9: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:649:41: error: ‘__len’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc: At global scope:
/usr/include/c++/4.7/bits/vector.tcc:690:19: error: variable or field ‘_M_reallocate’ declared void
/usr/include/c++/4.7/bits/vector.tcc:690:19: error: ‘size_type’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:703:41: error: ‘size_type’ has not been declared
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘void std::vector::_M_fill_insert(std::vector::iterator, int, bool)’:
/usr/include/c++/4.7/bits/vector.tcc:707:20: error: there are no arguments to ‘capacity’ that depend on a template parameter, so a declaration of ‘capacity’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:707:29: error: there are no arguments to ‘size’ that depend on a template parameter, so a declaration of ‘size’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:710:54: error: there are no arguments to ‘difference_type’ that depend on a template parameter, so a declaration of ‘difference_type’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:711:58: error: there are no arguments to ‘difference_type’ that depend on a template parameter, so a declaration of ‘difference_type’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:712:50: error: there are no arguments to ‘difference_type’ that depend on a template parameter, so a declaration of ‘difference_type’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:716:10: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:718:40: error: ‘__len’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:721:44: error: there are no arguments to ‘difference_type’ that depend on a template parameter, so a declaration of ‘difference_type’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:723:37: error: there are no arguments to ‘difference_type’ that depend on a template parameter, so a declaration of ‘difference_type’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘void std::vector::_M_insert_range(std::vector::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag)’:
/usr/include/c++/4.7/bits/vector.tcc:739:6: error: ‘size_type’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:739:16: error: expected ‘;’ before ‘__n’
/usr/include/c++/4.7/bits/vector.tcc:740:19: error: there are no arguments to ‘capacity’ that depend on a template parameter, so a declaration of ‘capacity’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:740:28: error: there are no arguments to ‘size’ that depend on a template parameter, so a declaration of ‘size’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:740:33: error: ‘__n’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc:744:29: error: there are no arguments to ‘difference_type’ that depend on a template parameter, so a declaration of ‘difference_type’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:746:49: error: there are no arguments to ‘difference_type’ that depend on a template parameter, so a declaration of ‘difference_type’ must be available [-fpermissive]
/usr/include/c++/4.7/bits/vector.tcc:750:9: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:752:39: error: ‘__len’ was not declared in this scope
/usr/include/c++/4.7/bits/vector.tcc: In member function ‘void std::vector::_M_insert_aux(std::vector::iterator, bool)’:
/usr/include/c++/4.7/bits/vector.tcc:778:10: error: ‘size_type’ does not name a type
/usr/include/c++/4.7/bits/vector.tcc:780:40: error: ‘__len’ was not declared in this scope
In file included from /usr/include/c++/4.7/ios:41:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/char_traits.h: At global scope:
/usr/include/c++/4.7/bits/char_traits.h:106:66: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h:108:14: error: ‘size_t’ in namespace ‘std’ does not name a type
/usr/include/c++/4.7/bits/char_traits.h:112:39: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h:115:57: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h:118:57: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h:121:35: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h:147:64: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h: In static member function ‘static int __gnu_cxx::char_traits::compare(const char_type*, const char_type*, int)’:
/usr/include/c++/4.7/bits/char_traits.h:149:12: error: ‘size_t’ is not a member of ‘std’
/usr/include/c++/4.7/bits/char_traits.h:149:12: note: suggested alternative:
In file included from /usr/include/gtest/internal/gtest-port.h:187:0,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/lib/gcc/i686-linux-gnu/4.7/include/stddef.h:213:23: note: ‘size_t’
In file included from /usr/include/c++/4.7/ios:41:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/char_traits.h:149:24: error: expected ‘;’ before ‘__i’
/usr/include/c++/4.7/bits/char_traits.h:149:33: error: ‘__i’ was not declared in this scope
/usr/include/c++/4.7/bits/char_traits.h: At global scope:
/usr/include/c++/4.7/bits/char_traits.h:158:5: error: ‘size_t’ in namespace ‘std’ does not name a type
/usr/include/c++/4.7/bits/char_traits.h:171:37: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h: In static member function ‘static const char_type* __gnu_cxx::char_traits::find(const char_type*, int, const char_type&)’:
/usr/include/c++/4.7/bits/char_traits.h:173:12: error: ‘size_t’ is not a member of ‘std’
/usr/include/c++/4.7/bits/char_traits.h:173:12: note: suggested alternative:
In file included from /usr/include/gtest/internal/gtest-port.h:187:0,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/lib/gcc/i686-linux-gnu/4.7/include/stddef.h:213:23: note: ‘size_t’
In file included from /usr/include/c++/4.7/ios:41:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/char_traits.h:173:24: error: expected ‘;’ before ‘__i’
/usr/include/c++/4.7/bits/char_traits.h:173:33: error: ‘__i’ was not declared in this scope
/usr/include/c++/4.7/bits/char_traits.h: At global scope:
/usr/include/c++/4.7/bits/char_traits.h:182:55: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h:191:55: error: ‘std::size_t’ has not been declared
/usr/include/c++/4.7/bits/char_traits.h:201:33: error: ‘std::size_t’ has not been declared
In file included from /usr/include/c++/4.7/string:54:0,
from /usr/include/c++/4.7/bits/locale_classes.h:42,
from /usr/include/c++/4.7/bits/ios_base.h:43,
from /usr/include/c++/4.7/ios:43,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h: In instantiation of ‘class std::basic_string’:
/usr/include/c++/4.7/bits/basic_string.tcc:1134:25: required from here
/usr/include/c++/4.7/bits/basic_string.h:118:57: error: no type named ‘size_type’ in ‘std::basic_string::_CharT_alloc_type {aka class std::allocator}’
/usr/include/c++/4.7/bits/basic_string.h:119:61: error: no type named ‘difference_type’ in ‘std::basic_string::_CharT_alloc_type {aka class std::allocator}’
/usr/include/c++/4.7/bits/basic_string.h: In instantiation of ‘class std::basic_string’:
/usr/include/c++/4.7/bits/basic_string.tcc:1149:25: required from here
/usr/include/c++/4.7/bits/basic_string.h:118:57: error: no type named ‘size_type’ in ‘std::basic_string::_CharT_alloc_type {aka class std::allocator}’
/usr/include/c++/4.7/bits/basic_string.h:119:61: error: no type named ‘difference_type’ in ‘std::basic_string::_CharT_alloc_type {aka class std::allocator}’
In file included from /usr/include/c++/4.7/bits/locale_facets.h:50:0,
from /usr/include/c++/4.7/bits/basic_ios.h:39,
from /usr/include/c++/4.7/ios:45,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/streambuf_iterator.h:59:16: error: wrong number of template arguments (5, should be 3)
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:66:0,
from /usr/include/c++/4.7/vector:61,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:119:12: error: provided for ‘template struct std::iterator’
In file included from /usr/include/c++/4.7/bits/locale_facets.h:50:0,
from /usr/include/c++/4.7/bits/basic_ios.h:39,
from /usr/include/c++/4.7/ios:45,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/streambuf_iterator.h:219:66: error: wrong number of template arguments (5, should be 3)
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:66:0,
from /usr/include/c++/4.7/vector:61,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:119:12: error: provided for ‘template struct std::iterator’
In file included from /usr/include/c++/4.7/bits/locale_facets.h:2607:0,
from /usr/include/c++/4.7/bits/basic_ios.h:39,
from /usr/include/c++/4.7/ios:45,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/locale_facets.tcc: In member function ‘_InIter std::num_get::_M_extract_float(_InIter, _InIter, std::ios_base&, std::ios_base::iostate&, std::string&) const’:
/usr/include/c++/4.7/bits/locale_facets.tcc:209:19: error: ‘std::string’ has no member named ‘reserve’
/usr/include/c++/4.7/bits/locale_facets.tcc:294:28: error: ‘std::string’ has no member named ‘size’
/usr/include/c++/4.7/bits/locale_facets.tcc:317:28: error: ‘std::string’ has no member named ‘size’
/usr/include/c++/4.7/bits/locale_facets.tcc:353:28: error: ‘std::string’ has no member named ‘size’
/usr/include/c++/4.7/bits/locale_facets.tcc: In member function ‘_InIter std::num_get::_M_extract_int(_InIter, _InIter, std::ios_base&, std::ios_base::iostate&, _ValueT&) const’:
/usr/include/c++/4.7/bits/locale_facets.tcc:465:21: error: ‘std::string’ has no member named ‘reserve’
/usr/include/c++/4.7/bits/locale_facets.tcc:551:23: error: ‘std::string’ has no member named ‘size’
/usr/include/c++/4.7/bits/locale_facets.tcc:564:56: error: ‘std::string’ has no member named ‘size’
/usr/include/c++/4.7/bits/locale_facets.tcc: In member function ‘virtual _InIter std::num_get::do_get(std::num_get::iter_type, std::num_get::iter_type, std::ios_base&, std::ios_base::iostate&, float&) const’:
/usr/include/c++/4.7/bits/locale_facets.tcc:692:14: error: ‘std::string’ has no member named ‘reserve’
/usr/include/c++/4.7/bits/locale_facets.tcc: In member function ‘virtual _InIter std::num_get::do_get(std::num_get::iter_type, std::num_get::iter_type, std::ios_base&, std::ios_base::iostate&, double&) const’:
/usr/include/c++/4.7/bits/locale_facets.tcc:707:14: error: ‘std::string’ has no member named ‘reserve’
/usr/include/c++/4.7/bits/locale_facets.tcc: In member function ‘virtual _InIter std::num_get::do_get(std::num_get::iter_type, std::num_get::iter_type, std::ios_base&, std::ios_base::iostate&, long double&) const’:
/usr/include/c++/4.7/bits/locale_facets.tcc:739:14: error: ‘std::string’ has no member named ‘reserve’
In file included from /usr/include/gtest/internal/gtest-internal.h:55:0,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/gtest/internal/gtest-string.h: In constructor ‘testing::internal::String::String(const string&)’:
/usr/include/gtest/internal/gtest-string.h:227:39: error: ‘const string’ has no member named ‘length’
/usr/include/gtest/internal/gtest-string.h: In member function ‘testing::internal::String::operator std::string() const’:
/usr/include/gtest/internal/gtest-string.h:230:74: error: no matching function for call to ‘std::basic_string::basic_string(const char*, size_t)’
/usr/include/gtest/internal/gtest-string.h:230:74: note: candidates are:
In file included from /usr/include/c++/4.7/string:54:0,
from /usr/include/c++/4.7/bits/locale_classes.h:42,
from /usr/include/c++/4.7/bits/ios_base.h:43,
from /usr/include/c++/4.7/ios:43,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:529:9: note: template std::basic_string::basic_string(_InputIterator, _InputIterator, const _Alloc&)
/usr/include/c++/4.7/bits/basic_string.h:529:9: note: template argument deduction/substitution failed:
In file included from /usr/include/gtest/internal/gtest-internal.h:55:0,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/gtest/internal/gtest-string.h:230:74: note: deduced conflicting types for parameter ‘_InputIterator’ (‘const char*’ and ‘unsigned int’)
In file included from /usr/include/c++/4.7/string:55:0,
from /usr/include/c++/4.7/bits/locale_classes.h:42,
from /usr/include/c++/4.7/bits/ios_base.h:43,
from /usr/include/c++/4.7/ios:43,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: note: std::basic_string::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
/usr/include/c++/4.7/bits/basic_string.tcc:214:5: note: no known conversion for argument 2 from ‘size_t {aka unsigned int}’ to ‘const std::allocator&’
/usr/include/c++/4.7/bits/basic_string.tcc:171:5: note: std::basic_string::basic_string(const std::basic_string&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string = std::basic_string]
/usr/include/c++/4.7/bits/basic_string.tcc:171:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/4.7/bits/basic_string.tcc:179:5: note: std::basic_string::basic_string(const _Alloc&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
/usr/include/c++/4.7/bits/basic_string.tcc:179:5: note: candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/4.7/string:54:0,
from /usr/include/c++/4.7/bits/locale_classes.h:42,
from /usr/include/c++/4.7/bits/ios_base.h:43,
from /usr/include/c++/4.7/ios:43,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:434:7: note: std::basic_string::basic_string() [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
/usr/include/c++/4.7/bits/basic_string.h:434:7: note: candidate expects 0 arguments, 2 provided
In file included from /usr/include/c++/4.7/iterator:66:0,
from /usr/include/gtest/internal/gtest-param-util.h:37,
from /usr/include/gtest/gtest-param-test.h:192,
from /usr/include/gtest/gtest.h:61,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stream_iterator.h: At global scope:
/usr/include/c++/4.7/bits/stream_iterator.h:50:77: error: wrong number of template arguments (5, should be 3)
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:66:0,
from /usr/include/c++/4.7/vector:61,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:119:12: error: provided for ‘template struct std::iterator’
In file included from /usr/include/c++/4.7/iterator:66:0,
from /usr/include/gtest/internal/gtest-param-util.h:37,
from /usr/include/gtest/gtest-param-test.h:192,
from /usr/include/gtest/gtest.h:61,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stream_iterator.h:155:66: error: wrong number of template arguments (5, should be 3)
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:66:0,
from /usr/include/c++/4.7/vector:61,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:119:12: error: provided for ‘template struct std::iterator’
In file included from /usr/include/gtest/internal/gtest-param-util.h:47:0,
from /usr/include/gtest/gtest-param-test.h:192,
from /usr/include/gtest/gtest.h:61,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/gtest/gtest-printers.h: In static member function ‘static void testing::internal2::TypeWithoutFormatter::PrintValue(const T&, std::ostream*)’:
/usr/include/gtest/gtest-printers.h:152:19: error: ‘const string’ has no member named ‘length’
In file included from /usr/include/c++/4.7/bits/stl_construct.h:63:0,
from /usr/include/c++/4.7/vector:63,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator<std::basic_string > >’:
/usr/include/c++/4.7/bits/stl_vector.h:76:28: required from ‘struct std::_Vector_base<std::basic_string, std::allocator<std::basic_string > >’
/usr/include/c++/4.7/bits/stl_vector.h:208:11: required from ‘class std::vector<std::basic_string >’
/usr/include/gtest/gtest-printers.h:729:12: required from here
/usr/include/c++/4.7/ext/alloc_traits.h:191:53: error: no type named ‘size_type’ in ‘class std::allocator<std::basic_string >’
/usr/include/c++/4.7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator >’:
/usr/include/c++/4.7/bits/stl_vector.h:76:28: required from ‘struct std::_Vector_base<testing::internal::ParameterizedTestCaseInfoBase*, std::allocator >’
/usr/include/c++/4.7/bits/stl_vector.h:208:11: required from ‘class std::vector’
/usr/include/gtest/internal/gtest-param-util.h:609:25: required from here
/usr/include/c++/4.7/ext/alloc_traits.h:191:53: error: no type named ‘size_type’ in ‘class std::allocator’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/vector:61,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stl_iterator.h: In instantiation of ‘class __gnu_cxx::__normal_iterator<testing::internal::ParameterizedTestCaseInfoBase**, std::vector >’:
/usr/include/gtest/internal/gtest-param-util.h:560:42: required from here
/usr/include/c++/4.7/bits/stl_iterator.h:721:56: error: no type named ‘difference_type’ in ‘struct std::iterator_traits’
In file included from /usr/include/c++/4.7/bits/stl_construct.h:63:0,
from /usr/include/c++/4.7/vector:63,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator >’:
/usr/include/c++/4.7/bits/stl_vector.h:76:28: required from ‘struct std::_Vector_base<testing::TestPartResult, std::allocator >’
/usr/include/c++/4.7/bits/stl_vector.h:208:11: required from ‘class std::vector’
/usr/include/gtest/gtest-test-part.h:137:31: required from here
/usr/include/c++/4.7/ext/alloc_traits.h:191:53: error: no type named ‘size_type’ in ‘class std::allocator’
/usr/include/c++/4.7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator >’:
/usr/include/c++/4.7/bits/stl_vector.h:76:28: required from ‘struct std::_Vector_base<testing::TestProperty, std::allocator >’
/usr/include/c++/4.7/bits/stl_vector.h:208:11: required from ‘class std::vector’
/usr/include/gtest/gtest.h:604:29: required from here
/usr/include/c++/4.7/ext/alloc_traits.h:191:53: error: no type named ‘size_type’ in ‘class std::allocator’
/usr/include/c++/4.7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator >’:
/usr/include/c++/4.7/bits/stl_vector.h:76:28: required from ‘struct std::_Vector_base<testing::TestInfo*, std::allocator >’
/usr/include/c++/4.7/bits/stl_vector.h:208:11: required from ‘class std::vector’
/usr/include/gtest/gtest.h:885:26: required from here
/usr/include/c++/4.7/ext/alloc_traits.h:191:53: error: no type named ‘size_type’ in ‘class std::allocator’
/usr/include/c++/4.7/ext/alloc_traits.h: In instantiation of ‘struct __gnu_cxx::__alloc_traits<std::allocator >’:
/usr/include/c++/4.7/bits/stl_vector.h:76:28: required from ‘struct std::_Vector_base<int, std::allocator >’
/usr/include/c++/4.7/bits/stl_vector.h:208:11: required from ‘class std::vector’
/usr/include/gtest/gtest.h:889:20: required from here
/usr/include/c++/4.7/ext/alloc_traits.h:191:53: error: no type named ‘size_type’ in ‘class std::allocator’
/home/shantanu/gtest_eg/tests.cpp: In member function ‘virtual void SquareRootTest_PositiveNos_Test::TestBody()’:
/home/shantanu/gtest_eg/tests.cpp:5:5: error: ‘squareRoot’ was not declared in this scope
/home/shantanu/gtest_eg/tests.cpp:6:5: error: ‘squareRoot’ was not declared in this scope
/home/shantanu/gtest_eg/tests.cpp:7:5: error: ‘squareRoot’ was not declared in this scope
/home/shantanu/gtest_eg/tests.cpp:8:5: error: ‘squareRoot’ was not declared in this scope
/home/shantanu/gtest_eg/tests.cpp: In member function ‘virtual void SquareRootTest_NegativeNos_Test::TestBody()’:
/home/shantanu/gtest_eg/tests.cpp:12:5: error: ‘squareRoot’ was not declared in this scope
/home/shantanu/gtest_eg/tests.cpp:13:5: error: ‘squareRoot’ was not declared in this scope
In file included from /usr/include/c++/4.7/string:54:0,
from /usr/include/c++/4.7/bits/locale_classes.h:42,
from /usr/include/c++/4.7/bits/ios_base.h:43,
from /usr/include/c++/4.7/ios:43,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h: In instantiation of ‘std::basic_string& std::basic_string::append(const _CharT*) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string = std::basic_string]’:
/usr/include/gtest/gtest.h:309:51: required from here
/usr/include/c++/4.7/bits/basic_string.h:1006:51: error: no matching function for call to ‘std::basic_string::append(const char*&, size_t)’
/usr/include/c++/4.7/bits/basic_string.h:1006:51: note: candidates are:
In file included from /usr/include/c++/4.7/string:55:0,
from /usr/include/c++/4.7/bits/locale_classes.h:42,
from /usr/include/c++/4.7/bits/ios_base.h:43,
from /usr/include/c++/4.7/ios:43,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/basic_string.tcc:326:5: note: std::basic_string& std::basic_string::append(const std::basic_string&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string = std::basic_string]
/usr/include/c++/4.7/bits/basic_string.tcc:326:5: note: candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/4.7/string:54:0,
from /usr/include/c++/4.7/bits/locale_classes.h:42,
from /usr/include/c++/4.7/bits/ios_base.h:43,
from /usr/include/c++/4.7/ios:43,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from /usr/include/gtest/internal/gtest-port.h:196,
from /usr/include/gtest/internal/gtest-internal.h:40,
from /usr/include/gtest/gtest.h:57,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:1003:7: note: std::basic_string& std::basic_string::append(const _CharT*) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string = std::basic_string]
/usr/include/c++/4.7/bits/basic_string.h:1003:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/4.7/bits/basic_string.h:1041:9: note: template std::basic_string& std::basic_string::append(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
/usr/include/c++/4.7/bits/basic_string.h:1041:9: note: template argument deduction/substitution failed:
/usr/include/c++/4.7/bits/basic_string.h:1006:51: note: deduced conflicting types for parameter ‘_InputIterator’ (‘const char*’ and ‘unsigned int’)
In file included from /usr/include/c++/4.7/vector:66:0,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/bits/stl_bvector.h: In instantiation of ‘class std::vector<bool, std::allocator >’:
/usr/include/gtest/internal/gtest-param-util.h:345:23: required from ‘class testing::internal::ValuesInIteratorRangeGenerator’
/usr/include/gtest/gtest-param-test.h:314:74: required from ‘testing::internal::ParamGenerator<typename testing::internal::IteratorTraits::value_type> testing::ValuesIn(ForwardIterator, ForwardIterator) [with ForwardIterator = const bool*; typename testing::internal::IteratorTraits::value_type = bool]’
/usr/include/gtest/gtest-param-test.h:319:35: required from ‘testing::internal::ParamGenerator testing::ValuesIn(const T (&)[N]) [with T = bool; unsigned int N = 2u]’
/usr/include/gtest/internal/gtest-param-util-generated.h:99:26: required from ‘testing::internal::ValueArray2::operator testing::internal::ParamGenerator() const [with T = bool; T1 = bool; T2 = bool]’
/usr/include/gtest/gtest-param-test.h:1221:28: required from here
/usr/include/c++/4.7/bits/stl_bvector.h:519:18: error: no members matching ‘std::vector<bool, std::allocator >::_Base {aka std::_Bvector_base<std::allocator >}::_S_nword’ in ‘std::vector<bool, std::allocator >::_Base {aka struct std::_Bvector_base<std::allocator >}’
In file included from /usr/include/c++/4.7/i686-linux-gnu/bits/c++allocator.h:34:0,
from /usr/include/c++/4.7/bits/allocator.h:48,
from /usr/include/c++/4.7/vector:62,
from /usr/include/gtest/gtest.h:55,
from /home/shantanu/gtest_eg/tests.cpp:2:
/usr/include/c++/4.7/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator::construct(__gnu_cxx::new_allocator::pointer, const _Tp&) [with _Tp = const char*; __gnu_cxx::new_allocator::pointer = const char**]’:
/usr/include/c++/4.7/bits/stl_tree.h:381:6: required from ‘std::_Rb_tree_node* std::_Rb_tree::_M_create_node(const value_type&) [with _Key = const char*; _Val = const char*; _KeyOfValue = std::_Identity; _Compare = std::less; _Alloc = std::allocator; std::_Rb_tree::_Link_type = std::_Rb_tree_node*; std::_Rb_tree::value_type = const char*]’
/usr/include/c++/4.7/bits/stl_tree.h:979:66: required from ‘std::_Rb_tree::iterator std::_Rb_tree::_M_insert_(std::_Rb_tree::_Const_Base_ptr, std::_Rb_tree::_Const_Base_ptr, const _Val&) [with _Key = const char*; _Val = const char*; _KeyOfValue = std::_Identity; _Compare = std::less; _Alloc = std::allocator; std::_Rb_tree::iterator = std::_Rb_tree_iterator; std::_Rb_tree::_Const_Base_ptr = const std::_Rb_tree_node_base*]’
/usr/include/c++/4.7/bits/stl_tree.h:1293:64: required from ‘std::pair<std::_Rb_tree_iterator, bool> std::_Rb_tree::_M_insert_unique(const _Val&) [with _Key = const char*; _Val = const char*; _KeyOfValue = std::_Identity; _Compare = std::less; _Alloc = std::allocator]’
/usr/include/c++/4.7/bits/stl_set.h:415:29: required from ‘std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity, _Compare, typename _Alloc::rebind::other>::const_iterator, bool> std::set::insert(const value_type&) [with _Key = const char*; _Compare = std::less; _Alloc = std::allocator; typename std::_Rb_tree<_Key, _Key, std::_Identity, _Compare, typename _Alloc::rebind::other>::const_iterator = std::_Rb_tree_const_iterator; std::set::value_type = const char*]’
/usr/include/gtest/internal/gtest-internal.h:599:41: required from here
/usr/include/c++/4.7/ext/new_allocator.h:120:9: error: no matching function for call to ‘operator new(sizetype, void*)’
/usr/include/c++/4.7/ext/new_allocator.h:120:9: note: candidate is:
:0:0: note: void* operator new(unsigned int)
:0:0: note: candidate expects 1 argument, 2 provided
/usr/include/c++/4.7/ext/new_allocator.h: In instantiation of ‘_Tp* __gnu_cxx::new_allocator::allocate(int, const void*) [with _Tp = std::_Rb_tree_node; __gnu_cxx::new_allocator::pointer = std::_Rb_tree_node*]’:
/usr/include/c++/4.7/bits/stl_tree.h:369:51: required from ‘std::_Rb_tree_node* std::_Rb_tree::_M_get_node() [with _Key = const char*; _Val = const char*; _KeyOfValue = std::_Identity; _Compare = std::less; _Alloc = std::allocator; std::_Rb_tree::_Link_type = std::_Rb_tree_node*]’
/usr/include/c++/4.7/bits/stl_tree.h:379:33: required from ‘std::_Rb_tree_node* std::_Rb_tree::_M_create_node(const value_type&) [with _Key = const char*; _Val = const char*; _KeyOfValue = std::_Identity; _Compare = std::less; _Alloc = std::allocator; std::_Rb_tree::_Link_type = std::_Rb_tree_node*; std::_Rb_tree::value_type = const char*]’
/usr/include/c++/4.7/bits/stl_tree.h:979:66: required from ‘std::_Rb_tree::iterator std::_Rb_tree::_M_insert_(std::_Rb_tree::_Const_Base_ptr, std::_Rb_tree::_Const_Base_ptr, const _Val&) [with _Key = const char*; _Val = const char*; _KeyOfValue = std::_Identity; _Compare = std::less; _Alloc = std::allocator; std::_Rb_tree::iterator = std::_Rb_tree_iterator; std::_Rb_tree::_Const_Base_ptr = const std::_Rb_tree_node_base*]’
/usr/include/c++/4.7/bits/stl_tree.h:1293:64: required from ‘std::pair<std::_Rb_tree_iterator, bool> std::_Rb_tree::_M_insert_unique(const _Val&) [with _Key = const char*; _Val = const char*; _KeyOfValue = std::_Identity; _Compare = std::less; _Alloc = std::allocator]’
/usr/include/c++/4.7/bits/stl_set.h:415:29: required from ‘std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity, _Compare, typename _Alloc::rebind::other>::const_iterator, bool> std::set::insert(const value_type&) [with _Key = const char*; _Compare = std::less; _Alloc = std::allocator; typename std::_Rb_tree<_Key, _Key, std::_Identity, _Compare, typename _Alloc::rebind::other>::const_iterator = std::_Rb_tree_const_iterator; std::set::value_type = const char*]’
/usr/include/gtest/internal/gtest-internal.h:599:41: required from here
/usr/include/c++/4.7/ext/new_allocator.h:91:2: error: ‘class __gnu_cxx::new_allocator<std::_Rb_tree_node >’ has no member named ‘max_size’
make[2]: *** [CMakeFiles/runTests.dir/tests.cpp.o] Error 1
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
make: *** [all] Error 2
shantanu@ubuntu:~/gtest_eg$ -
- Comment Feed for this Post
It helped me alot, Thanks..