Commit f8ef72e8 authored by jds2's avatar jds2

- modified dtd and xsl files to support inactive suites/tests.

- instrumented entire framework/interfaces for gettext
    (not activated yet, just instrumented source).


git-svn-id: http://svn.code.sf.net/p/cunit/code/trunk@101 f00e6729-6848-4c17-8bfb-678c97c00071
parent 58a586f1
......@@ -19,7 +19,7 @@
*/
/*
* Contains Interface for console Run tests.
* Contains Interface for curses Run tests.
*
* Aug 2001 Initial implementation. (AK)
*
......
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
* Copyright (C) 2004-2006 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
......@@ -19,7 +19,7 @@
*/
/*
* Contains ASSERT Macro definitions.
* ASSERT Macro definitions and general CUnit configuration definitions.
*
* 09/Aug/2001 ASSERT definitions. (AK)
*
......@@ -83,7 +83,15 @@
#define CU_UNREFERENCED_PARAMETER(x) (void)x
#endif
#ifdef WIN32
#ifndef CU_MAX
# define CU_MAX(a,b) (((a) >= (b)) ? (a) : (b))
#endif
#ifndef CU_MIN
# define CU_MIN(a,b) (((a) >= (b)) ? (b) : (a))
#endif
#if defined(WIN32) || defined(_WIN32) || defined(_WIN32_)
# ifdef CU_DLL
# ifdef CU_BUILD_DLL
# define CU_EXPORT __declspec(dllexport)
......@@ -93,9 +101,13 @@
# else
# define CU_EXPORT
# endif
# ifdef _MSC_VER
# define snprintf _snprintf
# define itoa _itoa
# endif
#else
# define CU_EXPORT
#endif
#endif /* WIN32 */
#include "CUError.h"
#include "TestDB.h" /* not needed here - included for user convenience */
......
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2006 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
*/
/*
* Internationalization support
*
* 05-May-2006 Initial implementation. (JDS)
*/
/** @file
* Internal CUnit header supporting internationalization of
* CUnit framework & interfaces.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_CUNIT_INTL_H_SEEN
#define CUNIT_CUNIT_INTL_H_SEEN
/* activate these when source preparation is complete
#include <libintl.h>
#ifndef _
# define _(String) gettext (String)
#endif
#ifndef gettext_noop
# define gettext_noop(String) String
#endif
#ifndef N_
# define N_(String) gettext_noop (String)
#endif
*/
/* deactivate these when source preparation is complete */
#undef _
#define _(String) (String)
#undef N_
#define N_(String) String
#undef textdomain
#define textdomain(Domain)
#undef bindtextdomain
#define bindtextdomain(Package, Directory)
#endif /* CUNIT_CUNIT_INTL_H_SEEN */
/** @} */
......@@ -281,7 +281,7 @@ CU_pSuite CU_add_suite(const char *strName,
* initialized before calling this function (checked by assertion).
* pInit and pClean may be NULL, in which case no corresponding
* initialization of cleanup function will be called when the suite
* is run.<br /><br />
* is run. strName may be empty ("") but may not be NULL.<br /><br />
*
* The return value is a pointer to the newly-created suite, or
* NULL if there was a problem with the suite creation or addition.
......
......@@ -38,6 +38,9 @@
* 23-Apr-2006 Moved doxygen comments into header.
* Added type marker to CU_FailureRecord.
* Added support for tracking inactive suites/tests. (JDS)
*
* 08-May-2006 Moved CU_print_run_results() functionality from
* console/basic test complete handler. (JDS)
*/
/** @file
......@@ -315,6 +318,20 @@ CU_EXPORT CU_pRunSummary CU_get_run_summary(void);
* initiates a run using CU_run_all_tests(), CU_run_suite(), or CU_run_test().
*/
CU_EXPORT void CU_print_run_results(FILE *file);
/**<
* Prints a summary of the current run to file.
* The run summary presents data for the suites, tests, and assertions
* encountered during the run. The data presented include the number
* of registered, run, passed, failed, and inactive entities for each.
* This function can be called at any time, although the test registry
* must have been initialized and file may not be NULL (both checked by
* assertion).
*
* @param file Pointer to stream to receive the printed summary.
*/
/*--------------------------------------------------------------------
* Functions for internal & testing use.
*--------------------------------------------------------------------*/
......
......@@ -31,7 +31,7 @@
*
* 5-Sep-2004 Added internal test interface. (JDS)
*
* 17-Apr-2006 Added CU_translated_strlen().
* 17-Apr-2006 Added CU_translated_strlen() and CU_number_width().
* Removed CUNIT_MAX_STRING_LENGTH - dangerous since not enforced.
* Fixed off-by-1 error in CU_translate_special_characters(),
* modifying implementation & results in some cases. User can
......@@ -74,7 +74,7 @@ CU_EXPORT size_t CU_translate_special_characters(const char *szSrc, char *szDest
* in an unspecified manner. It is the caller's responsibility to make
* sure there is sufficient room in szDest to hold the converted string.
* CU_translated_strlen() may be used to calculate the length of buffer
* required (remembering to add 1 for the terminating \0).
* required (remember to add 1 for the terminating \0).
*
* @param szSrc Source string to convert (non-NULL).
* @param szDest Location to hold the converted string (non-NULL).
......@@ -107,22 +107,28 @@ CU_EXPORT int CU_compare_strings(const char *szSrc, const char *szDest);
CU_EXPORT void CU_trim_left(char *szString);
/**<
* Trim leading whitespace from the specified string.
* Trims leading whitespace from the specified string.
* @param szString The string to trim.
*/
CU_EXPORT void CU_trim_right(char *szString);
/**<
* Trim trailing whitespace from the specified string.
* Trims trailing whitespace from the specified string.
* @param szString The string to trim.
*/
CU_EXPORT void CU_trim(char *szString);
/**<
* Trim leading and trailing whitespace from the specified string.
* Trims leading and trailing whitespace from the specified string.
* @param szString The string to trim.
*/
CU_EXPORT size_t CU_number_width(int number);
/**<
* Calulates the number of places required to display
* number in decimal.
*/
#ifdef CUNIT_BUILD_TESTS
void test_cunit_Util(void);
#endif
......
......@@ -35,6 +35,8 @@
* none has been supplied. (JDS)
*
* 30-Apr-2005 Added notification of failed suite cleanup function. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
......@@ -58,6 +60,7 @@
#include "Util.h"
#include "TestRun.h"
#include "Automated.h"
#include "CUnit_intl.h"
/*=================================================================
* Global / Static data definitions
......@@ -103,7 +106,7 @@ void CU_automated_run_tests(void)
}
if (CUE_SUCCESS != initialize_result_file(f_szTestResultFileName)) {
fprintf(stderr, "\nERROR - Failed to create/initialize the result file.");
fprintf(stderr, "\n%s", _("ERROR - Failed to create/initialize the result file."));
}
else {
/* set up the message handlers for writing xml output */
......@@ -118,7 +121,7 @@ void CU_automated_run_tests(void)
automated_run_all_tests(NULL);
if (CUE_SUCCESS != uninitialize_result_file()) {
fprintf(stderr, "\nERROR - Failed to close/uninitialize the result files.");
fprintf(stderr, "\n%s", _("ERROR - Failed to close/uninitialize the result files."));
}
}
}
......@@ -233,6 +236,7 @@ static void automated_test_start_message_handler(const CU_pTest pTest, const CU_
assert(NULL != pTest);
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
assert(NULL != f_pTestResultFile);
/* write suite close/open tags if this is the 1st test for this szSuite */
......@@ -247,7 +251,7 @@ static void automated_test_start_message_handler(const CU_pTest pTest, const CU_
" <CUNIT_RUN_SUITE> \n"
" <CUNIT_RUN_SUITE_SUCCESS> \n"
" <SUITE_NAME> %s </SUITE_NAME> \n",
(NULL != pSuite->pName) ? pSuite->pName : "");
pSuite->pName);
f_bWriting_CUNIT_RUN_SUITE = CU_TRUE;
f_pRunningSuite = pSuite;
......@@ -272,7 +276,9 @@ static void automated_test_complete_message_handler(const CU_pTest pTest,
CU_UNREFERENCED_PARAMETER(pSuite); /* pSuite is not used except in assertion */
assert(NULL != pTest);
assert(NULL != pTest->pName);
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
assert(NULL != f_pTestResultFile);
if (NULL != pTempFailure) {
......@@ -314,7 +320,7 @@ static void automated_test_complete_message_handler(const CU_pTest pTest,
" <CONDITION> %s </CONDITION> \n"
" </CUNIT_RUN_TEST_FAILURE> \n"
" </CUNIT_RUN_TEST_RECORD> \n",
(NULL != pTest->pName) ? pTest->pName : "",
pTest->pName,
(NULL != pTempFailure->strFileName) ? pTempFailure->strFileName : "",
pTempFailure->uiLineNumber,
szTemp);
......@@ -328,7 +334,7 @@ static void automated_test_complete_message_handler(const CU_pTest pTest,
" <TEST_NAME> %s </TEST_NAME> \n"
" </CUNIT_RUN_TEST_SUCCESS> \n"
" </CUNIT_RUN_TEST_RECORD> \n",
(NULL != pTest->pName) ? pTest->pName : "");
pTest->pName);
}
if (NULL != szTemp) {
......@@ -363,13 +369,14 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUMMARY_RECORD> \n"
" <TYPE> Suites </TYPE> \n"
" <TYPE> %s </TYPE> \n"
" <TOTAL> %u </TOTAL> \n"
" <RUN> %u </RUN> \n"
" <SUCCEEDED> - NA - </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> %u </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n",
_("Suites"),
pRegistry->uiNumberOfSuites,
pRunSummary->nSuitesRun,
pRunSummary->nSuitesFailed,
......@@ -378,13 +385,14 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUMMARY_RECORD> \n"
" <TYPE> Test Cases </TYPE> \n"
" <TYPE> %s </TYPE> \n"
" <TOTAL> %u </TOTAL> \n"
" <RUN> %u </RUN> \n"
" <SUCCEEDED> %u </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> %u </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n",
_("Test Cases"),
pRegistry->uiNumberOfTests,
pRunSummary->nTestsRun,
pRunSummary->nTestsRun - pRunSummary->nTestsFailed,
......@@ -394,18 +402,20 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
fprintf(f_pTestResultFile,
" <CUNIT_RUN_SUMMARY_RECORD> \n"
" <TYPE> Assertions </TYPE> \n"
" <TYPE> %s </TYPE> \n"
" <TOTAL> %u </TOTAL> \n"
" <RUN> %u </RUN> \n"
" <SUCCEEDED> %u </SUCCEEDED> \n"
" <FAILED> %u </FAILED> \n"
" <INACTIVE> -NA- </INACTIVE> \n"
" <INACTIVE> %s </INACTIVE> \n"
" </CUNIT_RUN_SUMMARY_RECORD> \n"
" </CUNIT_RUN_SUMMARY> \n",
_("Assertions"),
pRunSummary->nAsserts,
pRunSummary->nAsserts,
pRunSummary->nAsserts - pRunSummary->nAssertsFailed,
pRunSummary->nAssertsFailed
pRunSummary->nAssertsFailed,
_("n/a")
);
}
......@@ -416,6 +426,7 @@ static void automated_all_tests_complete_message_handler(const CU_pFailureRecord
static void automated_suite_init_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
assert(NULL != f_pTestResultFile);
if (CU_TRUE == f_bWriting_CUNIT_RUN_SUITE) {
......@@ -432,8 +443,8 @@ static void automated_suite_init_failure_message_handler(const CU_pSuite pSuite)
" <FAILURE_REASON> %s </FAILURE_REASON> \n"
" </CUNIT_RUN_SUITE_FAILURE> \n"
" </CUNIT_RUN_SUITE> \n",
(NULL != pSuite->pName) ? pSuite->pName : "",
"Suite Initialization Failed");
pSuite->pName,
_("Suite Initialization Failed"));
}
/*------------------------------------------------------------------------*/
......@@ -443,6 +454,7 @@ static void automated_suite_init_failure_message_handler(const CU_pSuite pSuite)
static void automated_suite_cleanup_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
assert(NULL != f_pTestResultFile);
if (CU_TRUE == f_bWriting_CUNIT_RUN_SUITE) {
......@@ -459,8 +471,8 @@ static void automated_suite_cleanup_failure_message_handler(const CU_pSuite pSui
" <FAILURE_REASON> %s </FAILURE_REASON> \n"
" </CUNIT_RUN_SUITE_FAILURE> \n"
" </CUNIT_RUN_SUITE> \n",
(NULL != pSuite->pName) ? pSuite->pName : "",
"Suite Cleanup Failed");
pSuite->pName,
_("Suite Cleanup Failed"));
}
/*------------------------------------------------------------------------*/
......@@ -479,8 +491,9 @@ static CU_ErrorCode uninitialize_result_file(void)
time(&tTime);
szTime = ctime(&tTime);
fprintf(f_pTestResultFile,
" <CUNIT_FOOTER> File Generated By CUnit v" CU_VERSION " at %s </CUNIT_FOOTER> \n"
" <CUNIT_FOOTER> %s" CU_VERSION " - %s </CUNIT_FOOTER> \n"
"</CUNIT_TEST_RUN_REPORT>",
_("File Generated By CUnit v"),
(NULL != szTime) ? szTime : "");
if (0 != fclose(f_pTestResultFile)) {
......@@ -531,17 +544,19 @@ static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const c
fprintf(pTestListFile,
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> Total Number of Suites </CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> %s </CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> %u </CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> \n"
" </CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n",
_("Total Number of Suites"),
pRegistry->uiNumberOfSuites);
fprintf(pTestListFile,
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> Total Number of Test Cases </CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> %s </CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT> \n"
" <CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> %u </CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE> \n"
" </CUNIT_LIST_TOTAL_SUMMARY_RECORD> \n"
" </CUNIT_LIST_TOTAL_SUMMARY> \n",
_("Total Number of Test Cases"),
pRegistry->uiNumberOfTests);
fprintf(pTestListFile,
......@@ -549,6 +564,7 @@ static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const c
pSuite = pRegistry->pSuite;
while (NULL != pSuite) {
assert(NULL != pSuite->pName);
pTest = pSuite->pTest;
fprintf(pTestListFile,
......@@ -560,22 +576,23 @@ static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const c
" <ACTIVE_VALUE> %s </ACTIVE_VALUE> \n"
" <TEST_COUNT_VALUE> %u </TEST_COUNT_VALUE> \n"
" </CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION> \n",
(NULL != pSuite->pName) ? pSuite->pName : "",
(NULL != pSuite->pInitializeFunc) ? "Yes" : "No",
(NULL != pSuite->pCleanupFunc) ? "Yes" : "No",
(CU_FALSE != pSuite->fActive) ? "Yes" : "No",
pSuite->pName,
(NULL != pSuite->pInitializeFunc) ? _("Yes") : _("No"),
(NULL != pSuite->pCleanupFunc) ? _("Yes") : _("No"),
(CU_FALSE != pSuite->fActive) ? _("Yes") : _("No"),
pSuite->uiNumberOfTests);
fprintf(pTestListFile,
" <CUNIT_ALL_TEST_LISTING_SUITE_TESTS> \n");
while (NULL != pTest) {
assert(NULL != pTest->pName);
fprintf(pTestListFile,
" <TEST_CASE_DEFINITION> \n"
" <TEST_CASE_NAME> %s </TEST_CASE_NAME> \n"
" <TEST_ACTIVE_VALUE> %s </TEST_ACTIVE_VALUE> \n"
" </TEST_CASE_DEFINITION> \n",
(NULL != pTest->pName) ? pTest->pName : "",
(CU_FALSE != pSuite->fActive) ? "Yes" : "No");
pTest->pName,
(CU_FALSE != pSuite->fActive) ? _("Yes") : _("No"));
pTest = pTest->pNext;
}
......@@ -591,8 +608,9 @@ static CU_ErrorCode automated_list_all_tests(CU_pTestRegistry pRegistry, const c
time(&tTime);
szTime = ctime(&tTime);
fprintf(pTestListFile,
" <CUNIT_FOOTER> File Generated By CUnit v" CU_VERSION " at %s </CUNIT_FOOTER> \n"
" <CUNIT_FOOTER> %s" CU_VERSION " - %s </CUNIT_FOOTER> \n"
"</CUNIT_TEST_LIST_REPORT>",
_("File Generated By CUnit v"),
(NULL != szTime) ? szTime : "");
if (0 != fclose(pTestListFile)) {
......
......@@ -25,6 +25,8 @@
* 8-Jan-2005 Fixed reporting bug (bug report cunit-Bugs-1093861). (JDS)
*
* 30-Apr-2005 Added notification of suite cleanup failure. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
......@@ -45,6 +47,7 @@
#include "Util.h"
#include "TestRun.h"
#include "Basic.h"
#include "CUnit_intl.h"
/*=================================================================
* Global/Static Definitions
......@@ -77,7 +80,7 @@ CU_ErrorCode CU_basic_run_tests(void)
if (NULL == CU_get_registry()) {
if (CU_BRM_SILENT != f_run_mode)
fprintf(stderr, "\n\nFATAL ERROR - Test registry is not initialized.\n");
fprintf(stderr, "\n\n%s\n", _("FATAL ERROR - Test registry is not initialized."));
error = CUE_NOREGISTRY;
}
else if (CUE_SUCCESS == (error = basic_initialize()))
......@@ -156,8 +159,10 @@ static CU_ErrorCode basic_initialize(void)
CU_set_error(CUE_SUCCESS);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout, "\n\n CUnit - A Unit testing framework for C - Version " CU_VERSION
"\n http://cunit.sourceforge.net/\n\n");
fprintf(stdout, "\n\n %s" CU_VERSION
"\n %s\n\n",
_("CUnit - A unit testing framework for C - Version "),
_("http://cunit.sourceforge.net/"));
CU_set_test_start_handler(basic_test_start_message_handler);
CU_set_test_complete_handler(basic_test_complete_message_handler);
......@@ -230,13 +235,15 @@ static void basic_test_start_message_handler(const CU_pTest pTest, const CU_pSui
assert(NULL != pTest);
if (CU_BRM_VERBOSE == f_run_mode) {
assert(NULL != pTest->pName);
if ((NULL == f_pRunningSuite) || (f_pRunningSuite != pSuite)) {
fprintf(stdout, "\nSuite: %s", (NULL != pSuite->pName) ? pSuite->pName : "");
fprintf(stdout, "\n Test: %s ... ", (NULL != pTest->pName) ? pTest->pName : "");
assert(NULL != pSuite->pName);
fprintf(stdout, "\n%s: %s", _("Suite"), pSuite->pName);
fprintf(stdout, "\n %s: %s ...", _("Test"), pTest->pName);
f_pRunningSuite = pSuite;
}
else {
fprintf(stdout, "\n Test: %s ... ", (NULL != pTest->pName) ? pTest->pName : "");
fprintf(stdout, "\n %s: %s ...", _("Test"), pTest->pName);
}
}
}
......@@ -259,18 +266,18 @@ static void basic_test_complete_message_handler(const CU_pTest pTest,
if (NULL == pFailure) {
if (CU_BRM_VERBOSE == f_run_mode) {
fprintf(stdout, "passed");
fprintf(stdout, _("passed"));
}
}
else {
switch (f_run_mode) {
case CU_BRM_VERBOSE:
fprintf(stdout, "FAILED");
fprintf(stdout, _("FAILED"));
break;
case CU_BRM_NORMAL:
fprintf(stdout, "\nSuite %s, Test %s had failures:",
(NULL != pSuite->pName) ? pSuite->pName : "",
(NULL != pTest->pName) ? pTest->pName : "");
assert(NULL != pSuite->pName);
assert(NULL != pTest->pName);
fprintf(stdout, _("\nSuite %s, Test %s had failures:"), pSuite->pName, pTest->pName);
break;
default: /* gcc wants all enums covered. ok. */
break;
......@@ -292,32 +299,8 @@ static void basic_test_complete_message_handler(const CU_pTest pTest,
*/
static void basic_all_tests_complete_message_handler(const CU_pFailureRecord pFailure)
{
CU_pRunSummary pRunSummary = CU_get_run_summary();
CU_pTestRegistry pRegistry = CU_get_registry();
CU_UNREFERENCED_PARAMETER(pFailure); /* not used in basic interface */
assert(NULL != pRunSummary);
assert(NULL != pRegistry);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout,"\n\n--Run Summary: Type Total Ran Passed Failed Inactive"
"\n suites %8u%8u n/a%8u%8u"
"\n tests %8u%8u%8u%8u%8u"
"\n asserts%8u%8u%8u%8u n/a\n",
pRegistry->uiNumberOfSuites,
pRunSummary->nSuitesRun,
pRunSummary->nSuitesFailed,
pRunSummary->nSuitesInactive,
pRegistry->uiNumberOfTests,
pRunSummary->nTestsRun,
pRunSummary->nTestsRun - pRunSummary->nTestsFailed,
pRunSummary->nTestsFailed,
pRunSummary->nTestsInactive,
pRunSummary->nAsserts,
pRunSummary->nAsserts,
pRunSummary->nAsserts - pRunSummary->nAssertsFailed,
pRunSummary->nAssertsFailed);
CU_print_run_results(stdout);
}
/*------------------------------------------------------------------------*/
......@@ -327,11 +310,10 @@ static void basic_all_tests_complete_message_handler(const CU_pFailureRecord pFa
static void basic_suite_init_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout,
"\nWARNING - Suite initialization failed for %s.",
(NULL != pSuite->pName) ? pSuite->pName : "");
fprintf(stdout, _("\nWARNING - Suite initialization failed for '%s'."), pSuite->pName);
}
/*------------------------------------------------------------------------*/
......@@ -341,11 +323,10 @@ static void basic_suite_init_failure_message_handler(const CU_pSuite pSuite)
static void basic_suite_cleanup_failure_message_handler(const CU_pSuite pSuite)
{
assert(NULL != pSuite);
assert(NULL != pSuite->pName);
if (CU_BRM_SILENT != f_run_mode)
fprintf(stdout,
"\nWARNING - Suite cleanup failed for %s.",
(NULL != pSuite->pName) ? pSuite->pName : "");
fprintf(stdout, _("\nWARNING - Suite cleanup failed for '%s'."), pSuite->pName);
}
/** @} */
......@@ -39,6 +39,8 @@
* Help function added for both menu levels.
* Option menu added. Immediate action on hotkeys
* without needing to <ENTER>, like curses. (JDS)
*
* 02-May-2006 Added internationalization hooks. (JDS)
*/
/** @file
......@@ -59,6 +61,7 @@
#include "Util.h"
#include "TestRun.h"
#include "Console.h"
#include "CUnit_intl.h"
/** Console interface status flag. */
typedef enum
......@@ -74,6 +77,10 @@ typedef enum
/** Pointer to the currently running suite. */
static CU_pSuite f_pRunningSuite = NULL;
/** Common width measurements for output formatting. */
static size_t f_yes_width = 0;
static size_t f_no_width = 0;
/*=================================================================
* Static function forward declarations
*=================================================================*/
......@@ -110,14 +117,19 @@ void CU_console_run_tests(void)
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
fprintf(stdout, "\n\n CUnit - A Unit testing framework for C - Version " CU_VERSION
"\n http://cunit.sourceforge.net/\n\n");
fprintf(stdout, "\n\n %s" CU_VERSION
"\n %s\n",
_("CUnit - A Unit testing framework for C - Version "),
_("http://cunit.sourceforge.net/"));
if (NULL == CU_get_registry()) {
fprintf(stderr, "\n\nFATAL ERROR - Test registry is not initialized.\n");
fprintf(stderr, "\n\n%s\n", _("FATAL ERROR - Test registry is not initialized."));
CU_set_error(CUE_NOREGISTRY);
}
else {
f_yes_width = strlen(_("Yes"));
f_no_width = strlen(_("No"));
CU_set_test_start_handler(console_test_start_message_handler);
CU_set_test_complete_handler(console_test_complete_message_handler);
CU_set_all_test_complete_handler(console_all_tests_complete_message_handler);
......@@ -147,69 +159,62 @@ static void console_registry_level_run(CU_pTestRegistry pRegistry)
while (CONTINUE == eStatus)
{
fprintf(stdout, "\n***************** CUNIT CONSOLE - MAIN MENU ******************************"
"\n(R)un (S)elect (L)ist (A)ctivate (F)ailures (O)ptions (H)elp (Q)uit"
"\nEnter command: ");
chChoice = getchar();
fprintf(stdout, "\n\n%s\n%s\n%s",
_("***************** CUNIT CONSOLE - MAIN MENU ******************************"),
_("(R)un (S)elect (L)ist (A)ctivate (F)ailures (O)ptions (H)elp (Q)uit"),
_("Enter command: "));
chChoice = toupper(getchar());
fgets(szTemp, 256, stdin); /* flush any chars out of the read buffer */
switch (tolower(chChoice)) {
case 'r':
if (chChoice == _("R")[0]) {
console_run_all_tests(pRegistry);
break;
}
case 's':
else if (chChoice == _("S")[0]) {
if (CUE_SUCCESS == select_suite(pRegistry, &pSuite)) {
fprintf(stdout, "Suite '%s' selected.\n", pSuite->pName);
assert(NULL != pSuite->pName);
fprintf(stdout, _("Suite '%s' selected."), pSuite->pName);
fprintf(stdout, "\n");
if (STOP == console_suite_level_run(pSuite)) {
eStatus = STOP;
}
}
else {
fprintf(stdout, "\nSuite not found.\n");
fprintf(stdout, "\n%s\n", _("Suite not found."));
}
}
break;
case 'l':
else if (chChoice == _("L")[0]) {
list_suites(pRegistry);
break;
}
case 'a':
if (CUE_SUCCESS == select_suite(pRegistry, &pSuite)) {
else if (chChoice == _("A")[0]) {
while (CUE_SUCCESS == select_suite(pRegistry, &pSuite)) {
CU_set_suite_active(pSuite, (CU_FALSE == pSuite->fActive) ? CU_TRUE : CU_FALSE);
fprintf(stdout, "Suite '%s' %s.\n",
pSuite->pName,
(CU_FALSE == pSuite->fActive) ? "deactivated" : "activated");
}
else {
fprintf(stdout, "\nSuite not found.\n");
}
break;
case 'f':
else if (chChoice == _("F")[0]) {
show_failures();
break;
}
case 'o':
else if (chChoice == _("O")[0]) {
console_set_options_run();
break;
}