It sure looks like you are pushing pointers to stack Arrays onto the M vector there. If that works, it would be purely accidental, because as you say, those arrays will be destroyed once SetUp finishes.

Is there a particular reason you want to have a vector of array pointers instead of a vector of arrays? If you really need to use pointers, you need to think more about object lifetimes.

cheers,

/Patrik



On Tue, Dec 10, 2013 at 9:59 AM, Florian Oswald <florian.oswald@gmail.com> wrote:
Dear all,

I'm using blitz++ together with google test. It works well in general, but I'm not able to set up a test fixture. This means that my tests become very long and tedious to work with. I wanted to see if anyone on the list had some experience/advice regarding that. It's basic stuff, I'm afraid.

I was able to set up the test fixture with the armadillo class. I have a reproducible example on github at https://github.com/floswald/cpptest/ in case that is helpful. in the googletest folder, you can find arma/ and blitz/. both should run by doing "make test".

In a nutshell, I create this test class:

#include <blitz/array.h>
#include <vector>

class TClass {
private: 
std::vector<blitz::Array<double,2> * > mats;
public:
TClass(std::vector<blitz::Array<double,2> * > m_);
blitz::Array<double,2> * GetM( int which ){ return( mats.at(which) );};

};

TClass::TClass(std::vector<blitz::Array<double,2> * > m_){
mats = m_;
}


and I want to run some tests on it. To do so, I set up a fixture like here:

#include <gtest/gtest.h> // Include the google test framework
#include "TClass.cpp"


class TClassTest : public ::testing::Test {
 protected:
int n;
int m;
std::vector<blitz::Array<double,2> * > M;
  virtual void SetUp() {
 n = 3;
 m = 2;
 blitz::Array<double,2> M1(n,m);
 blitz::Array<double,2> M2(n,m);
 M.push_back( &M1);
 M.push_back( &M2);
 T = new TClass(M);
  }

  virtual void TearDown() {delete T;}

  TClass  *T;
};

and I call a test from this fixture with 

TEST_F(TClassTest, CanSeeM){

EXPECT_EQ( 3, (*M.at(0)).extent(1) );

}

This particular test fails with

TClassTest.cpp:43: Failure
Value of: (*M.at(0)).extent(1)
  Actual: 32767
Expected: 3

which looks as if M1 (i.e. the element behind M.at(0)) was never properly allocated. Or it went out of scope after SetUp finished. As I said, the identical example but using arma::mat instead of the blitz arrays worked, so I'm a bit confused. I tried to allocate M1 and M2 on the heap with "new" but that didnt' work.

Thanks for your help!
Florian

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Blitz-support mailing list
Blitz-support@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/blitz-support