]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/convtest.h
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / intltest / convtest.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 * Copyright (C) 2003-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 *******************************************************************************
10 * file name: convtest.h
11 * encoding: UTF-8
12 * tab size: 8 (not used)
13 * indentation:4
14 *
15 * created on: 2003jul15
16 * created by: Markus W. Scherer
17 *
18 * Test file for data-driven conversion tests.
19 */
20
21 #ifndef __CONVTEST_H__
22 #define __CONVTEST_H__
23
24 #include "unicode/utypes.h"
25
26 #if !UCONFIG_NO_LEGACY_CONVERSION
27
28 #include "unicode/ucnv.h"
29 #include "intltest.h"
30
31 struct ConversionCase {
32 /* setup */
33 int32_t caseNr;
34 const char *charset, *cbopt, *name;
35 UChar subString[16];
36 char subchar[8];
37 int8_t setSub;
38
39 /* input and expected output */
40 const uint8_t *bytes;
41 int32_t bytesLength;
42 const UChar *unicode;
43 int32_t unicodeLength;
44 const int32_t *offsets;
45
46 /* UTF-8 version of unicode[unicodeLength] */
47 const char *utf8;
48 int32_t utf8Length;
49
50 /* options */
51 UBool finalFlush;
52 UBool fallbacks;
53 UErrorCode outErrorCode;
54 const uint8_t *invalidChars;
55 const UChar *invalidUChars;
56 int32_t invalidLength;
57
58 /* actual output */
59 uint8_t resultBytes[200];
60 UChar resultUnicode[200];
61 int32_t resultOffsets[200];
62 int32_t resultLength;
63
64 UErrorCode resultErrorCode;
65 };
66
67 class ConversionTest : public IntlTest {
68 public:
69 ConversionTest();
70 virtual ~ConversionTest();
71
72 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=0);
73
74 void TestToUnicode();
75 void TestFromUnicode();
76 void TestGetUnicodeSet();
77 void TestGetUnicodeSet2();
78 void TestDefaultIgnorableCallback();
79 void TestUTF8ToUTF8Overflow();
80
81 private:
82 UBool
83 ToUnicodeCase(ConversionCase &cc, UConverterToUCallback callback, const char *option);
84
85 UBool
86 FromUnicodeCase(ConversionCase &cc, UConverterFromUCallback callback, const char *option);
87
88 UBool
89 checkToUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
90 const UChar *result, int32_t resultLength,
91 const int32_t *resultOffsets,
92 UErrorCode resultErrorCode);
93
94 UBool
95 checkFromUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
96 const uint8_t *result, int32_t resultLength,
97 const int32_t *resultOffsets,
98 UErrorCode resultErrorCode);
99
100 UConverter *
101 cnv_open(const char *name, UErrorCode &errorCode);
102
103 /* for testing direct UTF-8 conversion */
104 UConverter *utf8Cnv;
105 };
106
107 #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
108
109 #endif