From 712d1aabde01638ad0f341495ed07b7ee12892da Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Mon, 23 Feb 2004 00:41:48 +0000 Subject: [PATCH] fixed some problems with the test suite --- test/Jamfile | 1 + test/main.cpp | 4 +- test/test_construction.cpp | 2 +- test/test_implicit_cast.cpp | 166 ++++++++++++++++++++------------------------ 4 files changed, 79 insertions(+), 94 deletions(-) rewrite test/test_implicit_cast.cpp (97%) diff --git a/test/Jamfile b/test/Jamfile index 0ed3b72..37fede2 100755 --- a/test/Jamfile +++ b/test/Jamfile @@ -1,6 +1,7 @@ import testing ; SOURCES = + test_implicit_cast.cpp test_scope.cpp test_typetraits.cpp test_construction.cpp diff --git a/test/main.cpp b/test/main.cpp index 068bbb2..fbba3ee 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -68,9 +68,9 @@ lua_state::lua_state() : m_state(lua_open()) { luaopen_base(m_state); + lua_baselibopen(m_state); m_top = lua_gettop(m_state); luabind::open(m_state); - lua_baselibopen(m_state); } lua_state::~lua_state() @@ -122,6 +122,7 @@ void test_scope(); void test_yield(); void test_construction(); void test_type_traits(); +void test_implicit_cast(); // -------------------------------------------------------------------------- @@ -147,6 +148,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test->add(BOOST_TEST_CASE(&test_construction)); test->add(BOOST_TEST_CASE(&test_yield)); test->add(BOOST_TEST_CASE(&test_type_traits)); + test->add(BOOST_TEST_CASE(&test_implicit_cast)); return test; } diff --git a/test/test_construction.cpp b/test/test_construction.cpp index 38e2ae9..efd0997 100644 --- a/test/test_construction.cpp +++ b/test/test_construction.cpp @@ -109,7 +109,7 @@ void test_construction() .def("doMore", &derived2::doMore) ]; - DOSTRING_EXPECTED(L, "a = C()", "no constructor of 'C' matched the arguments ()\ncandidates are:\n\n"); + DOSTRING_EXPECTED(L, "a = C()", "no constructor of 'C' matched the arguments ()\n candidates are:\n"); DOSTRING(L, "a = A(4)\n" diff --git a/test/test_implicit_cast.cpp b/test/test_implicit_cast.cpp dissimilarity index 97% index 964aab7..f9963c7 100644 --- a/test/test_implicit_cast.cpp +++ b/test/test_implicit_cast.cpp @@ -1,92 +1,74 @@ -#include "test.h" - -namespace -{ - LUABIND_ANONYMOUS_FIX int feedback = 0; - - struct A { virtual ~A() {} }; - struct B: public A {}; - - struct test_implicit - { - void f(A*) { feedback = 1; } - void f(B*) { feedback = 2; } - }; - - - struct char_pointer_convertable - { - operator const char*() const { return "foo!"; } - }; - - void func(const char_pointer_convertable& f) - { - if (std::string("foo!") == (const char*)f) feedback = 3; - } - -} // anonymous namespace -/* -#include - -void test_instance_holder(lua_State* L) -{ - using namespace luabind; - -// pointer_holder holder(new B); - -// void* p = holder.holds(LUABIND_TYPEID(B)); -} -*/ -bool test_implicit_cast() -{ - using namespace luabind; - - lua_State* L = lua_open(); - lua_closer c(L); - int top = lua_gettop(L); - - open(L); - - typedef void (test_implicit::*f1)(A*); - typedef void (test_implicit::*f2)(B*); - - module(L) - [ - class_("A") - .def(constructor<>()), - - class_("B") - .def(constructor<>()), - - class_("test") - .def(constructor<>()) - .def("f", (f1) &test_implicit::f) - .def("f", (f2) &test_implicit::f), - - class_("char_ptr") - .def(constructor<>()), - - def("func", &func) - ]; - -// test_instance_holder(L); - - if (dostring(L, "a = A()")) return false; - if (dostring(L, "b = B()")) return false; - if (dostring(L, "t = test()")) return false; - - if (dostring(L, "t:f(a)")) return false; - if (feedback != 1) return false; - - if (dostring(L, "t:f(b)")) return false; - if (feedback != 2) return false; - - if (dostring(L, - "a = char_ptr()\n" - "func(a)\n")) return false; - if (feedback != 3) return false; - - if (top != lua_gettop(L)) return false; - - return true; -} +#include "test.hpp" +#include + +namespace { + + struct A : counted_type + { virtual ~A() {} }; + + struct B : A, counted_type + {}; + + struct test_implicit : counted_type + { + char const* f(A*) { return "f(A*)"; } + char const* f(B*) { return "f(B*)"; } + }; + + struct char_pointer_convertible + : counted_type + { + operator const char*() const { return "foo!"; } + }; + + void func(const char_pointer_convertible& f) + { + } + +} // anonymous namespace + +void test_implicit_cast() +{ + COUNTER_GUARD(A); + COUNTER_GUARD(B); + COUNTER_GUARD(test_implicit); + COUNTER_GUARD(char_pointer_convertible); + + lua_state L; + + using namespace luabind; + + typedef char const*(test_implicit::*f1)(A*); + typedef char const*(test_implicit::*f2)(B*); + + module(L) + [ + class_("A") + .def(constructor<>()), + + class_("B") + .def(constructor<>()), + + class_("test") + .def(constructor<>()) + .def("f", (f1)&test_implicit::f) + .def("f", (f2)&test_implicit::f), + + class_("char_ptr") + .def(constructor<>()), + + def("func", &func) + ]; + + DOSTRING(L, "a = A()"); + DOSTRING(L, "b = B()"); + DOSTRING(L, "t = test()"); + + DOSTRING(L, "assert(t:f(a) == 'f(A*)')"); + DOSTRING(L, "assert(t:f(b) == 'f(B*)')"); + + DOSTRING(L, + "a = char_ptr()\n" + "func(a)"); +} + -- 2.11.4.GIT