• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) override;
73 
74     void TestToUnicode();
75     void TestFromUnicode();
76     void TestGetUnicodeSet();
77     void TestGetUnicodeSet2();
78     void TestDefaultIgnorableCallback();
79     void TestUTF8ToUTF8Overflow();
80     void TestUTF8ToUTF8Streaming();
81 
82 private:
83     UBool
84     ToUnicodeCase(ConversionCase &cc, UConverterToUCallback callback, const char *option);
85 
86     UBool
87     FromUnicodeCase(ConversionCase &cc, UConverterFromUCallback callback, const char *option);
88 
89     UBool
90     checkToUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
91                    const UChar *result, int32_t resultLength,
92                    const int32_t *resultOffsets,
93                    UErrorCode resultErrorCode);
94 
95     UBool
96     checkFromUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
97                      const uint8_t *result, int32_t resultLength,
98                      const int32_t *resultOffsets,
99                      UErrorCode resultErrorCode);
100 
101     UConverter *
102     cnv_open(const char *name, UErrorCode &errorCode);
103 
104     /* for testing direct UTF-8 conversion */
105     UConverter *utf8Cnv;
106 };
107 
108 #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
109 
110 #endif
111