1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1999-2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: gentest.c
12 * tab size: 8 (not used)
15 * created on: 2000mar03
16 * created by: Madhu Katragadda
18 * This program writes a little data file for testing the udata API.
23 #include "unicode/utypes.h"
24 #include "unicode/putil.h"
25 #include "unicode/uclean.h"
26 #include "unicode/udata.h"
34 #define DATA_NAME "test"
35 #define DATA_TYPE "icu"
37 /* UDataInfo cf. udata.h */
38 static const UDataInfo dataInfo
={
47 {0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
48 {1, 0, 0, 0}, /* formatVersion */
49 {1, 0, 0, 0} /* dataVersion */
52 static void createData(const char*, UErrorCode
*);
54 static int outputJavaStuff(const char * progname
, const char *outputDir
);
56 static UOption options
[]={
58 /*1*/ UOPTION_HELP_QUESTION_MARK
,
59 /*2*/ UOPTION_DESTDIR
,
60 /*3*/ UOPTION_DEF("genres", 'r', UOPT_NO_ARG
),
61 /*4*/ UOPTION_DEF("javastuff", 'j', UOPT_NO_ARG
),
65 main(int argc
, char* argv
[]) {
66 UErrorCode errorCode
= U_ZERO_ERROR
;
68 /* preset then read command line options */
69 options
[2].value
=u_getDataDirectory();
70 argc
=u_parseArgs(argc
, argv
, UPRV_LENGTHOF(options
), options
);
72 /* error handling, printing usage message */
75 "error in command line argument \"%s\"\n",
78 if(argc
<0 || options
[0].doesOccur
|| options
[1].doesOccur
) {
80 "usage: %s [-options]\n"
81 "\tcreate the test file " DATA_NAME
"." DATA_TYPE
" unless the -r option is given.\n"
83 "\t\t-h or -? or --help this usage text\n"
84 "\t\t-d or --destdir destination directory, followed by the path\n"
85 "\t\t-r or --genres generate resource file testtable32.txt instead of UData test \n"
86 "\t\t-j or --javastuff generate Java source for DebugUtilities. \n",
88 return argc
<0 ? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
91 if( options
[4].doesOccur
) {
92 return outputJavaStuff( argv
[0], options
[2].value
);
93 } else if ( options
[3].doesOccur
) {
94 return genres32( argv
[0], options
[2].value
);
96 /* printf("Generating the test memory mapped file\n"); */
97 createData(options
[2].value
, &errorCode
);
99 return U_FAILURE(errorCode
);
102 /* Create data file ----------------------------------------------------- */
104 createData(const char* outputDirectory
, UErrorCode
*errorCode
) {
105 UNewDataMemory
*pData
;
106 char stringValue
[]={'Y', 'E', 'A', 'R', '\0'};
107 uint16_t intValue
=2000;
112 pData
=udata_create(outputDirectory
, DATA_TYPE
, DATA_NAME
, &dataInfo
,
113 U_COPYRIGHT_STRING
, errorCode
);
114 if(U_FAILURE(*errorCode
)) {
115 fprintf(stderr
, "gentest: unable to create data memory, %s\n", u_errorName(*errorCode
));
119 /* write the data to the file */
120 /* a 16 bit value and a String*/
121 udata_write16(pData
, intValue
);
122 udata_writeString(pData
, stringValue
, sizeof(stringValue
));
125 dataLength
=udata_finish(pData
, errorCode
);
126 if(U_FAILURE(*errorCode
)) {
127 fprintf(stderr
, "gentest: error %d writing the output file\n", *errorCode
);
130 size
=sizeof(stringValue
) + sizeof(intValue
);
133 if(dataLength
!=(long)size
) {
134 fprintf(stderr
, "gentest: data length %ld != calculated size %lu\n",
135 dataLength
, (unsigned long)size
);
136 exit(U_INTERNAL_PROGRAM_ERROR
);
140 /* Create Java file ----------------------------------------------------- */
143 outputJavaStuff(const char* progname
, const char *outputDir
) {
148 uprv_strcpy(file
,outputDir
);
149 if(*outputDir
&& /* don't put a trailing slash if outputDir is empty */
150 file
[strlen(file
)-1]!=U_FILE_SEP_CHAR
) {
151 uprv_strcat(file
,U_FILE_SEP_STRING
);
153 uprv_strcat(file
,"DebugUtilitiesData.java");
154 out
= fopen(file
, "w");
156 printf("%s: Generating %s\n", progname
, file
);
158 fprintf(stderr
, "%s: Couldn't create resource test file %s\n",
163 fprintf(out
, "// Copyright (C) 2016 and later: Unicode, Inc. and others.\n");
164 fprintf(out
, "// License & terms of use: http://www.unicode.org/copyright.html\n\n");
165 fprintf(out
, "/** Copyright (C) 2007-2016, International Business Machines Corporation and Others. All Rights Reserved. **/\n\n");
166 fprintf(out
, "/* NOTE: this file is AUTOMATICALLY GENERATED by gentest.\n"
167 " * See: {ICU4C}/source/data/icu4j-readme.txt for more information. \n"
169 fprintf(out
, "package com.ibm.icu.dev.test.util;\n\n");
170 fprintf(out
, "public class DebugUtilitiesData extends Object {\n");
171 fprintf(out
, " public static final String ICU4C_VERSION=\"%s\";\n", U_ICU_VERSION
);
172 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
173 fprintf(out
, " public static final int %s = %d;\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
175 fprintf(out
, " public static final String [] TYPES = { \n");
176 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
177 fprintf(out
, " \"%s\", /* %d */\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
179 fprintf(out
, " };\n\n");
181 fprintf(out
, " public static final String [][] NAMES = { \n");
182 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
183 count
= udbg_enumCount((UDebugEnumType
)t
);
184 fprintf(out
, " /* %s, %d */\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
185 fprintf(out
, " { \n");
186 for(i
=0;i
<count
;i
++) {
188 " \"%s\", /* %d */ \n", udbg_enumName((UDebugEnumType
)t
,i
), i
);
190 fprintf(out
, " },\n");
192 fprintf(out
, " };\n\n");
194 fprintf(out
, " public static final int [][] VALUES = { \n");
195 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
196 count
= udbg_enumCount((UDebugEnumType
)t
);
197 fprintf(out
, " /* %s, %d */\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
198 fprintf(out
, " { \n");
199 for(i
=0;i
<count
;i
++) {
203 #if !UCONFIG_NO_FORMATTING
204 case UDBG_UCalendarDateFields
:
205 case UDBG_UCalendarMonths
:
206 /* Temporary workaround for IS_LEAP_MONTH #6051 */
207 if (t
== UDBG_UCalendarDateFields
&& i
== 22) {
208 fprintf(out
, "com.ibm.icu.util.ChineseCalendar.%s, /* %d */", udbg_enumName((UDebugEnumType
)t
,i
), i
);
210 fprintf(out
, "com.ibm.icu.util.Calendar.%s, /* %d */", udbg_enumName((UDebugEnumType
)t
,i
), i
);
214 case UDBG_UDebugEnumType
:
216 fprintf(out
,"%d, /* %s */", i
, udbg_enumName((UDebugEnumType
)t
,i
));
220 fprintf(out
, " },\n");
222 fprintf(out
, " };\n\n");