AceUnit.h

Go to the documentation of this file.
00001 /* Copyright (c) 2007-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 ACEUNIT_H
00029 
00030 #define ACEUNIT_H 1
00031 
00213 #ifdef ACEUNIT_CONFIG_FILE
00214 #include ACEUNIT_CONFIG_FILE
00215 #endif
00216 
00217 /* Auto-definition of ACEUNIT_C_MODE if it is not defined. */
00218 #if !defined(ACEUNIT_C_MODE)
00219 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00220 /* C99 or better environment: Default to using C99. */
00221 #define ACEUNIT_C_MODE ACEUNIT_C_MODE_C99_INCLUDES
00222 #else
00223 /* <C99: Use its own definitions. */
00224 #define ACEUNIT_C_MODE ACEUNIT_C_MODE_C89
00225 #endif
00226 #endif
00227 
00229 #define ACEUNIT_C_MODE_C99_INCLUDES 1
00230 
00232 #define ACEUNIT_C_MODE_C89 2
00233 
00235 #define ACEUNIT_C_MODE_PROPRIETARY 3
00236 
00237 #if ACEUNIT_C_MODE == ACEUNIT_C_MODE_C99_INCLUDES
00238 #include <stddef.h>
00239 #include <stdint.h>
00240 #include <stdbool.h>
00241 #elif ACEUNIT_C_MODE == ACEUNIT_C_MODE_C89
00242 #ifndef __int8_t_defined
00243 #define __int8_t_defined
00244 
00245 typedef signed char int8_t;
00247 typedef signed short int int16_t;
00249 typedef signed long int int32_t;
00251 typedef unsigned char uint8_t;
00253 typedef unsigned short int uint16_t;
00255 typedef unsigned long int uint32_t;
00256 #endif
00257 #ifndef _SIZE_T_DEFINED
00258 #ifndef _SIZE_T_DEFINED_
00259 
00260 typedef long unsigned int size_t;
00261 #endif
00262 #endif
00263 #ifndef __bool_true_false_are_defined
00264 
00265 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00266 #define bool _Bool
00267 #else
00268 #define bool int
00269 #endif
00270 
00271 #define true 1
00272 
00273 #define false 0
00274 
00275 #define __bool_true_false_are_defined 1
00276 #endif
00277 #ifndef NULL
00278 
00279 #if defined(__cplusplus)
00280 #define NULL 0
00281 #else
00282 #define NULL ((void *) 0)
00283 #endif
00284 #endif
00285 #elif ACEUNIT_C_MODE == ACEUNIT_C_MODE_PROPRIETARY
00286 /* no definitions for proprietary mode */
00287 #else
00288 #error Unknown value for ACEUNIT_C_MODE
00289 #endif
00290 
00291 #include "AceUnitAnnotations.h"
00292 
00307 #define ACEUNIT_ASSERTION_STYLE_RETURN 1
00308 
00326 #define ACEUNIT_ASSERTION_STYLE_ASSERT 2
00327 
00338 #define ACEUNIT_ASSERTION_STYLE_ABORT 3
00339 
00347 #define ACEUNIT_ASSERTION_STYLE_LONGJMP 4
00348 
00354 #define ACEUNIT_ASSERTION_STYLE_CUSTOM 5
00355 
00356 #ifndef ACEUNIT_ASSERTION_STYLE
00357 
00367 #ifdef ACEUNIT_CUSTOM_ASSERT
00368 #define ACEUNIT_ASSERTION_STYLE ACEUNIT_ASSERTION_STYLE_CUSTOM
00369 #else
00370 #define ACEUNIT_ASSERTION_STYLE ACEUNIT_ASSERTION_STYLE_LONGJMP
00371 #endif
00372 #endif
00373 
00374 #if ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_CUSTOM
00375 #ifndef ACEUNIT_CUSTOM_ASSERT
00376 #error You MUST define ACEUNIT_CUSTOM_ASSERT when using ACEUNIT_ASSERTION_STYLE_CUSTOM.
00377 #endif
00378 #endif
00379 
00380 /* Abort style specific configuration. */
00381 #if ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_RETURN
00382     /* nothing special */
00383 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_ASSERT
00384     #include <assert.h>
00385 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_ABORT
00386     #include <stdlib.h>
00387 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_LONGJMP
00388     #ifdef ACEUNIT_SETJMP_INCLUDE
00389     #include ACEUNIT_SETJMP_INCLUDE
00390     #elif defined(ACEUNIT_SKIP_SETJMP_INCLUDE)
00391     #else
00392     #include <setjmp.h>
00393     #endif
00394 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_CUSTOM
00395     /* nothing special */
00396 #else
00397     #error Unknown value for ACEUNIT_ASSERTION_STYLE.
00398 #endif
00399 
00401 #if ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_RETURN
00402     #define ACEUNIT_ABORT return
00403 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_ASSERT
00404     #define ACEUNIT_ABORT assert(0)
00405 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_ABORT
00406     #define ACEUNIT_ABORT abort()
00407 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_LONGJMP
00408     #define ACEUNIT_ABORT longjmp(runnerData->jmpBuf, 1)
00409 #elif ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_CUSTOM
00410     #define ACEUNIT_ABORT ACEUNIT_CUSTOM_ASSERT
00411 #else
00412     #error Unexpected internal error.
00413 #endif
00414 
00416 typedef uint16_t AceTestId_t;
00417 
00422 #define NO_TEST ((AceTestId_t) 0)
00423 
00428 #define ALL_TESTS ((AceTestId_t) -1)
00429 
00431 typedef uint16_t AceGroupId_t;
00432 
00438 typedef AceTestId_t SuiteId_t;
00439 
00444 typedef SuiteId_t FixtureId_t;
00445 
00450 typedef AceTestId_t TestCaseId_t;
00451 
00453 #define TestCaseId_NULL 0
00454 
00456 #ifdef ACEUNIT_EMBEDDED
00457 typedef uint16_t linenumber_t;
00458 #else
00459 typedef int linenumber_t;
00460 #endif
00461 
00466 typedef struct {
00467 
00469     linenumber_t lineNumber;
00470 
00471 #ifndef ACEUNIT_EMBEDDED
00472 
00473     const char *message;
00474 #endif
00475 
00476 } AssertionId_t;
00477 
00481 #ifdef ACEUNIT_EMBEDDED
00482 #define newAssertionError(message) { AssertionId_t assertion = { __LINE__ }; recordError(A_FIXTURE_ID, assertion); } ACEUNIT_ABORT
00483 #else
00484 #define newAssertionError(message) { AssertionId_t assertion = { __LINE__, message }; recordError(A_FIXTURE_ID, assertion); } ACEUNIT_ABORT
00485 #endif
00486 
00490 typedef struct {
00491 
00493     FixtureId_t fixtureId;
00494 
00496     TestCaseId_t testId;
00497 
00499     AssertionId_t assertionId;
00500 
00501 } AssertionError_t;
00502 
00503 #include "AceUnitAssert.h"
00504 
00513 typedef void(*testMethod_t)(void);
00514 
00518 typedef struct TestSuite_tt {
00519 
00520     /* Implementation note: Take care that the beginning of TestSuite_t is identical to that of TestFixture_t! */
00521 
00523     SuiteId_t const id;
00524 
00525 #ifndef ACEUNIT_EMBEDDED
00526 
00527     const char *name;
00528 #endif
00529 
00533     const struct TestSuite_tt *const *const suites;
00534 
00535 } TestSuite_t;
00536 
00537 #ifdef ACEUNIT_LOOP
00538 
00539 typedef uint16_t aceunit_loop_t;
00540 #endif
00541 
00545 typedef struct {
00546 
00547     /* Implementation note: Take care that the beginning of TestFixture_t is identical to that of TestSuite_t! */
00548 
00550     FixtureId_t const id;
00551 
00552 #ifndef ACEUNIT_EMBEDDED
00553 
00554     const char *const name;
00555 #endif
00556 
00557 #ifdef ACEUNIT_SUITES
00558 
00561     const TestSuite_t *const *const suites;
00562 #endif
00563 
00565     const TestCaseId_t *const testIds;
00566 
00567 #ifndef ACEUNIT_EMBEDDED
00568 
00569     const char *const *const testNames;
00570 #endif
00571 
00572 #ifdef ACEUNIT_LOOP
00573 
00574     const aceunit_loop_t *const loops;
00575 #endif
00576 
00577 #ifdef ACEUNIT_GROUP
00578 
00579     const AceGroupId_t *const groups;
00580 #endif
00581 
00583     const testMethod_t *const testCase;
00584 
00586     const testMethod_t *const before;
00587 
00589     const testMethod_t *const after;
00590 
00592     const testMethod_t *const beforeClass;
00593 
00595     const testMethod_t *const afterClass;
00596 
00597 } TestFixture_t;
00598 
00603 extern void recordError(const FixtureId_t fixtureId, const AssertionId_t assertionId);
00604 
00610 #if defined(ACEUNIT_GROUP) || defined(_doxygen)
00611 extern void runFixture(const TestFixture_t *const fixture, AceGroupId_t group);
00612 #else
00613 extern void runFixture(const TestFixture_t *const fixture);
00614 #endif
00615 
00621 #if defined(ACEUNIT_GROUP) || defined(_doxygen)
00622 extern void runSuite(const TestSuite_t *const suite, AceGroupId_t group);
00623 #else
00624 extern void runSuite(const TestSuite_t *const suite);
00625 #endif
00626 
00627 #if ACEUNIT_ASSERTION_STYLE == ACEUNIT_ASSERTION_STYLE_LONGJMP
00628 #include "AceUnitData.h"
00629 #endif
00630 
00631 #endif /* ACEUNIT_H */

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