1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
3c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert * Copyright (c) 1997-2015, International Business Machines Corporation and
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************************
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CINTLTST.C
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History:
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*        Name                     Description
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*     Madhu Katragadda               Creation
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*********************************************************************************
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*The main root for C API tests*/
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h>
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/putil.h"
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cstring.h"
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h"
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uassert.h"
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h"
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uchar.h"
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucnv.h"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ures.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uclean.h"
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucal.h"
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uoptions.h"
3427f654740f2a26ad62a5c155af9199af9e69b889claireho#include "putilimp.h" /* for uprv_getRawUTCtime() */
3550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#ifdef URES_DEBUG
3650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "uresimp.h" /* for ures_dumpCacheContents() */
3750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef XP_MAC_CONSOLE
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#   include <console.h>
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
4354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#define CTST_MAX_ALLOC 8192
4454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius/* Array used as a queue */
4554dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic void * ctst_allocated_stuff[CTST_MAX_ALLOC] = {0};
4654dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic int ctst_allocated = 0;
4754dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic UBool ctst_free = FALSE;
4854dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic int ctst_allocated_total = 0;
4954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CTST_LEAK_CHECK 1
5154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef CTST_LEAK_CHECK
5354dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic void ctst_freeAll(void);
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char* _testDataPath=NULL;
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *  Forward Declarations
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid ctest_setICU_DATA(void);
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if UCONFIG_NO_LEGACY_CONVERSION
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#   define TRY_CNV_1 "iso-8859-1"
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#   define TRY_CNV_2 "ibm-1208"
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#   define TRY_CNV_1 "iso-8859-7"
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#   define TRY_CNV_2 "sjis"
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
7385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic int gOrigArgc;
7485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const char* const * gOrigArgv;
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert#ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
77c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik RoubertU_CAPI void unistr_printLengths();
78c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert#endif
79c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint main(int argc, const char* const argv[])
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int nerrors = 0;
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool   defaultDataFound;
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TestNode *root;
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *warnOrErr = "Failure";
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UDate startTime, endTime;
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t diffTime;
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* initial check for the default converter */
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode = U_ZERO_ERROR;
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UResourceBundle *rb;
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter *cnv;
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    U_MAIN_INIT_ARGS(argc, argv);
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
9627f654740f2a26ad62a5c155af9199af9e69b889claireho    startTime = uprv_getRawUTCtime();
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
9885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    gOrigArgc = argc;
9985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    gOrigArgv = argv;
10085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (!initArgs(argc, argv, NULL, NULL)) {
10185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* Error already displayed. */
10285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return -1;
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
10485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
10585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* Check whether ICU will initialize without forcing the build data directory into
10685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *  the ICU_DATA path.  Success here means either the data dll contains data, or that
10785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *  this test program was run with ICU_DATA set externally.  Failure of this check
10885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *  is normal when ICU data is not packaged into a shared library.
10985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *
11085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *  Whether or not this test succeeds, we want to cleanup and reinitialize
11185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho     *  with a data path so that data loading from individual files can be tested.
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
11385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    defaultDataFound = TRUE;
11485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    u_init(&errorCode);
11585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (U_FAILURE(errorCode)) {
11685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        fprintf(stderr,
11785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            "#### Note:  ICU Init without build-specific setDataDirectory() failed. %s\n", u_errorName(errorCode));
11885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        defaultDataFound = FALSE;
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
12085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    u_cleanup();
12150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#ifdef URES_DEBUG
12250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    fprintf(stderr, "After initial u_cleanup: RB cache %s empty.\n", ures_dumpCacheContents()?"WAS NOT":"was");
12350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
12527f654740f2a26ad62a5c155af9199af9e69b889claireho    while (getTestOption(REPEAT_TESTS_OPTION) > 0) {   /* Loop runs once per complete execution of the tests
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  *   used for -r  (repeat) test option.                */
12785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (!initArgs(argc, argv, NULL, NULL)) {
12885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* Error already displayed. */
12985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return -1;
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errorCode = U_ZERO_ERROR;
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Initialize ICU */
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (!defaultDataFound) {
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ctest_setICU_DATA();    /* u_setDataDirectory() must happen Before u_init() */
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_init(&errorCode);
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (U_FAILURE(errorCode)) {
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr,
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "#### ERROR! %s: u_init() failed with status = \"%s\".\n"
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "*** Check the ICU_DATA environment variable and \n"
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                "*** check that the data files are present.\n", argv[0], u_errorName(errorCode));
14327f654740f2a26ad62a5c155af9199af9e69b889claireho                if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fprintf(stderr, "*** Exiting.  Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    u_cleanup();
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return 1;
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* try more data */
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        cnv = ucnv_open(TRY_CNV_2, &errorCode);
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(cnv != 0) {
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* ok */
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucnv_close(cnv);
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr,
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** %s! The converter for " TRY_CNV_2 " cannot be opened.\n"
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** Check the ICU_DATA environment variable and \n"
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** check that the data files are present.\n", warnOrErr);
16227f654740f2a26ad62a5c155af9199af9e69b889claireho            if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                fprintf(stderr, "*** Exitting.  Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_cleanup();
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                return 1;
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        rb = ures_open(NULL, "en", &errorCode);
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(errorCode)) {
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* ok */
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ures_close(rb);
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr,
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** %s! The \"en\" locale resource bundle cannot be opened.\n"
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** Check the ICU_DATA environment variable and \n"
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** check that the data files are present.\n", warnOrErr);
17827f654740f2a26ad62a5c155af9199af9e69b889claireho            if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                fprintf(stderr, "*** Exitting.  Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_cleanup();
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                return 1;
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errorCode = U_ZERO_ERROR;
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        rb = ures_open(NULL, NULL, &errorCode);
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(errorCode)) {
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* ok */
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (errorCode == U_USING_DEFAULT_WARNING || errorCode == U_USING_FALLBACK_WARNING) {
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                fprintf(stderr,
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        "#### Note: The default locale %s is not available\n", uloc_getDefault());
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ures_close(rb);
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr,
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** %s! Can not open a resource bundle for the default locale %s\n", warnOrErr, uloc_getDefault());
19727f654740f2a26ad62a5c155af9199af9e69b889claireho            if(!getTestOption(WARN_ON_MISSING_DATA_OPTION)) {
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                fprintf(stderr, "*** Exitting.  Use the '-w' option if data files were\n"
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    "*** purposely removed, to continue test anyway.\n");
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_cleanup();
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                return 1;
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stdout, "Default locale for this run is %s\n", uloc_getDefault());
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Build a tree of all tests.
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         *   Subsequently will be used to find / iterate the tests to run */
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        root = NULL;
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        addAllTests(&root);
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*  Tests acutally run HERE.   TODO:  separate command line option parsing & setting from test execution!! */
21285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        nerrors = runTestRequest(root, argc, argv);
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21427f654740f2a26ad62a5c155af9199af9e69b889claireho        setTestOption(REPEAT_TESTS_OPTION, DECREMENT_OPTION_VALUE);
21527f654740f2a26ad62a5c155af9199af9e69b889claireho        if (getTestOption(REPEAT_TESTS_OPTION) > 0) {
21627f654740f2a26ad62a5c155af9199af9e69b889claireho            printf("Repeating tests %d more time(s)\n", getTestOption(REPEAT_TESTS_OPTION));
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        cleanUpTestTree(root);
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef CTST_LEAK_CHECK
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ctst_freeAll();
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* To check for leaks */
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */
22454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
22554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        if(getTestOption(VERBOSITY_OPTION) && ctst_allocated_total>0) {
22654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius          fprintf(stderr,"ctst_freeAll():  cleaned up after %d allocations (queue of %d)\n", ctst_allocated_total, CTST_MAX_ALLOC);
22754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        }
22850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#ifdef URES_DEBUG
22950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        if(ures_dumpCacheContents()) {
23050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho          fprintf(stderr, "Error: After final u_cleanup, RB cache was not empty.\n");
23150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho          nerrors++;
23250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        } else {
23350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho          fprintf(stderr,"OK: After final u_cleanup, RB cache was empty.\n");
23450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        }
23550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }  /* End of loop that repeats the entire test, if requested.  (Normally doesn't loop)  */
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
240c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert#ifdef UNISTR_COUNT_FINAL_STRING_LENGTHS
241c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert    unistr_printLengths();
242c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert#endif
243c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert
24427f654740f2a26ad62a5c155af9199af9e69b889claireho    endTime = uprv_getRawUTCtime();
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    diffTime = (int32_t)(endTime - startTime);
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    printf("Elapsed Time: %02d:%02d:%02d.%03d\n",
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        (int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR),
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        (int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE),
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        (int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND),
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        (int)(diffTime%U_MILLIS_PER_SECOND));
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return nerrors ? 1 : 0;
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void ctest_appendToDataDirectory(const char *toAppend)
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *oldPath ="";
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char newBuf [1024];
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *newPath = newBuf;
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t oldLen;
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t newLen;
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if((toAppend == NULL) || (*toAppend == 0)) {
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    oldPath = u_getDataDirectory();
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if( (oldPath==NULL) || (*oldPath == 0)) {
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_setDataDirectory(toAppend);
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        oldLen = strlen(oldPath);
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        newLen = strlen(toAppend)+1+oldLen;
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(newLen > 1022)
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            newPath = (char *)ctst_malloc(newLen);
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcpy(newPath, oldPath);
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcpy(newPath+oldLen, U_PATH_SEP_STRING);
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcpy(newPath+oldLen+1, toAppend);
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_setDataDirectory(newPath);
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(newPath != newBuf)
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            free(newPath);
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* returns the path to icu/source/data */
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char *  ctest_dataSrcDir()
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const char *dataSrcDir = NULL;
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(dataSrcDir) {
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return dataSrcDir;
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* U_TOPSRCDIR is set by the makefiles on UNIXes when building cintltst and intltst
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              to point to the top of the build hierarchy, which may or
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              may not be the same as the source directory, depending on
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              the configure options used.  At any rate,
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              set the data path to the built data from this directory.
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              The value is complete with quotes, so it can be used
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              as-is as a string constant.
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    */
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if defined (U_TOPSRCDIR)
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        dataSrcDir = U_TOPSRCDIR  U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else
316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* On Windows, the file name obtained from __FILE__ includes a full path.
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *             This file is "wherever\icu\source\test\cintltst\cintltst.c"
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *             Change to    "wherever\icu\source\data"
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static char p[sizeof(__FILE__) + 20];
323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char *pBackSlash;
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int i;
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcpy(p, __FILE__);
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* We want to back over three '\' chars.                            */
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*   Only Windows should end up here, so looking for '\' is safe.   */
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for (i=1; i<=3; i++) {
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (pBackSlash != NULL) {
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                *pBackSlash = 0;        /* Truncate the string at the '\'   */
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (pBackSlash != NULL) {
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* We found and truncated three names from the path.
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             *  Now append "source\data" and set the environment
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             */
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING );
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            dataSrcDir = p;
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else {
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* __FILE__ on MSVC7 does not contain the directory */
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r");
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (file) {
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                fclose(file);
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                dataSrcDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            else {
35185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                dataSrcDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return dataSrcDir;
358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* returns the path to icu/source/data/out */
362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char *ctest_dataOutDir()
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const char *dataOutDir = NULL;
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(dataOutDir) {
367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return dataOutDir;
368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* U_TOPBUILDDIR is set by the makefiles on UNIXes when building cintltst and intltst
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              to point to the top of the build hierarchy, which may or
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              may not be the same as the source directory, depending on
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              the configure options used.  At any rate,
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              set the data path to the built data from this directory.
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              The value is complete with quotes, so it can be used
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //              as-is as a string constant.
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    */
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if defined (U_TOPBUILDDIR)
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        dataOutDir = U_TOPBUILDDIR "data"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else
383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* On Windows, the file name obtained from __FILE__ includes a full path.
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *             This file is "wherever\icu\source\test\cintltst\cintltst.c"
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *             Change to    "wherever\icu\source\data"
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static char p[sizeof(__FILE__) + 20];
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char *pBackSlash;
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int i;
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcpy(p, __FILE__);
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* We want to back over three '\' chars.                            */
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*   Only Windows should end up here, so looking for '\' is safe.   */
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for (i=1; i<=3; i++) {
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (pBackSlash != NULL) {
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                *pBackSlash = 0;        /* Truncate the string at the '\'   */
400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (pBackSlash != NULL) {
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* We found and truncated three names from the path.
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             *  Now append "source\data" and set the environment
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             */
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING);
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            dataOutDir = p;
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else {
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* __FILE__ on MSVC7 does not contain the directory */
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r");
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (file) {
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                fclose(file);
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            else {
41885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return dataOutDir;
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*  ctest_setICU_DATA  - if the ICU_DATA environment variable is not already
428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *                       set, try to deduce the directory in which ICU was built,
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *                       and set ICU_DATA to "icu/source/data" in that location.
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *                       The intent is to allow the tests to have a good chance
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *                       of running without requiring that the user manually set
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *                       ICU_DATA.  Common data isn't a problem, since it is
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *                       picked up via a static (build time) reference, but the
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *                       tests dynamically load some data.
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid ctest_setICU_DATA() {
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* No location for the data dir was identifiable.
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *   Add other fallbacks for the test data location here if the need arises
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (getenv("ICU_DATA") == NULL) {
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* If ICU_DATA isn't set, set it to the usual location */
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_setDataDirectory(ctest_dataOutDir());
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/*  These tests do cleanup and reinitialize ICU in the course of their operation.
44885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho *    The ICU data directory must be preserved across these operations.
44985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho *    Here is a helper function to assist with that.
45085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */
45185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic char *safeGetICUDataDirectory() {
45285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const char *dataDir = u_getDataDirectory();  /* Returned string vanashes with u_cleanup */
45385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char *retStr = NULL;
45485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (dataDir != NULL) {
45585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        retStr = (char *)malloc(strlen(dataDir)+1);
45685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        strcpy(retStr, dataDir);
45785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
45885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    return retStr;
45985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
46085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
46185bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoUBool ctest_resetICU() {
46285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UErrorCode   status = U_ZERO_ERROR;
46385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char         *dataDir = safeGetICUDataDirectory();
46485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
46585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    u_cleanup();
46685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (!initArgs(gOrigArgc, gOrigArgv, NULL, NULL)) {
46785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* Error already displayed. */
46885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return FALSE;
46985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
47085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    u_setDataDirectory(dataDir);
47185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    free(dataDir);
47285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    u_init(&status);
47385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (U_FAILURE(status)) {
47485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "u_init failed with %s\n", u_errorName(status));
47585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return FALSE;
47685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
47785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    return TRUE;
47885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
47985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar* CharsToUChars(const char* str) {
481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Might be faster to just use uprv_strlen() as the preflight len - liu */
482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t len = u_unescape(str, 0, 0); /* preflight */
483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Do NOT use malloc() - we are supposed to be acting like user code! */
484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *buf = (UChar*) malloc(sizeof(UChar) * (len + 1));
485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_unescape(str, buf, len + 1);
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return buf;
487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruchar *austrdup(const UChar* unichars)
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int   length;
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *newString;
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    length    = u_strlen ( unichars );
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*newString = (char*)malloc  ( sizeof( char ) * 4 * ( length + 1 ) );*/ /* this leaks for now */
496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    newString = (char*)ctst_malloc  ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */
497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if ( newString == NULL )
499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return NULL;
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_austrcpy ( newString, unichars );
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return newString;
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruchar *aescstrdup(const UChar* unichars,int32_t length){
507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *newString,*targetLimit,*target;
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverterFromUCallback cb;
509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const void *p;
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode = U_ZERO_ERROR;
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
512103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#   if U_PLATFORM == U_PF_OS390
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const char convName[] = "ibm-1047";
514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#   else
515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        static const char convName[] = "ibm-37";
516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#   endif
517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else
518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const char convName[] = "US-ASCII";
519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter* conv = ucnv_open(convName, &errorCode);
521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(length==-1){
522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        length = u_strlen( unichars);
523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    newString = (char*)ctst_malloc ( sizeof(char) * 8 * (length +1));
525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    target = newString;
526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    targetLimit = newString+sizeof(char) * 8 * (length +1);
52750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, &cb, &p, &errorCode);
528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_fromUnicode(conv,&target,targetLimit, &unichars, (UChar*)(unichars+length),NULL,TRUE,&errorCode);
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucnv_close(conv);
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    *target = '\0';
531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return newString;
532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char* loadTestData(UErrorCode* err){
535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if( _testDataPath == NULL){
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char*      directory=NULL;
537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UResourceBundle* test =NULL;
538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char* tdpath=NULL;
539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* tdrelativepath;
540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if defined (U_TOPBUILDDIR)
541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        tdrelativepath = "test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        directory = U_TOPBUILDDIR;
543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else
544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        tdrelativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        directory= ctest_dataOutDir();
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        tdpath = (char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10));
549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* u_getDataDirectory shoul return \source\data ... set the
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         * directory to ..\source\data\..\test\testdata\out\testdata
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         *
554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         * Fallback: When Memory mapped file is built
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         * ..\source\data\out\..\..\test\testdata\out\testdata
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         */
557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcpy(tdpath, directory);
558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcat(tdpath, tdrelativepath);
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcat(tdpath,"testdata");
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        test=ures_open(tdpath, "testtypes", err);
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Fall back did not succeed either so return */
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(*err)){
566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            *err = U_FILE_ACCESS_ERROR;
56785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_data_err("Could not load testtypes.res in testdata bundle with path %s - %s\n", tdpath, u_errorName(*err));
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return "";
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ures_close(test);
571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        _testDataPath = tdpath;
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return _testDataPath;
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return _testDataPath;
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CTEST_MAX_TIMEZONE_SIZE 256
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UChar gOriginalTimeZone[CTEST_MAX_TIMEZONE_SIZE] = {0};
579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value.
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param optionalTimeZone Set this to a requested timezone.
583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *      Set to NULL to use the standard test timezone (Pacific Time)
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status) {
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar zoneID[CTEST_MAX_TIMEZONE_SIZE];
588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (optionalTimeZone == NULL) {
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        optionalTimeZone = "America/Los_Angeles";
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (gOriginalTimeZone[0]) {
59385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_data_err("*** Error: time zone saved twice. New value will be %s (Are you missing data?)\n",
594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               optionalTimeZone);
595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucal_getDefaultTimeZone(gOriginalTimeZone, CTEST_MAX_TIMEZONE_SIZE, status);
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("*** Error: Failed to save default time zone: %s\n",
599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               u_errorName(*status));
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *status = U_ZERO_ERROR;
601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrncpy(zoneID, optionalTimeZone, CTEST_MAX_TIMEZONE_SIZE-1);
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    zoneID[CTEST_MAX_TIMEZONE_SIZE-1] = 0;
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucal_setDefaultTimeZone(zoneID, status);
606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("*** Error: Failed to set default time zone to \"%s\": %s\n",
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               optionalTimeZone, u_errorName(*status));
609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Call this once get back the original timezone
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC void ctest_resetTimeZone(void) {
617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING
618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucal_setDefaultTimeZone(gOriginalTimeZone, &status);
621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("*** Error: Failed to reset default time zone: %s\n",
623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               u_errorName(status));
624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Set to an empty state */
626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    gOriginalTimeZone[0] = 0;
627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid *ctst_malloc(size_t size) {
63254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius  ctst_allocated_total++;
633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ctst_allocated >= CTST_MAX_ALLOC - 1) {
634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ctst_allocated = 0;
635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ctst_free = TRUE;
636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ctst_allocated_stuff[ctst_allocated]) {
638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(ctst_allocated_stuff[ctst_allocated]);
639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return ctst_allocated_stuff[ctst_allocated++] = malloc(size);
641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef CTST_LEAK_CHECK
64454dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic void ctst_freeAll() {
645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i;
64654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    if(ctst_free == FALSE) { /* only free up to the allocated mark */
647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i=0; i<ctst_allocated; i++) {
648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            free(ctst_allocated_stuff[i]);
649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ctst_allocated_stuff[i] = NULL;
650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
65154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    } else { /* free all */
652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i=0; i<CTST_MAX_ALLOC; i++) {
653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            free(ctst_allocated_stuff[i]);
654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ctst_allocated_stuff[i] = NULL;
655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ctst_allocated = 0;
658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    _testDataPath=NULL;
659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define VERBOSE_ASSERTIONS
662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
66359d709d503bab6e2b61931737e662dd293b40578ccorneliusU_CFUNC UBool assertSuccessCheck(const char* msg, UErrorCode* ec, UBool possibleDataError) {
664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    U_ASSERT(ec!=NULL);
665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*ec)) {
66659d709d503bab6e2b61931737e662dd293b40578ccornelius        if (possibleDataError) {
66759d709d503bab6e2b61931737e662dd293b40578ccornelius            log_data_err("FAIL: %s (%s)\n", msg, u_errorName(*ec));
66859d709d503bab6e2b61931737e662dd293b40578ccornelius        } else {
66959d709d503bab6e2b61931737e662dd293b40578ccornelius            log_err_status(*ec, "FAIL: %s (%s)\n", msg, u_errorName(*ec));
67059d709d503bab6e2b61931737e662dd293b40578ccornelius        }
671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return TRUE;
674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
67659d709d503bab6e2b61931737e662dd293b40578ccorneliusU_CFUNC UBool assertSuccess(const char* msg, UErrorCode* ec) {
67759d709d503bab6e2b61931737e662dd293b40578ccornelius    U_ASSERT(ec!=NULL);
67859d709d503bab6e2b61931737e662dd293b40578ccornelius    return assertSuccessCheck(msg, ec, FALSE);
67959d709d503bab6e2b61931737e662dd293b40578ccornelius}
68059d709d503bab6e2b61931737e662dd293b40578ccornelius
681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* if 'condition' is a UBool, the compiler complains bitterly about
682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   expressions like 'a > 0' which it evaluates as int */
683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC UBool assertTrue(const char* msg, int /*not UBool*/ condition) {
684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (!condition) {
685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: assertTrue() failed: %s\n", msg);
686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef VERBOSE_ASSERTIONS
688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else {
689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Ok: %s\n", msg);
690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return (UBool)condition;
693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC UBool assertEquals(const char* message, const char* expected,
696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           const char* actual) {
697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (uprv_strcmp(expected, actual) != 0) {
698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: %s; got \"%s\"; expected \"%s\"\n",
699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                message, actual, expected);
700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef VERBOSE_ASSERTIONS
703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else {
704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Ok: %s; got \"%s\"\n", message, actual);
705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return TRUE;
708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
709103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius
710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
711