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]

  1. Open the [Test Editor Section] -> [Test structure] of barkAnimal Test.
  2. Change the method of generating an Animal* object below [Parameter/return] to [User code].
  3. You can generate the Animal* object by using cs_create_classcode_factory_cpp_Animal(); function of Animal’s Class code In [Class Factory View].
    • Add CS_FACTORY in front of cs_create_classcode_factory_cpp_Animal();, such as Animal * animal =CS_FACTORY cs_create_classcode_factory_cpp_Animal();.

Use in [Stub View]

  1. Make sure the barkAnimal stub is connected to the main test.
  2. Open the barkAnimal stub in the [Stub View].
  3. 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.

Thanks for your feedback.