def test01_string_argument_passing(self): """Test mapping of python strings and std::string""" from cppyy.gbl import std, StringyClass c, s = StringyClass(), std.string("test1") # pass through const std::string& c.SetString1(s) assert type(c.GetString1()) == str assert c.GetString1() == s c.SetString1("test2") assert c.GetString1() == "test2" # pass through std::string (by value) s = std.string("test3") c.SetString2(s) assert c.GetString1() == s c.SetString2("test4") assert c.GetString1() == "test4" # getting through std::string& s2 = std.string() c.GetString2(s2) assert s2 == "test4" raises(TypeError, c.GetString2, "temp string")
def test03_string_with_null_Character(self): """Test that strings with NULL do not get truncated""" from cppyy.gbl import std, StringyClass t0 = "aap\0noot" assert t0 == "aap\0noot" c, s = StringyClass(), std.string(t0, len(t0)) c.SetString1(s) assert t0 == c.GetString1() assert s == c.GetString1()
def test02_string_data_access(self): """Test access to std::string object data members""" from cppyy.gbl import std, StringyClass c, s = StringyClass(), std.string("test string") c.m_string = s assert c.m_string == s assert c.GetString1() == s c.m_string = "another test" assert c.m_string == "another test" assert c.GetString1() == "another test"