~ubuntu-branches/ubuntu/gutsy/icu/gutsy

« back to all changes in this revision

Viewing changes to source/tools/gentest/gentest.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
*******************************************************************************
3
 
*
4
 
*   Copyright (C) 1999-2001, International Business Machines
5
 
*   Corporation and others.  All Rights Reserved.
6
 
*
7
 
*******************************************************************************
8
 
*   file name:  gentest.c
9
 
*   encoding:   US-ASCII
10
 
*   tab size:   8 (not used)
11
 
*   indentation:4
12
 
*
13
 
*   created on: 2000mar03
14
 
*   created by: Madhu Katragadda
15
 
*
16
 
*   This program writes a little data file for testing the udata API.
17
 
*/
18
 
 
19
 
#include <stdio.h>
20
 
#include <stdlib.h>
21
 
#include "unicode/utypes.h"
22
 
#include "unicode/putil.h"
23
 
#include "unicode/udata.h"
24
 
#include "unewdata.h"
25
 
#include "cmemory.h"
26
 
#include "cstring.h"
27
 
#include "uoptions.h"
28
 
 
29
 
#define DATA_NAME "test"
30
 
#define DATA_TYPE "dat"
31
 
 
32
 
/* UDataInfo cf. udata.h */
33
 
static const UDataInfo dataInfo={
34
 
    sizeof(UDataInfo),
35
 
    0,
36
 
 
37
 
    U_IS_BIG_ENDIAN,
38
 
    U_CHARSET_FAMILY,
39
 
    sizeof(UChar),
40
 
    0,
41
 
 
42
 
    {0x54, 0x65, 0x73, 0x74},     /* dataFormat="Test" */
43
 
    {1, 0, 0, 0},                 /* formatVersion */
44
 
    {1, 0, 0, 0}                  /* dataVersion */
45
 
};
46
 
 
47
 
static void createData(const char*);
48
 
 
49
 
static UOption options[]={
50
 
    UOPTION_HELP_H,
51
 
    UOPTION_HELP_QUESTION_MARK,
52
 
    UOPTION_DESTDIR
53
 
};
54
 
 
55
 
extern int
56
 
main(int argc, char* argv[]) {
57
 
    /* preset then read command line options */
58
 
    options[2].value=u_getDataDirectory();
59
 
    argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
60
 
 
61
 
    /* error handling, printing usage message */
62
 
    if(argc<0) {
63
 
        fprintf(stderr,
64
 
            "error in command line argument \"%s\"\n",
65
 
            argv[-argc]);
66
 
    }
67
 
    if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
68
 
        fprintf(stderr,
69
 
            "usage: %s [-options]\n"
70
 
            "\tcreate the test file " DATA_NAME "." DATA_TYPE "\n"
71
 
            "\toptions:\n"
72
 
            "\t\t-h or -? or --help  this usage text\n"
73
 
            "\t\t-d or --destdir     destination directory, followed by the path\n",
74
 
            argv[0]);
75
 
        return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
76
 
    }
77
 
 
78
 
    /* printf("Generating the test memory mapped file\n"); */
79
 
    createData(options[2].value);
80
 
    return 0;
81
 
}
82
 
 
83
 
/* Create data file ----------------------------------------------------- */
84
 
static void
85
 
createData(const char* outputDirectory) {
86
 
    UNewDataMemory *pData;
87
 
    UErrorCode errorCode=U_ZERO_ERROR;
88
 
    char stringValue[]={'Y', 'E', 'A', 'R', '\0'};
89
 
    uint16_t intValue=2000;
90
 
 
91
 
    long dataLength;
92
 
    uint32_t size;
93
 
 
94
 
    pData=udata_create(outputDirectory, DATA_TYPE, DATA_NAME, &dataInfo,
95
 
                       U_COPYRIGHT_STRING, &errorCode);
96
 
    if(U_FAILURE(errorCode)) {
97
 
        fprintf(stderr, "gentest: unable to create data memory, error %d\n", errorCode);
98
 
        exit(errorCode);
99
 
    }
100
 
 
101
 
    /* write the data to the file */
102
 
    /* a 16 bit value  and a String*/
103
 
    udata_write16(pData, intValue);
104
 
    udata_writeString(pData, stringValue, sizeof(stringValue));
105
 
 
106
 
    /* finish up */
107
 
    dataLength=udata_finish(pData, &errorCode);
108
 
    if(U_FAILURE(errorCode)) {
109
 
        fprintf(stderr, "gentest: error %d writing the output file\n", errorCode);
110
 
        exit(errorCode);
111
 
    }
112
 
    size=sizeof(stringValue) + sizeof(intValue);
113
 
 
114
 
 
115
 
    if(dataLength!=(long)size) {
116
 
        fprintf(stderr, "gentest: data length %ld != calculated size %lu\n",
117
 
            dataLength, (unsigned long)size);
118
 
        exit(U_INTERNAL_PROGRAM_ERROR);
119
 
    }
120
 
}