]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/cintltst/cctest.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cctest.c
CommitLineData
b75a7d8f
A
1/********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7#include "unicode/ucnv.h"
8#include "unicode/ucnv_err.h"
9
10#include "cintltst.h"
11#include "ustr_imp.h"
12void TestFlushCache(void); /* keep gcc happy */
13
14
15void TestFlushCache(void) {
16 UErrorCode err = U_ZERO_ERROR;
17 UConverter* someConverters[5];
18 int flushCount = 0;
19
20 /* flush the converter cache to get a consistent state before the flushing is tested */
21 ucnv_flushCache();
22
23 /*Testing ucnv_open()*/
24 /* Note: These converters have been chosen because they do NOT
25 encode the Latin characters (U+0041, ...), and therefore are
26 highly unlikely to be chosen as system default codepages */
27
28 someConverters[0] = ucnv_open("ibm-1047", &err);
29 if (U_FAILURE(err)) {
30 log_data_err("FAILURE! %s\n", myErrorName(err));
31 }
32
33 someConverters[1] = ucnv_open("ibm-1047", &err);
34 if (U_FAILURE(err)) {
35 log_data_err("FAILURE! %s\n", myErrorName(err));
36 }
37
38 someConverters[2] = ucnv_open("ibm-1047", &err);
39 if (U_FAILURE(err)) {
40 log_data_err("FAILURE! %s\n", myErrorName(err));
41 }
42
43 someConverters[3] = ucnv_open("gb18030", &err);
44 if (U_FAILURE(err)) {
45 log_data_err("FAILURE! %s\n", myErrorName(err));
46 }
47
48 someConverters[4] = ucnv_open("ibm-949", &err);
49 if (U_FAILURE(err)) {
50 log_data_err("FAILURE! %s\n", myErrorName(err));
51 }
52
53
54 /* Testing ucnv_flushCache() */
55 log_verbose("\n---Testing ucnv_flushCache...\n");
56 if ((flushCount=ucnv_flushCache())==0)
57 log_verbose("Flush cache ok\n");
58 else
59 log_data_err("Flush Cache failed [line %d], expect 0 got %d \n", __LINE__, flushCount);
60
61 /*testing ucnv_close() and ucnv_flushCache() */
62 ucnv_close(someConverters[0]);
63 ucnv_close(someConverters[1]);
64
65 if ((flushCount=ucnv_flushCache())==0)
66 log_verbose("Flush cache ok\n");
67 else
68 log_data_err("Flush Cache failed [line %d], expect 0 got %d \n", __LINE__, flushCount);
69
70 ucnv_close(someConverters[2]);
71 ucnv_close(someConverters[3]);
72
73 if ((flushCount=ucnv_flushCache())==2)
74 log_verbose("Flush cache ok\n"); /*because first, second and third are same */
75 else
76 log_data_err("Flush Cache failed line %d, got %d expected 2 or there is an error in ucnv_close()\n",
77 __LINE__,
78 flushCount);
79
80 ucnv_close(someConverters[4]);
81 if ( (flushCount=ucnv_flushCache())==1)
82 log_verbose("Flush cache ok\n");
83 else
84 log_data_err("Flush Cache failed line %d, expected 1 got %d \n", __LINE__, flushCount);
85
86}
87
88
89