Commit 03e93a14 authored by jds2's avatar jds2

Merge jds-v2-expt branch into HEAD. Release 2.0-1.


git-svn-id: http://svn.code.sf.net/p/cunit/code/trunk@55 f00e6729-6848-4c17-8bfb-678c97c00071
parent 7f042772
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
*
* Copyright (C) 2004 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
......@@ -24,10 +25,21 @@
* Last Modified : 13/Feb/2002
* Comment : Single interface to automated_run_tests
* EMail : aksaharan@yahoo.com
*
* Modified : 20-Jul-2004 (JDS)
* Comment : New interface, doxygen comments.
* EMail : jds2@users.sourceforge.net
*/
/** @file
* Automated testing interface with xml output (user interface).
*/
/** @addtogroup Automated
* @{
*/
#ifndef _CUNIT_AUTOMATED_H
#define _CUNIT_AUTOMATED_H 1
#define _CUNIT_AUTOMATED_H
#include "CUnit.h"
#include "TestDB.h"
......@@ -35,11 +47,20 @@
#ifdef __cplusplus
extern "C" {
#endif
extern void automated_run_tests(void);
extern void set_output_filename(char* szFilename);
void CU_automated_run_tests(void);
CU_ErrorCode CU_list_tests_to_file(void);
void CU_set_output_filename(const char* szFilenameRoot);
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_automated_run_tests(). */
#define automated_run_tests() CU_automated_run_tests()
/** Deprecated (version 1). @deprecated Use CU_set_output_filename(). */
#define set_output_filename(x) CU_set_output_filename((x))
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef __cplusplus
}
#endif
#endif /* _CUNIT_AUTOMATED_H_ */
/** @} */
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
*
* Copyright (C) 2004 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
......@@ -18,28 +18,47 @@
*/
/*
* Contains ASSERT implementation which handles the assert.
* If logs if the Condition is false else it ignores it.
*
* Created By : Anil Kumar on ...(in month of Aug 2001)
* Last Modified : 09/Aug/2001
* Comment : Added only skeleton function.
* Email : aksaharan@yahoo.com
* Interface for simple test runner.
*
* Last Modified : 19/Aug/2001
* Comment : Added add_failure routine call.
* Email : aksaharan@yahoo.com
* Created By : Jerry St.Clair (11-Aug-2004)
* Comment : Initial implementation of basic test runner interface
* EMail : jds2@users.sourceforge.net
*
*/
#include <stdio.h>
/** @file
* Basic interface with output to stdout.
*/
/** @addtogroup Basic
* @{
*/
#ifndef _CUNIT_BASIC_H
#define _CUNIT_BASIC_H
#include "CUnit.h"
#include "TestDB.h"
#include "TestRun.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Run modes for the basic interface. */
typedef enum {
CU_BRM_NORMAL = 0, /**< Normal mode - failures and run summary are printed [default]. */
CU_BRM_SILENT, /**< Silent mode - no output is printed except framework error messages. */
CU_BRM_VERBOSE, /**< Verbose mode - maximum output of run details. */
} CU_BasicRunMode;
CU_ErrorCode CU_basic_run_tests(void);
CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite);
CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest);
void CU_basic_set_mode(CU_BasicRunMode mode);
CU_BasicRunMode CU_basic_get_mode(void);
void CU_basic_show_failures(CU_pFailureRecord pFailure);
void assertImplementation(unsigned int uiValue, unsigned int uiLine,
char strCondition[], char strFile[], char strFunction[])
{
add_failure(uiLine, strCondition, strFile, g_pTestGroup, g_pTestCase);
#ifdef __cplusplus
}
#endif
#endif /* _CUNIT_BASIC_H */
/** @} */
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains CUnit error codes which can be used externally.
*
* Created By : Anil Kumar on ...(in month of Aug 2001)
* Last Modified : 09/Aug/2001
* Comment : -------
* EMail : aksaharan@yahoo.com
*
* Modified : 02/Oct/2001
* Comment : Added proper Eror Codes
* EMail : aksaharan@yahoo.com
*
* Modified : 13-Oct-2001
* Comment : Added Error Codes for Duplicate TestGroup and Test
* EMail : aksaharan@yahoo.com
*
* Modified : 3-Aug-2004 (JDS)
* Comment : Converted error code macros to an enum, doxygen comments
* moved error handing code here, changed file name from Errno.h,
* added error codes for file open errors, added error action selection
* EMail : jds2@users.sourceforge.net
*
* Modified : 5-Sep-2004 (JDS)
* Comment : Added internal test interface.
* EMail : jds2@users.sourceforge.net
*/
/** @file
* Error handling functions (user interface).
* CUnit uses a simple (and conventional) error handling strategy.
* Functions that can generate errors set (and usually return) an
* error code to indicate the run status. The error code can be
* inspected using the CU_get_error() function. A descriptive
* error message can be retrieved using CU_get_error_msg().
*/
/** @addtogroup Framework
* @{
*/
#ifndef _CUNIT_CUERROR_H
#define _CUNIT_CUERROR_H
#include <errno.h>
/*------------------------------------------------------------------------*/
/** CUnit error codes.
* If codes are added or removed, be sure to make a change to the
* error messages in CUError.c/get_error_desc().
* @see CU_set_error()
* @see CU_get_error()
* @see CU_get_error_msg()
*/
typedef enum {
/* basic errors */
CUE_SUCCESS = 0, /**< No error condition. */
CUE_NOMEMORY = 1, /**< Memory allocation failed. */
/* Test Registry Level Errors */
CUE_NOREGISTRY = 10, /**< Test registry not initialized. */
CUE_REGISTRY_EXISTS = 11, /**< Attempt to CU_set_registry() without CU_cleanup_registry(). */
/* Test Suite Level Errors */
CUE_NOSUITE = 20, /**< A required CU_pSuite pointer was NULL. */
CUE_NO_SUITENAME = 21, /**< Required CU_Suite name not provided. */
CUE_SINIT_FAILED = 22, /**< Suite initialization failed. */
CUE_SCLEAN_FAILED = 23, /**< Suite cleanup failed. */
CUE_DUP_SUITE = 24, /**< Duplicate suite name not allowed. */
/* Test Case Level Errors */
CUE_NOTEST = 30, /**< A required CU_pTest pointer was NULL. */
CUE_NO_TESTNAME = 31, /**< Required CU_Test name not provided. */
CUE_DUP_TEST = 32, /**< Duplicate test case name not allowed. */
CUE_TEST_NOT_IN_SUITE = 33, /**< Test not registered in specified suite. */
/* File handling errors */
CUE_FOPEN_FAILED = 40, /**< An error occurred opening a file. */
CUE_FCLOSE_FAILED = 41, /**< An error occurred closing a file. */
CUE_BAD_FILENAME = 42, /**< A bad filename was requested (NULL, empty, nonexistent, etc.). */
CUE_WRITE_ERROR = 43, /**< An error occurred during a write to a file. */
} CU_ErrorCode;
/*------------------------------------------------------------------------*/
/** CUnit error action codes.
* These are used to set the action desired when an error
* condition is detected in the CUnit framework.
* @see CU_set_error_action()
* @see CU_get_error_action()
*/
typedef enum CU_ErrorAction {
CUEA_IGNORE, /**< Runs should be continued when an error condition occurs (if possible). */
CUEA_FAIL, /**< Runs should be stopped when an error condition occurs. */
CUEA_ABORT, /**< The application should exit() when an error conditions occurs. */
} CU_ErrorAction;
/* Error handling & reporting functions. */
#ifdef __cplusplus
extern "C" {
#endif
CU_ErrorCode CU_get_error(void);
const char* CU_get_error_msg(void);
void CU_set_error_action(CU_ErrorAction action);
CU_ErrorAction CU_get_error_action(void);
#ifdef CUNIT_BUILD_TESTS
void test_cunit_CUError(void);
#endif
/* Internal function - users should not generally call this function */
void CU_set_error(CU_ErrorCode error);
#ifdef __cplusplus
}
#endif
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_get_error_msg(). */
#define get_error() CU_get_error_msg()
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#endif /* _CUNIT_CUERROR_H */
/** @} */
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
*
* Copyright (C) 2004 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
......@@ -24,10 +25,21 @@
* Last Modified : 09/Aug/2001
* Comment : Single interface to Console_run_tests
* EMail : aksaharan@yahoo.com
*
* Modified : 20-Jul-2004 (JDS)
* Comment : New interface, doxygen comments
* EMail : jds2@users.sourceforge.net
*/
/** @file
* Console interface with interactive output (user interface).
*/
/** @addtogroup Console
* @{
*/
#ifndef _CUNIT_CONSOLE_H
#define _CUNIT_CONSOLE_H 1
#define _CUNIT_CONSOLE_H
#include "CUnit.h"
#include "TestDB.h"
......@@ -36,9 +48,15 @@
extern "C" {
#endif
extern void console_run_tests(void);
void CU_console_run_tests(void);
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_console_run_tests(). */
#define console_run_tests() CU_console_run_tests()
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef __cplusplus
}
#endif
#endif /* _CUNIT_CONSOLE_H_ */
/** @} */
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains CUnit error codes which can be used externally.
*
* Created By : Anil Kumar on ...(in month of Aug 2001)
* Last Modified : 09/Aug/2001
* Comment : -------
* EMail : aksaharan@yahoo.com
*
* Modified : 02/Oct/2001
* Comment : Added proper Eror Codes
* EMail : aksaharan@yahoo.com
*
* Modified : 13/Oct/2001
* Comment : Added Eror Codes for Duplicate TestGroup and Test
* EMail : aksaharan@yahoo.com
*
*/
#ifndef _CUNIT_ERRNO_H
#define _CUNIT_ERRNO_H 1
#include <errno.h>
#define CUE_SUCCESS 0
#define CUE_NOMEMORY 1
/* Test Registry Level Errors */
#define CUE_NOREGISTRY 10
#define CUE_REGISTRY_EXISTS 11
/* Test Group Level Errors */
#define CUE_NOGROUP 20
#define CUE_NO_GROUPNAME 21
#define CUE_GRPINIT_FAILED 22
#define CUE_GRPCLEAN_FAILED 23
#define CUE_DUP_GROUP 24
/* Test Case Level Errors */
#define CUE_NOTEST 30
#define CUE_NO_TESTNAME 31
#define CUE_DUP_TEST 32
#endif /* _CUNIT_ERRNO_H */
......@@ -21,16 +21,17 @@ Automated.o Automated.o: Automated.c \
/usr/include/limits.h /usr/include/bits/posix1_lim.h \
/usr/include/bits/local_lim.h /usr/include/linux/limits.h \
/usr/include/bits/posix2_lim.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/CUnit.h /usr/include/math.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUnit.h /usr/include/math.h \
/usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \
/usr/include/bits/mathcalls.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Errno.h /usr/include/errno.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUError.h /usr/include/errno.h \
/usr/include/bits/errno.h /usr/include/linux/errno.h \
/usr/include/asm/errno.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestDB.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Util.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestRun.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Automated.h
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestDB.h /usr/include/setjmp.h \
/usr/include/bits/setjmp.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestRun.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Util.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Automated.h
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2.2/include/stdio.h:
......@@ -110,7 +111,7 @@ Automated.o Automated.o: Automated.c \
/usr/include/bits/posix2_lim.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/CUnit.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUnit.h:
/usr/include/math.h:
......@@ -120,7 +121,7 @@ Automated.o Automated.o: Automated.c \
/usr/include/bits/mathcalls.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Errno.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUError.h:
/usr/include/errno.h:
......@@ -130,10 +131,14 @@ Automated.o Automated.o: Automated.c \
/usr/include/asm/errno.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestDB.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestDB.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Util.h:
/usr/include/setjmp.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestRun.h:
/usr/include/bits/setjmp.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Automated.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestRun.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Util.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Automated.h:
This diff is collapsed.
AssertImpl.o AssertImpl.o: AssertImpl.c \
Basic.o Basic.o: Basic.c \
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2.2/include/stdio.h \
/usr/include/features.h /usr/include/sys/cdefs.h \
/usr/include/gnu/stubs.h \
......@@ -9,14 +9,24 @@ AssertImpl.o AssertImpl.o: AssertImpl.c \
/usr/include/gconv.h \
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2.2/include/stdarg.h \
/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestDB.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/CUnit.h /usr/include/string.h \
/usr/include/math.h /usr/include/bits/huge_val.h \
/usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Errno.h /usr/include/errno.h \
/usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \
/usr/include/endian.h /usr/include/bits/endian.h \
/usr/include/sys/select.h /usr/include/bits/select.h \
/usr/include/bits/sigset.h /usr/include/bits/time.h \
/usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
/usr/include/bits/sched.h /usr/include/alloca.h /usr/include/ctype.h \
/usr/include/assert.h /usr/include/string.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUnit.h /usr/include/math.h \
/usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \
/usr/include/bits/mathcalls.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUError.h /usr/include/errno.h \
/usr/include/bits/errno.h /usr/include/linux/errno.h \
/usr/include/asm/errno.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestRun.h
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestDB.h /usr/include/setjmp.h \
/usr/include/bits/setjmp.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestRun.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Util.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Basic.h
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2.2/include/stdio.h:
......@@ -50,12 +60,40 @@ AssertImpl.o AssertImpl.o: AssertImpl.c \
/usr/include/bits/sys_errlist.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestDB.h:
/usr/include/stdlib.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/CUnit.h:
/usr/include/sys/types.h:
/usr/include/time.h:
/usr/include/endian.h:
/usr/include/bits/endian.h:
/usr/include/sys/select.h:
/usr/include/bits/select.h:
/usr/include/bits/sigset.h:
/usr/include/bits/time.h:
/usr/include/sys/sysmacros.h:
/usr/include/bits/pthreadtypes.h:
/usr/include/bits/sched.h:
/usr/include/alloca.h:
/usr/include/ctype.h:
/usr/include/assert.h:
/usr/include/string.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUnit.h:
/usr/include/math.h:
/usr/include/bits/huge_val.h:
......@@ -64,7 +102,7 @@ AssertImpl.o AssertImpl.o: AssertImpl.c \
/usr/include/bits/mathcalls.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Errno.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUError.h:
/usr/include/errno.h:
......@@ -74,4 +112,14 @@ AssertImpl.o AssertImpl.o: AssertImpl.c \
/usr/include/asm/errno.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestRun.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestDB.h:
/usr/include/setjmp.h:
/usr/include/bits/setjmp.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestRun.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Util.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Basic.h:
This diff is collapsed.
......@@ -16,16 +16,17 @@ Console.o Console.o: Console.c \
/usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
/usr/include/bits/sched.h /usr/include/alloca.h /usr/include/ctype.h \
/usr/include/assert.h /usr/include/string.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/CUnit.h /usr/include/math.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUnit.h /usr/include/math.h \
/usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \
/usr/include/bits/mathcalls.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Errno.h /usr/include/errno.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUError.h /usr/include/errno.h \
/usr/include/bits/errno.h /usr/include/linux/errno.h \
/usr/include/asm/errno.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestDB.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Util.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestRun.h \
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Console.h
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestDB.h /usr/include/setjmp.h \
/usr/include/bits/setjmp.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestRun.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Util.h \
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Console.h
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.2.2/include/stdio.h:
......@@ -91,7 +92,7 @@ Console.o Console.o: Console.c \
/usr/include/string.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/CUnit.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUnit.h:
/usr/include/math.h:
......@@ -101,7 +102,7 @@ Console.o Console.o: Console.c \
/usr/include/bits/mathcalls.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Errno.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/CUError.h:
/usr/include/errno.h:
......@@ -111,10 +112,14 @@ Console.o Console.o: Console.c \
/usr/include/asm/errno.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestDB.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestDB.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Util.h:
/usr/include/setjmp.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/TestRun.h:
/usr/include/bits/setjmp.h:
/home/jds/dev/CUnit-1.1-2/CUnit/Headers/Console.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/TestRun.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Util.h:
/home/jds/dev/CUnit-2.0-1/CUnit/Headers/Console.h:
This diff is collapsed.
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Error handling code used by CUnit
*
* Created By : Jerry St.Clair
* Created on : 16-Jul-2004
* Comment : Created access functions for error code,
* error action functions, messages for new error codes.
* Email : jds2@users.sourceforge.net
*
*/
/** @file
* Error handling functions (implementation).
*/
/** @addtogroup Framework
@{
*/
#include <stdio.h>
#include <stdlib.h>
#include "CUError.h"
/*
* Global/Static Definitions
*/
/** Local variable holding the current error code. */
static CU_ErrorCode g_error_number = CUE_SUCCESS;
/** Local variable holding the current error action code. */
static CU_ErrorCode g_error_action = CUEA_IGNORE;
/* Private function forward declarations */
static const char* get_error_desc(CU_ErrorCode error);
#ifdef CUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS
void test_exit(int status);
#endif
/*------------------------------------------------------------------------*/
/** Set the error code.
* This function is used internally by CUnit implementation functions
* when an error condition occurs within the framework. It should
* not generally be called by user code. NOTE that if the current
* error action is CUEA_ABORT, then calling this function will
* result in exit() being called for the current application.
* @param error CU_ErrorCode indicating the current error condition.
* @see CU_get_error()
* @see CU_get_error_msg()
* @see CU_ErrorCode
*/
void CU_set_error(CU_ErrorCode error)
{
if ((error != CUE_SUCCESS) && (g_error_action == CUEA_ABORT)) {
#ifndef CUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS
fprintf(stderr, "\nAborting due to error #%d: %s\n",
error,
get_error_desc(error));
exit(error);
#else
test_exit(error);
#endif
}
g_error_number = error;
}
/*------------------------------------------------------------------------*/
/** Get the error code.
* CUnit implementation functions set the error code to indicate the
* status of the most recent operation. In general, the CUnit functions
* will clear the code to CUE_SUCCESS, then reset it to a specific error
* code if an exception condition is encountered. Some functions
* return the code, others leave it to the user to inspect if desired.
* @return The current error condition code.
* @see CU_get_error_msg()
* @see CU_ErrorCode
*/
CU_ErrorCode CU_get_error(void)
{
return g_error_number;
}
/*------------------------------------------------------------------------*/
/** Get the message corresponding to the error code.
* CUnit implementation functions set the error code to indicate the
* of the most recent operation. In general, the CUnit functions will
* clear the code to CUE_SUCCESS, then reset it to a specific error
* code if an exception condition is encountered. This function allows
* the user to retrieve a descriptive error message corresponding to the
* error code set by the last operation.
* @return A message corresponding to the current error condition.
* @see CU_get_error()
* @see CU_ErrorCode
*/
const char* CU_get_error_msg(void)
{
return get_error_desc(g_error_number);
}
/*------------------------------------------------------------------------*/
/** Set the action to take when an error condition occurs.
* This function should be used to specify the action to take
* when an error condition is encountered. The default action is
* CUEA_IGNORE, which results in errors being ignored and test runs
* being continued (if possible). A value of CUEA_FAIL causes test