1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************************
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
4fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius*   Copyright (C) 1996-2014, International Business Machines
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************************
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h>
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <assert.h>
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdarg.h>
1427f654740f2a26ad62a5c155af9199af9e69b889claireho#include <ctype.h>
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utrace.h"
1785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "unicode/uclean.h"
1827f654740f2a26ad62a5c155af9199af9e69b889claireho#include "putilimp.h"
1959d709d503bab6e2b61931737e662dd293b40578ccornelius#include "udbgutil.h"
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* NOTES:
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   3/20/1999 srl - strncpy called w/o setting nulls at the end
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAXTESTNAME 128
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAXTESTS  512
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAX_TEST_LOG 4096
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2927f654740f2a26ad62a5c155af9199af9e69b889claireho/**
3027f654740f2a26ad62a5c155af9199af9e69b889claireho *  How may columns to indent the 'OK' markers.
3127f654740f2a26ad62a5c155af9199af9e69b889claireho */
3227f654740f2a26ad62a5c155af9199af9e69b889claireho#define FLAG_INDENT 45
3327f654740f2a26ad62a5c155af9199af9e69b889claireho/**
3427f654740f2a26ad62a5c155af9199af9e69b889claireho *   How many lines of scrollage can go by before we need to remind the user what the test is.
3527f654740f2a26ad62a5c155af9199af9e69b889claireho */
3627f654740f2a26ad62a5c155af9199af9e69b889claireho#define PAGE_SIZE_LIMIT 25
3727f654740f2a26ad62a5c155af9199af9e69b889claireho
3827f654740f2a26ad62a5c155af9199af9e69b889claireho#ifndef SHOW_TIMES
3927f654740f2a26ad62a5c155af9199af9e69b889claireho#define SHOW_TIMES 1
4027f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
4127f654740f2a26ad62a5c155af9199af9e69b889claireho
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct TestNode
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  void (*test)(void);
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  struct TestNode* sibling;
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  struct TestNode* child;
4785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  char name[1]; /* This is dynamically allocated off the end with malloc. */
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const struct TestNode* currentTest;
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef enum { RUNTESTS, SHOWTESTS } TestMode;
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define TEST_SEPARATOR '/'
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef C_TEST_IMPL
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define C_TEST_IMPL
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ctest.h"
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char ERROR_LOG[MAX_TEST_LOG][MAXTESTNAME];
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Local prototypes */
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic TestNode* addTestNode( TestNode *root, const char *name );
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
6785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic TestNode *createTestNode(const char* name, int32_t nameLen);
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int strncmp_nullcheck( const char* s1,
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                  const char* s2,
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                  int n );
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void getNextLevel( const char* name,
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              int* nameLen,
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              const char** nextName );
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
7727f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void iterateTestsWithLevel( const TestNode *root, int depth,
7827f654740f2a26ad62a5c155af9199af9e69b889claireho                   const TestNode** nodeList,
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                   TestMode mode);
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void help ( const char *argv0 );
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Do the work of logging an error. Doesn't increase the error count.
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @prefix optional prefix prepended to message, or NULL.
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param pattern printf style pattern
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param ap vprintf style arg list
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void vlog_err(const char *prefix, const char *pattern, va_list ap);
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void vlog_verbose(const char *prefix, const char *pattern, va_list ap);
9259d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic UBool vlog_knownIssue(const char *ticket, const char *pattern, va_list ap);
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
9427f654740f2a26ad62a5c155af9199af9e69b889claireho/**
9527f654740f2a26ad62a5c155af9199af9e69b889claireho * Log test structure, with indent
9627f654740f2a26ad62a5c155af9199af9e69b889claireho * @param pattern printf pattern
9727f654740f2a26ad62a5c155af9199af9e69b889claireho */
9827f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void log_testinfo_i(const char *pattern, ...);
9927f654740f2a26ad62a5c155af9199af9e69b889claireho
10027f654740f2a26ad62a5c155af9199af9e69b889claireho/**
10127f654740f2a26ad62a5c155af9199af9e69b889claireho * Log test structure, NO indent
10227f654740f2a26ad62a5c155af9199af9e69b889claireho * @param pattern printf pattern
10327f654740f2a26ad62a5c155af9199af9e69b889claireho */
10427f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void log_testinfo(const char *pattern, ...);
10527f654740f2a26ad62a5c155af9199af9e69b889claireho
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* If we need to make the framework multi-thread safe
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   we need to pass around the following vars
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int ERRONEOUS_FUNCTION_COUNT = 0;
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int ERROR_COUNT = 0; /* Count of errors from all tests. */
11127f654740f2a26ad62a5c155af9199af9e69b889clairehostatic int ONE_ERROR = 0; /* were there any other errors? */
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int DATA_ERROR_COUNT = 0; /* count of data related errors or warnings */
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int INDENT_LEVEL = 0;
11459d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic UBool NO_KNOWN = FALSE;
11559d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic void *knownList = NULL;
11659d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic char gTestName[1024] = "";
11727f654740f2a26ad62a5c155af9199af9e69b889clairehostatic UBool ON_LINE = FALSE; /* are we on the top line with our test name? */
11827f654740f2a26ad62a5c155af9199af9e69b889clairehostatic UBool HANGING_OUTPUT = FALSE; /* did the user leave us without a trailing \n ? */
11927f654740f2a26ad62a5c155af9199af9e69b889clairehostatic int GLOBAL_PRINT_COUNT = 0; /* global count of printouts */
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint REPEAT_TESTS_INIT = 0; /* Was REPEAT_TESTS initialized? */
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint REPEAT_TESTS = 1; /* Number of times to run the test */
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint VERBOSITY = 0; /* be No-verbose by default */
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint ERR_MSG =1; /* error messages will be displayed by default*/
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint QUICK = 1;  /* Skip some of the slower tests? */
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint WARN_ON_MISSING_DATA = 0; /* Reduce data errs to warnings? */
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUTraceLevel ICU_TRACE = UTRACE_OFF;  /* ICU tracing level */
12785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hosize_t MINIMUM_MEMORY_SIZE_FAILURE = (size_t)-1; /* Minimum library memory allocation window that will fail. */
12885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hosize_t MAXIMUM_MEMORY_SIZE_FAILURE = (size_t)-1; /* Maximum library memory allocation window that will fail. */
12927f654740f2a26ad62a5c155af9199af9e69b889clairehostatic const char *ARGV_0 = "[ALL]";
13027f654740f2a26ad62a5c155af9199af9e69b889clairehostatic const char *XML_FILE_NAME=NULL;
13127f654740f2a26ad62a5c155af9199af9e69b889clairehostatic char XML_PREFIX[256];
13259d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic const char *SUMMARY_FILE = NULL;
13327f654740f2a26ad62a5c155af9199af9e69b889clairehoFILE *XML_FILE = NULL;
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*-------------------------------------------*/
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* strncmp that also makes sure there's a \0 at s2[0] */
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int strncmp_nullcheck( const char* s1,
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               const char* s2,
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               int n )
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (((int)strlen(s2) >= n) && s2[n] != 0) {
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return 3; /* null check fails */
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else {
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return strncmp ( s1, s2, n );
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void getNextLevel( const char* name,
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           int* nameLen,
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           const char** nextName )
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Get the next component of the name */
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    *nextName = strchr(name, TEST_SEPARATOR);
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if( *nextName != 0 )
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char n[255];
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *nameLen = (int)((*nextName) - name);
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        (*nextName)++; /* skip '/' */
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strncpy(n, name, *nameLen);
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        n[*nameLen] = 0;
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*printf("->%s-< [%d] -> [%s]\n", name, *nameLen, *nextName);*/
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else {
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *nameLen = (int)strlen(name);
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic TestNode *createTestNode(const char* name, int32_t nameLen)
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNode *newNode;
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    newNode = (TestNode*)malloc(sizeof(TestNode) + (nameLen + 1));
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    newNode->test = NULL;
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    newNode->sibling = NULL;
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    newNode->child = NULL;
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    strncpy( newNode->name, name, nameLen );
18185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    newNode->name[nameLen] = 0;
18285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return  newNode;
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucleanUpTestTree(TestNode *tn)
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(tn->child != NULL) {
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        cleanUpTestTree(tn->child);
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(tn->sibling != NULL) {
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        cleanUpTestTree(tn->sibling);
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(tn);
19727f654740f2a26ad62a5c155af9199af9e69b889claireho
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddTest(TestNode** root,
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TestFunctionPtr test,
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* name )
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNode *newNode;
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*if this is the first Test created*/
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (*root == NULL)
21085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        *root = createTestNode("", 0);
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    newNode = addTestNode( *root, name );
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    assert(newNode != 0 );
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*  printf("addTest: nreName = %s\n", newNode->name );*/
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    newNode->test = test;
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* non recursive insert function */
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic TestNode *addTestNode ( TestNode *root, const char *name )
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* nextName;
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNode *nextNode, *curNode;
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int nameLen; /* length of current 'name' */
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* remove leading slash */
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if ( *name == TEST_SEPARATOR )
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        name++;
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    curNode = root;
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(;;)
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Start with the next child */
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        nextNode = curNode->child;
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        getNextLevel ( name, &nameLen, &nextName );
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*      printf("* %s\n", name );*/
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* if nextNode is already null, then curNode has no children
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        -- add them */
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if( nextNode == NULL )
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* Add all children of the node */
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            do
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            {
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* Get the next component of the name */
24985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                getNextLevel(name, &nameLen, &nextName);
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* update curName to have the next name segment */
25285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                curNode->child = createTestNode(name, nameLen);
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* printf("*** added %s\n", curNode->child->name );*/
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                curNode = curNode->child;
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                name = nextName;
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            while( name != NULL );
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return curNode;
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Search across for the name */
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        while (strncmp_nullcheck ( name, nextNode->name, nameLen) != 0 )
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            curNode = nextNode;
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            nextNode = nextNode -> sibling;
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if ( nextNode == NULL )
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            {
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* Did not find 'name' on this level. */
27185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                nextNode = createTestNode(name, nameLen);
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                curNode->sibling = nextNode;
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                break;
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* nextNode matches 'name' */
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (nextName == NULL) /* end of the line */
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return nextNode;
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Loop again with the next item */
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        name = nextName;
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        curNode = nextNode;
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
29027f654740f2a26ad62a5c155af9199af9e69b889claireho/**
29127f654740f2a26ad62a5c155af9199af9e69b889claireho * Log the time taken. May not output anything.
29227f654740f2a26ad62a5c155af9199af9e69b889claireho * @param deltaTime change in time
29327f654740f2a26ad62a5c155af9199af9e69b889claireho */
29427f654740f2a26ad62a5c155af9199af9e69b889clairehovoid T_CTEST_EXPORT2 str_timeDelta(char *str, UDate deltaTime) {
29527f654740f2a26ad62a5c155af9199af9e69b889claireho  if (deltaTime > 110000.0 ) {
29627f654740f2a26ad62a5c155af9199af9e69b889claireho    double mins = uprv_floor(deltaTime/60000.0);
29727f654740f2a26ad62a5c155af9199af9e69b889claireho    sprintf(str, "[(%.0fm %.1fs)]", mins, (deltaTime-(mins*60000.0))/1000.0);
29827f654740f2a26ad62a5c155af9199af9e69b889claireho  } else if (deltaTime > 1500.0) {
29927f654740f2a26ad62a5c155af9199af9e69b889claireho    sprintf(str, "((%.1fs))", deltaTime/1000.0);
30027f654740f2a26ad62a5c155af9199af9e69b889claireho  } else if(deltaTime>900.0) {
30127f654740f2a26ad62a5c155af9199af9e69b889claireho    sprintf(str, "( %.2fs )", deltaTime/1000.0);
30227f654740f2a26ad62a5c155af9199af9e69b889claireho  } else if(deltaTime > 5.0) {
30327f654740f2a26ad62a5c155af9199af9e69b889claireho    sprintf(str, " (%.0fms) ", deltaTime);
30427f654740f2a26ad62a5c155af9199af9e69b889claireho  } else {
30527f654740f2a26ad62a5c155af9199af9e69b889claireho    str[0]=0; /* at least terminate it. */
30627f654740f2a26ad62a5c155af9199af9e69b889claireho  }
30727f654740f2a26ad62a5c155af9199af9e69b889claireho}
30827f654740f2a26ad62a5c155af9199af9e69b889claireho
30927f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void print_timeDelta(UDate deltaTime) {
31027f654740f2a26ad62a5c155af9199af9e69b889claireho  char str[256];
31127f654740f2a26ad62a5c155af9199af9e69b889claireho  str_timeDelta(str, deltaTime);
31227f654740f2a26ad62a5c155af9199af9e69b889claireho  if(str[0]) {
31327f654740f2a26ad62a5c155af9199af9e69b889claireho    printf("%s", str);
31427f654740f2a26ad62a5c155af9199af9e69b889claireho  }
31527f654740f2a26ad62a5c155af9199af9e69b889claireho}
31627f654740f2a26ad62a5c155af9199af9e69b889claireho
31727f654740f2a26ad62a5c155af9199af9e69b889claireho/**
31827f654740f2a26ad62a5c155af9199af9e69b889claireho * Run or list tests (according to mode) in a subtree.
31927f654740f2a26ad62a5c155af9199af9e69b889claireho *
32027f654740f2a26ad62a5c155af9199af9e69b889claireho * @param root root of the subtree to operate on
32127f654740f2a26ad62a5c155af9199af9e69b889claireho * @param depth The depth of this tree (0=root)
32227f654740f2a26ad62a5c155af9199af9e69b889claireho * @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.
32327f654740f2a26ad62a5c155af9199af9e69b889claireho * @param mode what mode we are operating in.
32427f654740f2a26ad62a5c155af9199af9e69b889claireho */
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void iterateTestsWithLevel ( const TestNode* root,
32627f654740f2a26ad62a5c155af9199af9e69b889claireho                 int depth,
32727f654740f2a26ad62a5c155af9199af9e69b889claireho                 const TestNode** nodeList,
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 TestMode mode)
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i;
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char pathToFunction[MAXTESTNAME] = "";
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char separatorString[2] = { TEST_SEPARATOR, '\0'};
33427f654740f2a26ad62a5c155af9199af9e69b889claireho#if SHOW_TIMES
33527f654740f2a26ad62a5c155af9199af9e69b889claireho    UDate allStartTime = -1, allStopTime = -1;
33627f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
33727f654740f2a26ad62a5c155af9199af9e69b889claireho
33827f654740f2a26ad62a5c155af9199af9e69b889claireho    if(depth<2) {
33927f654740f2a26ad62a5c155af9199af9e69b889claireho      allStartTime = uprv_getRawUTCtime();
34027f654740f2a26ad62a5c155af9199af9e69b889claireho    }
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if ( root == NULL )
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
34527f654740f2a26ad62a5c155af9199af9e69b889claireho    /* record the current root node, and increment depth. */
34627f654740f2a26ad62a5c155af9199af9e69b889claireho    nodeList[depth++] = root;
34727f654740f2a26ad62a5c155af9199af9e69b889claireho    /* depth is now the depth of root's children. */
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
34927f654740f2a26ad62a5c155af9199af9e69b889claireho    /* Collect the 'path' to the current subtree. */
35027f654740f2a26ad62a5c155af9199af9e69b889claireho    for ( i=0;i<(depth-1);i++ )
351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
35227f654740f2a26ad62a5c155af9199af9e69b889claireho        strcat(pathToFunction, nodeList[i]->name);
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcat(pathToFunction, separatorString);
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
35527f654740f2a26ad62a5c155af9199af9e69b889claireho    strcat(pathToFunction, nodeList[i]->name); /* including 'root' */
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35727f654740f2a26ad62a5c155af9199af9e69b889claireho    /* print test name and space. */
35827f654740f2a26ad62a5c155af9199af9e69b889claireho    INDENT_LEVEL = depth-1;
35927f654740f2a26ad62a5c155af9199af9e69b889claireho    if(root->name[0]) {
36027f654740f2a26ad62a5c155af9199af9e69b889claireho    	log_testinfo_i("%s ", root->name);
36127f654740f2a26ad62a5c155af9199af9e69b889claireho    } else {
36227f654740f2a26ad62a5c155af9199af9e69b889claireho    	log_testinfo_i("(%s) ", ARGV_0);
36327f654740f2a26ad62a5c155af9199af9e69b889claireho    }
36427f654740f2a26ad62a5c155af9199af9e69b889claireho    ON_LINE = TRUE;  /* we are still on the line with the test name */
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36627f654740f2a26ad62a5c155af9199af9e69b889claireho
36727f654740f2a26ad62a5c155af9199af9e69b889claireho    if ( (mode == RUNTESTS) &&
36827f654740f2a26ad62a5c155af9199af9e69b889claireho		(root->test != NULL))  /* if root is a leaf node, run it */
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int myERROR_COUNT = ERROR_COUNT;
37127f654740f2a26ad62a5c155af9199af9e69b889claireho        int myGLOBAL_PRINT_COUNT = GLOBAL_PRINT_COUNT;
37227f654740f2a26ad62a5c155af9199af9e69b889claireho#if SHOW_TIMES
37327f654740f2a26ad62a5c155af9199af9e69b889claireho        UDate startTime, stopTime;
37427f654740f2a26ad62a5c155af9199af9e69b889claireho        char timeDelta[256];
37527f654740f2a26ad62a5c155af9199af9e69b889claireho        char timeSeconds[256];
37627f654740f2a26ad62a5c155af9199af9e69b889claireho#else
37727f654740f2a26ad62a5c155af9199af9e69b889claireho        const char timeDelta[] = "(unknown)";
37827f654740f2a26ad62a5c155af9199af9e69b889claireho        const char timeSeconds[] = "0.000";
37927f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        currentTest = root;
38127f654740f2a26ad62a5c155af9199af9e69b889claireho        INDENT_LEVEL = depth;  /* depth of subitems */
38227f654740f2a26ad62a5c155af9199af9e69b889claireho        ONE_ERROR=0;
38327f654740f2a26ad62a5c155af9199af9e69b889claireho        HANGING_OUTPUT=FALSE;
38427f654740f2a26ad62a5c155af9199af9e69b889claireho#if SHOW_TIMES
38527f654740f2a26ad62a5c155af9199af9e69b889claireho        startTime = uprv_getRawUTCtime();
38627f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
38759d709d503bab6e2b61931737e662dd293b40578ccornelius        strcpy(gTestName, pathToFunction);
38827f654740f2a26ad62a5c155af9199af9e69b889claireho        root->test();   /* PERFORM THE TEST ************************/
38927f654740f2a26ad62a5c155af9199af9e69b889claireho#if SHOW_TIMES
39027f654740f2a26ad62a5c155af9199af9e69b889claireho        stopTime = uprv_getRawUTCtime();
39127f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
39227f654740f2a26ad62a5c155af9199af9e69b889claireho        if(HANGING_OUTPUT) {
39327f654740f2a26ad62a5c155af9199af9e69b889claireho          log_testinfo("\n");
39427f654740f2a26ad62a5c155af9199af9e69b889claireho          HANGING_OUTPUT=FALSE;
39527f654740f2a26ad62a5c155af9199af9e69b889claireho        }
39627f654740f2a26ad62a5c155af9199af9e69b889claireho        INDENT_LEVEL = depth-1;  /* depth of root */
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        currentTest = NULL;
39827f654740f2a26ad62a5c155af9199af9e69b889claireho        if((ONE_ERROR>0)&&(ERROR_COUNT==0)) {
39927f654740f2a26ad62a5c155af9199af9e69b889claireho          ERROR_COUNT++; /* There was an error without a newline */
40027f654740f2a26ad62a5c155af9199af9e69b889claireho        }
40127f654740f2a26ad62a5c155af9199af9e69b889claireho        ONE_ERROR=0;
40227f654740f2a26ad62a5c155af9199af9e69b889claireho
40327f654740f2a26ad62a5c155af9199af9e69b889claireho#if SHOW_TIMES
40427f654740f2a26ad62a5c155af9199af9e69b889claireho        str_timeDelta(timeDelta, stopTime-startTime);
40527f654740f2a26ad62a5c155af9199af9e69b889claireho        sprintf(timeSeconds, "%f", (stopTime-startTime)/1000.0);
40627f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
40727f654740f2a26ad62a5c155af9199af9e69b889claireho        ctest_xml_testcase(pathToFunction, pathToFunction, timeSeconds, (myERROR_COUNT!=ERROR_COUNT)?"error":NULL);
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
40927f654740f2a26ad62a5c155af9199af9e69b889claireho        if (myERROR_COUNT != ERROR_COUNT) {
41027f654740f2a26ad62a5c155af9199af9e69b889claireho          log_testinfo_i("} ---[%d ERRORS in %s] ", ERROR_COUNT - myERROR_COUNT, pathToFunction);
41127f654740f2a26ad62a5c155af9199af9e69b889claireho          strcpy(ERROR_LOG[ERRONEOUS_FUNCTION_COUNT++], pathToFunction);
41227f654740f2a26ad62a5c155af9199af9e69b889claireho        } else {
41327f654740f2a26ad62a5c155af9199af9e69b889claireho          if(!ON_LINE) { /* had some output */
41427f654740f2a26ad62a5c155af9199af9e69b889claireho            int spaces = FLAG_INDENT-(depth-1);
41527f654740f2a26ad62a5c155af9199af9e69b889claireho            log_testinfo_i("} %*s[OK] ", spaces, "---");
41627f654740f2a26ad62a5c155af9199af9e69b889claireho            if((GLOBAL_PRINT_COUNT-myGLOBAL_PRINT_COUNT)>PAGE_SIZE_LIMIT) {
41727f654740f2a26ad62a5c155af9199af9e69b889claireho              log_testinfo(" %s ", pathToFunction); /* in case they forgot. */
41827f654740f2a26ad62a5c155af9199af9e69b889claireho            }
41927f654740f2a26ad62a5c155af9199af9e69b889claireho          } else {
42027f654740f2a26ad62a5c155af9199af9e69b889claireho            /* put -- out at 30 sp. */
42127f654740f2a26ad62a5c155af9199af9e69b889claireho            int spaces = FLAG_INDENT-(strlen(root->name)+depth);
42227f654740f2a26ad62a5c155af9199af9e69b889claireho            if(spaces<0) spaces=0;
42327f654740f2a26ad62a5c155af9199af9e69b889claireho            log_testinfo(" %*s[OK] ", spaces,"---");
42427f654740f2a26ad62a5c155af9199af9e69b889claireho          }
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
42627f654740f2a26ad62a5c155af9199af9e69b889claireho
42727f654740f2a26ad62a5c155af9199af9e69b889claireho#if SHOW_TIMES
42827f654740f2a26ad62a5c155af9199af9e69b889claireho        if(timeDelta[0]) printf("%s", timeDelta);
42927f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
43027f654740f2a26ad62a5c155af9199af9e69b889claireho
43127f654740f2a26ad62a5c155af9199af9e69b889claireho        ON_LINE = TRUE; /* we are back on-line */
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
43427f654740f2a26ad62a5c155af9199af9e69b889claireho    INDENT_LEVEL = depth-1; /* root */
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* we want these messages to be at 0 indent. so just push the indent level breifly. */
43727f654740f2a26ad62a5c155af9199af9e69b889claireho    if(mode==SHOWTESTS) {
43827f654740f2a26ad62a5c155af9199af9e69b889claireho    	log_testinfo("---%s%c\n",pathToFunction, nodeList[i]->test?' ':TEST_SEPARATOR );
43927f654740f2a26ad62a5c155af9199af9e69b889claireho    }
44027f654740f2a26ad62a5c155af9199af9e69b889claireho
44127f654740f2a26ad62a5c155af9199af9e69b889claireho    INDENT_LEVEL = depth;
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44327f654740f2a26ad62a5c155af9199af9e69b889claireho    if(root->child) {
44427f654740f2a26ad62a5c155af9199af9e69b889claireho        int myERROR_COUNT = ERROR_COUNT;
44527f654740f2a26ad62a5c155af9199af9e69b889claireho        int myGLOBAL_PRINT_COUNT = GLOBAL_PRINT_COUNT;
44627f654740f2a26ad62a5c155af9199af9e69b889claireho        if(mode!=SHOWTESTS) {
44727f654740f2a26ad62a5c155af9199af9e69b889claireho    		INDENT_LEVEL=depth-1;
44827f654740f2a26ad62a5c155af9199af9e69b889claireho    		log_testinfo("{\n");
44927f654740f2a26ad62a5c155af9199af9e69b889claireho    		INDENT_LEVEL=depth;
45027f654740f2a26ad62a5c155af9199af9e69b889claireho    	}
45127f654740f2a26ad62a5c155af9199af9e69b889claireho
45227f654740f2a26ad62a5c155af9199af9e69b889claireho    	iterateTestsWithLevel ( root->child, depth, nodeList, mode );
45327f654740f2a26ad62a5c155af9199af9e69b889claireho
45427f654740f2a26ad62a5c155af9199af9e69b889claireho    	if(mode!=SHOWTESTS) {
45527f654740f2a26ad62a5c155af9199af9e69b889claireho    		INDENT_LEVEL=depth-1;
45627f654740f2a26ad62a5c155af9199af9e69b889claireho    		log_testinfo_i("} "); /* TODO:  summarize subtests */
45727f654740f2a26ad62a5c155af9199af9e69b889claireho    		if((depth>1) && (ERROR_COUNT > myERROR_COUNT)) {
45827f654740f2a26ad62a5c155af9199af9e69b889claireho    			log_testinfo("[%d %s in %s] ", ERROR_COUNT-myERROR_COUNT, (ERROR_COUNT-myERROR_COUNT)==1?"error":"errors", pathToFunction);
45927f654740f2a26ad62a5c155af9199af9e69b889claireho    		} else if((GLOBAL_PRINT_COUNT-myGLOBAL_PRINT_COUNT)>PAGE_SIZE_LIMIT || (depth<1)) {
46027f654740f2a26ad62a5c155af9199af9e69b889claireho                  if(pathToFunction[0]) {
46127f654740f2a26ad62a5c155af9199af9e69b889claireho                    log_testinfo(" %s ", pathToFunction); /* in case they forgot. */
46227f654740f2a26ad62a5c155af9199af9e69b889claireho                  } else {
46327f654740f2a26ad62a5c155af9199af9e69b889claireho                    log_testinfo(" / (%s) ", ARGV_0);
46427f654740f2a26ad62a5c155af9199af9e69b889claireho                  }
46527f654740f2a26ad62a5c155af9199af9e69b889claireho                }
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
46727f654740f2a26ad62a5c155af9199af9e69b889claireho    		ON_LINE=TRUE;
46827f654740f2a26ad62a5c155af9199af9e69b889claireho    	}
46927f654740f2a26ad62a5c155af9199af9e69b889claireho	}
47027f654740f2a26ad62a5c155af9199af9e69b889claireho    depth--;
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
47227f654740f2a26ad62a5c155af9199af9e69b889claireho#if SHOW_TIMES
47327f654740f2a26ad62a5c155af9199af9e69b889claireho    if(depth<2) {
47427f654740f2a26ad62a5c155af9199af9e69b889claireho      allStopTime = uprv_getRawUTCtime();
47527f654740f2a26ad62a5c155af9199af9e69b889claireho      print_timeDelta(allStopTime-allStartTime);
47627f654740f2a26ad62a5c155af9199af9e69b889claireho    }
47727f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
47827f654740f2a26ad62a5c155af9199af9e69b889claireho
47927f654740f2a26ad62a5c155af9199af9e69b889claireho    if(mode!=SHOWTESTS && ON_LINE) {
48027f654740f2a26ad62a5c155af9199af9e69b889claireho    	log_testinfo("\n");
48127f654740f2a26ad62a5c155af9199af9e69b889claireho    }
48227f654740f2a26ad62a5c155af9199af9e69b889claireho
48327f654740f2a26ad62a5c155af9199af9e69b889claireho    if ( depth != 0 ) { /* DO NOT iterate over siblings of the root. TODO: why not? */
48427f654740f2a26ad62a5c155af9199af9e69b889claireho        iterateTestsWithLevel ( root->sibling, depth, nodeList, mode );
48527f654740f2a26ad62a5c155af9199af9e69b889claireho    }
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerushowTests ( const TestNode *root )
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* make up one for them */
49427f654740f2a26ad62a5c155af9199af9e69b889claireho    const TestNode *nodeList[MAXTESTS];
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (root == NULL)
497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("TEST CAN'T BE FOUND!");
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
49927f654740f2a26ad62a5c155af9199af9e69b889claireho    iterateTestsWithLevel ( root, 0, nodeList, SHOWTESTS );
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerurunTests ( const TestNode *root )
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i;
50727f654740f2a26ad62a5c155af9199af9e69b889claireho    const TestNode *nodeList[MAXTESTS];
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* make up one for them */
509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (root == NULL)
512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("TEST CAN'T BE FOUND!\n");
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ERRONEOUS_FUNCTION_COUNT = ERROR_COUNT = 0;
51527f654740f2a26ad62a5c155af9199af9e69b889claireho    iterateTestsWithLevel ( root, 0, nodeList, RUNTESTS );
516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*print out result summary*/
518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
51927f654740f2a26ad62a5c155af9199af9e69b889claireho    ON_LINE=FALSE; /* just in case */
52027f654740f2a26ad62a5c155af9199af9e69b889claireho
52159d709d503bab6e2b61931737e662dd293b40578ccornelius    if(knownList != NULL) {
52259d709d503bab6e2b61931737e662dd293b40578ccornelius      if( udbg_knownIssue_print(knownList) ) {
52359d709d503bab6e2b61931737e662dd293b40578ccornelius        fprintf(stdout, "(To run suppressed tests, use the -K option.) \n\n");
52459d709d503bab6e2b61931737e662dd293b40578ccornelius      }
52559d709d503bab6e2b61931737e662dd293b40578ccornelius      udbg_knownIssue_close(knownList);
526fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius      knownList = NULL;
52759d709d503bab6e2b61931737e662dd293b40578ccornelius    }
52859d709d503bab6e2b61931737e662dd293b40578ccornelius
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ERROR_COUNT)
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
53127f654740f2a26ad62a5c155af9199af9e69b889claireho        fprintf(stdout,"\nSUMMARY:\n");
53227f654740f2a26ad62a5c155af9199af9e69b889claireho    	fflush(stdout);
53327f654740f2a26ad62a5c155af9199af9e69b889claireho        fprintf(stdout,"******* [Total error count:\t%d]\n", ERROR_COUNT);
53427f654740f2a26ad62a5c155af9199af9e69b889claireho    	fflush(stdout);
53527f654740f2a26ad62a5c155af9199af9e69b889claireho        fprintf(stdout, " Errors in\n");
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for (i=0;i < ERRONEOUS_FUNCTION_COUNT; i++)
53727f654740f2a26ad62a5c155af9199af9e69b889claireho            fprintf(stdout, "[%s]\n",ERROR_LOG[i]);
53859d709d503bab6e2b61931737e662dd293b40578ccornelius	if(SUMMARY_FILE != NULL) {
53959d709d503bab6e2b61931737e662dd293b40578ccornelius	  FILE *summf = fopen(SUMMARY_FILE, "w");
54059d709d503bab6e2b61931737e662dd293b40578ccornelius	  if(summf!=NULL) {
54159d709d503bab6e2b61931737e662dd293b40578ccornelius	    for (i=0;i < ERRONEOUS_FUNCTION_COUNT; i++)
54259d709d503bab6e2b61931737e662dd293b40578ccornelius	      fprintf(summf, "%s\n",ERROR_LOG[i]);
54359d709d503bab6e2b61931737e662dd293b40578ccornelius	    fclose(summf);
54459d709d503bab6e2b61931737e662dd293b40578ccornelius	  }
54559d709d503bab6e2b61931737e662dd293b40578ccornelius	}
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
54927f654740f2a26ad62a5c155af9199af9e69b889claireho      log_testinfo("\n[All tests passed successfully...]\n");
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(DATA_ERROR_COUNT) {
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if(WARN_ON_MISSING_DATA==0) {
55427f654740f2a26ad62a5c155af9199af9e69b889claireho    	  log_testinfo("\t*Note* some errors are data-loading related. If the data used is not the \n"
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "\tstock ICU data (i.e some have been added or removed), consider using\n"
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "\tthe '-w' option to turn these errors into warnings.\n");
557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      } else {
55827f654740f2a26ad62a5c155af9199af9e69b889claireho    	  log_testinfo("\t*WARNING* some data-loading errors were ignored by the -w option.\n");
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char* T_CTEST_EXPORT2
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerugetTestName(void)
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(currentTest != NULL) {
567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return currentTest->name;
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } else {
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return NULL;
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst TestNode* T_CTEST_EXPORT2
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerugetTest(const TestNode* root, const char* name)
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* nextName;
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNode *nextNode;
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const TestNode* curNode;
579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int nameLen; /* length of current 'name' */
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (root == NULL) {
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("TEST CAN'T BE FOUND!\n");
583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return NULL;
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* remove leading slash */
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if ( *name == TEST_SEPARATOR )
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        name++;
588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    curNode = root;
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(;;)
592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Start with the next child */
594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        nextNode = curNode->child;
595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        getNextLevel ( name, &nameLen, &nextName );
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*      printf("* %s\n", name );*/
599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* if nextNode is already null, then curNode has no children
601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        -- add them */
602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if( nextNode == NULL )
603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return NULL;
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Search across for the name */
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        while (strncmp_nullcheck ( name, nextNode->name, nameLen) != 0 )
609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            curNode = nextNode;
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            nextNode = nextNode -> sibling;
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if ( nextNode == NULL )
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            {
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* Did not find 'name' on this level. */
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                return NULL;
617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* nextNode matches 'name' */
621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (nextName == NULL) /* end of the line */
623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return nextNode;
625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Loop again with the next item */
628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        name = nextName;
629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        curNode = nextNode;
630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63327f654740f2a26ad62a5c155af9199af9e69b889claireho/*  =========== io functions ======== */
63427f654740f2a26ad62a5c155af9199af9e69b889claireho
63527f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void go_offline_with_marker(const char *mrk) {
63627f654740f2a26ad62a5c155af9199af9e69b889claireho  UBool wasON_LINE = ON_LINE;
63727f654740f2a26ad62a5c155af9199af9e69b889claireho
63827f654740f2a26ad62a5c155af9199af9e69b889claireho  if(ON_LINE) {
63927f654740f2a26ad62a5c155af9199af9e69b889claireho    log_testinfo(" {\n");
64027f654740f2a26ad62a5c155af9199af9e69b889claireho    ON_LINE=FALSE;
64127f654740f2a26ad62a5c155af9199af9e69b889claireho  }
64227f654740f2a26ad62a5c155af9199af9e69b889claireho
64327f654740f2a26ad62a5c155af9199af9e69b889claireho  if(!HANGING_OUTPUT || wasON_LINE) {
64427f654740f2a26ad62a5c155af9199af9e69b889claireho    if(mrk != NULL) {
64527f654740f2a26ad62a5c155af9199af9e69b889claireho      fputs(mrk, stdout);
64627f654740f2a26ad62a5c155af9199af9e69b889claireho    }
64727f654740f2a26ad62a5c155af9199af9e69b889claireho  }
64827f654740f2a26ad62a5c155af9199af9e69b889claireho}
64927f654740f2a26ad62a5c155af9199af9e69b889claireho
65027f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void go_offline() {
65127f654740f2a26ad62a5c155af9199af9e69b889claireho	go_offline_with_marker(NULL);
65227f654740f2a26ad62a5c155af9199af9e69b889claireho}
65327f654740f2a26ad62a5c155af9199af9e69b889claireho
65427f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void go_offline_err() {
65527f654740f2a26ad62a5c155af9199af9e69b889claireho	go_offline();
65627f654740f2a26ad62a5c155af9199af9e69b889claireho}
65727f654740f2a26ad62a5c155af9199af9e69b889claireho
65827f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void first_line_verbose() {
65927f654740f2a26ad62a5c155af9199af9e69b889claireho    go_offline_with_marker("v");
66027f654740f2a26ad62a5c155af9199af9e69b889claireho}
66127f654740f2a26ad62a5c155af9199af9e69b889claireho
66227f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void first_line_err() {
66327f654740f2a26ad62a5c155af9199af9e69b889claireho    go_offline_with_marker("!");
66427f654740f2a26ad62a5c155af9199af9e69b889claireho}
66527f654740f2a26ad62a5c155af9199af9e69b889claireho
66627f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void first_line_info() {
66727f654740f2a26ad62a5c155af9199af9e69b889claireho    go_offline_with_marker("\"");
66827f654740f2a26ad62a5c155af9199af9e69b889claireho}
66927f654740f2a26ad62a5c155af9199af9e69b889claireho
67027f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void first_line_test() {
67127f654740f2a26ad62a5c155af9199af9e69b889claireho	fputs(" ", stdout);
67227f654740f2a26ad62a5c155af9199af9e69b889claireho}
67327f654740f2a26ad62a5c155af9199af9e69b889claireho
67427f654740f2a26ad62a5c155af9199af9e69b889claireho
675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void vlog_err(const char *prefix, const char *pattern, va_list ap)
676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if( ERR_MSG == FALSE){
678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
68027f654740f2a26ad62a5c155af9199af9e69b889claireho    fputs("!", stdout); /* col 1 - bang */
68127f654740f2a26ad62a5c155af9199af9e69b889claireho    fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(prefix) {
68327f654740f2a26ad62a5c155af9199af9e69b889claireho        fputs(prefix, stdout);
684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
68527f654740f2a26ad62a5c155af9199af9e69b889claireho    vfprintf(stdout, pattern, ap);
68627f654740f2a26ad62a5c155af9199af9e69b889claireho    fflush(stdout);
687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_end(ap);
68827f654740f2a26ad62a5c155af9199af9e69b889claireho    if((*pattern==0) || (pattern[strlen(pattern)-1]!='\n')) {
68927f654740f2a26ad62a5c155af9199af9e69b889claireho    	HANGING_OUTPUT=1;
69027f654740f2a26ad62a5c155af9199af9e69b889claireho    } else {
69127f654740f2a26ad62a5c155af9199af9e69b889claireho    	HANGING_OUTPUT=0;
69227f654740f2a26ad62a5c155af9199af9e69b889claireho    }
69327f654740f2a26ad62a5c155af9199af9e69b889claireho    GLOBAL_PRINT_COUNT++;
694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69659d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic UBool vlog_knownIssue(const char *ticket, const char *pattern, va_list ap)
69759d709d503bab6e2b61931737e662dd293b40578ccornelius{
69859d709d503bab6e2b61931737e662dd293b40578ccornelius    char buf[2048];
69959d709d503bab6e2b61931737e662dd293b40578ccornelius    UBool firstForTicket;
70059d709d503bab6e2b61931737e662dd293b40578ccornelius    UBool firstForWhere;
70159d709d503bab6e2b61931737e662dd293b40578ccornelius
70259d709d503bab6e2b61931737e662dd293b40578ccornelius    if(NO_KNOWN) return FALSE;
70359d709d503bab6e2b61931737e662dd293b40578ccornelius    if(pattern==NULL) pattern="";
70459d709d503bab6e2b61931737e662dd293b40578ccornelius
70559d709d503bab6e2b61931737e662dd293b40578ccornelius    vsprintf(buf, pattern, ap);
70659d709d503bab6e2b61931737e662dd293b40578ccornelius    knownList = udbg_knownIssue_open(knownList, ticket, gTestName, buf,
70759d709d503bab6e2b61931737e662dd293b40578ccornelius                                     &firstForTicket, &firstForWhere);
70859d709d503bab6e2b61931737e662dd293b40578ccornelius
70959d709d503bab6e2b61931737e662dd293b40578ccornelius    if(firstForTicket || firstForWhere) {
710fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius      log_info("(Known issue #%s) %s\n", ticket, buf);
71159d709d503bab6e2b61931737e662dd293b40578ccornelius    } else {
712fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius      log_verbose("(Known issue #%s) %s\n", ticket, buf);
71359d709d503bab6e2b61931737e662dd293b40578ccornelius    }
71459d709d503bab6e2b61931737e662dd293b40578ccornelius
71559d709d503bab6e2b61931737e662dd293b40578ccornelius    return TRUE;
71659d709d503bab6e2b61931737e662dd293b40578ccornelius}
71759d709d503bab6e2b61931737e662dd293b40578ccornelius
71859d709d503bab6e2b61931737e662dd293b40578ccornelius
719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvlog_info(const char *prefix, const char *pattern, va_list ap)
721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
72227f654740f2a26ad62a5c155af9199af9e69b889claireho	first_line_info();
72327f654740f2a26ad62a5c155af9199af9e69b889claireho    fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(prefix) {
725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fputs(prefix, stdout);
726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    vfprintf(stdout, pattern, ap);
728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fflush(stdout);
729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_end(ap);
73027f654740f2a26ad62a5c155af9199af9e69b889claireho    if((*pattern==0) || (pattern[strlen(pattern)-1]!='\n')) {
73127f654740f2a26ad62a5c155af9199af9e69b889claireho    	HANGING_OUTPUT=1;
73227f654740f2a26ad62a5c155af9199af9e69b889claireho    } else {
73327f654740f2a26ad62a5c155af9199af9e69b889claireho    	HANGING_OUTPUT=0;
73427f654740f2a26ad62a5c155af9199af9e69b889claireho    }
73527f654740f2a26ad62a5c155af9199af9e69b889claireho    GLOBAL_PRINT_COUNT++;
73627f654740f2a26ad62a5c155af9199af9e69b889claireho}
73727f654740f2a26ad62a5c155af9199af9e69b889claireho/**
73827f654740f2a26ad62a5c155af9199af9e69b889claireho * Log test structure, with indent
73927f654740f2a26ad62a5c155af9199af9e69b889claireho */
74027f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void log_testinfo_i(const char *pattern, ...)
74127f654740f2a26ad62a5c155af9199af9e69b889claireho{
74227f654740f2a26ad62a5c155af9199af9e69b889claireho    va_list ap;
74327f654740f2a26ad62a5c155af9199af9e69b889claireho    first_line_test();
74427f654740f2a26ad62a5c155af9199af9e69b889claireho    fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
74527f654740f2a26ad62a5c155af9199af9e69b889claireho    va_start(ap, pattern);
74627f654740f2a26ad62a5c155af9199af9e69b889claireho    vfprintf(stdout, pattern, ap);
74727f654740f2a26ad62a5c155af9199af9e69b889claireho    fflush(stdout);
74827f654740f2a26ad62a5c155af9199af9e69b889claireho    va_end(ap);
74927f654740f2a26ad62a5c155af9199af9e69b889claireho    GLOBAL_PRINT_COUNT++;
75027f654740f2a26ad62a5c155af9199af9e69b889claireho}
75127f654740f2a26ad62a5c155af9199af9e69b889claireho/**
75227f654740f2a26ad62a5c155af9199af9e69b889claireho * Log test structure (no ident)
75327f654740f2a26ad62a5c155af9199af9e69b889claireho */
75427f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void log_testinfo(const char *pattern, ...)
75527f654740f2a26ad62a5c155af9199af9e69b889claireho{
75627f654740f2a26ad62a5c155af9199af9e69b889claireho    va_list ap;
75727f654740f2a26ad62a5c155af9199af9e69b889claireho    va_start(ap, pattern);
75827f654740f2a26ad62a5c155af9199af9e69b889claireho    first_line_test();
75927f654740f2a26ad62a5c155af9199af9e69b889claireho    vfprintf(stdout, pattern, ap);
76027f654740f2a26ad62a5c155af9199af9e69b889claireho    fflush(stdout);
76127f654740f2a26ad62a5c155af9199af9e69b889claireho    va_end(ap);
76227f654740f2a26ad62a5c155af9199af9e69b889claireho    GLOBAL_PRINT_COUNT++;
763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76527f654740f2a26ad62a5c155af9199af9e69b889claireho
766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void vlog_verbose(const char *prefix, const char *pattern, va_list ap)
767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if ( VERBOSITY == FALSE )
769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
77127f654740f2a26ad62a5c155af9199af9e69b889claireho    first_line_verbose();
77227f654740f2a26ad62a5c155af9199af9e69b889claireho    fprintf(stdout, "%-*s", INDENT_LEVEL,"" );
773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(prefix) {
774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fputs(prefix, stdout);
775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    vfprintf(stdout, pattern, ap);
777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fflush(stdout);
778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_end(ap);
77927f654740f2a26ad62a5c155af9199af9e69b889claireho    GLOBAL_PRINT_COUNT++;
78027f654740f2a26ad62a5c155af9199af9e69b889claireho    if((*pattern==0) || (pattern[strlen(pattern)-1]!='\n')) {
78127f654740f2a26ad62a5c155af9199af9e69b889claireho    	HANGING_OUTPUT=1;
78227f654740f2a26ad62a5c155af9199af9e69b889claireho    } else {
78327f654740f2a26ad62a5c155af9199af9e69b889claireho    	HANGING_OUTPUT=0;
78427f654740f2a26ad62a5c155af9199af9e69b889claireho    }
785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querulog_err(const char* pattern, ...)
789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_list ap;
79127f654740f2a26ad62a5c155af9199af9e69b889claireho    first_line_err();
792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strchr(pattern, '\n') != NULL) {
793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*
794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         * Count errors only if there is a line feed in the pattern
795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         * so that we do not exaggerate our error count.
796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         */
797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ++ERROR_COUNT;
79827f654740f2a26ad62a5c155af9199af9e69b889claireho    } else {
79927f654740f2a26ad62a5c155af9199af9e69b889claireho    	/* Count at least one error. */
80027f654740f2a26ad62a5c155af9199af9e69b889claireho    	ONE_ERROR=1;
801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_start(ap, pattern);
803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    vlog_err(NULL, pattern, ap);
804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
80659d709d503bab6e2b61931737e662dd293b40578ccorneliusUBool T_CTEST_EXPORT2
80759d709d503bab6e2b61931737e662dd293b40578ccorneliuslog_knownIssue(const char *ticket, const char *pattern, ...) {
80859d709d503bab6e2b61931737e662dd293b40578ccornelius  va_list ap;
80959d709d503bab6e2b61931737e662dd293b40578ccornelius  va_start(ap, pattern);
81059d709d503bab6e2b61931737e662dd293b40578ccornelius  return vlog_knownIssue(ticket, pattern, ap);
81159d709d503bab6e2b61931737e662dd293b40578ccornelius}
81259d709d503bab6e2b61931737e662dd293b40578ccornelius
813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
81485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Holog_err_status(UErrorCode status, const char* pattern, ...)
81585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{
81685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    va_list ap;
81785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    va_start(ap, pattern);
81885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
81985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if ((status == U_FILE_ACCESS_ERROR || status == U_MISSING_RESOURCE_ERROR)) {
82085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ++DATA_ERROR_COUNT; /* for informational message at the end */
82185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
82285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (WARN_ON_MISSING_DATA == 0) {
823b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            first_line_err();
82485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* Fatal error. */
82585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if (strchr(pattern, '\n') != NULL) {
82685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                ++ERROR_COUNT;
82727f654740f2a26ad62a5c155af9199af9e69b889claireho            } else {
828b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                ++ONE_ERROR;
82985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
83085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            vlog_err(NULL, pattern, ap); /* no need for prefix in default case */
83185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        } else {
83285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            vlog_info("[DATA] ", pattern, ap);
83385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
83485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    } else {
835b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        first_line_err();
83685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* Fatal error. */
83785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if(strchr(pattern, '\n') != NULL) {
83885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ++ERROR_COUNT;
83927f654740f2a26ad62a5c155af9199af9e69b889claireho        } else {
840b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            ++ONE_ERROR;
84185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
84285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        vlog_err(NULL, pattern, ap); /* no need for prefix in default case */
84385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
84485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
84585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
84685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hovoid T_CTEST_EXPORT2
847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querulog_info(const char* pattern, ...)
848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_list ap;
850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_start(ap, pattern);
852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    vlog_info(NULL, pattern, ap);
853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querulog_verbose(const char* pattern, ...)
857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_list ap;
859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    va_start(ap, pattern);
861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    vlog_verbose(NULL, pattern, ap);
862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid T_CTEST_EXPORT2
866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querulog_data_err(const char* pattern, ...)
867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
86885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    va_list ap;
86985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    va_start(ap, pattern);
870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
87127f654740f2a26ad62a5c155af9199af9e69b889claireho    go_offline_err();
87285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    ++DATA_ERROR_COUNT; /* for informational message at the end */
873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
87485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if(WARN_ON_MISSING_DATA == 0) {
87585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* Fatal error. */
87685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if(strchr(pattern, '\n') != NULL) {
87785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ++ERROR_COUNT;
87885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
87985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        vlog_err(NULL, pattern, ap); /* no need for prefix in default case */
88085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    } else {
88185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        vlog_info("[DATA] ", pattern, ap);
882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
88685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/*
88785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Tracing functions.
88885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */
88985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic int traceFnNestingDepth = 0;
89085bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoU_CDECL_BEGIN
89185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void U_CALLCONV TraceEntry(const void *context, int32_t fnNumber) {
89285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char buf[500];
89385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    utrace_format(buf, sizeof(buf), traceFnNestingDepth*3, "%s() enter.\n", utrace_functionName(fnNumber));    buf[sizeof(buf)-1]=0;
89485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    fputs(buf, stdout);
89585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    traceFnNestingDepth++;
89685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
89785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
89885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void U_CALLCONV TraceExit(const void *context, int32_t fnNumber, const char *fmt, va_list args) {    char buf[500];
89985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
90085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (traceFnNestingDepth>0) {
90185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        traceFnNestingDepth--;
90285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
90385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    utrace_format(buf, sizeof(buf), traceFnNestingDepth*3, "%s() ", utrace_functionName(fnNumber));    buf[sizeof(buf)-1]=0;
90485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    fputs(buf, stdout);
90585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    utrace_vformat(buf, sizeof(buf), traceFnNestingDepth*3, fmt, args);
90685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    buf[sizeof(buf)-1]=0;
90785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    fputs(buf, stdout);
90885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    putc('\n', stdout);
90985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
91085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
91185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void U_CALLCONV TraceData(const void *context, int32_t fnNumber,
91285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                          int32_t level, const char *fmt, va_list args) {
91385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char buf[500];
91485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    utrace_vformat(buf, sizeof(buf), traceFnNestingDepth*3, fmt, args);
91585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    buf[sizeof(buf)-1]=0;
91685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    fputs(buf, stdout);
91785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    putc('\n', stdout);
91885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
91985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
92085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void *U_CALLCONV ctest_libMalloc(const void *context, size_t size) {
92185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /*if (VERBOSITY) {
92285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        printf("Allocated %ld\n", (long)size);
92385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }*/
92485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (MINIMUM_MEMORY_SIZE_FAILURE <= size && size <= MAXIMUM_MEMORY_SIZE_FAILURE) {
92585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return NULL;
92685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
92785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    return malloc(size);
92885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
92985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void *U_CALLCONV ctest_libRealloc(const void *context, void *mem, size_t size) {
93085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /*if (VERBOSITY) {
93185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        printf("Reallocated %ld\n", (long)size);
93285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }*/
93385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (MINIMUM_MEMORY_SIZE_FAILURE <= size && size <= MAXIMUM_MEMORY_SIZE_FAILURE) {
93485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /*free(mem);*/ /* Realloc doesn't free on failure. */
93585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return NULL;
93685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
93785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    return realloc(mem, size);
93885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
93985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void U_CALLCONV ctest_libFree(const void *context, void *mem) {
94085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    free(mem);
94185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
94285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint T_CTEST_EXPORT2
94485bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoinitArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context)
945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int                i;
947103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    int                argSkip = 0;
948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    VERBOSITY = FALSE;
950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ERR_MSG = TRUE;
951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
95227f654740f2a26ad62a5c155af9199af9e69b889claireho    ARGV_0=argv[0];
95327f654740f2a26ad62a5c155af9199af9e69b889claireho
954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for( i=1; i<argc; i++)
955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if ( argv[i][0] == '/' )
957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
95885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* We don't run the tests here. */
95985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            continue;
96085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
96185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        else if ((strcmp( argv[i], "-a") == 0) || (strcmp(argv[i],"-all") == 0))
96285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        {
96385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* We don't run the tests here. */
96485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            continue;
965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-v" )==0 || strcmp( argv[i], "-verbose")==0)
967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            VERBOSITY = TRUE;
969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-l" )==0 )
971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
972103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            /* doList = TRUE; */
973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-e1") == 0)
975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            QUICK = -1;
977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-e") ==0)
979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            QUICK = 0;
981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
98259d709d503bab6e2b61931737e662dd293b40578ccornelius        else if (strcmp( argv[i], "-K") ==0)
98359d709d503bab6e2b61931737e662dd293b40578ccornelius        {
98459d709d503bab6e2b61931737e662dd293b40578ccornelius            NO_KNOWN = 1;
98559d709d503bab6e2b61931737e662dd293b40578ccornelius        }
98659d709d503bab6e2b61931737e662dd293b40578ccornelius        else if (strncmp( argv[i], "-E",2) ==0)
98759d709d503bab6e2b61931737e662dd293b40578ccornelius        {
98859d709d503bab6e2b61931737e662dd293b40578ccornelius	    SUMMARY_FILE=argv[i]+2;
98959d709d503bab6e2b61931737e662dd293b40578ccornelius        }
990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-w") ==0)
991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            WARN_ON_MISSING_DATA = TRUE;
993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
99485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        else if (strcmp( argv[i], "-m") ==0)
99585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        {
99685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            UErrorCode errorCode = U_ZERO_ERROR;
99785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if (i+1 < argc) {
99885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                char *endPtr = NULL;
99985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                i++;
100085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                MINIMUM_MEMORY_SIZE_FAILURE = (size_t)strtol(argv[i], &endPtr, 10);
100185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                if (endPtr == argv[i]) {
100285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    printf("Can't parse %s\n", argv[i]);
100385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    help(argv[0]);
100485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    return 0;
100585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                }
100685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                if (*endPtr == '-') {
100785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    char *maxPtr = endPtr+1;
100885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    endPtr = NULL;
100985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    MAXIMUM_MEMORY_SIZE_FAILURE = (size_t)strtol(maxPtr, &endPtr, 10);
101085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    if (endPtr == argv[i]) {
101185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                        printf("Can't parse %s\n", argv[i]);
101285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                        help(argv[0]);
101385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                        return 0;
101485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    }
101585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                }
101685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
101785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* Use the default value */
101885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            u_setMemoryFunctions(NULL, ctest_libMalloc, ctest_libRealloc, ctest_libFree, &errorCode);
101985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if (U_FAILURE(errorCode)) {
102085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                printf("u_setMemoryFunctions returned %s\n", u_errorName(errorCode));
102185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                return 0;
102285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
102385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
1024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if(strcmp( argv[i], "-n") == 0 || strcmp( argv[i], "-no_err_msg") == 0)
1025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
1026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ERR_MSG = FALSE;
1027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-r") == 0)
1029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
1030ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (!REPEAT_TESTS_INIT) {
1031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                REPEAT_TESTS++;
1032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1033ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
103427f654740f2a26ad62a5c155af9199af9e69b889claireho        else if (strcmp( argv[i], "-x") == 0)
103527f654740f2a26ad62a5c155af9199af9e69b889claireho        {
103627f654740f2a26ad62a5c155af9199af9e69b889claireho          if(++i>=argc) {
103727f654740f2a26ad62a5c155af9199af9e69b889claireho            printf("* Error: '-x' option requires an argument. usage: '-x outfile.xml'.\n");
103827f654740f2a26ad62a5c155af9199af9e69b889claireho            return 0;
103927f654740f2a26ad62a5c155af9199af9e69b889claireho          }
104027f654740f2a26ad62a5c155af9199af9e69b889claireho          if(ctest_xml_setFileName(argv[i])) { /* set the name */
104127f654740f2a26ad62a5c155af9199af9e69b889claireho            return 0;
104227f654740f2a26ad62a5c155af9199af9e69b889claireho          }
104327f654740f2a26ad62a5c155af9199af9e69b889claireho        }
1044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-t_info") == 0) {
1045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ICU_TRACE = UTRACE_INFO;
1046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-t_error") == 0) {
1048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ICU_TRACE = UTRACE_ERROR;
1049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-t_warn") == 0) {
1051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ICU_TRACE = UTRACE_WARNING;
1052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-t_verbose") == 0) {
1054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ICU_TRACE = UTRACE_VERBOSE;
1055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-t_oc") == 0) {
1057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ICU_TRACE = UTRACE_OPEN_CLOSE;
1058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else if (strcmp( argv[i], "-h" )==0 || strcmp( argv[i], "--help" )==0)
1060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
1061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            help( argv[0] );
1062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return 0;
1063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
106485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        else if (argHandler != NULL && (argSkip = argHandler(i, argc, argv, context)) > 0)
106585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        {
106685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            i += argSkip - 1;
106785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
1068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else
1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            printf("* unknown option: %s\n", argv[i]);
1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            help( argv[0] );
107285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return 0;
107385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
107485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
107585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (ICU_TRACE != UTRACE_OFF) {
107685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        utrace_setFunctions(NULL, TraceEntry, TraceExit, TraceData);
107785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        utrace_setLevel(ICU_TRACE);
107885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
107985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
108085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    return 1; /* total error count */
108185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
108285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
108385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hoint T_CTEST_EXPORT2
108485bf2e2fbc60a9f938064abc8127d61da7d19882Claire HorunTestRequest(const TestNode* root,
108585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho             int argc,
108685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho             const char* const argv[])
108785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{
108885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /**
108985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     * This main will parse the l, v, h, n, and path arguments
109085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     */
109185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const TestNode*    toRun;
109285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int                i;
109385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int                doList = FALSE;
109485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int                subtreeOptionSeen = FALSE;
109585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
109685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int                errorCount = 0;
109785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
109885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    toRun = root;
109985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
110027f654740f2a26ad62a5c155af9199af9e69b889claireho    if(ctest_xml_init(ARGV_0)) {
110127f654740f2a26ad62a5c155af9199af9e69b889claireho      return 1; /* couldn't fire up XML thing */
110227f654740f2a26ad62a5c155af9199af9e69b889claireho    }
110327f654740f2a26ad62a5c155af9199af9e69b889claireho
110485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    for( i=1; i<argc; i++)
110585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    {
110685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if ( argv[i][0] == '/' )
110785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        {
110885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            printf("Selecting subtree '%s'\n", argv[i]);
110985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
111085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if ( argv[i][1] == 0 )
111185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                toRun = root;
111285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            else
111385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                toRun = getTest(root, argv[i]);
111485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
111585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if ( toRun == NULL )
111685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            {
111785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                printf("* Could not find any matching subtree\n");
111885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                return -1;
111985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
112085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
112127f654740f2a26ad62a5c155af9199af9e69b889claireho            ON_LINE=FALSE; /* just in case */
112227f654740f2a26ad62a5c155af9199af9e69b889claireho
112385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if( doList == TRUE)
112485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                showTests(toRun);
112585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            else
112685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                runTests(toRun);
112785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
112827f654740f2a26ad62a5c155af9199af9e69b889claireho            ON_LINE=FALSE; /* just in case */
112927f654740f2a26ad62a5c155af9199af9e69b889claireho
113085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            errorCount += ERROR_COUNT;
113185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
113285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            subtreeOptionSeen = TRUE;
113385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        } else if ((strcmp( argv[i], "-a") == 0) || (strcmp(argv[i],"-all") == 0)) {
113485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            subtreeOptionSeen=FALSE;
113585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        } else if (strcmp( argv[i], "-l") == 0) {
113685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            doList = TRUE;
1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
113885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* else option already handled by initArgs */
1139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if( subtreeOptionSeen == FALSE) /* no other subtree given, run the default */
1142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
114327f654740f2a26ad62a5c155af9199af9e69b889claireho        ON_LINE=FALSE; /* just in case */
1144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if( doList == TRUE)
1145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            showTests(toRun);
1146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else
1147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            runTests(toRun);
114827f654740f2a26ad62a5c155af9199af9e69b889claireho        ON_LINE=FALSE; /* just in case */
1149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errorCount += ERROR_COUNT;
1151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
1153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if( ( doList == FALSE ) && ( errorCount > 0 ) )
1155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            printf(" Total errors: %d\n", errorCount );
1156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    REPEAT_TESTS_INIT = 1;
115927f654740f2a26ad62a5c155af9199af9e69b889claireho
116027f654740f2a26ad62a5c155af9199af9e69b889claireho    if(ctest_xml_fini()) {
116127f654740f2a26ad62a5c155af9199af9e69b889claireho      errorCount++;
116227f654740f2a26ad62a5c155af9199af9e69b889claireho    }
1163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return errorCount; /* total error count */
1165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
1168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Display program invocation arguments
1169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
1170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void help ( const char *argv0 )
1172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("Usage: %s [ -l ] [ -v ] [ -verbose] [-a] [ -all] [-n] [ -no_err_msg]\n"
117485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho           "    [ -h ] [-t_info | -t_error | -t_warn | -t_oc | -t_verbose] [-m n[-q] ]\n"
117585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho           "    [ /path/to/test ]\n",
1176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            argv0);
1177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -l  To get a list of test names\n");
1178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -e  to do exhaustive testing\n");
1179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -verbose To turn ON verbosity\n");
1180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -v  To turn ON verbosity(same as -verbose)\n");
118127f654740f2a26ad62a5c155af9199af9e69b889claireho    printf("    -x file.xml   Write junit format output to file.xml\n");
1182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -h  To print this message\n");
118359d709d503bab6e2b61931737e662dd293b40578ccornelius    printf("    -K  to turn OFF suppressing known issues\n");
1184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -n  To turn OFF printing error messages\n");
1185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -w  Don't fail on data-loading errs, just warn. Useful if\n"
1186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "        user has reduced/changed the common set of ICU data \n");
1187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -t_info | -t_error | -t_warn | -t_oc | -t_verbose  Enable ICU tracing\n");
1188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    -no_err_msg (same as -n) \n");
118985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    printf("    -m n[-q] Min-Max memory size that will cause an allocation failure.\n");
119085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    printf("        The default is the maximum value of size_t. Max is optional.\n");
119185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    printf("    -r  Repeat tests after calling u_cleanup \n");
119285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    printf("    [/subtest]  To run a subtest \n");
1193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("    eg: to run just the utility tests type: cintltest /tsutil) \n");
1194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
119627f654740f2a26ad62a5c155af9199af9e69b889clairehoint32_t T_CTEST_EXPORT2
119727f654740f2a26ad62a5c155af9199af9e69b889clairehogetTestOption ( int32_t testOption ) {
119827f654740f2a26ad62a5c155af9199af9e69b889claireho    switch (testOption) {
119927f654740f2a26ad62a5c155af9199af9e69b889claireho        case VERBOSITY_OPTION:
120027f654740f2a26ad62a5c155af9199af9e69b889claireho            return VERBOSITY;
120127f654740f2a26ad62a5c155af9199af9e69b889claireho        case WARN_ON_MISSING_DATA_OPTION:
120227f654740f2a26ad62a5c155af9199af9e69b889claireho            return WARN_ON_MISSING_DATA;
120327f654740f2a26ad62a5c155af9199af9e69b889claireho        case QUICK_OPTION:
120427f654740f2a26ad62a5c155af9199af9e69b889claireho            return QUICK;
120527f654740f2a26ad62a5c155af9199af9e69b889claireho        case REPEAT_TESTS_OPTION:
120627f654740f2a26ad62a5c155af9199af9e69b889claireho            return REPEAT_TESTS;
120727f654740f2a26ad62a5c155af9199af9e69b889claireho        case ERR_MSG_OPTION:
120827f654740f2a26ad62a5c155af9199af9e69b889claireho            return ERR_MSG;
120927f654740f2a26ad62a5c155af9199af9e69b889claireho        case ICU_TRACE_OPTION:
121027f654740f2a26ad62a5c155af9199af9e69b889claireho            return ICU_TRACE;
121127f654740f2a26ad62a5c155af9199af9e69b889claireho        default :
121227f654740f2a26ad62a5c155af9199af9e69b889claireho            return 0;
121327f654740f2a26ad62a5c155af9199af9e69b889claireho    }
121427f654740f2a26ad62a5c155af9199af9e69b889claireho}
121527f654740f2a26ad62a5c155af9199af9e69b889claireho
121627f654740f2a26ad62a5c155af9199af9e69b889clairehovoid T_CTEST_EXPORT2
121727f654740f2a26ad62a5c155af9199af9e69b889clairehosetTestOption ( int32_t testOption, int32_t value) {
121827f654740f2a26ad62a5c155af9199af9e69b889claireho    if (value == DECREMENT_OPTION_VALUE) {
121927f654740f2a26ad62a5c155af9199af9e69b889claireho        value = getTestOption(testOption);
122027f654740f2a26ad62a5c155af9199af9e69b889claireho        --value;
122127f654740f2a26ad62a5c155af9199af9e69b889claireho    }
122227f654740f2a26ad62a5c155af9199af9e69b889claireho    switch (testOption) {
122327f654740f2a26ad62a5c155af9199af9e69b889claireho        case VERBOSITY_OPTION:
122427f654740f2a26ad62a5c155af9199af9e69b889claireho            VERBOSITY = value;
122527f654740f2a26ad62a5c155af9199af9e69b889claireho            break;
122627f654740f2a26ad62a5c155af9199af9e69b889claireho        case WARN_ON_MISSING_DATA_OPTION:
122727f654740f2a26ad62a5c155af9199af9e69b889claireho            WARN_ON_MISSING_DATA = value;
122827f654740f2a26ad62a5c155af9199af9e69b889claireho            break;
122927f654740f2a26ad62a5c155af9199af9e69b889claireho        case QUICK_OPTION:
123027f654740f2a26ad62a5c155af9199af9e69b889claireho            QUICK = value;
123127f654740f2a26ad62a5c155af9199af9e69b889claireho            break;
123227f654740f2a26ad62a5c155af9199af9e69b889claireho        case REPEAT_TESTS_OPTION:
123327f654740f2a26ad62a5c155af9199af9e69b889claireho            REPEAT_TESTS = value;
123427f654740f2a26ad62a5c155af9199af9e69b889claireho            break;
123527f654740f2a26ad62a5c155af9199af9e69b889claireho        case ICU_TRACE_OPTION:
123654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            ICU_TRACE = (UTraceLevel)value;
123727f654740f2a26ad62a5c155af9199af9e69b889claireho            break;
123827f654740f2a26ad62a5c155af9199af9e69b889claireho        default :
123927f654740f2a26ad62a5c155af9199af9e69b889claireho            break;
124027f654740f2a26ad62a5c155af9199af9e69b889claireho    }
124127f654740f2a26ad62a5c155af9199af9e69b889claireho}
124227f654740f2a26ad62a5c155af9199af9e69b889claireho
124327f654740f2a26ad62a5c155af9199af9e69b889claireho
124427f654740f2a26ad62a5c155af9199af9e69b889claireho/*
124527f654740f2a26ad62a5c155af9199af9e69b889claireho * ================== JUnit support ================================
124627f654740f2a26ad62a5c155af9199af9e69b889claireho */
124727f654740f2a26ad62a5c155af9199af9e69b889claireho
124827f654740f2a26ad62a5c155af9199af9e69b889clairehoint32_t
124927f654740f2a26ad62a5c155af9199af9e69b889clairehoT_CTEST_EXPORT2
125027f654740f2a26ad62a5c155af9199af9e69b889clairehoctest_xml_setFileName(const char *name) {
125127f654740f2a26ad62a5c155af9199af9e69b889claireho  XML_FILE_NAME=name;
125227f654740f2a26ad62a5c155af9199af9e69b889claireho  return 0;
125327f654740f2a26ad62a5c155af9199af9e69b889claireho}
125427f654740f2a26ad62a5c155af9199af9e69b889claireho
125527f654740f2a26ad62a5c155af9199af9e69b889claireho
125627f654740f2a26ad62a5c155af9199af9e69b889clairehoint32_t
125727f654740f2a26ad62a5c155af9199af9e69b889clairehoT_CTEST_EXPORT2
125827f654740f2a26ad62a5c155af9199af9e69b889clairehoctest_xml_init(const char *rootName) {
125927f654740f2a26ad62a5c155af9199af9e69b889claireho  if(!XML_FILE_NAME) return 0;
126027f654740f2a26ad62a5c155af9199af9e69b889claireho  XML_FILE = fopen(XML_FILE_NAME,"w");
126127f654740f2a26ad62a5c155af9199af9e69b889claireho  if(!XML_FILE) {
126227f654740f2a26ad62a5c155af9199af9e69b889claireho    perror("fopen");
126327f654740f2a26ad62a5c155af9199af9e69b889claireho    fprintf(stderr," Error: couldn't open XML output file %s\n", XML_FILE_NAME);
126427f654740f2a26ad62a5c155af9199af9e69b889claireho    return 1;
126527f654740f2a26ad62a5c155af9199af9e69b889claireho  }
1266103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius  while(*rootName&&!isalnum((int)*rootName)) {
126727f654740f2a26ad62a5c155af9199af9e69b889claireho    rootName++;
126827f654740f2a26ad62a5c155af9199af9e69b889claireho  }
126927f654740f2a26ad62a5c155af9199af9e69b889claireho  strcpy(XML_PREFIX,rootName);
127027f654740f2a26ad62a5c155af9199af9e69b889claireho  {
127127f654740f2a26ad62a5c155af9199af9e69b889claireho    char *p = XML_PREFIX+strlen(XML_PREFIX);
1272103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    for(p--;*p&&p>XML_PREFIX&&!isalnum((int)*p);p--) {
127327f654740f2a26ad62a5c155af9199af9e69b889claireho      *p=0;
127427f654740f2a26ad62a5c155af9199af9e69b889claireho    }
127527f654740f2a26ad62a5c155af9199af9e69b889claireho  }
127627f654740f2a26ad62a5c155af9199af9e69b889claireho  /* write prefix */
127727f654740f2a26ad62a5c155af9199af9e69b889claireho  fprintf(XML_FILE, "<testsuite name=\"%s\">\n", XML_PREFIX);
127827f654740f2a26ad62a5c155af9199af9e69b889claireho
127927f654740f2a26ad62a5c155af9199af9e69b889claireho  return 0;
128027f654740f2a26ad62a5c155af9199af9e69b889claireho}
128127f654740f2a26ad62a5c155af9199af9e69b889claireho
128227f654740f2a26ad62a5c155af9199af9e69b889clairehoint32_t
128327f654740f2a26ad62a5c155af9199af9e69b889clairehoT_CTEST_EXPORT2
128427f654740f2a26ad62a5c155af9199af9e69b889clairehoctest_xml_fini(void) {
128527f654740f2a26ad62a5c155af9199af9e69b889claireho  if(!XML_FILE) return 0;
128627f654740f2a26ad62a5c155af9199af9e69b889claireho
128727f654740f2a26ad62a5c155af9199af9e69b889claireho  fprintf(XML_FILE, "</testsuite>\n");
128827f654740f2a26ad62a5c155af9199af9e69b889claireho  fclose(XML_FILE);
128927f654740f2a26ad62a5c155af9199af9e69b889claireho  printf(" ( test results written to %s )\n", XML_FILE_NAME);
129027f654740f2a26ad62a5c155af9199af9e69b889claireho  XML_FILE=0;
129127f654740f2a26ad62a5c155af9199af9e69b889claireho  return 0;
129227f654740f2a26ad62a5c155af9199af9e69b889claireho}
129327f654740f2a26ad62a5c155af9199af9e69b889claireho
129427f654740f2a26ad62a5c155af9199af9e69b889claireho
129527f654740f2a26ad62a5c155af9199af9e69b889clairehoint32_t
129627f654740f2a26ad62a5c155af9199af9e69b889clairehoT_CTEST_EXPORT2
129759d709d503bab6e2b61931737e662dd293b40578ccorneliusctest_xml_testcase(const char *classname, const char *name, const char *timeSeconds, const char *failMsg) {
129827f654740f2a26ad62a5c155af9199af9e69b889claireho  if(!XML_FILE) return 0;
129927f654740f2a26ad62a5c155af9199af9e69b889claireho
130059d709d503bab6e2b61931737e662dd293b40578ccornelius  fprintf(XML_FILE, "\t<testcase classname=\"%s:%s\" name=\"%s:%s\" time=\"%s\"", XML_PREFIX, classname, XML_PREFIX, name, timeSeconds);
130127f654740f2a26ad62a5c155af9199af9e69b889claireho  if(failMsg) {
130227f654740f2a26ad62a5c155af9199af9e69b889claireho    fprintf(XML_FILE, ">\n\t\t<failure type=\"err\" message=\"%s\"/>\n\t</testcase>\n", failMsg);
130327f654740f2a26ad62a5c155af9199af9e69b889claireho  } else {
130427f654740f2a26ad62a5c155af9199af9e69b889claireho    fprintf(XML_FILE, "/>\n");
130527f654740f2a26ad62a5c155af9199af9e69b889claireho  }
130627f654740f2a26ad62a5c155af9199af9e69b889claireho
130727f654740f2a26ad62a5c155af9199af9e69b889claireho  return 0;
130827f654740f2a26ad62a5c155af9199af9e69b889claireho}
130927f654740f2a26ad62a5c155af9199af9e69b889claireho
131027f654740f2a26ad62a5c155af9199af9e69b889claireho
1311