]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/threadtest/converttest.cpp
ICU-400.39.tar.gz
[apple/icu.git] / icuSources / test / threadtest / converttest.cpp
CommitLineData
b75a7d8f
A
1//
2//********************************************************************
374ca955 3// Copyright (C) 2002-2003, International Business Machines
b75a7d8f
A
4// Corporation and others. All Rights Reserved.
5//********************************************************************
6//
7// File converttest.cpp
8//
9
10#include "threadtest.h"
11#include "unicode/utypes.h"
12#include "unicode/ucnv.h"
13#include "unicode/uclean.h"
14#include "stdio.h"
15
16U_CAPI UBool U_EXPORT2 ucnv_cleanup();
17
18class ConvertThreadTest: public AbstractThreadTest {
19public:
20 ConvertThreadTest();
21 virtual ~ConvertThreadTest();
22 virtual void check();
23 virtual void runOnce();
24
25private:
26 UConverter *fCnv;
27};
28
29
30ConvertThreadTest::ConvertThreadTest() {
31 UErrorCode err = U_ZERO_ERROR;
32
33 fCnv = ucnv_open("gb18030", &err);
34 if (U_FAILURE(err)) {
35 fprintf(stderr, "ConvertTest - could not ucnv_open(\"gb18030\")\n");
36 fCnv = NULL;
37 }
38};
39
40
41ConvertThreadTest::~ConvertThreadTest() {
42 ucnv_close(fCnv);
43 fCnv = 0;
44}
45
46void ConvertThreadTest::runOnce() {
47 UErrorCode err = U_ZERO_ERROR;
48 UConverter *cnv1;
49 UConverter *cnv2;
50 char buf[U_CNV_SAFECLONE_BUFFERSIZE];
51 int32_t bufSize = U_CNV_SAFECLONE_BUFFERSIZE;
52
53 cnv1 = ucnv_open("shift_jis", &err);
54 if (U_FAILURE(err)) {
55 fprintf(stderr, "ucnv_open(\"shift_jis\") failed.\n");
56 }
57
58 cnv2 = ucnv_safeClone(fCnv, // The source converter, common to all threads.
59 buf,
60 &bufSize,
61 &err);
62 if (U_FAILURE(err)) {
63 fprintf(stderr, "ucnv_safeClone() failed.\n");
64 }
65 ucnv_close(cnv1);
66 ucnv_close(cnv2);
67 ucnv_flushCache();
68}
69
70void ConvertThreadTest::check() {
71 UErrorCode err = U_ZERO_ERROR;
72
73 if (fCnv) {ucnv_close(fCnv);}
74 //if (ucnv_cleanup () == FALSE) {
75 // fprintf(stderr, "ucnv_cleanup() failed - cache was not empty.\n");
76 //}
77 fCnv = ucnv_open("gb18030", &err);
78 if (U_FAILURE(err)) {
79 fprintf(stderr, "ConvertTest::check() - could not redo ucnv_open(\"gb18030\")\n");
80 fCnv = NULL;
81 }
82}
83
84
85AbstractThreadTest *createConvertTest() {
86 return new ConvertThreadTest();
87}
88