Skip to content

Commit

Permalink
test of using boost::any
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Aug 7, 2017
1 parent f81600c commit 080ecb4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/test_boost_any.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import py, os, sys
from pytest import raises
from .support import setup_make


class TestBOOSTANY:
def setup_class(cls):
import cppyy
cppyy.include('boost/any.hpp')

def test01_any_class(self):
"""Availability of boost::any"""

import cppyy
assert cppyy.gbl.boost.any

from cppyy.gbl import std
from cppyy.gbl.boost import any

assert std.list(any)

def test02_any_usage(self):
"""boost::any assignment and casting"""

import cppyy
assert cppyy.gbl.boost

from cppyy.gbl import std, boost

val = boost.any()
val.__assign__(std.vector[int]())
assert val.type() == cppyy.typeid(std.vector[int])

extract = boost.any_cast[std.vector[int]](std.move(val))
assert type(extract) is std.vector[int]
extract += xrange(100)

val.__assign__(std.move(extract))
assert len(extract) == 0

raises(Exception, boost.any_cast[int], std.move(val))

extract = boost.any_cast[std.vector[int]](std.move(val))
assert len(extract) == 100

0 comments on commit 080ecb4

Please sign in to comment.