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