You can generate pointer objects in [Stub View] or [User code] in [Test View] by using classcode.
Example
Generate test with the source code below.
using namespace std;
class Animal {
public:
virtual void bark() const = 0;
virtual ~Animal() {}
};
class Dog: public Animal {
public:
void bark() const override {
std::cout << "wal!" << std::endl;
}
};
void barkAnimal(Animal* animal){
animal -> bark();
}
int main(){
Animal * dog = new Dog();
barkAnimal(dog);
return 0;
}
Use in [User code]
- Open the [Test Editor Section] -> [Test structure] of
barkAnimal
Test. - Change the method of generating an Animal* object below [Parameter/return] to [User code].
- You can generate the Animal* object by using
cs_create_classcode_factory_cpp_Animal();
function of Animal’s Class code In [Class Factory View].
Use in [Stub View]
- Make sure the
barkAnimal
stub is connected to themain
test. - Open the barkAnimal stub in the [Stub View].
- Create an Animal* object in the empty barkAnimal stub using the function created in the [Class Factory View].
Animal* animal = CS_FACTORY cs_create_classcode_factory_cpp_Animal(); animal->bark();
Need more help with this?
Don’t hesitate to contact us here.