cppguy / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

GTEST - ASSERT_EQ and EXPECT_EQ compile error #472

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have been trying to use the assertion of ASSERT_EQ and EXPECT_EQ,

ASSERT_EQ(queue_->size(),6);

even using this

ASSERT_EQ(6,6);

However, I encountered this compiler error and everywhere I searched no one 
seems to be facing this problem.

/tmp/cczZfMaq.o: In function testing::AssertionResult 
testing::internal::EqHelper<false>::Compare<char, char>(char const*, char 
const*, char const&, char const&)':
/usr/include/gtest/gtest.h:1485: undefined reference totesting::AssertionResult 
testing::internal::CmpHelperEQ(char const*, char const*, char const&, char 
const&)' collect2: error: ld returned 1 exit status make: * 
[priority_queue_test.out] Error 1

Full Test File :

     //Include the class which you would like to test
        #include "priority_queue.h"

        //Include the google c++ test framework
        #include 

        #include 
        #include  

        //use the namespace for the testing class 
        using namespace algorithms;
        using namespace containers;

        namespace{
        //Test Fixture Class
        //multple tests in a test case shared common objects and subroutines
        class PriorityQueueTest : public ::testing::Test{
            protected:

                PriorityQueueTest(){
                }

                virtual ~PriorityQueueTest(){

                }

                virtual void SetUp(){
                    queue_ = new PriorityQueue(1000);
                }

                virtual void TearDown(){

                }

                PriorityQueue *queue_=NULL;
        };

        TEST_F(PriorityQueueTest,CheckAllMemberInitSuccessfully){

            //ASSERT is a critcal assertion which will fail the test program
            ASSERT_TRUE(queue_!=NULL) capacity()==1000) capacity();
        }

        TEST_F(PriorityQueueTest,CheckIfItemsAreEnqueueCorrectly){

            //test cases    
            queue_->Enqueue(0,0);
            queue_->Enqueue(1,1);
            queue_->Enqueue(6,6);
            queue_->Enqueue(5,5);
            queue_->Enqueue(3,3);
            queue_->Enqueue(2,2);

            ASSERT_EQ('a','a');
        }

        }//namespace

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

            return RUN_ALL_TESTS();
        }

Original issue reported on code.google.com by m...@ethanlim.net on 14 Aug 2014 at 9:24

GoogleCodeExporter commented 9 years ago
> /usr/include/gtest/gtest.h:1485: undefined reference 
totesting::AssertionResult ...

This is a link time error.
Most likely you forgot to compile/link the appropriate .cc files from gtest.

Original comment by sbe...@google.com on 14 Aug 2014 at 1:55