GTEST - ASSERT_EQ and EXPECT_EQ compile error

831 views
Skip to first unread message

Ethan Lim

unread,
Aug 14, 2014, 4:32:42 AM8/14/14
to googletes...@googlegroups.com

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();
        }



Samuel Benzaquen

unread,
Aug 26, 2014, 11:15:46 AM8/26/14
to Ethan Lim, Google C++ Testing Framework
On Thu, Aug 14, 2014 at 4:32 AM, Ethan Lim <ma...@ethanlim.net> wrote:

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

This is not a compiler error. This is a linker error.
Just like any other library, gTest needs to be compiled itself and linked into the binary. Using the headers without linking the library is not supported.
_Sam
 

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--


Ethan Lim

unread,
Sep 2, 2014, 7:14:37 AM9/2/14
to googletes...@googlegroups.com
I realised that if the following options -fno-implicit-templates is used, there would be the following errors.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframework+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages