def test08_shared_ptr(self): """Shared pointer transparency""" import cppyy cppyy.cppdef(""" namespace Zoo { std::shared_ptr<Lion> free_lion{new Lion{}}; std::string identify_animal_smart(std::shared_ptr<Lion>& smart) { return "the animal is a lion"; } } """) from cppyy.gbl import Zoo assert type(Zoo.free_lion).__name__ == 'Lion' smart_lion = Zoo.free_lion.__smartptr__() assert type(smart_lion).__name__ in [ 'shared_ptr<Zoo::Lion>', 'std::shared_ptr<Zoo::Lion>' ] assert Zoo.identify_animal(Zoo.free_lion) == "the animal is a lion" assert Zoo.identify_animal_smart( Zoo.free_lion) == "the animal is a lion"
def test07_run_zoo(self): """Bunch of zoo animals running around""" from cppyy.gbl import Zoo assert raises(TypeError, Zoo.Animal) assert issubclass(Zoo.Lion, Zoo.Animal) mouse = Zoo.release_animal(Zoo.eMouse) assert type(mouse) == Zoo.Mouse lion = Zoo.release_animal(Zoo.eLion) assert type(lion) == Zoo.Lion assert lion.__python_owns__ assert mouse.__python_owns__ assert mouse.make_sound() == 'peep!' assert lion.make_sound() == 'growl!' Zoo.Lion.s_lion_sound = "mooh!" assert lion.make_sound() == 'mooh!' assert Zoo.identify_animal(mouse) == "the animal is a mouse" assert Zoo.identify_animal(lion) == "the animal is a lion"