Note that there are some explanatory texts on larger screens.

plurals
  1. POGTest fixture when constructor takes parameters?
    primarykey
    data
    text
    <p>I have a simple example class. It has one data member, which is a std::vector of pointers to armadillo matrices. the constructor takes such a vector as the only argument. here's file <code>TClass.cpp</code>:</p> <pre><code>#include &lt;armadillo&gt; #include &lt;vector&gt; class TClass { private: std::vector&lt;arma::mat * &gt; mats; public: TClass(std::vector&lt;arma::mat * &gt; m_); arma::mat * GetM( int which ){ return( mats.at(which) );}; }; TClass::TClass(std::vector&lt;arma::mat * &gt; m_){ mats = m_; } </code></pre> <p>I want to construct a GTest fixture to test member function <code>GetM</code>. Here is what I have done:</p> <pre><code>#include &lt;gtest/gtest.h&gt; #include "TClass.cpp" class TClassTest : public ::testing::Test { protected: int n; int m; std::vector&lt;arma::mat * &gt; M; virtual void SetUp() { n = 3; m = 2; arma::mat M1 = arma::randu&lt;arma::mat&gt;(n,m); arma::mat M2 = arma::randu&lt;arma::mat&gt;(n,m); M.push_back( &amp;M1); M.push_back( &amp;M2); } // virtual void TearDown() {} // initiate a TClass object TClass T(M); }; // my test TEST_F(TClassTest, CanGetM1){ EXPECT_EQ( T.GetM(0), M.at(0) ); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&amp;argc, argv); return RUN_ALL_TESTS(); } </code></pre> <p>I compile this with <code>g++ TClassTest.cpp -o tclass -larmadillo</code>. It tells me that <code>TClassTest.cpp:24: error: ‘M’ is not a type</code>. I dont' understand why I cannot construct the TClass object in the fixture definition?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload