• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *******************************************************************************
3  *
4  *   Copyright (C) 2003-2007, 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 
77 private:
78     UBool
79     ToUnicodeCase(ConversionCase &cc, UConverterToUCallback callback, const char *option);
80 
81     UBool
82     FromUnicodeCase(ConversionCase &cc, UConverterFromUCallback callback, const char *option);
83 
84     UBool
85     checkToUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
86                    const UChar *result, int32_t resultLength,
87                    const int32_t *resultOffsets,
88                    UErrorCode resultErrorCode);
89 
90     UBool
91     checkFromUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
92                      const uint8_t *result, int32_t resultLength,
93                      const int32_t *resultOffsets,
94                      UErrorCode resultErrorCode);
95 
96     UConverter *
97     cnv_open(const char *name, UErrorCode &errorCode);
98 
99     /* for testing direct UTF-8 conversion */
100     UConverter *utf8Cnv;
101 };
102 
103 #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
104 
105 #endif
106