Commit 9b8c86b6 authored by jds2's avatar jds2

Add K. Cheung/Aurema contributed code to v1.1 source.


git-svn-id: http://svn.code.sf.net/p/cunit/code/trunk@48 f00e6729-6848-4c17-8bfb-678c97c00071
parent 5d88b392
......@@ -58,13 +58,15 @@ make install
%{_prefix}/man/man3/set_registry.3
%{_prefix}/man/man8/CUnit.8
########## Share information and Example Files
########## Share information and Example Files
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Automated/README
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Automated/AutomatedTest
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Console/README
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Console/ConsoleTest
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Curses/README
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Curses/CursesTest
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Register/README
%{_prefix}/share/@PACKAGE@-@VERSION@-@RELEASE@/Example/Register/RegisterTest
%{_prefix}/share/@PACKAGE@/CUnit-List.dtd
%{_prefix}/share/@PACKAGE@/CUnit-List.xsl
%{_prefix}/share/@PACKAGE@/CUnit-Run.dtd
......
......@@ -16,7 +16,7 @@ CFG=CUnit - Win32 Debug
!MESSAGE NMAKE /f "CUnit.mak" CFG="CUnit - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE
!MESSAGE "CUnit - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "CUnit - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
......
......@@ -28,6 +28,7 @@ CU_HEADERS =
Curses.h
Errno.h
MyMem.h
Register.h
TestDB.h
TestRun.h
Util.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
......@@ -30,6 +31,11 @@
* Comment : Made the linked list from SLL to DLL(doubly linked list).
* EMail : aksaharan@yahoo.com
*
* Last Modified : 29-Aug-2004 by Jerry St.Clair
* Comment : Added suite registration shortcut types & functions
* contributed by K. Cheung.
* EMail : jds2@users.sourceforge.net
*
*/
#ifndef _CUNIT_TESTDB_H
......@@ -126,6 +132,167 @@ extern void add_failure(unsigned int uiLineNumber, char szCondition[],
extern const char* get_error(void);
/*=========================================================================
* This section
* Copyright (C) 2004 Aurema Pty Ltd.
*
* 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
*/
/* Contributed by K. Cheung and Aurema Pty Ltd. (thanks!)
*
* The changes made herein (JDS) to the contributed code were:
* - added this comment block & example usage comment block
* - incorporated code into TestDB.h
* - eliminated unneeded #include's
* - compacted doxygen comments
*
* NOTE - this code is likely to change significantly in
* the upcoming version 2 CUnit release to better
* integrate it with the new CUnit API.
*/
/* Example Usage
#include <CUnit/CUnit.h>
#include <CUnit/TestDB.h>
#include <CUnit/Curses.h>
#include <stdio.h>
static void group_A_case_1(void)
{
ASSERT_TRUE(1);
}
static void group_A_case_2(void)
{
ASSERT_TRUE(2);
}
static void group_B_case_1(void)
{
ASSERT_FALSE(1);
}
static void group_B_case_2(void)
{
ASSERT_FALSE(2);
}
static test_case_t group_A_test_cases[] = {
{ "1", group_A_case_1 },
{ "2", group_A_case_2 },
TEST_CASE_NULL,
};
static test_case_t group_B_test_cases[] = {
{ "1", group_B_case_1 },
{ "2", group_B_case_2 },
TEST_CASE_NULL,
};
static test_group_t groups[] = {
{ "A", NULL, NULL, group_A_test_cases },
{ "B", NULL, NULL, group_B_test_cases },
TEST_GROUP_NULL,
};
static test_suite_t suite = { "suite", groups };
int main(void)
{
setbuf(stdout, NULL);
if (initialize_registry() != CUE_SUCCESS) {
fprintf(stderr, "initialize_registry failed - %s\n",
get_error());
exit(EXIT_FAILURE);
}
if (test_suite_register(&suite) != CUE_SUCCESS) {
fprintf(stderr, "test_suite_register failed - %s\n",
get_error());
exit(EXIT_FAILURE);
}
curses_run_tests();
cleanup_registry();
return 0;
}
*/
/** Unit test case. */
typedef struct test_case {
char *name; /**< Case name. */
void (*test)(void); /**< Case function. */
} test_case_t;
/** Group of unit tests. */
typedef struct test_group {
char *name; /**< Group name. */
int (*init)(void); /**< Group initialisation function. */
int (*cleanup)(void); /**< Group cleanup function */
test_case_t *cases; /**< Test cases. This must be a NULL terminated array. */
} test_group_t;
/** Unit test suite. */
typedef struct test_suite {
char *name; /**< Suite name. Currently not used. */
test_group_t *groups; /**< Test groups. This must be a NULL terminated array. */
} test_suite_t;
/** Macros for ease of defining cases and groups. */
#define TEST_CASE_NULL { NULL, NULL }
#define TEST_GROUP_NULL { NULL, NULL, NULL, NULL }
/** Registers unit test group.
* @param tg Pointer to a test group.
* @precondition tg is initialised.
* @return
* CUE_SUCCESS On success.
* CUE_NOREGISTRY Test Registry is not initialized
* CUE_NO_GROUPNAME Test group name is not specified or is NULL
* CUE_DUP_GROUP Test group with this name already exists in the registry
* CUE_NOGROUP Specified group name doesn't exists in the registry
* CUE_NO_TESTNAME Test name is not specified or is NULL
* CUE_NOTEST Test function not specified
* CUE_DUP_TEST Test case with this name already exists in the specified test group
*/
int test_group_register(test_group_t *tg);
/* Registers unit test suite.
* @param ts Pointer to a test suite.
* @precondition ts is initialised.
* @return
* CUE_SUCCESS On success.
* CUE_NOREGISTRY Test Registry is not initialized
* CUE_NO_GROUPNAME Test group name is not specified or is NULL
* CUE_DUP_GROUP Test group with this name already exists in the registry
* CUE_NOGROUP Specified group name doesn't exists in the registry
* CUE_NO_TESTNAME Test name is not specified or is NULL
* CUE_NOTEST Test function not specified
* CUE_DUP_TEST Test case with this name already exists inthe specified test group
*/
int test_suite_register(test_suite_t *ts);
/*=========================================================================
* End Aurema section
*=========================================================================*/
#ifdef __cplusplus
}
#endif
......
/*
* 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
......@@ -18,25 +19,29 @@
*/
/*
* Contains the Registry/TestGroup/Testcase management Routine
* implementation.
* Contains the Registry/TestGroup/Testcase management Routine implementation.
*
* Created By : Anil Kumar on ...(in month of Aug 2001)
* Last Modified : 09/Aug/2001
* Comment : Added startup initialize/cleanup registry functions.
* Email : aksaharan@yahoo.com
*
*
* Last Modified : 29/Aug/2001 (Anil Kumar)
* Comment : Added Test and Group Add functions
* Email : aksaharan@yahoo.com
*
*
* Modified : 02/Oct/2001 (Anil Kumar)
* Comment : Added Proper Error codes and Messages on the failure conditions.
* Email : aksaharan@yahoo.com
*
*
* Modified : 13/Oct/2001 (Anil Kumar)
* Comment : Added Code to Check for the Duplicate Group name and test name.
* Email : aksaharan@yahoo.com
*
* Modified : 29-Aug-2004 (Jerry St.Clair)
* Comment : Added suite registration shortcut types & functions
* contributed by K. Cheung.
* EMail : jds2@users.sourceforge.net
*/
#include <stdio.h>
......@@ -93,7 +98,7 @@ int initialize_registry(void)
g_pTestRegistry->uiNumberOfGroups = 0;
g_pTestRegistry->uiNumberOfTests = 0;
g_pTestRegistry->uiNumberOfFailures = 0;
exit:
return error_number;
}
......@@ -377,3 +382,67 @@ static int test_exists(PTestGroup pTestGroup, char* szTestName)
return FALSE;
}
/*=========================================================================
* This section
* Copyright (C) 2004 Aurema Pty Ltd.
*
* 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
*/
/* Contributed by K. Cheung and Aurema Pty Ltd. (thanks!)
*
* The changes made herein (JDS) to the contributed code were:
* - added this comment block
* - incorporated code into TestDB.c
* - eliminated unneeded #include's
*
* NOTE - this code is likely to change significantly in
* the upcoming version 2 CUnit release to better
* integrate it with the new CUnit API.
*/
/* Registers a unit test group. */
int test_group_register(test_group_t *tg)
{
test_case_t *tc;
PTestGroup group;
if (!(group = add_test_group(tg->name, tg->init, tg->cleanup)))
return error_number;
for (tc = tg->cases; tc->name; tc++)
if (!add_test_case(group, tc->name, tc->test))
return error_number;
return CUE_SUCCESS;
}
/* Registers unit test suite. */
int test_suite_register(test_suite_t *ts)
{
test_group_t *tg;
int error;
for (tg = ts->groups; tg->name; tg++)
if ((error = test_group_register(tg)) != CUE_SUCCESS)
return error;
return CUE_SUCCESS;
}
/*=========================================================================
* End Aurema section
*=========================================================================*/
AUTOMATED_OBJECTS = Automated/Automated.o
CONSOLE_OBJECTS = Console/Console.o
CURSES_OBJECTS = Curses/Curses.o
FRAMEWORK_OBJECTS = Framework/AssertImpl.o Framework/MyMem.o Framework/TestDB.o Framework/TestRun.o Framework/Util.o
FRAMEWORK_OBJECTS = Framework/AssertImpl.o Framework/MyMem.o Framework/TestDB.o Framework/TestRun.o Framework/Util.o
# Default configuration without enabling anything
OBJECT_FILES = $(FRAMEWORK_OBJECTS) $(CONSOLE_OBJECTS) $(CURSES_OBJECTS) $(AUTOMATED_OBJECTS)
......
* Sun 29-Aug-2004 Jerry St.Clair <jds2@users.sourceforge.net>
- Updated Linux build system files.
- Updated Jamrules & Jamrules.in for Linux build.
- Added K. Cheung contributed code shortcut for registering tests.
* Tue 24-Aug-2004 Jerry St.Clair <jds2@users.sourceforge.net>
- Bug fixes to CUnit.h
* Fri 20-Aug-2004 Jerry St.Clair <jds2@users.sourceforge.net>
- Add Jamrules.in, modify configure.in to process it.
- Add JDS to AUTHORS.
......
......@@ -37,6 +37,7 @@ NOTFILE examples ;
SubInclude TOP Examples AutomatedTest ;
SubInclude TOP Examples ConsoleTest ;
SubInclude TOP Examples RegistrationTest ;
if $(UNIX)
{
......
EXAMPLE_DIRS = ConsoleTest AutomatedTest CursesTest
EXAMPLE_DIRS = ConsoleTest AutomatedTest CursesTest RegistrationTest
SUBDIRS = ${EXAMPLE_DIRS}
#
# Jamfile to build CUnit - Examples/RegistrationTest
# (see http://www.freetype.org/jam/index.html)
#
# 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
# 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
#---------------------------------------------------------------------------
SubDir TOP Examples RegistrationTest ;
SubDirHdrs $(CUNIT_HDR_DIR) ;
# set location for target, source, and temporary files
LOCATE_TARGET = $(TMP_DIR)$(SLASH)Examples$(SLASH)RegistrationTest ;
Main RegisterTest : RegisterTest.c ;
LinkLibraries RegisterTest : $(CUNIT_LIB_NAME) ;
if $(NT) && ($(BCCROOT) || ($(TOOLSET) = BORLANDC))
{
# need to fix Borland to include library location
LINKFLAGS on RegisterTest$(SUFEXE) += -L$(STDLIBPATH) -tWC ;
}
MakeLocate RegisterTest$(SUFEXE) : $(BUILD_DIR) ;
This diff is collapsed.
exampledir=${datadir}/@PACKAGE@-@VERSION@-@RELEASE@/Example/Register
example_PROGRAMS = RegisterTest
ConsoleTest_SOURCE = RegisterTest.c
ConsoleTest_HEADER = RegisterTest.h
ConsoleTest_LDADD = -lcunit
example_DATA = README
This diff is collapsed.
Usage of Example :
./RegisterTest
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004 Aurema Pty Ltd.
*
* 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
*/
/* Contributed by K. Cheung and Aurema Pty Ltd. (thanks!)
*
* The changes made herein (JDS) to the contributed code were:
* - added this comment block
* - changed name of file from example.c to TestRegister.c
* - eliminated unneeded #include's
*
* NOTE - this code is likely to change significantly in
* the upcoming version 2 CUnit release to better
* integrate it with the new CUnit API.
*/
#include "CUnit.h"
#include "TestDB.h"
#include "Console.h"
#include <stdio.h>
#include <stdlib.h>
static void group_A_case_1(void)
{
ASSERT_TRUE(1);
}
static void group_A_case_2(void)
{
ASSERT_TRUE(2);
}
static void group_B_case_1(void)
{
ASSERT_FALSE(1);
}
static void group_B_case_2(void)
{
ASSERT_FALSE(2);
}
static test_case_t group_A_test_cases[] = {
{ "1", group_A_case_1 },
{ "2", group_A_case_2 },
TEST_CASE_NULL,
};
static test_case_t group_B_test_cases[] = {
{ "1", group_B_case_1 },
{ "2", group_B_case_2 },
TEST_CASE_NULL,
};
static test_group_t groups[] = {
{ "A", NULL, NULL, group_A_test_cases },
{ "B", NULL, NULL, group_B_test_cases },
TEST_GROUP_NULL,
};
static test_suite_t suite = { "suite", groups };
int main(void)
{
/* No line buffering. */
setbuf(stdout, NULL);
/* Intialise test registry. */
if (initialize_registry() != CUE_SUCCESS) {
fprintf(stderr, "initialize_registry failed - %s\n",
get_error());
exit(EXIT_FAILURE);
}
/* Register test groups. */
if (test_suite_register(&suite) != CUE_SUCCESS) {
fprintf(stderr, "test_suite_register failed - %s\n",
get_error());
exit(EXIT_FAILURE);
}
/* Execute unit tests. */
console_run_tests();
/* Cleanup test registry. */
cleanup_registry();
return 0;
}
# Microsoft Developer Studio Project File - Name="RegisterTest" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=RegisterTest - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "RegisterTest.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "RegisterTest.mak" CFG="RegisterTest - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "RegisterTest - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "RegisterTest - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "RegisterTest - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Temp"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "../../CUnit/Headers" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_DELAYTEST" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../../CUnit/CUnit.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "RegisterTest - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Temp"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../CUnit/Headers" /D "_CONSOLE" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_DELAYTEST" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../../CUnit/CUnit.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "RegisterTest - Win32 Release"
# Name "RegisterTest - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\RegisterTest.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
......@@ -116,10 +116,11 @@ AC_CONFIG_FILES( Makefile \
Examples/AutomatedTest/Makefile \
Examples/ConsoleTest/Makefile \
Examples/CursesTest/Makefile \
Man/Makefile \
Examples/RegistrationTest/Makefile \
Man/Makefile \
Man/man3/Makefile \
Man/man8/Makefile \
Share/Makefile )
AC_OUTPUT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment