Update of /cvsroot/luabind/luabind/luabind/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15879/luabind/test
Modified Files:
Jamfile makefile test.hpp test_attributes.cpp
test_free_functions.cpp test_held_type.cpp
test_lua_classes.cpp test_object.cpp test_operators.cpp
test_policies.cpp test_typetraits.cpp test_yield.cpp
Added Files:
test_back_reference.cpp test_def_from_base.cpp
test_has_get_pointer.cpp test_value_wrapper.cpp
Log Message:
merged in changes from beta7-devel2 (tag: beta7-devel2-merge)
--- NEW FILE: test_def_from_base.cpp ---
// Copyright (c) 2005 Daniel Wallin, Arvid Norberg
// 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>
struct V
{
int f(int,int)
{
return 2;
}
};
struct W : V
{};
void test_main(lua_State* L)
{
using namespace luabind;
module(L)
[
class_<W>("W")
.def(constructor<>())
.def("f", &V::f)
];
DOSTRING(L,
"x = W()\n"
"assert(x:f(1,2) == 2)\n"
);
}
Index: test_held_type.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_held_type.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- test_held_type.cpp 15 Apr 2005 13:46:17 -0000 1.29
+++ test_held_type.cpp 28 Nov 2005 20:55:34 -0000 1.30
@@ -160,7 +160,7 @@
.def("f", &derived::f)
];
- object g = get_globals(L);
+ object g = globals(L);
g["ptr"] = base_ptr;
DOSTRING(L, "tester(ptr)");
@@ -203,7 +203,7 @@
"candidates are:\n"
"tester12(const custom&)\n");
*/
- object nil = get_globals(L)["non_existing_variable_is_nil"];
+ object nil = globals(L)["non_existing_variable_is_nil"];
TEST_CHECK(object_cast<boost::shared_ptr<base> >(nil).get() == 0);
TEST_CHECK(object_cast<boost::shared_ptr<const base> >(nil).get() == 0);
--- 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> ));
Index: test.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- test.hpp 15 Apr 2005 13:46:17 -0000 1.8
+++ test.hpp 28 Nov 2005 20:55:34 -0000 1.9
@@ -103,9 +103,9 @@
catch (luabind::error const& e) \
{ \
using namespace std; \
- if (strcmp( \
+ if (std::strcmp( \
lua_tostring(e.state(), -1) \
- , expected)) \
+ , (char const*)expected)) \
{ \
TEST_ERROR(lua_tostring(e.state(), -1)); \
} \
Index: test_lua_classes.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_lua_classes.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- test_lua_classes.cpp 15 Apr 2005 13:46:17 -0000 1.26
+++ test_lua_classes.cpp 28 Nov 2005 20:55:34 -0000 1.27
@@ -138,50 +138,40 @@
void test_main(lua_State* L)
{
- module(L)
- [
+ module(L)
+ [
class_<A, A_wrap, boost::shared_ptr<A> >("A")
- .def(constructor<>())
- .def("f", &A::f, &A_wrap::default_f)
+ .def(constructor<>())
+ .def("f", &A::f, &A_wrap::default_f)
.def("g", &A::g, &A_wrap::default_g),
class_<B, A, B_wrap, boost::shared_ptr<A> >("B")
- .def(constructor<>())
- .def("f", &B::f, &B_wrap::default_f)
+ .def(constructor<>())
+ .def("f", &B::f, &B_wrap::default_f)
.def("g", &B::g, &B_wrap::default_g),
def("filter", &filter),
class_<base, base_wrap>("base")
- .def(constructor<>())
- .def("f", &base::f, &base_wrap::default_f)
+ .def(constructor<>())
+ .def("f", &base::f, &base_wrap::default_f)
.def("g", &base::g),
class_<T_>("T")
.def("f", &T_::f),
class_<U, T_>("U")
- .def(constructor<>())
+ .def(constructor<>())
.def("f", &U::f)
.def("g", &U::g)
];
-
- try
- {
- dostring(L, "u = U()\n"
+
+ DOSTRING(L,
+ "u = U()\n"
"assert(u:f(0) == 1)\n"
"assert(u:f(0,0) == 2)\n"
"assert(u:g() == 3)\n");
- }
- catch (luabind::error const& e)
- {
- TEST_ERROR(lua_tostring(e.state(), -1));
- }
- catch (std::string const& s)
- {
- TEST_ERROR(s.c_str());
- }
-
+
DOSTRING(L,
"u = U()\n"
"assert(u:f(0) == 1)\n"
@@ -299,7 +289,7 @@
LUABIND_CHECK_STACK(L);
TEST_NOTHROW(
- object a = get_globals(L)["ba"];
+ object a = globals(L)["ba"];
TEST_CHECK(call_member<int>(a, "fun") == 4);
);
}
@@ -307,7 +297,7 @@
{
LUABIND_CHECK_STACK(L);
- object make_derived = get_globals(L)["make_derived"];
+ object make_derived = globals(L)["make_derived"];
TEST_NOTHROW(
call_function<void>(make_derived)
);
Index: test_operators.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_operators.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- test_operators.cpp 15 Apr 2005 13:46:17 -0000 1.15
+++ test_operators.cpp 28 Nov 2005 20:55:34 -0000 1.16
@@ -51,9 +51,18 @@
{
return 2.5f + a;
}
-
};
+float operator*(operator_tester const& lhs, operator_tester const& rhs)
+{
+ return 35.f;
+}
+
+std::string operator*(operator_tester const&, int v)
+{
+ return "(operator_tester, int) overload";
+}
+
int operator+(int a, const operator_tester&)
{
return 2 + a;
@@ -101,11 +110,14 @@
.def(self + int())
.def(other<int>() + self)
.def(-self)
- .def(self + other<operator_tester2&>())
+ .def(self + other<operator_tester2&>())
.def(self())
.def(const_self(int()))
.def(self(int()))
- .def(tostring(const_self)),
+ .def(tostring(const_self))
+// .def(const_self * other<operator_tester const&>())
+ .def(const_self * const_self)
+ .def(const_self * other<int>()),
// .def("clone", &clone, adopt(return_value)),
class_<operator_tester2>("operator_tester2")
@@ -134,6 +146,8 @@
DOSTRING(L, "assert(test(5) == 2.5 + 5)");
DOSTRING(L, "assert(-test == 46)");
+ DOSTRING(L, "assert(test * test == 35)");
+ DOSTRING(L, "assert(test * 3 == '(operator_tester, int) overload')")
DOSTRING(L, "assert(test + test2 == 73)");
DOSTRING(L, "assert(2 + test == 2 + 2)");
DOSTRING(L, "assert(test + 2 == 1 + 2)");
Index: test_attributes.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_attributes.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- test_attributes.cpp 15 Apr 2005 13:46:17 -0000 1.31
+++ test_attributes.cpp 28 Nov 2005 20:55:34 -0000 1.32
@@ -23,18 +23,41 @@
#include "test.hpp"
#include <luabind/luabind.hpp>
+struct A
+{
+ int get() const
+ {
+ return 5;
+ }
+};
+
+struct B : A
+{
+};
+
+struct C
+{
+ int a;
+};
+
struct property_test : counted_type<property_test>
{
- property_test(): o(6) {}
+ property_test(): o(6), c_ref(&c) {}
+ ~property_test() { c.a = 0; }
- std::string str_;
+ std::string str_;
int a_;
float o;
- signed char b;
+ signed char b;
+ C c;
+ C* c_ref;
void set(int a) { a_ = a; }
int get() const { return a_; }
+ void setA(A* a) {}
+ A* getA() const { return 0; }
+
void set_str(const char* str)
{ str_ = str; }
@@ -50,18 +73,6 @@
int free_getter(const property_test& p)
{ return p.get(); }
-struct A
-{
- int get() const
- {
- return 5;
- }
-};
-
-struct B : A
-{
-};
-
void test_main(lua_State* L)
{
using namespace luabind;
@@ -72,11 +83,13 @@
.def(luabind::constructor<>())
.def("get", &property_test::get)
.property("a", &property_test::get, &property_test::set)
- .property(
- "str", &property_test::get_str, &property_test::set_str)
+ .property("str", &property_test::get_str, &property_test::set_str)
+ .property("A", &property_test::getA, &property_test::setA)
.def_readonly("o", &property_test::o)
- .property("free", &free_getter, &free_setter)
- .def_readwrite("b", &property_test::b),
+ .property("free", &free_getter, &free_setter)
+ .def_readwrite("b", &property_test::b)
+ .def_readwrite("c", &property_test::c)
+ .def_readwrite("c_ref", &property_test::c_ref),
class_<A>("A")
.def(constructor<>())
@@ -84,18 +97,34 @@
class_<B, A>("B")
.def(constructor<>())
- .property("x", &A::get)
+ .property("x", &A::get),
+
+ class_<C>("C")
+ .def(constructor<>())
+ .def_readwrite("a", &C::a)
];
DOSTRING(L, "test = property()\n");
- DOSTRING(L,
- "test.a = 5\n"
- "assert(test.a == 5)");
+ DOSTRING(L,
+ "test.a = 5\n"
+ "assert(test.a == 5)");
DOSTRING(L, "assert(test.o == 6)");
- DOSTRING(L,
+ DOSTRING(L,
+ "test.new_member = 'foo'\n"
+ "assert(test.new_member == 'foo')");
+
+ DOSTRING(L,
+ "property.new_member2 = 'bar'\n"
+ "assert(property.new_member2 == 'bar')");
+
+ DOSTRING(L,
+ "b = property()\n"
+ "assert(b.new_member2 == 'bar')");
+
+ DOSTRING(L,
"test.str = 'foobar'\n"
"assert(test.str == 'foobar')\n");
@@ -107,6 +136,20 @@
"test.b = 3\n"
"assert(test.b == 3)\n");
+ DOSTRING(L, "test.c.a = 1\n"
+ "assert(test.c.a == 1)\n"
+ "assert(test.c_ref.a == 1)");
+
+ DOSTRING(L, "t1 = property()\n"
+ "c = t1.c\n"
+ "c2 = t1.c_ref\n"
+ "c.a = 1\n"
+ "t1 = nil\n"
+ "collectgarbage()\n"
+ "collectgarbage()\n"
+ "assert(c.a == 1)\n"
+ "assert(c2.a == 1)");
+
DOSTRING(L,
"a = B()\n");
Index: makefile
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/makefile,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- makefile 12 Aug 2004 06:31:51 -0000 1.20
+++ makefile 28 Nov 2005 20:55:34 -0000 1.21
@@ -1,7 +1,6 @@
include ../config
SOURCES = \
- main.cpp \
test_abstract_base.cpp \
test_attributes.cpp \
test_const.cpp \
@@ -17,39 +16,32 @@
test_operators.cpp \
test_policies.cpp \
test_scope.cpp \
- test_separate_registration.cpp \
test_separation.cpp \
test_simple_class.cpp \
test_typetraits.cpp \
- test_yield.cpp
-
-# not converted yet
-
-# test_null_pointer.cpp \
+ test_yield.cpp \
+ test_null_pointer.cpp \
test_policies.cpp \
test_free_functions.cpp \
test_iterator.cpp \
-TARGET = test_luabind
-
-
-
-
-OBJECTS = $(SOURCES:.cpp=.o)
+CPPFLAGS = -Wno-long-double
-all: $(TARGET)
+all: $(SOURCES:.cpp=.exe)
-$(TARGET): $(OBJECTS)
- $(CXX) -g $(OBJECTS) -L$(LUA_PATH)/lib -L../lib -lluabind -llua -llualib -o $@
+%.exe:%.o main.o
+ $(CXX) $? -o $@ -g -L$(LUA_PATH)/lib -L../lib -lluabind -llualib -llua
%.o:%.cpp
- $(CXX) -Wall -ftemplate-depth-100 -g $(CONFIG) -I$(LUA_PATH)/include -I. -I- -I../ -I$(BOOST_ROOT) -c $? -o $@
+ $(CXX) -Wall -ftemplate-depth-100 -g $(CPPFLAGS) $(CONFIG) -I$(LUA_PATH)/include -I. -I- -I../ -I$(BOOST_ROOT) -c $? -o $@
-relink:
- rm -f $(TARGET)
- make
+#just to force the tests to be run
+test: $(SOURCES:.cpp=.dummy)
+
+%.dummy:%.exe
+ ./$?
clean:
- rm -f $(OBJECTS) $(TARGET) core
+ rm -f $(SOURCES:.cpp=.o) $(SOURCES:.cpp=.exe) main.o core
Index: test_policies.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_policies.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- test_policies.cpp 15 Apr 2005 13:46:17 -0000 1.10
+++ test_policies.cpp 28 Nov 2005 20:55:34 -0000 1.11
@@ -30,6 +30,14 @@
#include <luabind/dependency_policy.hpp>
#include <luabind/luabind.hpp>
+struct test_copy {};
+
+
+struct secret_type {};
+
+secret_type sec_;
+
+
struct policies_test_class
{
policies_test_class(const char* name): name_(name)
@@ -58,6 +66,9 @@
// private:
policies_test_class(policies_test_class const& c): name_(c.name_)
{ ++count; }
+
+ void member_out_val(int* v) { *v = 5; }
+ secret_type* member_secret() { return &sec_; }
};
int policies_test_class::count = 0;
@@ -67,10 +78,6 @@
void out_val(float* f) { *f = 3.f; }
policies_test_class* copy_val() { return &global; }
-struct secret_type {};
-
-secret_type sec_;
-
secret_type* secret() { return &sec_; }
void aux_test();
@@ -96,15 +103,17 @@
module(L)
[
- class_<test_t>("test_t")
- .def("make", &test_t::make, adopt(return_value))
- .def("take", &test_t::take, adopt(_2))
+ class_<test_t>("test_t")
+ .def("make", &test_t::make, adopt(return_value))
+ .def("take", &test_t::take, adopt(_2))
];
module(L)
[
class_<policies_test_class>("test")
.def(constructor<>())
+ .def("member_out_val", &policies_test_class::member_out_val, pure_out_value(_2))
+ .def("member_secret", &policies_test_class::member_secret, discard_result)
.def("f", &policies_test_class::f, adopt(_2))
.def("make", &policies_test_class::make, adopt(return_value))
.def("internal_ref", &policies_test_class::internal_ref, dependency(result, _1))
@@ -186,6 +195,8 @@
TEST_CHECK(policies_test_class::count == 2);
DOSTRING(L, "b = a:make('tjosan')");
+ DOSTRING(L, "assert(a:member_out_val() == 5)");
+ DOSTRING(L, "a:member_secret()");
// make instantiated a new policies_test_class
TEST_CHECK(policies_test_class::count == 3);
Index: test_object.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_object.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- test_object.cpp 15 Apr 2005 13:46:17 -0000 1.27
+++ test_object.cpp 28 Nov 2005 20:55:34 -0000 1.28
@@ -20,6 +20,7 @@
// 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 <luabind/adopt_policy.hpp>
@@ -32,44 +33,41 @@
int test_object_param(const object& table)
{
- LUABIND_CHECK_STACK(table.lua_state());
+ LUABIND_CHECK_STACK(table.interpreter());
object current_object;
current_object = table;
+ lua_State* L = table.interpreter();
- if (table.type() == LUA_TTABLE)
+ if (type(table) == LUA_TTABLE)
{
-
- int sum = object_cast<int>(table["oh"]);
- for (object::array_iterator i = table.abegin(); i != table.aend(); ++i)
+ int sum1 = 0;
+ for (iterator i(table), e; i != e; ++i)
{
- assert(i->type() == LUA_TNUMBER);
- sum += object_cast<int>(*i);
+ assert(type(*i) == LUA_TNUMBER);
+ sum1 += object_cast<int>(*i);
}
int sum2 = 0;
- for (object::iterator i = table.begin(); i != table.end(); ++i)
+ for (raw_iterator i(table), e; i != e; ++i)
{
- assert(i->type() == LUA_TNUMBER);
+ assert(type(*i) == LUA_TNUMBER);
sum2 += object_cast<int>(*i);
}
- int sum3 = 0;
- for (object::raw_iterator i = table.raw_begin(); i != table.raw_end(); ++i)
- {
- assert(i->type() == LUA_TNUMBER);
- sum3 += object_cast<int>(*i);
- }
-
- table["sum"] = sum;
+ // test iteration of empty table
+ object empty_table = newtable(L);
+ for (iterator i(empty_table), e; i != e; ++i)
+ {}
+
+ table["sum1"] = sum1;
table["sum2"] = sum2;
- table["sum3"] = sum3;
table["blurp"] = 5;
return 0;
}
else
{
- if (table.type() != LUA_TNIL)
+ if (type(table) != LUA_TNIL)
{
return 1;
}
@@ -131,6 +129,10 @@
.def_readonly("obj2", &test_param::obj2)
];
+ object uninitialized;
+ TEST_CHECK(!uninitialized);
+ TEST_CHECK(!uninitialized.is_valid());
+
DOSTRING(L,
"t = 2\n"
"assert(test_object_param(t) == 1)");
@@ -138,19 +140,17 @@
DOSTRING(L, "assert(test_object_param(nil) == 2)");
DOSTRING(L, "t = { ['oh'] = 4, 3, 5, 7, 13 }");
DOSTRING(L, "assert(test_object_param(t) == 0)");
- DOSTRING(L, "assert(t.sum == 4 + 3 + 5 + 7 + 13)");
+ DOSTRING(L, "assert(t.sum1 == 4 + 3 + 5 + 7 + 13)");
DOSTRING(L, "assert(t.sum2 == 4 + 3 + 5 + 7 + 13)");
- DOSTRING(L, "assert(t.sum3 == 4 + 3 + 5 + 7 + 13)");
DOSTRING(L, "assert(t.blurp == 5)");
- object g = get_globals(L);
- object fun = g["test_fun"];
- object ret = fun();
+ object g = globals(L);
+ object ret = g["test_fun"]();
TEST_CHECK(object_cast<int>(ret) == 42);
DOSTRING(L, "function test_param_policies(x, y) end");
object test_param_policies = g["test_param_policies"];
- int a = test_param_policies.type();
+ int a = type(test_param_policies);
TEST_CHECK(a == LUA_TFUNCTION);
// call the function and tell lua to adopt the pointer passed as first argument
@@ -172,13 +172,20 @@
object test_object_policies = g["test_object_policies"];
object ret_val = test_object_policies("teststring")[detail::null_type()];
TEST_CHECK(object_cast<int>(ret_val) == 6);
+ TEST_CHECK(ret_val == 6);
+ TEST_CHECK(6 == ret_val);
+ g["temp_val"] = 6;
+ TEST_CHECK(ret_val == g["temp_val"]);
+ object temp_val = g["temp_val"];
+ TEST_CHECK(ret_val == temp_val);
+
TEST_CHECK(object_cast<std::string>(g["glob"]) == "teststring");
- TEST_CHECK(object_cast<std::string>(g.at("glob")) == "teststring");
- TEST_CHECK(object_cast<std::string>(g.raw_at("glob")) == "teststring");
+ TEST_CHECK(object_cast<std::string>(gettable(g, "glob")) == "teststring");
+ TEST_CHECK(object_cast<std::string>(rawget(g, "glob")) == "teststring");
object t = newtable(L);
- TEST_CHECK(t.begin() == t.end());
- TEST_CHECK(t.raw_begin() == t.raw_end());
+ TEST_CHECK(iterator(t) == iterator());
+ TEST_CHECK(raw_iterator(t) == raw_iterator());
DOSTRING(L,
"p1 = {}\n"
@@ -189,6 +196,7 @@
"assert(p2.ret == 2)\n"
"assert(p3.ret == 3)\n");
+
#ifndef LUABIND_NO_EXCEPTIONS
try
@@ -202,6 +210,34 @@
#endif
- object not_initialized;
- TEST_CHECK(!object_cast_nothrow<int>(not_initialized));
+ object not_initialized;
+ TEST_CHECK(!object_cast_nothrow<int>(not_initialized));
+ TEST_CHECK(!not_initialized.is_valid());
+ TEST_CHECK(!not_initialized);
+
+ DOSTRING(L, "t = { {1}, {2}, {3}, {4} }");
+
+ int inner_sum = 0;
+
+ for (iterator i(globals(L)["t"]), e; i != e; ++i)
+ {
+ inner_sum += object_cast<int>((*i)[1]);
+ }
+
+ TEST_CHECK(inner_sum == 1 + 2 + 3 + 4);
+
+ DOSTRING(L, "t = { {1, 2}, {3, 4}, {5, 6}, {7, 8} }");
+
+ inner_sum = 0;
+
+ for (iterator i(globals(L)["t"]), e; i != e; ++i)
+ {
+ for (iterator j(*i), e; j != e; ++j)
+ {
+ inner_sum += object_cast<int>(*j);
+ }
+ }
+
+ TEST_CHECK(inner_sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
+ TEST_CHECK(object_cast<int>(globals(L)["t"][2][2]) == 4);
}
--- 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"
);
}
--- NEW FILE: test_value_wrapper.cpp ---
// Copyright (c) 2005 Daniel Wallin and Arvid Norberg
// 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/value_wrapper.hpp>
#include <luabind/object.hpp>
#include <boost/mpl/assert.hpp>
struct X_tag;
struct X
{
typedef X_tag value_wrapper_tag;
};
namespace luabind
{
#ifdef LUABIND_USE_VALUE_WRAPPER_TAG
template<>
struct value_wrapper_traits<X_tag>
{
typedef boost::mpl::true_ is_specialized;
};
#else
// used on compilers supporting partial template specialization
template<>
struct value_wrapper_traits<X>
{
typedef boost::mpl::true_ is_specialized;
};
#endif
} // namespace luabind
BOOST_MPL_ASSERT(( luabind::is_value_wrapper<X> ));
BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper<X&> ));
BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper<X const&> ));
BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X> ));
BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X const> ));
BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X&> ));
BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X const&> ));
BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper_arg<int> ));
BOOST_MPL_ASSERT_NOT(( luabind::is_value_wrapper_arg<int[4]> ));
BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<X const&> ));
BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<luabind::object&> ));
BOOST_MPL_ASSERT(( luabind::is_value_wrapper_arg<luabind::object const&> ));
int main()
{
}
Index: test_yield.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_yield.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- test_yield.cpp 15 Apr 2005 13:46:17 -0000 1.15
+++ test_yield.cpp 28 Nov 2005 20:55:34 -0000 1.16
@@ -92,7 +92,7 @@
{
lua_State* thread = lua_newthread(L);
- object g = get_globals(thread)["g"];
+ object g = globals(thread)["g"];
TEST_CHECK(resume_function<int>(g, "foobar") == 5);
for (int i = 1; i < 10; ++i)
Index: test_free_functions.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_free_functions.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- test_free_functions.cpp 15 Apr 2005 13:46:17 -0000 1.18
+++ test_free_functions.cpp 28 Nov 2005 20:55:34 -0000 1.19
@@ -22,15 +22,16 @@
#include "test.hpp"
#include <luabind/luabind.hpp>
-#include <luabind/functor.hpp>
+//#include <luabind/functor.hpp>
#include <luabind/adopt_policy.hpp>
-
+/*
luabind::functor<int> functor_test;
void set_functor(luabind::functor<int> f)
{
functor_test = f;
}
+*/
struct base : counted_type<base>
{
@@ -125,8 +126,8 @@
def("f", (int(*)(int)) &f),
def("f", (int(*)(int, int)) &f),
- def("create", &create_base, adopt(return_value)),
- def("set_functor", &set_functor)
+ def("create", &create_base, adopt(return_value))
+// def("set_functor", &set_functor)
#if !(BOOST_MSVC < 1300)
,
@@ -144,11 +145,11 @@
DOSTRING(L, "assert(f(3, 9) == 12)");
- DOSTRING(L, "set_functor(function(x) return x * 10 end)");
+// DOSTRING(L, "set_functor(function(x) return x * 10 end)");
- TEST_CHECK(functor_test(20) == 200);
+// TEST_CHECK(functor_test(20) == 200);
- DOSTRING(L, "set_functor(nil)");
+// DOSTRING(L, "set_functor(nil)");
DOSTRING(L, "function lua_create() return create() end");
base* ptr = call_function<base*>(L, "lua_create") [ adopt(result) ];
@@ -165,20 +166,17 @@
"f(number)\n"
"f(number, number)\n");
- DOSTRING(L,
- "function functor_test(a) glob = a\n"
- " return 'foobar'\n"
- "end");
- functor<std::string> functor_test = object_cast<functor<std::string> >(get_globals(L)["functor_test"]);
+// DOSTRING(L,
+// "function functor_test(a) glob = a\n"
+// " return 'foobar'\n"
+// "end");
+// functor<std::string> functor_test = object_cast<functor<std::string> >(globals(L)["functor_test"]);
- TEST_CHECK(functor_test(6)[detail::null_type()] == "foobar");
- TEST_CHECK(object_cast<int>(get_globals(L)["glob"]) == 6);
-
- functor<std::string> functor_test2 = object_cast<functor<std::string> >(get_globals(L)["functor_test"]);
+// TEST_CHECK(functor_test(6)[detail::null_type()] == "foobar");
+// TEST_CHECK(object_cast<int>(globals(L)["glob"]) == 6);
- TEST_CHECK(functor_test == functor_test2);
+// functor<std::string> functor_test2 = object_cast<functor<std::string> >(globals(L)["functor_test"]);
- // this must be reset before the lua state is destructed!
- functor_test.reset();
+// TEST_CHECK(functor_test == functor_test2);
}
Index: test_typetraits.cpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/test_typetraits.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_typetraits.cpp 15 Apr 2005 13:46:17 -0000 1.5
+++ test_typetraits.cpp 28 Nov 2005 20:55:34 -0000 1.6
@@ -29,8 +29,9 @@
using namespace luabind::detail;
struct tester {};
+struct lua_State;
-int main()
+int test_main(lua_State*)
{
BOOST_STATIC_ASSERT(is_nonconst_reference<int&>::value);
BOOST_STATIC_ASSERT(!is_nonconst_reference<const int&>::value);
Index: Jamfile
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/test/Jamfile,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Jamfile 15 Apr 2005 13:46:17 -0000 1.15
+++ Jamfile 28 Nov 2005 20:55:34 -0000 1.16
@@ -3,6 +3,9 @@
use-project /luabind : ../ ;
SOURCES =
+ test_back_reference.cpp
+ test_def_from_base.cpp
+ test_object.cpp
test_abstract_base.cpp
test_attributes.cpp
test_const.cpp
@@ -14,7 +17,6 @@
test_iterator.cpp
test_lua_classes.cpp
test_null_pointer.cpp
- test_object.cpp
test_operators.cpp
test_policies.cpp
test_scope.cpp
@@ -23,6 +25,8 @@
test_yield.cpp
;
+project : default-build <link>static ;
+
lib main-lib
: main.cpp /luabind//luabind/<link>static /luabind//lua /luabind//lualib
: <link>static
@@ -35,5 +39,9 @@
tests += [ run $(src) main-lib ] ;
}
-test-suite luabind-test : $(tests) [ compile test_typetraits.cpp ] ;
+test-suite luabind-test : $(tests)
+ [ compile test_typetraits.cpp ]
+ [ compile test_value_wrapper.cpp ]
+ [ compile test_has_get_pointer.cpp ]
+ ;
|