You have to declare your getter functions const to be able to access them through the const Test& test you have.
...
int getA() const { return a; }
int getB() const { if (b) return *b; else return 0; }
bool isB() const { if(b) return true; else return false; }
...