2001-03-21 23:22:16 +00:00
|
|
|
/*
|
2006-03-25 22:16:50 +00:00
|
|
|
********************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2010-04-07 16:18:38 +00:00
|
|
|
* Copyright (C) 1996-2010, International Business Machines
|
1999-12-13 22:28:37 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
2006-03-25 22:16:50 +00:00
|
|
|
********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
2010-10-08 20:14:26 +00:00
|
|
|
#include <ctype.h>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-09-20 01:21:23 +00:00
|
|
|
#include "unicode/utrace.h"
|
2007-12-07 10:49:34 +00:00
|
|
|
#include "unicode/uclean.h"
|
|
|
|
#include "umutex.h"
|
2010-05-25 19:55:05 +00:00
|
|
|
#include "putilimp.h"
|
2003-09-20 01:21:23 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* NOTES:
|
2001-03-21 23:22:16 +00:00
|
|
|
3/20/1999 srl - strncpy called w/o setting nulls at the end
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAXTESTNAME 128
|
|
|
|
#define MAXTESTS 512
|
|
|
|
#define MAX_TEST_LOG 4096
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
/**
|
|
|
|
* How may columns to indent the 'OK' markers.
|
|
|
|
*/
|
|
|
|
#define FLAG_INDENT 45
|
|
|
|
/**
|
|
|
|
* How many lines of scrollage can go by before we need to remind the user what the test is.
|
|
|
|
*/
|
2010-10-08 20:14:26 +00:00
|
|
|
#define PAGE_SIZE_LIMIT 25
|
2010-05-06 22:22:38 +00:00
|
|
|
|
2010-05-25 19:55:05 +00:00
|
|
|
#ifndef SHOW_TIMES
|
|
|
|
#define SHOW_TIMES 1
|
|
|
|
#endif
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
struct TestNode
|
|
|
|
{
|
2002-03-28 18:26:25 +00:00
|
|
|
void (*test)(void);
|
1999-08-16 21:50:52 +00:00
|
|
|
struct TestNode* sibling;
|
|
|
|
struct TestNode* child;
|
2007-12-16 01:20:13 +00:00
|
|
|
char name[1]; /* This is dynamically allocated off the end with malloc. */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2002-05-02 21:16:33 +00:00
|
|
|
|
|
|
|
static const struct TestNode* currentTest;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
typedef enum { RUNTESTS, SHOWTESTS } TestMode;
|
|
|
|
#define TEST_SEPARATOR '/'
|
|
|
|
|
2002-07-19 23:25:41 +00:00
|
|
|
#ifndef C_TEST_IMPL
|
|
|
|
#define C_TEST_IMPL
|
|
|
|
#endif
|
|
|
|
|
2000-01-17 22:53:44 +00:00
|
|
|
#include "unicode/ctest.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-07-12 06:43:32 +00:00
|
|
|
static char ERROR_LOG[MAX_TEST_LOG][MAXTESTNAME];
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-09-17 19:45:03 +00:00
|
|
|
/* Local prototypes */
|
1999-08-16 21:50:52 +00:00
|
|
|
static TestNode* addTestNode( TestNode *root, const char *name );
|
|
|
|
|
2007-12-16 01:20:13 +00:00
|
|
|
static TestNode *createTestNode(const char* name, int32_t nameLen);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
static int strncmp_nullcheck( const char* s1,
|
|
|
|
const char* s2,
|
|
|
|
int n );
|
|
|
|
|
|
|
|
static void getNextLevel( const char* name,
|
|
|
|
int* nameLen,
|
|
|
|
const char** nextName );
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
static void iterateTestsWithLevel( const TestNode *root, int depth,
|
|
|
|
const TestNode** nodeList,
|
1999-08-16 21:50:52 +00:00
|
|
|
TestMode mode);
|
|
|
|
|
|
|
|
static void help ( const char *argv0 );
|
|
|
|
|
2002-09-17 19:45:03 +00:00
|
|
|
/**
|
|
|
|
* Do the work of logging an error. Doesn't increase the error count.
|
|
|
|
*
|
|
|
|
* @prefix optional prefix prepended to message, or NULL.
|
|
|
|
* @param pattern printf style pattern
|
|
|
|
* @param ap vprintf style arg list
|
|
|
|
*/
|
|
|
|
static void vlog_err(const char *prefix, const char *pattern, va_list ap);
|
|
|
|
static void vlog_verbose(const char *prefix, const char *pattern, va_list ap);
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
/**
|
|
|
|
* Log test structure, with indent
|
|
|
|
* @param pattern printf pattern
|
|
|
|
*/
|
|
|
|
static void log_testinfo_i(const char *pattern, ...);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log test structure, NO indent
|
|
|
|
* @param pattern printf pattern
|
|
|
|
*/
|
|
|
|
static void log_testinfo(const char *pattern, ...);
|
|
|
|
|
2002-09-17 19:45:03 +00:00
|
|
|
/* If we need to make the framework multi-thread safe
|
|
|
|
we need to pass around the following vars
|
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
static int ERRONEOUS_FUNCTION_COUNT = 0;
|
2002-01-16 04:33:33 +00:00
|
|
|
static int ERROR_COUNT = 0; /* Count of errors from all tests. */
|
2010-05-06 22:22:38 +00:00
|
|
|
static int ONE_ERROR = 0; /* were there any other errors? */
|
2002-09-17 19:45:03 +00:00
|
|
|
static int DATA_ERROR_COUNT = 0; /* count of data related errors or warnings */
|
1999-08-16 21:50:52 +00:00
|
|
|
static int INDENT_LEVEL = 0;
|
2010-05-06 22:22:38 +00:00
|
|
|
static UBool ON_LINE = FALSE; /* are we on the top line with our test name? */
|
|
|
|
static UBool HANGING_OUTPUT = FALSE; /* did the user leave us without a trailing \n ? */
|
|
|
|
static int GLOBAL_PRINT_COUNT = 0; /* global count of printouts */
|
2002-01-16 04:33:33 +00:00
|
|
|
int REPEAT_TESTS_INIT = 0; /* Was REPEAT_TESTS initialized? */
|
|
|
|
int REPEAT_TESTS = 1; /* Number of times to run the test */
|
|
|
|
int VERBOSITY = 0; /* be No-verbose by default */
|
|
|
|
int ERR_MSG =1; /* error messages will be displayed by default*/
|
|
|
|
int QUICK = 1; /* Skip some of the slower tests? */
|
2002-09-17 19:45:03 +00:00
|
|
|
int WARN_ON_MISSING_DATA = 0; /* Reduce data errs to warnings? */
|
2003-09-20 01:21:23 +00:00
|
|
|
UTraceLevel ICU_TRACE = UTRACE_OFF; /* ICU tracing level */
|
2008-02-10 20:17:14 +00:00
|
|
|
size_t MINIMUM_MEMORY_SIZE_FAILURE = (size_t)-1; /* Minimum library memory allocation window that will fail. */
|
|
|
|
size_t MAXIMUM_MEMORY_SIZE_FAILURE = (size_t)-1; /* Maximum library memory allocation window that will fail. */
|
2007-12-07 10:49:34 +00:00
|
|
|
int32_t ALLOCATION_COUNT = 0;
|
2010-05-06 22:22:38 +00:00
|
|
|
static const char *ARGV_0 = "[ALL]";
|
2010-07-12 15:24:57 +00:00
|
|
|
static const char *XML_FILE_NAME=NULL;
|
|
|
|
static char XML_PREFIX[256];
|
|
|
|
|
|
|
|
FILE *XML_FILE = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
/*-------------------------------------------*/
|
|
|
|
|
|
|
|
/* strncmp that also makes sure there's a \0 at s2[0] */
|
2000-08-11 02:08:59 +00:00
|
|
|
static int strncmp_nullcheck( const char* s1,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* s2,
|
|
|
|
int n )
|
|
|
|
{
|
2002-05-23 22:10:23 +00:00
|
|
|
if (((int)strlen(s2) >= n) && s2[n] != 0) {
|
|
|
|
return 3; /* null check fails */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return strncmp ( s1, s2, n );
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-08-11 02:08:59 +00:00
|
|
|
static void getNextLevel( const char* name,
|
1999-08-16 21:50:52 +00:00
|
|
|
int* nameLen,
|
|
|
|
const char** nextName )
|
|
|
|
{
|
2002-05-23 22:10:23 +00:00
|
|
|
/* Get the next component of the name */
|
|
|
|
*nextName = strchr(name, TEST_SEPARATOR);
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2002-05-23 22:10:23 +00:00
|
|
|
if( *nextName != 0 )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-05-23 22:10:23 +00:00
|
|
|
char n[255];
|
|
|
|
*nameLen = (int)((*nextName) - name);
|
|
|
|
(*nextName)++; /* skip '/' */
|
|
|
|
strncpy(n, name, *nameLen);
|
|
|
|
n[*nameLen] = 0;
|
|
|
|
/*printf("->%s-< [%d] -> [%s]\n", name, *nameLen, *nextName);*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*nameLen = (int)strlen(name);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-16 01:20:13 +00:00
|
|
|
static TestNode *createTestNode(const char* name, int32_t nameLen)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-05-23 22:10:23 +00:00
|
|
|
TestNode *newNode;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2007-12-16 01:20:13 +00:00
|
|
|
newNode = (TestNode*)malloc(sizeof(TestNode) + (nameLen + 1));
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2002-05-23 22:10:23 +00:00
|
|
|
newNode->test = NULL;
|
|
|
|
newNode->sibling = NULL;
|
|
|
|
newNode->child = NULL;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2007-12-16 01:20:13 +00:00
|
|
|
strncpy( newNode->name, name, nameLen );
|
|
|
|
newNode->name[nameLen] = 0;
|
|
|
|
|
2002-05-23 22:10:23 +00:00
|
|
|
return newNode;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
cleanUpTestTree(TestNode *tn)
|
|
|
|
{
|
2000-07-06 23:01:50 +00:00
|
|
|
if(tn->child != NULL) {
|
|
|
|
cleanUpTestTree(tn->child);
|
|
|
|
}
|
|
|
|
if(tn->sibling != NULL) {
|
|
|
|
cleanUpTestTree(tn->sibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(tn);
|
2010-07-12 15:24:57 +00:00
|
|
|
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
addTest(TestNode** root,
|
|
|
|
TestFunctionPtr test,
|
|
|
|
const char* name )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
TestNode *newNode;
|
|
|
|
|
|
|
|
/*if this is the first Test created*/
|
|
|
|
if (*root == NULL)
|
2007-12-16 01:20:13 +00:00
|
|
|
*root = createTestNode("", 0);
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
newNode = addTestNode( *root, name );
|
|
|
|
assert(newNode != 0 );
|
|
|
|
/* printf("addTest: nreName = %s\n", newNode->name );*/
|
|
|
|
|
|
|
|
newNode->test = test;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* non recursive insert function */
|
2000-11-21 18:48:10 +00:00
|
|
|
static TestNode *addTestNode ( TestNode *root, const char *name )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
const char* nextName;
|
|
|
|
TestNode *nextNode, *curNode;
|
|
|
|
int nameLen; /* length of current 'name' */
|
|
|
|
|
|
|
|
/* remove leading slash */
|
|
|
|
if ( *name == TEST_SEPARATOR )
|
|
|
|
name++;
|
|
|
|
|
|
|
|
curNode = root;
|
|
|
|
|
|
|
|
for(;;)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
/* Start with the next child */
|
|
|
|
nextNode = curNode->child;
|
|
|
|
|
|
|
|
getNextLevel ( name, &nameLen, &nextName );
|
|
|
|
|
|
|
|
/* printf("* %s\n", name );*/
|
|
|
|
|
|
|
|
/* if nextNode is already null, then curNode has no children
|
|
|
|
-- add them */
|
|
|
|
if( nextNode == NULL )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
/* Add all children of the node */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Get the next component of the name */
|
2007-12-16 01:20:13 +00:00
|
|
|
getNextLevel(name, &nameLen, &nextName);
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
/* update curName to have the next name segment */
|
2007-12-16 01:20:13 +00:00
|
|
|
curNode->child = createTestNode(name, nameLen);
|
2000-11-30 20:02:51 +00:00
|
|
|
/* printf("*** added %s\n", curNode->child->name );*/
|
|
|
|
curNode = curNode->child;
|
|
|
|
name = nextName;
|
|
|
|
}
|
|
|
|
while( name != NULL );
|
|
|
|
|
|
|
|
return curNode;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
/* Search across for the name */
|
|
|
|
while (strncmp_nullcheck ( name, nextNode->name, nameLen) != 0 )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
curNode = nextNode;
|
|
|
|
nextNode = nextNode -> sibling;
|
|
|
|
|
|
|
|
if ( nextNode == NULL )
|
|
|
|
{
|
|
|
|
/* Did not find 'name' on this level. */
|
2007-12-16 01:20:13 +00:00
|
|
|
nextNode = createTestNode(name, nameLen);
|
2000-11-30 20:02:51 +00:00
|
|
|
curNode->sibling = nextNode;
|
|
|
|
break;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
/* nextNode matches 'name' */
|
|
|
|
|
|
|
|
if (nextName == NULL) /* end of the line */
|
|
|
|
{
|
|
|
|
return nextNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop again with the next item */
|
|
|
|
name = nextName;
|
|
|
|
curNode = nextNode;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 19:55:05 +00:00
|
|
|
/**
|
|
|
|
* Log the time taken. May not output anything.
|
|
|
|
* @param deltaTime change in time
|
|
|
|
*/
|
|
|
|
void T_CTEST_EXPORT2 str_timeDelta(char *str, UDate deltaTime) {
|
|
|
|
if (deltaTime > 110000.0 ) {
|
|
|
|
double mins = uprv_floor(deltaTime/60000.0);
|
|
|
|
sprintf(str, "[(%.0fm %.1fs)]", mins, (deltaTime-(mins*60000.0))/1000.0);
|
|
|
|
} else if (deltaTime > 1500.0) {
|
|
|
|
sprintf(str, "((%.1fs))", deltaTime/1000.0);
|
|
|
|
} else if(deltaTime>900.0) {
|
|
|
|
sprintf(str, "( %.2fs )", deltaTime/1000.0);
|
|
|
|
} else if(deltaTime > 5.0) {
|
|
|
|
sprintf(str, " (%.0fms) ", deltaTime);
|
|
|
|
} else {
|
|
|
|
str[0]=0; /* at least terminate it. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_timeDelta(UDate deltaTime) {
|
|
|
|
char str[256];
|
|
|
|
str_timeDelta(str, deltaTime);
|
|
|
|
if(str[0]) {
|
|
|
|
printf("%s", str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
/**
|
|
|
|
* Run or list tests (according to mode) in a subtree.
|
|
|
|
*
|
|
|
|
* @param root root of the subtree to operate on
|
|
|
|
* @param depth The depth of this tree (0=root)
|
|
|
|
* @param nodeList an array of MAXTESTS depth that's used for keeping track of where we are. nodeList[depth] points to the 'parent' at depth depth.
|
|
|
|
* @param mode what mode we are operating in.
|
|
|
|
*/
|
2000-08-11 02:08:59 +00:00
|
|
|
static void iterateTestsWithLevel ( const TestNode* root,
|
2010-05-06 22:22:38 +00:00
|
|
|
int depth,
|
|
|
|
const TestNode** nodeList,
|
1999-08-16 21:50:52 +00:00
|
|
|
TestMode mode)
|
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
int i;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
char pathToFunction[MAXTESTNAME] = "";
|
|
|
|
char separatorString[2] = { TEST_SEPARATOR, '\0'};
|
2010-05-25 19:55:05 +00:00
|
|
|
#if SHOW_TIMES
|
|
|
|
UDate allStartTime = -1, allStopTime = -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(depth<2) {
|
|
|
|
allStartTime = uprv_getRawUTCtime();
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
if ( root == NULL )
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
/* record the current root node, and increment depth. */
|
|
|
|
nodeList[depth++] = root;
|
|
|
|
/* depth is now the depth of root's children. */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
/* Collect the 'path' to the current subtree. */
|
|
|
|
for ( i=0;i<(depth-1);i++ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2010-05-06 22:22:38 +00:00
|
|
|
strcat(pathToFunction, nodeList[i]->name);
|
2000-11-30 20:02:51 +00:00
|
|
|
strcat(pathToFunction, separatorString);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2010-05-06 22:22:38 +00:00
|
|
|
strcat(pathToFunction, nodeList[i]->name); /* including 'root' */
|
|
|
|
|
|
|
|
/* print test name and space. */
|
|
|
|
INDENT_LEVEL = depth-1;
|
|
|
|
if(root->name[0]) {
|
|
|
|
log_testinfo_i("%s ", root->name);
|
|
|
|
} else {
|
|
|
|
log_testinfo_i("(%s) ", ARGV_0);
|
|
|
|
}
|
|
|
|
ON_LINE = TRUE; /* we are still on the line with the test name */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
if ( (mode == RUNTESTS) &&
|
|
|
|
(root->test != NULL)) /* if root is a leaf node, run it */
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
int myERROR_COUNT = ERROR_COUNT;
|
2010-05-06 22:22:38 +00:00
|
|
|
int myGLOBAL_PRINT_COUNT = GLOBAL_PRINT_COUNT;
|
2010-05-25 19:55:05 +00:00
|
|
|
#if SHOW_TIMES
|
|
|
|
UDate startTime, stopTime;
|
2010-07-12 15:24:57 +00:00
|
|
|
char timeDelta[256];
|
|
|
|
char timeSeconds[256];
|
|
|
|
#else
|
|
|
|
const char timeDelta[] = "(unknown)";
|
|
|
|
const char timeSeconds[] = "0.000";
|
2010-05-25 19:55:05 +00:00
|
|
|
#endif
|
2002-05-02 21:16:33 +00:00
|
|
|
currentTest = root;
|
2010-05-06 22:22:38 +00:00
|
|
|
INDENT_LEVEL = depth; /* depth of subitems */
|
|
|
|
ONE_ERROR=0;
|
|
|
|
HANGING_OUTPUT=FALSE;
|
2010-05-25 19:55:05 +00:00
|
|
|
#if SHOW_TIMES
|
|
|
|
startTime = uprv_getRawUTCtime();
|
|
|
|
#endif
|
|
|
|
root->test(); /* PERFORM THE TEST ************************/
|
|
|
|
#if SHOW_TIMES
|
|
|
|
stopTime = uprv_getRawUTCtime();
|
|
|
|
#endif
|
2010-05-06 22:22:38 +00:00
|
|
|
if(HANGING_OUTPUT) {
|
2010-05-25 19:55:05 +00:00
|
|
|
log_testinfo("\n");
|
|
|
|
HANGING_OUTPUT=FALSE;
|
2010-05-06 22:22:38 +00:00
|
|
|
}
|
|
|
|
INDENT_LEVEL = depth-1; /* depth of root */
|
2002-05-02 21:16:33 +00:00
|
|
|
currentTest = NULL;
|
2010-05-06 22:22:38 +00:00
|
|
|
if((ONE_ERROR>0)&&(ERROR_COUNT==0)) {
|
2010-05-25 19:55:05 +00:00
|
|
|
ERROR_COUNT++; /* There was an error without a newline */
|
2000-11-30 20:02:51 +00:00
|
|
|
}
|
2010-05-06 22:22:38 +00:00
|
|
|
ONE_ERROR=0;
|
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
#if SHOW_TIMES
|
|
|
|
str_timeDelta(timeDelta, stopTime-startTime);
|
|
|
|
sprintf(timeSeconds, "%f", (stopTime-startTime)/1000.0);
|
|
|
|
#endif
|
|
|
|
ctest_xml_testcase(pathToFunction, pathToFunction, timeSeconds, (myERROR_COUNT!=ERROR_COUNT)?"error":NULL);
|
|
|
|
|
2010-05-25 19:55:05 +00:00
|
|
|
if (myERROR_COUNT != ERROR_COUNT) {
|
|
|
|
log_testinfo_i("} ---[%d ERRORS in %s] ", ERROR_COUNT - myERROR_COUNT, pathToFunction);
|
|
|
|
strcpy(ERROR_LOG[ERRONEOUS_FUNCTION_COUNT++], pathToFunction);
|
|
|
|
} else {
|
|
|
|
if(!ON_LINE) { /* had some output */
|
|
|
|
int spaces = FLAG_INDENT-(depth-1);
|
|
|
|
log_testinfo_i("} %*s[OK] ", spaces, "---");
|
2010-10-08 20:14:26 +00:00
|
|
|
if((GLOBAL_PRINT_COUNT-myGLOBAL_PRINT_COUNT)>PAGE_SIZE_LIMIT) {
|
2010-05-25 19:55:05 +00:00
|
|
|
log_testinfo(" %s ", pathToFunction); /* in case they forgot. */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* put -- out at 30 sp. */
|
|
|
|
int spaces = FLAG_INDENT-(strlen(root->name)+depth);
|
|
|
|
if(spaces<0) spaces=0;
|
|
|
|
log_testinfo(" %*s[OK] ", spaces,"---");
|
|
|
|
}
|
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
|
2010-05-25 19:55:05 +00:00
|
|
|
#if SHOW_TIMES
|
2010-07-12 15:24:57 +00:00
|
|
|
if(timeDelta[0]) printf("%s", timeDelta);
|
2010-05-25 19:55:05 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
ON_LINE = TRUE; /* we are back on-line */
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
INDENT_LEVEL = depth-1; /* root */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
/* we want these messages to be at 0 indent. so just push the indent level breifly. */
|
2010-05-06 22:22:38 +00:00
|
|
|
if(mode==SHOWTESTS) {
|
|
|
|
log_testinfo("---%s%c\n",pathToFunction, nodeList[i]->test?' ':TEST_SEPARATOR );
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
INDENT_LEVEL = depth;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
if(root->child) {
|
|
|
|
int myERROR_COUNT = ERROR_COUNT;
|
|
|
|
int myGLOBAL_PRINT_COUNT = GLOBAL_PRINT_COUNT;
|
|
|
|
if(mode!=SHOWTESTS) {
|
|
|
|
INDENT_LEVEL=depth-1;
|
|
|
|
log_testinfo("{\n");
|
|
|
|
INDENT_LEVEL=depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
iterateTestsWithLevel ( root->child, depth, nodeList, mode );
|
|
|
|
|
|
|
|
if(mode!=SHOWTESTS) {
|
|
|
|
INDENT_LEVEL=depth-1;
|
|
|
|
log_testinfo_i("} "); /* TODO: summarize subtests */
|
|
|
|
if((depth>1) && (ERROR_COUNT > myERROR_COUNT)) {
|
|
|
|
log_testinfo("[%d %s in %s] ", ERROR_COUNT-myERROR_COUNT, (ERROR_COUNT-myERROR_COUNT)==1?"error":"errors", pathToFunction);
|
2010-10-08 20:14:26 +00:00
|
|
|
} else if((GLOBAL_PRINT_COUNT-myGLOBAL_PRINT_COUNT)>PAGE_SIZE_LIMIT || (depth<1)) {
|
2010-05-25 19:55:05 +00:00
|
|
|
if(pathToFunction[0]) {
|
|
|
|
log_testinfo(" %s ", pathToFunction); /* in case they forgot. */
|
|
|
|
} else {
|
|
|
|
log_testinfo(" / (%s) ", ARGV_0);
|
|
|
|
}
|
|
|
|
}
|
2010-05-06 22:22:38 +00:00
|
|
|
|
|
|
|
ON_LINE=TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
depth--;
|
|
|
|
|
2010-05-25 19:55:05 +00:00
|
|
|
#if SHOW_TIMES
|
|
|
|
if(depth<2) {
|
|
|
|
allStopTime = uprv_getRawUTCtime();
|
|
|
|
print_timeDelta(allStopTime-allStartTime);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
if(mode!=SHOWTESTS && ON_LINE) {
|
|
|
|
log_testinfo("\n");
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
if ( depth != 0 ) { /* DO NOT iterate over siblings of the root. TODO: why not? */
|
|
|
|
iterateTestsWithLevel ( root->sibling, depth, nodeList, mode );
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
showTests ( const TestNode *root )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
/* make up one for them */
|
2010-05-06 22:22:38 +00:00
|
|
|
const TestNode *nodeList[MAXTESTS];
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
if (root == NULL)
|
|
|
|
log_err("TEST CAN'T BE FOUND!");
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
iterateTestsWithLevel ( root, 0, nodeList, SHOWTESTS );
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
runTests ( const TestNode *root )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
int i;
|
2010-05-06 22:22:38 +00:00
|
|
|
const TestNode *nodeList[MAXTESTS];
|
2000-11-30 20:02:51 +00:00
|
|
|
/* make up one for them */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
if (root == NULL)
|
|
|
|
log_err("TEST CAN'T BE FOUND!\n");
|
|
|
|
|
2001-03-21 23:22:16 +00:00
|
|
|
ERRONEOUS_FUNCTION_COUNT = ERROR_COUNT = 0;
|
2010-05-06 22:22:38 +00:00
|
|
|
iterateTestsWithLevel ( root, 0, nodeList, RUNTESTS );
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
/*print out result summary*/
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
ON_LINE=FALSE; /* just in case */
|
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
if (ERROR_COUNT)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2010-05-06 22:22:38 +00:00
|
|
|
fprintf(stdout,"\nSUMMARY:\n");
|
|
|
|
fflush(stdout);
|
|
|
|
fprintf(stdout,"******* [Total error count:\t%d]\n", ERROR_COUNT);
|
|
|
|
fflush(stdout);
|
|
|
|
fprintf(stdout, " Errors in\n");
|
2000-11-30 20:02:51 +00:00
|
|
|
for (i=0;i < ERRONEOUS_FUNCTION_COUNT; i++)
|
2010-05-06 22:22:38 +00:00
|
|
|
fprintf(stdout, "[%s]\n",ERROR_LOG[i]);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
else
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2010-05-06 22:22:38 +00:00
|
|
|
log_testinfo("\n[All tests passed successfully...]\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-09-17 19:45:03 +00:00
|
|
|
if(DATA_ERROR_COUNT) {
|
|
|
|
if(WARN_ON_MISSING_DATA==0) {
|
2010-05-06 22:22:38 +00:00
|
|
|
log_testinfo("\t*Note* some errors are data-loading related. If the data used is not the \n"
|
2002-12-13 04:02:37 +00:00
|
|
|
"\tstock ICU data (i.e some have been added or removed), consider using\n"
|
2002-09-17 19:45:03 +00:00
|
|
|
"\tthe '-w' option to turn these errors into warnings.\n");
|
|
|
|
} else {
|
2010-05-06 22:22:38 +00:00
|
|
|
log_testinfo("\t*WARNING* some data-loading errors were ignored by the -w option.\n");
|
2002-09-17 19:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
const char* T_CTEST_EXPORT2
|
|
|
|
getTestName(void)
|
2002-05-02 21:16:33 +00:00
|
|
|
{
|
|
|
|
if(currentTest != NULL) {
|
|
|
|
return currentTest->name;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
const TestNode* T_CTEST_EXPORT2
|
|
|
|
getTest(const TestNode* root, const char* name)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
const char* nextName;
|
|
|
|
TestNode *nextNode;
|
|
|
|
const TestNode* curNode;
|
|
|
|
int nameLen; /* length of current 'name' */
|
|
|
|
|
2006-03-30 09:27:31 +00:00
|
|
|
if (root == NULL) {
|
2000-11-30 20:02:51 +00:00
|
|
|
log_err("TEST CAN'T BE FOUND!\n");
|
2006-03-30 09:27:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
/* remove leading slash */
|
|
|
|
if ( *name == TEST_SEPARATOR )
|
|
|
|
name++;
|
|
|
|
|
|
|
|
curNode = root;
|
|
|
|
|
|
|
|
for(;;)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
/* Start with the next child */
|
|
|
|
nextNode = curNode->child;
|
|
|
|
|
|
|
|
getNextLevel ( name, &nameLen, &nextName );
|
|
|
|
|
|
|
|
/* printf("* %s\n", name );*/
|
|
|
|
|
|
|
|
/* if nextNode is already null, then curNode has no children
|
|
|
|
-- add them */
|
|
|
|
if( nextNode == NULL )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
/* Search across for the name */
|
|
|
|
while (strncmp_nullcheck ( name, nextNode->name, nameLen) != 0 )
|
|
|
|
{
|
|
|
|
curNode = nextNode;
|
|
|
|
nextNode = nextNode -> sibling;
|
|
|
|
|
|
|
|
if ( nextNode == NULL )
|
|
|
|
{
|
|
|
|
/* Did not find 'name' on this level. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nextNode matches 'name' */
|
|
|
|
|
|
|
|
if (nextName == NULL) /* end of the line */
|
|
|
|
{
|
|
|
|
return nextNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop again with the next item */
|
|
|
|
name = nextName;
|
|
|
|
curNode = nextNode;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
/* =========== io functions ======== */
|
|
|
|
|
|
|
|
static void go_offline_with_marker(const char *mrk) {
|
2010-05-25 19:55:05 +00:00
|
|
|
UBool wasON_LINE = ON_LINE;
|
|
|
|
|
|
|
|
if(ON_LINE) {
|
|
|
|
log_testinfo(" {\n");
|
|
|
|
ON_LINE=FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!HANGING_OUTPUT || wasON_LINE) {
|
|
|
|
if(mrk != NULL) {
|
|
|
|
fputs(mrk, stdout);
|
|
|
|
}
|
|
|
|
}
|
2010-05-06 22:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void go_offline() {
|
|
|
|
go_offline_with_marker(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void go_offline_err() {
|
|
|
|
go_offline();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void first_line_verbose() {
|
|
|
|
go_offline_with_marker("v");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void first_line_err() {
|
|
|
|
go_offline_with_marker("!");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void first_line_info() {
|
|
|
|
go_offline_with_marker("\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void first_line_test() {
|
|
|
|
fputs(" ", stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-30 19:07:43 +00:00
|
|
|
static void vlog_err(const char *prefix, const char *pattern, va_list ap)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
if( ERR_MSG == FALSE){
|
|
|
|
return;
|
|
|
|
}
|
2010-05-06 22:22:38 +00:00
|
|
|
fputs("!", stdout); /* col 1 - bang */
|
|
|
|
fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
|
2002-09-17 19:45:03 +00:00
|
|
|
if(prefix) {
|
2010-05-06 22:22:38 +00:00
|
|
|
fputs(prefix, stdout);
|
2002-09-17 19:45:03 +00:00
|
|
|
}
|
2010-05-06 22:22:38 +00:00
|
|
|
vfprintf(stdout, pattern, ap);
|
|
|
|
fflush(stdout);
|
2000-11-30 20:02:51 +00:00
|
|
|
va_end(ap);
|
2010-05-06 22:22:38 +00:00
|
|
|
if((*pattern==0) || (pattern[strlen(pattern)-1]!='\n')) {
|
|
|
|
HANGING_OUTPUT=1;
|
|
|
|
} else {
|
|
|
|
HANGING_OUTPUT=0;
|
|
|
|
}
|
|
|
|
GLOBAL_PRINT_COUNT++;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
vlog_info(const char *prefix, const char *pattern, va_list ap)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2010-05-06 22:22:38 +00:00
|
|
|
first_line_info();
|
|
|
|
fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
|
2002-09-17 19:45:03 +00:00
|
|
|
if(prefix) {
|
2006-03-25 22:16:50 +00:00
|
|
|
fputs(prefix, stdout);
|
2002-09-17 19:45:03 +00:00
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
vfprintf(stdout, pattern, ap);
|
|
|
|
fflush(stdout);
|
|
|
|
va_end(ap);
|
2010-05-06 22:22:38 +00:00
|
|
|
if((*pattern==0) || (pattern[strlen(pattern)-1]!='\n')) {
|
|
|
|
HANGING_OUTPUT=1;
|
|
|
|
} else {
|
|
|
|
HANGING_OUTPUT=0;
|
|
|
|
}
|
|
|
|
GLOBAL_PRINT_COUNT++;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Log test structure, with indent
|
|
|
|
*/
|
|
|
|
static void log_testinfo_i(const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
first_line_test();
|
|
|
|
fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
|
|
|
|
va_start(ap, pattern);
|
|
|
|
vfprintf(stdout, pattern, ap);
|
|
|
|
fflush(stdout);
|
|
|
|
va_end(ap);
|
|
|
|
GLOBAL_PRINT_COUNT++;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2010-05-06 22:22:38 +00:00
|
|
|
/**
|
|
|
|
* Log test structure (no ident)
|
|
|
|
*/
|
|
|
|
static void log_testinfo(const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, pattern);
|
|
|
|
first_line_test();
|
|
|
|
vfprintf(stdout, pattern, ap);
|
|
|
|
fflush(stdout);
|
|
|
|
va_end(ap);
|
|
|
|
GLOBAL_PRINT_COUNT++;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-05-30 19:07:43 +00:00
|
|
|
static void vlog_verbose(const char *prefix, const char *pattern, va_list ap)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
if ( VERBOSITY == FALSE )
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
first_line_verbose();
|
|
|
|
fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
|
2002-09-17 19:45:03 +00:00
|
|
|
if(prefix) {
|
2006-03-25 22:16:50 +00:00
|
|
|
fputs(prefix, stdout);
|
2002-09-17 19:45:03 +00:00
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
vfprintf(stdout, pattern, ap);
|
|
|
|
fflush(stdout);
|
|
|
|
va_end(ap);
|
2010-05-06 22:22:38 +00:00
|
|
|
GLOBAL_PRINT_COUNT++;
|
|
|
|
if((*pattern==0) || (pattern[strlen(pattern)-1]!='\n')) {
|
|
|
|
HANGING_OUTPUT=1;
|
|
|
|
} else {
|
|
|
|
HANGING_OUTPUT=0;
|
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
log_err(const char* pattern, ...)
|
2002-09-17 19:45:03 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
2010-05-06 22:22:38 +00:00
|
|
|
first_line_err();
|
2002-09-17 19:45:03 +00:00
|
|
|
if(strchr(pattern, '\n') != NULL) {
|
|
|
|
/*
|
|
|
|
* Count errors only if there is a line feed in the pattern
|
|
|
|
* so that we do not exaggerate our error count.
|
|
|
|
*/
|
|
|
|
++ERROR_COUNT;
|
2010-05-06 22:22:38 +00:00
|
|
|
} else {
|
|
|
|
/* Count at least one error. */
|
|
|
|
ONE_ERROR=1;
|
2002-09-17 19:45:03 +00:00
|
|
|
}
|
|
|
|
va_start(ap, pattern);
|
|
|
|
vlog_err(NULL, pattern, ap);
|
|
|
|
}
|
|
|
|
|
2009-06-09 21:28:13 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
log_err_status(UErrorCode status, const char* pattern, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, pattern);
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
first_line_err();
|
2009-06-09 21:28:13 +00:00
|
|
|
if ((status == U_FILE_ACCESS_ERROR || status == U_MISSING_RESOURCE_ERROR)) {
|
|
|
|
++DATA_ERROR_COUNT; /* for informational message at the end */
|
|
|
|
|
|
|
|
if (WARN_ON_MISSING_DATA == 0) {
|
|
|
|
/* Fatal error. */
|
|
|
|
if (strchr(pattern, '\n') != NULL) {
|
|
|
|
++ERROR_COUNT;
|
2010-05-06 22:22:38 +00:00
|
|
|
} else {
|
|
|
|
++ONE_ERROR;
|
2009-06-09 21:28:13 +00:00
|
|
|
}
|
|
|
|
vlog_err(NULL, pattern, ap); /* no need for prefix in default case */
|
|
|
|
} else {
|
|
|
|
vlog_info("[DATA] ", pattern, ap);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Fatal error. */
|
|
|
|
if(strchr(pattern, '\n') != NULL) {
|
|
|
|
++ERROR_COUNT;
|
2010-05-06 22:22:38 +00:00
|
|
|
} else {
|
|
|
|
++ONE_ERROR;
|
2009-06-09 21:28:13 +00:00
|
|
|
}
|
|
|
|
vlog_err(NULL, pattern, ap); /* no need for prefix in default case */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
log_info(const char* pattern, ...)
|
2002-09-17 19:45:03 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, pattern);
|
|
|
|
vlog_info(NULL, pattern, ap);
|
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
log_verbose(const char* pattern, ...)
|
2002-09-17 19:45:03 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, pattern);
|
|
|
|
vlog_verbose(NULL, pattern, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
log_data_err(const char* pattern, ...)
|
2002-09-17 19:45:03 +00:00
|
|
|
{
|
2007-12-07 10:49:34 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, pattern);
|
2002-09-17 19:45:03 +00:00
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
go_offline_err();
|
2007-12-07 10:49:34 +00:00
|
|
|
++DATA_ERROR_COUNT; /* for informational message at the end */
|
2002-09-17 19:45:03 +00:00
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
if(WARN_ON_MISSING_DATA == 0) {
|
|
|
|
/* Fatal error. */
|
|
|
|
if(strchr(pattern, '\n') != NULL) {
|
|
|
|
++ERROR_COUNT;
|
|
|
|
}
|
|
|
|
vlog_err(NULL, pattern, ap); /* no need for prefix in default case */
|
|
|
|
} else {
|
2009-06-09 21:28:13 +00:00
|
|
|
vlog_info("[DATA] ", pattern, ap);
|
2002-09-17 19:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
/*
|
|
|
|
* Tracing functions.
|
|
|
|
*/
|
|
|
|
static int traceFnNestingDepth = 0;
|
|
|
|
U_CDECL_BEGIN
|
|
|
|
static void U_CALLCONV TraceEntry(const void *context, int32_t fnNumber) {
|
|
|
|
char buf[500];
|
|
|
|
utrace_format(buf, sizeof(buf), traceFnNestingDepth*3, "%s() enter.\n", utrace_functionName(fnNumber)); buf[sizeof(buf)-1]=0;
|
|
|
|
fputs(buf, stdout);
|
|
|
|
traceFnNestingDepth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void U_CALLCONV TraceExit(const void *context, int32_t fnNumber, const char *fmt, va_list args) { char buf[500];
|
|
|
|
|
|
|
|
if (traceFnNestingDepth>0) {
|
|
|
|
traceFnNestingDepth--;
|
|
|
|
}
|
|
|
|
utrace_format(buf, sizeof(buf), traceFnNestingDepth*3, "%s() ", utrace_functionName(fnNumber)); buf[sizeof(buf)-1]=0;
|
|
|
|
fputs(buf, stdout);
|
|
|
|
utrace_vformat(buf, sizeof(buf), traceFnNestingDepth*3, fmt, args);
|
|
|
|
buf[sizeof(buf)-1]=0;
|
|
|
|
fputs(buf, stdout);
|
|
|
|
putc('\n', stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void U_CALLCONV TraceData(const void *context, int32_t fnNumber,
|
|
|
|
int32_t level, const char *fmt, va_list args) {
|
|
|
|
char buf[500];
|
|
|
|
utrace_vformat(buf, sizeof(buf), traceFnNestingDepth*3, fmt, args);
|
|
|
|
buf[sizeof(buf)-1]=0;
|
|
|
|
fputs(buf, stdout);
|
|
|
|
putc('\n', stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *U_CALLCONV ctest_libMalloc(const void *context, size_t size) {
|
|
|
|
/*if (VERBOSITY) {
|
|
|
|
printf("Allocated %ld\n", (long)size);
|
|
|
|
}*/
|
2008-02-10 20:17:14 +00:00
|
|
|
if (MINIMUM_MEMORY_SIZE_FAILURE <= size && size <= MAXIMUM_MEMORY_SIZE_FAILURE) {
|
2007-12-07 10:49:34 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
umtx_atomic_inc(&ALLOCATION_COUNT);
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
static void *U_CALLCONV ctest_libRealloc(const void *context, void *mem, size_t size) {
|
|
|
|
/*if (VERBOSITY) {
|
|
|
|
printf("Reallocated %ld\n", (long)size);
|
|
|
|
}*/
|
2008-02-10 20:17:14 +00:00
|
|
|
if (MINIMUM_MEMORY_SIZE_FAILURE <= size && size <= MAXIMUM_MEMORY_SIZE_FAILURE) {
|
2007-12-14 09:23:07 +00:00
|
|
|
/*free(mem);*/ /* Realloc doesn't free on failure. */
|
2007-12-07 10:49:34 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (mem == NULL) {
|
2008-02-19 20:56:50 +00:00
|
|
|
/* New allocation. */
|
2007-12-07 10:49:34 +00:00
|
|
|
umtx_atomic_inc(&ALLOCATION_COUNT);
|
|
|
|
}
|
|
|
|
return realloc(mem, size);
|
|
|
|
}
|
|
|
|
static void U_CALLCONV ctest_libFree(const void *context, void *mem) {
|
2008-02-19 20:56:50 +00:00
|
|
|
if (mem != NULL) {
|
|
|
|
umtx_atomic_dec(&ALLOCATION_COUNT);
|
|
|
|
}
|
2007-12-07 10:49:34 +00:00
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
|
2004-07-16 15:05:14 +00:00
|
|
|
int T_CTEST_EXPORT2
|
2008-06-12 01:01:00 +00:00
|
|
|
initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
int i;
|
|
|
|
int doList = FALSE;
|
2008-06-12 01:01:00 +00:00
|
|
|
int argSkip = 0;
|
2000-11-30 20:02:51 +00:00
|
|
|
|
|
|
|
VERBOSITY = FALSE;
|
|
|
|
ERR_MSG = TRUE;
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
ARGV_0=argv[0];
|
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
for( i=1; i<argc; i++)
|
|
|
|
{
|
|
|
|
if ( argv[i][0] == '/' )
|
|
|
|
{
|
2007-12-07 10:49:34 +00:00
|
|
|
/* We don't run the tests here. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if ((strcmp( argv[i], "-a") == 0) || (strcmp(argv[i],"-all") == 0))
|
|
|
|
{
|
|
|
|
/* We don't run the tests here. */
|
|
|
|
continue;
|
2000-11-30 20:02:51 +00:00
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
else if (strcmp( argv[i], "-v" )==0 || strcmp( argv[i], "-verbose")==0)
|
2000-11-30 20:02:51 +00:00
|
|
|
{
|
|
|
|
VERBOSITY = TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp( argv[i], "-l" )==0 )
|
|
|
|
{
|
|
|
|
doList = TRUE;
|
|
|
|
}
|
2003-02-20 01:16:40 +00:00
|
|
|
else if (strcmp( argv[i], "-e1") == 0)
|
|
|
|
{
|
|
|
|
QUICK = -1;
|
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
else if (strcmp( argv[i], "-e") ==0)
|
2000-11-30 20:02:51 +00:00
|
|
|
{
|
2003-02-20 01:16:40 +00:00
|
|
|
QUICK = 0;
|
2000-11-30 20:02:51 +00:00
|
|
|
}
|
2002-09-17 19:45:03 +00:00
|
|
|
else if (strcmp( argv[i], "-w") ==0)
|
|
|
|
{
|
|
|
|
WARN_ON_MISSING_DATA = TRUE;
|
|
|
|
}
|
2007-12-07 10:49:34 +00:00
|
|
|
else if (strcmp( argv[i], "-m") ==0)
|
|
|
|
{
|
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
if (i+1 < argc) {
|
|
|
|
char *endPtr = NULL;
|
|
|
|
i++;
|
2008-02-10 20:17:14 +00:00
|
|
|
MINIMUM_MEMORY_SIZE_FAILURE = (size_t)strtol(argv[i], &endPtr, 10);
|
2007-12-07 10:49:34 +00:00
|
|
|
if (endPtr == argv[i]) {
|
|
|
|
printf("Can't parse %s\n", argv[i]);
|
2008-02-10 20:17:14 +00:00
|
|
|
help(argv[0]);
|
2007-12-07 10:49:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-10 20:17:14 +00:00
|
|
|
if (*endPtr == '-') {
|
|
|
|
char *maxPtr = endPtr+1;
|
|
|
|
endPtr = NULL;
|
|
|
|
MAXIMUM_MEMORY_SIZE_FAILURE = (size_t)strtol(maxPtr, &endPtr, 10);
|
|
|
|
if (endPtr == argv[i]) {
|
|
|
|
printf("Can't parse %s\n", argv[i]);
|
|
|
|
help(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-12-07 10:49:34 +00:00
|
|
|
}
|
|
|
|
/* Use the default value */
|
2008-02-10 20:17:14 +00:00
|
|
|
u_setMemoryFunctions(NULL, ctest_libMalloc, ctest_libRealloc, ctest_libFree, &errorCode);
|
2007-12-07 10:49:34 +00:00
|
|
|
if (U_FAILURE(errorCode)) {
|
|
|
|
printf("u_setMemoryFunctions returned %s\n", u_errorName(errorCode));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
else if(strcmp( argv[i], "-n") == 0 || strcmp( argv[i], "-no_err_msg") == 0)
|
2000-11-30 20:02:51 +00:00
|
|
|
{
|
|
|
|
ERR_MSG = FALSE;
|
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
else if (strcmp( argv[i], "-r") == 0)
|
2000-11-30 20:02:51 +00:00
|
|
|
{
|
2002-01-16 04:33:33 +00:00
|
|
|
if (!REPEAT_TESTS_INIT) {
|
|
|
|
REPEAT_TESTS++;
|
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
else if (strcmp( argv[i], "-x") == 0)
|
|
|
|
{
|
|
|
|
if(++i>=argc) {
|
|
|
|
printf("* Error: '-x' option requires an argument. usage: '-x outfile.xml'.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(ctest_xml_setFileName(argv[i])) { /* set the name */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-09-20 01:21:23 +00:00
|
|
|
else if (strcmp( argv[i], "-t_info") == 0) {
|
|
|
|
ICU_TRACE = UTRACE_INFO;
|
|
|
|
}
|
|
|
|
else if (strcmp( argv[i], "-t_error") == 0) {
|
|
|
|
ICU_TRACE = UTRACE_ERROR;
|
|
|
|
}
|
|
|
|
else if (strcmp( argv[i], "-t_warn") == 0) {
|
|
|
|
ICU_TRACE = UTRACE_WARNING;
|
|
|
|
}
|
|
|
|
else if (strcmp( argv[i], "-t_verbose") == 0) {
|
|
|
|
ICU_TRACE = UTRACE_VERBOSE;
|
|
|
|
}
|
2003-11-26 03:09:51 +00:00
|
|
|
else if (strcmp( argv[i], "-t_oc") == 0) {
|
|
|
|
ICU_TRACE = UTRACE_OPEN_CLOSE;
|
|
|
|
}
|
2003-09-20 01:21:23 +00:00
|
|
|
else if (strcmp( argv[i], "-h" )==0 || strcmp( argv[i], "--help" )==0)
|
2000-11-30 20:02:51 +00:00
|
|
|
{
|
|
|
|
help( argv[0] );
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-12 01:01:00 +00:00
|
|
|
else if (argHandler != NULL && (argSkip = argHandler(i, argc, argv, context)) > 0)
|
|
|
|
{
|
|
|
|
i += argSkip - 1;
|
|
|
|
}
|
2000-11-30 20:02:51 +00:00
|
|
|
else
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
printf("* unknown option: %s\n", argv[i]);
|
|
|
|
help( argv[0] );
|
2007-12-07 10:49:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ICU_TRACE != UTRACE_OFF) {
|
|
|
|
utrace_setFunctions(NULL, TraceEntry, TraceExit, TraceData);
|
|
|
|
utrace_setLevel(ICU_TRACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1; /* total error count */
|
|
|
|
}
|
|
|
|
|
|
|
|
int T_CTEST_EXPORT2
|
|
|
|
runTestRequest(const TestNode* root,
|
|
|
|
int argc,
|
|
|
|
const char* const argv[])
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This main will parse the l, v, h, n, and path arguments
|
|
|
|
*/
|
|
|
|
const TestNode* toRun;
|
|
|
|
int i;
|
|
|
|
int doList = FALSE;
|
|
|
|
int subtreeOptionSeen = FALSE;
|
|
|
|
|
|
|
|
int errorCount = 0;
|
|
|
|
|
|
|
|
toRun = root;
|
|
|
|
|
2010-07-12 15:24:57 +00:00
|
|
|
if(ctest_xml_init(ARGV_0)) {
|
|
|
|
return 1; /* couldn't fire up XML thing */
|
|
|
|
}
|
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
for( i=1; i<argc; i++)
|
|
|
|
{
|
|
|
|
if ( argv[i][0] == '/' )
|
|
|
|
{
|
|
|
|
printf("Selecting subtree '%s'\n", argv[i]);
|
|
|
|
|
|
|
|
if ( argv[i][1] == 0 )
|
|
|
|
toRun = root;
|
|
|
|
else
|
|
|
|
toRun = getTest(root, argv[i]);
|
|
|
|
|
|
|
|
if ( toRun == NULL )
|
|
|
|
{
|
|
|
|
printf("* Could not find any matching subtree\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
ON_LINE=FALSE; /* just in case */
|
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
if( doList == TRUE)
|
|
|
|
showTests(toRun);
|
|
|
|
else
|
|
|
|
runTests(toRun);
|
|
|
|
|
2010-05-06 22:22:38 +00:00
|
|
|
ON_LINE=FALSE; /* just in case */
|
|
|
|
|
2007-12-07 10:49:34 +00:00
|
|
|
errorCount += ERROR_COUNT;
|
|
|
|
|
|
|
|
subtreeOptionSeen = TRUE;
|
2008-04-14 22:38:10 +00:00
|
|
|
} else if ((strcmp( argv[i], "-a") == 0) || (strcmp(argv[i],"-all") == 0)) {
|
2007-12-07 10:49:34 +00:00
|
|
|
subtreeOptionSeen=FALSE;
|
2008-04-14 22:38:10 +00:00
|
|
|
} else if (strcmp( argv[i], "-l") == 0) {
|
|
|
|
doList = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2007-12-07 10:49:34 +00:00
|
|
|
/* else option already handled by initArgs */
|
2000-11-30 20:02:51 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
if( subtreeOptionSeen == FALSE) /* no other subtree given, run the default */
|
|
|
|
{
|
2010-05-06 22:22:38 +00:00
|
|
|
ON_LINE=FALSE; /* just in case */
|
1999-08-16 21:50:52 +00:00
|
|
|
if( doList == TRUE)
|
2000-11-30 20:02:51 +00:00
|
|
|
showTests(toRun);
|
1999-08-16 21:50:52 +00:00
|
|
|
else
|
2000-11-30 20:02:51 +00:00
|
|
|
runTests(toRun);
|
2010-05-06 22:22:38 +00:00
|
|
|
ON_LINE=FALSE; /* just in case */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
errorCount += ERROR_COUNT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-30 20:02:51 +00:00
|
|
|
if( ( doList == FALSE ) && ( errorCount > 0 ) )
|
|
|
|
printf(" Total errors: %d\n", errorCount );
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 04:33:33 +00:00
|
|
|
REPEAT_TESTS_INIT = 1;
|
2010-07-12 15:24:57 +00:00
|
|
|
|
|
|
|
if(ctest_xml_fini()) {
|
|
|
|
errorCount++;
|
|
|
|
}
|
2002-01-16 04:33:33 +00:00
|
|
|
|
2000-11-30 20:02:51 +00:00
|
|
|
return errorCount; /* total error count */
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display program invocation arguments
|
|
|
|
*/
|
|
|
|
|
2000-08-11 02:08:59 +00:00
|
|
|
static void help ( const char *argv0 )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-09-20 01:21:23 +00:00
|
|
|
printf("Usage: %s [ -l ] [ -v ] [ -verbose] [-a] [ -all] [-n] [ -no_err_msg]\n"
|
2008-02-10 20:17:14 +00:00
|
|
|
" [ -h ] [-t_info | -t_error | -t_warn | -t_oc | -t_verbose] [-m n[-q] ]\n"
|
|
|
|
" [ /path/to/test ]\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
argv0);
|
2003-09-20 01:21:23 +00:00
|
|
|
printf(" -l To get a list of test names\n");
|
|
|
|
printf(" -e to do exhaustive testing\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
printf(" -verbose To turn ON verbosity\n");
|
2003-09-20 01:21:23 +00:00
|
|
|
printf(" -v To turn ON verbosity(same as -verbose)\n");
|
2010-07-12 15:24:57 +00:00
|
|
|
printf(" -x file.xml Write junit format output to file.xml\n");
|
2003-09-20 01:21:23 +00:00
|
|
|
printf(" -h To print this message\n");
|
|
|
|
printf(" -n To turn OFF printing error messages\n");
|
|
|
|
printf(" -w Don't fail on data-loading errs, just warn. Useful if\n"
|
2002-09-17 19:45:03 +00:00
|
|
|
" user has reduced/changed the common set of ICU data \n");
|
2003-11-26 03:09:51 +00:00
|
|
|
printf(" -t_info | -t_error | -t_warn | -t_oc | -t_verbose Enable ICU tracing\n");
|
1999-08-16 21:50:52 +00:00
|
|
|
printf(" -no_err_msg (same as -n) \n");
|
2008-02-10 20:17:14 +00:00
|
|
|
printf(" -m n[-q] Min-Max memory size that will cause an allocation failure.\n");
|
|
|
|
printf(" The default is the maximum value of size_t. Max is optional.\n");
|
|
|
|
printf(" -r Repeat tests after calling u_cleanup \n");
|
|
|
|
printf(" [/subtest] To run a subtest \n");
|
1999-08-16 21:50:52 +00:00
|
|
|
printf(" eg: to run just the utility tests type: cintltest /tsutil) \n");
|
|
|
|
}
|
|
|
|
|
2010-04-07 16:18:38 +00:00
|
|
|
int32_t T_CTEST_EXPORT2
|
|
|
|
getTestOption ( int32_t testOption ) {
|
|
|
|
switch (testOption) {
|
|
|
|
case VERBOSITY_OPTION:
|
|
|
|
return VERBOSITY;
|
|
|
|
case WARN_ON_MISSING_DATA_OPTION:
|
|
|
|
return WARN_ON_MISSING_DATA;
|
|
|
|
case QUICK_OPTION:
|
|
|
|
return QUICK;
|
|
|
|
case REPEAT_TESTS_OPTION:
|
|
|
|
return REPEAT_TESTS;
|
|
|
|
case ERR_MSG_OPTION:
|
|
|
|
return ERR_MSG;
|
|
|
|
case ICU_TRACE_OPTION:
|
|
|
|
return ICU_TRACE;
|
|
|
|
default :
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_CTEST_EXPORT2
|
|
|
|
setTestOption ( int32_t testOption, int32_t value) {
|
|
|
|
if (value == DECREMENT_OPTION_VALUE) {
|
|
|
|
value = getTestOption(testOption);
|
|
|
|
--value;
|
|
|
|
}
|
|
|
|
switch (testOption) {
|
|
|
|
case VERBOSITY_OPTION:
|
|
|
|
VERBOSITY = value;
|
|
|
|
break;
|
|
|
|
case WARN_ON_MISSING_DATA_OPTION:
|
|
|
|
WARN_ON_MISSING_DATA = value;
|
|
|
|
break;
|
|
|
|
case QUICK_OPTION:
|
|
|
|
QUICK = value;
|
|
|
|
break;
|
|
|
|
case REPEAT_TESTS_OPTION:
|
|
|
|
REPEAT_TESTS = value;
|
|
|
|
break;
|
|
|
|
case ICU_TRACE_OPTION:
|
|
|
|
ICU_TRACE = value;
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-12 15:24:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ================== JUnit support ================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
T_CTEST_EXPORT2
|
|
|
|
ctest_xml_setFileName(const char *name) {
|
|
|
|
XML_FILE_NAME=name;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
T_CTEST_EXPORT2
|
|
|
|
ctest_xml_init(const char *rootName) {
|
|
|
|
if(!XML_FILE_NAME) return 0;
|
|
|
|
XML_FILE = fopen(XML_FILE_NAME,"w");
|
|
|
|
if(!XML_FILE) {
|
|
|
|
perror("fopen");
|
|
|
|
fprintf(stderr," Error: couldn't open XML output file %s\n", XML_FILE_NAME);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
while(*rootName&&!isalnum(*rootName)) {
|
|
|
|
rootName++;
|
|
|
|
}
|
|
|
|
strcpy(XML_PREFIX,rootName);
|
|
|
|
{
|
|
|
|
char *p = XML_PREFIX+strlen(XML_PREFIX);
|
|
|
|
for(p--;*p&&p>XML_PREFIX&&!isalnum(*p);p--) {
|
|
|
|
*p=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* write prefix */
|
|
|
|
fprintf(XML_FILE, "<testsuite name=\"%s\">\n", XML_PREFIX);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
T_CTEST_EXPORT2
|
|
|
|
ctest_xml_fini(void) {
|
|
|
|
if(!XML_FILE) return 0;
|
|
|
|
|
|
|
|
fprintf(XML_FILE, "</testsuite>\n");
|
|
|
|
fclose(XML_FILE);
|
|
|
|
printf(" ( test results written to %s )\n", XML_FILE_NAME);
|
|
|
|
XML_FILE=0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
T_CTEST_EXPORT2
|
|
|
|
ctest_xml_testcase(const char *classname, const char *name, const char *time, const char *failMsg) {
|
|
|
|
if(!XML_FILE) return 0;
|
|
|
|
|
|
|
|
fprintf(XML_FILE, "\t<testcase classname=\"%s:%s\" name=\"%s:%s\" time=\"%s\"", XML_PREFIX, classname, XML_PREFIX, name, time);
|
|
|
|
if(failMsg) {
|
|
|
|
fprintf(XML_FILE, ">\n\t\t<failure type=\"err\" message=\"%s\"/>\n\t</testcase>\n", failMsg);
|
|
|
|
} else {
|
|
|
|
fprintf(XML_FILE, "/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|