21 #pragma warning(disable : 4127) // some tests use constant arguments to if() statements in macros 34 static bool m_asserting =
true;
46 #include <cxxtest/TestSuite.h> 57 class XmAssertScopedDisable
59 bool const m_initialValue;
62 XmAssertScopedDisable()
67 ~XmAssertScopedDisable()
75 void iTest_XM_ENSURE_TRUE_VOID(
bool a_assert)
77 char* foo =
new char[123];
85 XmAssertScopedDisable disable;
93 TS_FAIL(
"iTest_XM_ENSURE_TRUE_VOID");
99 void iTest_XM_ENSURE_TRUE_T(
bool a_assert)
103 char* foo =
new char[123];
111 XmAssertScopedDisable disable;
119 TS_FAIL(
"iTest_XM_ENSURE_TRUE_T");
121 catch (std::runtime_error& e)
123 std::string s = e.what();
124 TS_ASSERT_EQUALS(s,
"2");
130 xmresult iTest_XM_ENSURE_TRUE_ptr(
bool a_assert)
132 char* foo =
new char[123];
140 XmAssertScopedDisable disable;
148 TS_FAIL(
"iTest_XM_ENSURE_TRUE_ptr");
154 xmresult iTest_XM_ENSURE_TRUE_boost_ptr(
bool a_assert)
156 BSHP<char> foo(
new char(123));
163 XmAssertScopedDisable disable;
171 TS_FAIL(
"iTest_XM_ENSURE_TRUE_boost_ptr");
177 void iTest_XM_ENSURE_SUCCESS_VOID(
bool a_assert)
186 XmAssertScopedDisable disable;
194 TS_FAIL(
"iTest_XM_ENSURE_SUCCESS_VOID");
199 xmresult iTest_XM_ENSURE_SUCCESS(
bool a_assert)
208 XmAssertScopedDisable disable;
216 TS_FAIL(
"iTest_XM_ENSURE_SUCCESS");
222 xmresult iTest_XM_ENSURE_SUCCESS_T(
bool a_assert)
233 XmAssertScopedDisable disable;
241 TS_FAIL(
"iTest_XM_ENSURE_SUCCESS");
245 TS_ASSERT_EQUALS(e, XR_FAILURE);
253 xmresult iTest_XM_RETURN_XMRESULT_bool(
bool a)
260 xmresult iTest_XM_RETURN_XMRESULT_boost_ptr_true()
262 BSHP<char> foo(
new char(123));
268 xmresult iTest_XM_RETURN_XMRESULT_boost_ptr_false()
291 xms::iTest_XM_ENSURE_TRUE_VOID(
false);
292 xms::iTest_XM_ENSURE_TRUE_VOID(
true);
295 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
296 rv = xms::iTest_XM_ENSURE_TRUE_ptr(
true);
297 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
299 rv = xms::iTest_XM_ENSURE_TRUE_boost_ptr(
false);
300 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
301 rv = xms::iTest_XM_ENSURE_TRUE_boost_ptr(
true);
302 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
306 xms::iTest_XM_ENSURE_SUCCESS_VOID(
false);
307 xms::iTest_XM_ENSURE_SUCCESS_VOID(
true);
309 rv = xms::iTest_XM_ENSURE_SUCCESS(
false);
310 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
311 rv = xms::iTest_XM_ENSURE_SUCCESS(
true);
312 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
314 xms::iTest_XM_ENSURE_SUCCESS_T(
false);
315 xms::iTest_XM_ENSURE_SUCCESS_T(
true);
319 rv = xms::iTest_XM_RETURN_XMRESULT_bool(
true);
320 TS_ASSERT_EQUALS(rv, xms::XR_SUCCESS);
322 rv = xms::iTest_XM_RETURN_XMRESULT_bool(
false);
323 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
325 rv = xms::iTest_XM_RETURN_XMRESULT_boost_ptr_true();
326 TS_ASSERT_EQUALS(rv, xms::XR_SUCCESS);
328 rv = xms::iTest_XM_RETURN_XMRESULT_boost_ptr_false();
329 TS_ASSERT_EQUALS(rv, xms::XR_FAILURE);
343 XmAssertScopedDisable disable;
#define XM_ENSURE_TRUE_VOID(...)
Returns (void) if x evaluates to false, logs, and optionally asserts.
#define XM_ENSURE_SUCCESS_VOID_NO_ASSERT(...)
Returns (void) if x evaluates to xms::XR_FAILURE and logs.
bool & xmAsserting()
Stores whether we want XM_ASSERT to do something or not.
void test_XM_ASSERT()
Tests for XM_ASSERT.
#define XM_ENSURE_TRUE_NO_ASSERT(...)
Returns (void) if x evaluates to false and logs.
#define XM_ENSURE_SUCCESS_NO_ASSERT(...)
Returns ret if x evaluates to xms::XR_FAILURE and logs.
xmresult
Like Mozilla's nsresult.
Macros etc that make boost more convenient to use.
#define XM_ENSURE_SUCCESS(...)
Returns ret if x evaluates to xms::XR_FAILURE, logs, and optionally asserts.
#define XM_ENSURE_TRUE(...)
Returns (void) if x evaluates to false, logs, and optionally asserts.
#define XM_RETURN_XMRESULT(x)
Returns XR_SUCCESS if cond == true, else XR_FAILURE. Useful to convert a true/false return value into...
#define XM_ENSURE_TRUE_VOID_NO_ASSERT(...)
Returns (void) if x evaluates to false and logs.
void test1()
Tests for XmError.
#define XM_ASSERT(x)
Does a regular ASSERT if xmAsserting, otherwise does nothing.
#define XM_ENSURE_TRUE_T_NO_ASSERT(...)
Throws ret if x evaluates to false and logs.
#define XM_ENSURE_SUCCESS_T(...)
Throws ret if x evaluates to xms::XR_FAILURE, logs, and optionally asserts.
#define XM_ENSURE_SUCCESS_T_NO_ASSERT(...)
Throws ret if x evaluates to xms::XR_FAILURE and logs.
Functions and macros for assertion and checking for errors.
#define XM_ENSURE_SUCCESS_VOID(...)
Returns (void) if x evaluates to xms::XR_FAILURE, logs, and optionally asserts.
#define XM_ENSURE_TRUE_T(...)
Throws ret if x evaluates to false, logs, and optionally asserts.