Fixed placeholder problem with GCC 4.2.3.
[luabind.git] / test / test_exceptions.cpp
blobeff3f4e7cab6a0bec72070da5735f6c86a8f7cd6
1 // Copyright (c) 2004 Daniel Wallin
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
23 #include "test.hpp"
24 #include <luabind/luabind.hpp>
26 struct ex : public std::exception
28 ex(const char* m): msg(m) {}
29 virtual const char* what() const throw() { return msg; }
30 const char* msg;
33 struct exception_thrower : counted_type<exception_thrower>
35 exception_thrower() {}
36 exception_thrower(int) { throw ex("exception description"); }
37 exception_thrower(int, int) { throw "a string exception"; }
38 exception_thrower(int, int, int) { throw 10; }
39 int f() { throw ex("exception from a member function"); }
40 int g() { throw "a string exception"; }
41 int h() { throw 10; }
44 COUNTER_GUARD(exception_thrower);
46 void test_main(lua_State* L)
48 using namespace luabind;
50 #ifndef LUABIND_NO_EXCEPTIONS
52 module(L)
54 class_<exception_thrower>("throw")
55 .def(constructor<>())
56 .def(constructor<int>())
57 .def(constructor<int, int>())
58 .def(constructor<int, int, int>())
59 .def("f", &exception_thrower::f)
60 .def("g", &exception_thrower::g)
61 .def("h", &exception_thrower::h)
64 DOSTRING_EXPECTED(L, "a = throw(1)", "exception description");
65 DOSTRING_EXPECTED(L, "a = throw(1,1)", "a string exception");
66 DOSTRING_EXPECTED(L, "a = throw(1,1,1)", "throw() threw an exception");
67 DOSTRING(L, "a = throw()");
68 DOSTRING_EXPECTED(L, "a:f()", "exception from a member function");
69 DOSTRING_EXPECTED(L, "a:g()", "a string exception");
71 DOSTRING_EXPECTED(L, "a:h()", "throw:h() threw an exception");
72 DOSTRING_EXPECTED(L,
73 "obj = throw('incorrect', 'parameters', 'constructor')",
74 "no constructor of 'throw' matched the arguments "
75 "(string, string, string)\n candidates are:\n"
76 "throw()\nthrow(number)\nthrow(number, number)\n"
77 "throw(number, number, number)\n");
79 #endif