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.



On Tue, Dec 10, 2013 at 9:59 AM, Florian Oswald <> 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 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 {
std::vector<blitz::Array<double,2> * > mats;
TClass(std::vector<blitz::Array<double,2> * > m_);
blitz::Array<double,2> * GetM( int which ){ return( );};


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 {
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, (* );


This particular test fails with

TClassTest.cpp:43: Failure
Value of: (*
  Actual: 32767
Expected: 3

which looks as if M1 (i.e. the element behind 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!

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!
Blitz-support mailing list