AceUnitAssert.h

Go to the documentation of this file.
00001 /* Copyright (c) 2008, Christian Hujer
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *     * Redistributions of source code must retain the above copyright
00007  *       notice, this list of conditions and the following disclaimer.
00008  *     * Redistributions in binary form must reproduce the above copyright
00009  *       notice, this list of conditions and the following disclaimer in the
00010  *       documentation and/or other materials provided with the distribution.
00011  *     * Neither the name of the AceUnit developers nor the
00012  *       names of its contributors may be used to endorse or promote products
00013  *       derived from this software without specific prior written permission.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00016  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00017  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00018  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00019  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00021  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00022  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00024  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 #ifndef ACEUNITASSERT_H
00029 
00030 #define ACEUNITASSERT_H 1
00031 
00032 #include "AceUnit.h"
00033 
00039 #ifdef ACEUNIT_EXPLICIT_MESSAGES
00040 #include <stdio.h> /* for snprintf(). */
00041 #endif
00042 
00046 #define fail(message) newAssertionError(message)
00047 
00053 #define assertTrue(message, condition) do { if (!(condition)) { fail(message); } } while (false)
00054 
00060 #define assertFalse(message, condition) do { if (condition) { fail(message); } } while (false)
00061 
00071 #ifdef ACEUNIT_EXPLICIT_MESSAGES
00072 #define assertEquals(message, expected, actual) \
00073     do { \
00074         int32_t lexpected = (expected); \
00075         int32_t lactual = (actual); \
00076         if (lexpected != lactual) { \
00077             snprintf(runnerData->explicitMsgBuf, ACEUNIT_EXPLICIT_MSG_BUF_SIZE, "%s (expected: %d, actual: %d)", message, lexpected, lactual); \
00078             fail(runnerData->explicitMsgBuf); \
00079         } \
00080     } while (false)
00081 #else
00082 #define assertEquals(message, expected, actual) do { if (!((expected) == (actual))) { fail(message); } } while (false)
00083 #endif
00084 
00094 #ifdef ACEUNIT_EXPLICIT_MESSAGES
00095 #define assertNotEquals(message, unexpected, actual) \
00096     do { \
00097         int32_t lunexpected = unexpected; \
00098         int32_t lactual = actual; \
00099         if (lunexpected == lactual) { \
00100             snprintf(runnerData->explicitMsgBuf, ACEUNIT_EXPLICIT_MSG_BUF_SIZE, "%s (unexpected: %d, actual: %d)", message, lunexpected, lactual); \
00101             fail(runnerData->explicitMsgBuf); \
00102         } \
00103     } while (false)
00104 #else
00105 #define assertNotEquals(message, unexpected, actual) do { if ((unexpected) == (actual)) { fail(message); } } while (false)
00106 #endif
00107 
00113 #define assertNotNull(message, ptr) do { if (NULL == (ptr)) { fail(message); } } while (false)
00114 
00120 #define assertNull(message, ptr) do { if (NULL != (ptr)) { fail(message); } } while (false)
00121 
00122 #endif /* ACEUNITASSERT_H */

Generated on Sun Feb 13 11:10:16 2011 for AceUnit by  doxygen 1.5.3