Пример #1
0
    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")
Пример #2
0
    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")
Пример #3
0
    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"

        if self.exp_pyroot:
            c, s = StringyClass(), std.string(t0, 0, len(t0))
        else:
            c, s = StringyClass(), std.string(t0, len(t0))

        c.SetString1(s)
        assert t0 == c.GetString1()
        assert s == c.GetString1()
Пример #4
0
    def test03_string_with_null_character(self):
        """Test that strings with NULL do not get truncated"""

        import cppyy
        std = cppyy.gbl.std
        stringy_class = cppyy.gbl.stringy_class["std::string"]

        t0 = "aap\0noot"
        assert t0 == "aap\0noot"

        c, s = stringy_class(""), std.string(t0)

        c.set_string1(s)
        assert t0 == c.get_string1()
        assert s == c.get_string1()

        assert std.string('ab\0c') == 'ab\0c'
        assert repr(std.string('ab\0c')) == repr('ab\0c')
        assert str(std.string('ab\0c')) == 'ab\0c'
Пример #5
0
    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()
Пример #6
0
    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"
Пример #7
0
    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"
Пример #8
0
    def test04_string_hash(self):
        """Test that std::string has the same hash as the equivalent Python str"""
        # ROOT-10830

        from cppyy.gbl import std

        assert hash(std.string("test")) == hash("test")

        # Somehow redundant, but for completeness
        v = std.vector(std.string)()
        v.push_back('a')
        v.push_back('b')
        v.push_back('c')
        assert set(v) == set('abc')
Пример #9
0
    def test03_string_with_null_character(self):
        """Test that strings with NULL do not get truncated"""

        return  # don't bother; is fixed in cling-support

        import cppyy
        std = cppyy.gbl.std
        stringy_class = cppyy.gbl.stringy_class["std::string"]

        t0 = "aap\0noot"
        assert t0 == "aap\0noot"

        c, s = stringy_class(""), std.string(t0, len(t0))

        c.set_string1(s)
        assert t0 == c.get_string1()
        assert s == c.get_string1()
Пример #10
0
from topologic import Vertex, Topology, Dictionary, Attribute, AttributeManager, IntAttribute, DoubleAttribute, StringAttribute
import cppyy
from cppyy.gbl.std import string, list

# Create an Integer Value
intVal = IntAttribute(340)

# Create a Double Value
doubleVal = DoubleAttribute(120.567)

# Create a String Value
s = string("Hello World")
stringVal = StringAttribute(s)

# Create a list of values
values = cppyy.gbl.std.list[Attribute.Ptr]()
values.push_back(intVal)
values.push_back(doubleVal)
values.push_back(stringVal)

# Create a list of keys
intKey = string("int")
doubleKey = string("double")
stringKey = string("string")

keys = cppyy.gbl.std.list[string]()
keys.push_back(intKey)
keys.push_back(doubleKey)
keys.push_back(stringKey)

# Create a Dictionary
Пример #11
0
v3 = Vertex.ByCoordinates(10, 10, 0)

# Create two edges in an L-shape
e1 = Edge.ByStartVertexEndVertex(v1, v2)
e2 = Edge.ByStartVertexEndVertex(v2, v3)

# Add the two edges to a list of edges
edges = cppyy.gbl.std.list[Edge.Ptr]()
edges.push_back(e1)
edges.push_back(e2)

# Create a wire from the list of edges
w1 = Wire.ByEdges(edges)

# Create an key called "number"
intKey = string("number")

# Create three integer attributes with values 1, 2, 3
intVal1 = IntAttribute(1)
intVal2 = IntAttribute(2)
intVal3 = IntAttribute(3)

# Create three dictionaries with different values (1, 2, 3)
keys = cppyy.gbl.std.list[str]()
values = cppyy.gbl.std.list[Attribute.Ptr]()
keys.push_back(intKey)
values.push_back(intVal1)
dict1 = Dictionary.ByKeysValues(keys, values)

keys = cppyy.gbl.std.list[str]()
values = cppyy.gbl.std.list[Attribute.Ptr]()