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