Getting compile errors when attempting to compile a google test suite...

421 views
Skip to first unread message

Braun Brelin

unread,
Jul 26, 2013, 7:08:13 AM7/26/13
to googletes...@googlegroups.com
Hello all,

i'm trying to create a simple google test framework like so:

 #include "factorial.h"$                                                     
 2 #include <gtest/gtest.h>$
 3 $                                                                           
 4 class factorialTest : public testing::Test {$                               
 5     protected:$                                                             
 6     TEST_F (factorialTest,negative) {$                                      
 7         EXPECT_EQ (1,f.calculate_factorial(-5));$                           
 8     }$                                                                      
 9     factorial f;$                                                           
10 };$                                                                         
11 $                                                                           
12 int main(int argc, char ** argv) {$                                         
13     testing::InitGoogleTest(&argc,argv);$         
14     return(RUN_ALL_TESTS);$                       
15 }$                                         

The factorial.h header contains the factorial class that I'm trying to test.

I'm getting the following compile time error:

/home/bbrelin/Projects/neueda/src/gtest/factorial_test.cpp:6:5: error: invalid use of incomplete type ‘class factorialTest’
/home/bbrelin/Projects/neueda/src/gtest/factorial_test.cpp:4:7: error: forward declaration of ‘class factorialTest’

Can anybody tell me what I'm doing wrong here?

Thanks,

Braun Brelin


Josh Kelley

unread,
Jul 27, 2013, 10:05:39 PM7/27/13
to Braun Brelin, Google C++ Testing Framework
The TEST_F goes after the test fixture class.  (Under the hood, TEST_F actually creates a subclass of the test fixture class to do its register-and-run-tests magic.)  Since you're trying to create it before the test fixture class is fully declared, it's an incomplete type.

#include "factorial.h"
#include <gtest/gtest.h>


class factorialTest : public testing::Test {
protected:
    factorial f;
};

TEST_F (factorialTest,negative) {
    EXPECT_EQ(1, f.calculate_factorial(-5));
}

I'm not sure about the overall design here (does factorial::calculate_factorial really need to be an object method, instead of just a free function?), but that's a separate issue.

--
Josh Kelley





--
 
---
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/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages