Hi, i've done what you told me, and i'm one step closer to the end but
when i'm going to link the files (i've renamed one.cpp -> uno.cpp ,
try.cpp -> prova.cpp and the function double -> doppio like a simple
translation in italian)...i'll show you the files modified and the
shell commands i used:
prova.cpp
#include <gtest/gtest.h>
#include "uno.h"
#include <iostream>
TEST(DoubleTest, positivo){
EXPECT_EQ(2,doppio(1));
EXPECT_EQ(4,doppio(2));
EXPECT_EQ(0,doppio(0));
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
uno.cpp:
#include <iostream>
int doppio(int x){
return 2*x;
}
and the command lines:
zen@ubuntu:~/workspace/testing$ g++ -I gtest-1.6.0/include/ -c
gtest-1.6.0/prova.cpp
zen@ubuntu:~/workspace/testing$ g++ -I gtest-1.6.0/ -c gtest-1.6.0/
uno.cpp
zen@ubuntu:~/workspace/testing$ g++ -I gtest-1.6.0/ uno.o prova.o -o
test
prova.o: In function `doppio(int)':
prova.cpp:(.text+0x0): multiple definition of `doppio(int)'
uno.o:uno.cpp:(.text+0x0): first defined here
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crt1.o: In
function `_start':
(.text+0x18): undefined reference to `main'
prova.o: In function `DoubleTest_positivo_Test::TestBody()':
prova.cpp:(.text+0x9b): undefined reference to
`testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type,
char const*, int, char const*)'
prova.cpp:(.text+0xad): undefined reference to
`testing::internal::AssertHelper::operator=(testing::Message const&)
const'
prova.cpp:(.text+0xb8): undefined reference to
`testing::internal::AssertHelper::~AssertHelper()'
prova.cpp:(.text+0x15c): undefined reference to
`testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type,
char const*, int, char const*)'
prova.cpp:(.text+0x16e): undefined reference to
`testing::internal::AssertHelper::operator=(testing::Message const&)
const'
prova.cpp:(.text+0x179): undefined reference to
`testing::internal::AssertHelper::~AssertHelper()'
prova.cpp:(.text+0x225): undefined reference to
`testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type,
char const*, int, char const*)'
prova.cpp:(.text+0x237): undefined reference to
`testing::internal::AssertHelper::operator=(testing::Message const&)
const'
prova.cpp:(.text+0x242): undefined reference to
`testing::internal::AssertHelper::~AssertHelper()'
prova.cpp:(.text+0x272): undefined reference to
`testing::internal::AssertHelper::~AssertHelper()'
prova.cpp:(.text+0x2af): undefined reference to
`testing::internal::AssertHelper::~AssertHelper()'
prova.cpp:(.text+0x2ec): undefined reference to
`testing::internal::AssertHelper::~AssertHelper()'
prova.o: In function `__static_initialization_and_destruction_0(int,
int)':
prova.cpp:(.text+0x37c): undefined reference to
`testing::internal::GetTestTypeId()'
prova.cpp:(.text+0x3b8): undefined reference to
`testing::internal::MakeAndRegisterTestInfo(char const*, char const*,
char const*, char const*, void const*, void (*)(), void (*)(),
testing::internal::TestFactoryBase*)'
prova.o: In function
`DoubleTest_positivo_Test::DoubleTest_positivo_Test()':
prova.cpp:
(.text._ZN24DoubleTest_positivo_TestC2Ev[_ZN24DoubleTest_positivo_TestC5Ev]
+0xd): undefined reference to `testing::Test::Test()'
prova.o: In function
`testing::internal::scoped_ptr<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >
>::reset(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >*)':
prova.cpp:
(.text._ZN7testing8internal10scoped_ptrISsE5resetEPSs[testing::internal::scoped_ptr<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >
>::reset(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >*)]+0x19): undefined reference to
`testing::internal::IsTrue(bool)'
prova.o: In function
`testing::internal::scoped_ptr<std::basic_stringstream<char,
std::char_traits<char>, std::allocator<char> >
>::reset(std::basic_stringstream<char, std::char_traits<char>,
std::allocator<char> >*)':
prova.cpp:
(.text._ZN7testing8internal10scoped_ptrISt18basic_stringstreamIcSt11char_traitsIcESaIcEEE5resetEPS6_[testing::internal::scoped_ptr<std::basic_stringstream<char,
std::char_traits<char>, std::allocator<char> >
>::reset(std::basic_stringstream<char, std::char_traits<char>,
std::allocator<char> >*)]+0x18): undefined reference to
`testing::internal::IsTrue(bool)'
prova.o: In function `testing::AssertionResult
testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int
const&, int const&)':
prova.cpp:
(.text._ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_[testing::AssertionResult
testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int
const&, int const&)]+0x1f): undefined reference to
`testing::AssertionSuccess()'
prova.cpp:
(.text._ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_[testing::AssertionResult
testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int
const&, int const&)]+0x8d): undefined reference to
`testing::internal::EqFailure(char const*, char const*,
testing::internal::String const&, testing::internal::String const&,
bool)'
prova.o:(.rodata._ZTV24DoubleTest_positivo_Test[vtable for
DoubleTest_positivo_Test]+0x10): undefined reference to
`testing::Test::SetUp()'
prova.o:(.rodata._ZTV24DoubleTest_positivo_Test[vtable for
DoubleTest_positivo_Test]+0x14): undefined reference to
`testing::Test::TearDown()'
prova.o: In function
`DoubleTest_positivo_Test::~DoubleTest_positivo_Test()':
prova.cpp:
(.text._ZN24DoubleTest_positivo_TestD2Ev[_ZN24DoubleTest_positivo_TestD5Ev]
+0x16): undefined reference to `testing::Test::~Test()'
prova.o:(.rodata._ZTI24DoubleTest_positivo_Test[typeinfo for
DoubleTest_positivo_Test]+0x8): undefined reference to `typeinfo for
testing::Test'
collect2: ld returned 1 exit status
i'm sorry, i've tryed understanding the README file but the examples
are just pieces of program and testing code and not easy for who is
new on c++...