summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu/icu-xetex/test/threadtest/converttest.cpp
blob: 8de22efa786ea623be94fc46d422a61517bd5f09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
//********************************************************************
//   Copyright (C) 2002-2003, International Business Machines
//   Corporation and others.  All Rights Reserved.
//********************************************************************
//
// File converttest.cpp
//

#include "threadtest.h"
#include "unicode/utypes.h"
#include "unicode/ucnv.h"
#include "unicode/uclean.h"
#include "stdio.h"

U_CAPI UBool U_EXPORT2 ucnv_cleanup();

class ConvertThreadTest: public AbstractThreadTest {
public:
                    ConvertThreadTest();
    virtual        ~ConvertThreadTest();
    virtual void    check();
    virtual void    runOnce();

private:
    UConverter      *fCnv;
};


ConvertThreadTest::ConvertThreadTest() {
    UErrorCode    err = U_ZERO_ERROR;

    fCnv = ucnv_open("gb18030", &err);
    if (U_FAILURE(err)) {
        fprintf(stderr, "ConvertTest - could not ucnv_open(\"gb18030\")\n");
        fCnv = NULL;
    }
};


ConvertThreadTest::~ConvertThreadTest() {
    ucnv_close(fCnv);
    fCnv = 0;
}

void ConvertThreadTest::runOnce() {
    UErrorCode     err = U_ZERO_ERROR;
    UConverter     *cnv1;
    UConverter     *cnv2;
    char           buf[U_CNV_SAFECLONE_BUFFERSIZE];
    int32_t        bufSize = U_CNV_SAFECLONE_BUFFERSIZE;

    cnv1 = ucnv_open("shift_jis", &err);
    if (U_FAILURE(err)) {
        fprintf(stderr, "ucnv_open(\"shift_jis\") failed.\n");
    }

    cnv2 = ucnv_safeClone(fCnv,       // The source converter, common to all threads.
                          buf,  
                          &bufSize,  
                          &err);
    if (U_FAILURE(err)) {
        fprintf(stderr, "ucnv_safeClone() failed.\n");
    }
    ucnv_close(cnv1);
    ucnv_close(cnv2);
    ucnv_flushCache();
}

void ConvertThreadTest::check() {
    UErrorCode     err = U_ZERO_ERROR;

    if (fCnv) {ucnv_close(fCnv);}
    //if (ucnv_cleanup () == FALSE) {
    //    fprintf(stderr, "ucnv_cleanup() failed - cache was not empty.\n");
    //}
    fCnv = ucnv_open("gb18030", &err);
    if (U_FAILURE(err)) {
        fprintf(stderr, "ConvertTest::check() - could not redo ucnv_open(\"gb18030\")\n");
        fCnv = NULL;
    }
}


AbstractThreadTest *createConvertTest() {
    return new ConvertThreadTest();
}