Update of /cvsroot/luabind/luabind/luabind/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24439
Modified Files:
Tag: beta7-devel2
Jamfile
Added Files:
Tag: beta7-devel2
test_back_reference.cpp test_has_get_pointer.cpp
Log Message:
Added back_reference and has_get_pointer tests.
--- NEW FILE: test_has_get_pointer.cpp ---
// Copyright (c) 2005 Daniel Wallin
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include <luabind/detail/has_get_pointer.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/get_pointer.hpp>
namespace lb = luabind::detail;
namespace test
{
struct X
{
};
struct Y
{
};
Y* get_pointer(Y const&);
} // namespace test
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
namespace luabind
{
using test::get_pointer;
using boost::get_pointer;
} // namespace luabind
#endif
BOOST_MPL_ASSERT(( lb::has_get_pointer<boost::shared_ptr<int> > ));
BOOST_MPL_ASSERT(( lb::has_get_pointer<test::Y> ));
BOOST_MPL_ASSERT(( lb::has_get_pointer<char*> ));
BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer<int> ));
BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer<test::X> ));
int main()
{
using namespace luabind;
test::Y const x;
char* z;
char*& y = z;
get_pointer(x);
}
#if 0
template<class T>
struct X
{
};
#include <boost/mpl/bool.hpp>
#include <boost/get_pointer.hpp>
#include <boost/shared_ptr.hpp>
namespace luabind {
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::get_pointer;
#endif
namespace has_get_pointer_
{
struct any
{
template<class T>
any(T const&);
};
struct tag {};
tag operator,(tag,int);
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
} // namespace has_get_pointer_
#endif
has_get_pointer_::tag get_pointer(has_get_pointer_::any);
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
namespace has_get_pointer_
{
#endif
typedef char(&yes)[1];
typedef char(&no)[2];
no check(tag);
template<class T>
yes check(T const&);
template<class T>
struct impl
{
BOOST_STATIC_CONSTANT(bool, value = sizeof(
check( (get_pointer(*(T*)0),0) )) == sizeof(yes)
);
typedef boost::mpl::bool_<value> type;
};
} // namespace has_get_pointer_
template<class T>
struct has_get_pointer
: has_get_pointer_::impl<T>::type
{};
} // namespace luabind
struct Y
{
};
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
namespace luabind
{
#endif
template<class T>
void get_pointer(X<T> const&)
{
///return (T*)0;
}
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
} // namespace luabind
#endif
#include <boost/static_assert.hpp>
int main()
{
X<int> x;
int* y;
boost::shared_ptr<int> z;
using namespace luabind;
//get_pointer(y);
// get_pointer(x);
BOOST_STATIC_ASSERT((luabind::has_get_pointer<int>::value == 0));
BOOST_STATIC_ASSERT((luabind::has_get_pointer<X<int> >::value == 1));
BOOST_STATIC_ASSERT((luabind::has_get_pointer<boost::shared_ptr<int> >::value == 1));
return 0;
}
#endif
Index: Jamfile
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/Jamfile,v
retrieving revision 1.15.2.8
retrieving revision 1.15.2.9
diff -u -d -r1.15.2.8 -r1.15.2.9
--- Jamfile 23 Oct 2005 10:45:03 -0000 1.15.2.8
+++ Jamfile 23 Oct 2005 21:35:21 -0000 1.15.2.9
@@ -3,6 +3,7 @@
use-project /luabind : ../ ;
SOURCES =
+ test_back_reference.cpp
test_def_from_base.cpp
test_object.cpp
test_abstract_base.cpp
@@ -41,5 +42,6 @@
test-suite luabind-test : $(tests)
[ compile test_typetraits.cpp ]
[ compile test_value_wrapper.cpp ]
+ [ compile test_has_get_pointer.cpp ]
;
--- NEW FILE: test_back_reference.cpp ---
// Copyright (c) 2005 Daniel Wallin
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include <luabind/luabind.hpp>
#include <boost/shared_ptr.hpp>
using namespace luabind;
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
namespace luabind
{
using boost::get_pointer;
}
#endif
namespace luabind
{
template<class T>
boost::shared_ptr<T const>* get_const_holder(boost::shared_ptr<T>*)
{
return 0;
}
}
struct base0
{
virtual ~base0() {}
};
struct base_wrap0 : base0, wrap_base
{};
struct base1
{
virtual ~base1() {}
};
struct base_wrap1 : base1, wrap_base
{};
base0* filter0(base0* p)
{
return p;
}
boost::shared_ptr<base1> filter1(boost::shared_ptr<base1> const& p)
{
return p;
}
void test_main(lua_State* L)
{
module(L)
[
class_<base0, base_wrap0>("base0")
.def(constructor<>()),
def("filter0", &filter0),
class_<base1, base_wrap1, boost::shared_ptr<base1> >("base1")
.def(constructor<>()),
def("filter1", &filter1)
];
DOSTRING(L,
"class 'derived0' (base0)\n"
" function derived0:__init()\n"
" super()\n"
" end\n"
"class 'derived1' (base1)\n"
" function derived1:__init()\n"
" super()\n"
" end\n"
);
DOSTRING(L,
"x = derived0()\n"
"y = filter0(x)\n"
"assert(x == y)\n"
);
DOSTRING(L,
"x = derived1()\n"
"y = filter1(x)\n"
"assert(x == y)\n"
);
}
|