Added missing dll-exports.
[luabind.git] / test / test.hpp
blobc3c591e043193457aec43b2e05eefa67ab866c3f
1 // Copyright (c) 2005 Daniel Wallin, Arvid Norberg
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 #ifndef TEST_050415_HPP
24 #define TEST_050415_HPP
26 #include <boost/preprocessor/cat.hpp>
27 #include <luabind/error.hpp>
29 extern "C"
31 #include "lua.h"
32 #include "lauxlib.h"
33 #include "lualib.h"
36 void report_failure(char const* str, char const* file, int line);
38 #if defined(_MSC_VER)
39 #define COUNTER_GUARD(x)
40 #else
41 #define COUNTER_GUARD(type) \
42 struct BOOST_PP_CAT(type, _counter_guard) \
43 { \
44 ~BOOST_PP_CAT(type, _counter_guard()) \
45 { \
46 TEST_CHECK(counted_type<type>::count == 0); \
47 } \
48 } BOOST_PP_CAT(type, _guard)
49 #endif
51 #define TEST_REPORT_AUX(x, line, file) \
52 report_failure(x, line, file)
54 #define TEST_CHECK(x) \
55 if (!(x)) \
56 TEST_REPORT_AUX("TEST_CHECK failed: \"" #x "\"", __FILE__, __LINE__)
58 #define TEST_ERROR(x) \
59 TEST_REPORT_AUX((std::string("ERROR: \"") + x + "\"").c_str(), __FILE__, __LINE__)
61 #define TEST_NOTHROW(x) \
62 try \
63 { \
64 x; \
65 } \
66 catch (...) \
67 { \
68 TEST_ERROR("Exception thrown: " #x); \
71 void dostring(lua_State* L, char const* str);
73 template<class T>
74 struct counted_type
76 static int count;
78 counted_type()
80 ++count;
83 counted_type(counted_type const&)
85 ++count;
88 ~counted_type()
90 TEST_CHECK(--count >= 0);
94 template<class T>
95 int counted_type<T>::count = 0;
97 #define DOSTRING_EXPECTED(state_, str, expected) \
98 { \
99 try \
101 dostring(state_, str); \
103 catch (luabind::error const& e) \
105 using namespace std; \
106 if (std::strcmp( \
107 lua_tostring(e.state(), -1) \
108 , (char const*)expected)) \
110 TEST_ERROR(lua_tostring(e.state(), -1)); \
111 lua_pop(L, 1); \
114 catch (std::string const& s) \
116 if (s != expected) \
117 TEST_ERROR(s.c_str()); \
121 #define DOSTRING(state_, str) \
123 try \
125 dostring(state_, str); \
127 catch (luabind::error const& e) \
129 TEST_ERROR(lua_tostring(e.state(), -1)); \
130 lua_pop(L, 1); \
132 catch (std::string const& s) \
134 TEST_ERROR(s.c_str()); \
138 #endif // TEST_050415_HPP