ICU-6337 Add callback to initArgs to handle unknown options. Change iotest to take the STANDARD_TEST_FILE name from the argument list.

X-SVN-Rev: 24158
This commit is contained in:
Eric Mader 2008-06-12 01:01:00 +00:00
parent d59b5c5e4c
commit 8b8e11bb47
7 changed files with 74 additions and 41 deletions

View File

@ -83,7 +83,7 @@ int main(int argc, const char* const argv[])
gOrigArgc = argc;
gOrigArgv = argv;
if (!initArgs(argc, argv)) {
if (!initArgs(argc, argv, NULL, NULL)) {
/* Error already displayed. */
return -1;
}
@ -107,7 +107,7 @@ int main(int argc, const char* const argv[])
while (REPEAT_TESTS > 0) { /* Loop runs once per complete execution of the tests
* used for -r (repeat) test option. */
if (!initArgs(argc, argv)) {
if (!initArgs(argc, argv, NULL, NULL)) {
/* Error already displayed. */
return -1;
}
@ -433,7 +433,7 @@ UBool ctest_resetICU() {
char *dataDir = safeGetICUDataDirectory();
u_cleanup();
if (!initArgs(gOrigArgc, gOrigArgv)) {
if (!initArgs(gOrigArgc, gOrigArgv, NULL, NULL)) {
/* Error already displayed. */
return FALSE;
}

View File

@ -1,16 +1,16 @@
/*
**********************************************************************
* Copyright (C) 2004-2006, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: filetst.c
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 2004apr06
* created by: George Rhoten
*/
**********************************************************************
* Copyright (C) 2004-2008, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: filetst.c
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 2004apr06
* created by: George Rhoten
*/
#include "iotest.h"
#include "unicode/ustdio.h"
@ -19,7 +19,7 @@
#include <string.h>
const char STANDARD_TEST_FILE[] = "iotest-c.txt";
const char *STANDARD_TEST_FILE = "iotest-c.txt";
#if !UCONFIG_NO_FORMATTING
@ -233,9 +233,17 @@ static void TestFileFromICU(UFILE *myFile) {
}
u_fgets(myUString, 4, myFile);
myString[2] = '!';
myString[3] = '!';
u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
if (myString == NULL || strcmp(myString, "\t\n") != 0) {
#if 0
log_err("u_fgets got \"%s\"\n", myString);
#else
log_err("u_fgets got \"\\u%04X\\u%04X\\u%04X\\u%04X\" u_austrncpy got \"\\x%02.2X\\x%02.2X\\x%02.2X\\x%02.2X\".\n",
myUString[0], myUString[1], myUString[2], myUString[3],
myString[0], myString[1], myString[2] & 0xFF, myString[3]);
#endif
}
if (u_fgets(myUString, sizeof(myUString)/sizeof(*myUString), myFile) != myUString) {

View File

@ -777,6 +777,25 @@ static void ctest_setICU_DATA() {
}
}
U_CDECL_BEGIN
/*
* Note: this assumes that context is a pointer to STANDARD_TEST_FILE. It would be
* cleaner to define an acutal context with a string pointer in it and set STANDARD_TEST_FILE
* after the call to initArgs()...
*/
static int U_CALLCONV argHandler(int arg, int /*argc*/, const char * const argv[], void *context)
{
const char **str = (const char **) context;
if (argv[arg][0] != '/' && argv[arg][0] != '-') {
*str = argv[arg];
return 1;
}
return 0;
}
U_CDECL_END
int main(int argc, char* argv[])
{
int32_t nerrors = 0;
@ -802,7 +821,7 @@ int main(int argc, char* argv[])
}
u_cleanup();
errorCode = U_ZERO_ERROR;
if (!initArgs(argc, argv)) {
if (!initArgs(argc, argv, argHandler, (void *) &STANDARD_TEST_FILE)) {
/* Error already displayed. */
return -1;
}

View File

@ -1,16 +1,16 @@
/*
**********************************************************************
* Copyright (C) 2004-2005, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: iotest.h
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 2004apr06
* created by: George Rhoten
*/
**********************************************************************
* Copyright (C) 2004-2008, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: iotest.h
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 2004apr06
* created by: George Rhoten
*/
#ifndef IOTEST_H
#define IOTEST_H 1
@ -33,7 +33,7 @@ addStreamTests(TestNode** root);
U_CDECL_BEGIN
extern const UChar NEW_LINE[];
extern const char C_NEW_LINE[];
extern const char STANDARD_TEST_FILE[];
extern const char *STANDARD_TEST_FILE;
U_CDECL_END
#define STANDARD_TEST_NUM_RANGE 1000

View File

@ -1068,7 +1068,7 @@ int main(int argc, char* argv[])
startTime = uprv_getUTCtime();
if (!initArgs(argc, argv)) {
if (!initArgs(argc, argv, NULL, NULL)) {
/* Error already displayed. */
return -1;
}
@ -1091,7 +1091,7 @@ int main(int argc, char* argv[])
u_cleanup();
errorCode = U_ZERO_ERROR;
if (!initArgs(argc, argv)) {
if (!initArgs(argc, argv, NULL, NULL)) {
/* Error already displayed. */
return -1;
}

View File

@ -586,10 +586,11 @@ static void U_CALLCONV ctest_libFree(const void *context, void *mem) {
}
int T_CTEST_EXPORT2
initArgs( int argc, const char* const argv[])
initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context)
{
int i;
int doList = FALSE;
int argSkip = 0;
VERBOSITY = FALSE;
ERR_MSG = TRUE;
@ -686,6 +687,10 @@ initArgs( int argc, const char* const argv[])
help( argv[0] );
return 0;
}
else if (argHandler != NULL && (argSkip = argHandler(i, argc, argv, context)) > 0)
{
i += argSkip - 1;
}
else
{
printf("* unknown option: %s\n", argv[i]);

View File

@ -1,11 +1,11 @@
/*
********************************************************************************
*
* Copyright (C) 1996-2007, International Business Machines
* Corporation and others. All Rights Reserved.
*
********************************************************************************
*/
********************************************************************************
*
* Copyright (C) 1996-2008, International Business Machines
* Corporation and others. All Rights Reserved.
*
********************************************************************************
*/
#ifndef CTEST_H
#define CTEST_H
@ -18,6 +18,7 @@
U_CDECL_BEGIN
typedef void (U_CALLCONV *TestFunctionPtr)(void);
typedef int (U_CALLCONV *ArgHandlerPtr)(int arg, int argc, const char* const argv[], void *context);
typedef struct TestNode TestNode;
U_CDECL_END
@ -193,7 +194,7 @@ log_data_err(const char *pattern, ...);
* This must be called before runTests.
*/
T_CTEST_API int T_CTEST_EXPORT2
initArgs( int argc, const char* const argv[]);
initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context);
/**
* Processes the command line arguments.