Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests for None <-> nullptr_t conversion
  • Loading branch information
huangqinjin committed Dec 13, 2022
commit 1c1db3ad05208fbba8986e6037e84081bbe2864c
6 changes: 6 additions & 0 deletions test/builtin_converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ BOOST_PYTHON_MODULE(builtin_converters_ext)
def("long_long_size", by_value<BOOST_PYTHON_LONG_LONG>::size);
#endif

#ifndef BOOST_NO_CXX11_NULLPTR
def("rewrap_value_nullptr_t", by_value<std::nullptr_t>::rewrap);
#endif
def("rewrap_value_bool", by_value<bool>::rewrap);
def("rewrap_value_char", by_value<char>::rewrap);
def("rewrap_value_signed_char", by_value<signed char>::rewrap);
Expand Down Expand Up @@ -121,6 +124,9 @@ BOOST_PYTHON_MODULE(builtin_converters_ext)
def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring);


#ifndef BOOST_NO_CXX11_NULLPTR
def("rewrap_const_reference_nullptr_t", by_const_reference<std::nullptr_t>::rewrap);
#endif
def("rewrap_const_reference_bool", by_const_reference<bool>::rewrap);
def("rewrap_const_reference_char", by_const_reference<char>::rewrap);
def("rewrap_const_reference_signed_char", by_const_reference<signed char>::rewrap);
Expand Down
9 changes: 9 additions & 0 deletions test/test_builtin_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
... def rewrap_const_reference_unsigned_long_long(x): return long(x)
>>> if not 'long_long_size' in dir():
... def long_long_size(): return long_size()
>>> if not 'rewrap_value_nullptr_t' in dir():
... def rewrap_value_nullptr_t(x): return x
... def rewrap_const_reference_nullptr_t(x): return x

>>> rewrap_value_nullptr_t(None) is None
True

>>> try: bool_exists = bool
... except: pass
Expand Down Expand Up @@ -156,6 +162,9 @@
>>> rewrap_value_mutable_cstring('hello, world')
'hello, world'

>>> rewrap_const_reference_nullptr_t(None) is None
True

>>> rewrap_const_reference_bool(None)
0
>>> rewrap_const_reference_bool(0)
Expand Down