Home | History | Annotate | Download | only in intltest
      1 // Copyright (C) 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:   US-ASCII
     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 
     80 private:
     81     UBool
     82     ToUnicodeCase(ConversionCase &cc, UConverterToUCallback callback, const char *option);
     83 
     84     UBool
     85     FromUnicodeCase(ConversionCase &cc, UConverterFromUCallback callback, const char *option);
     86 
     87     UBool
     88     checkToUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
     89                    const UChar *result, int32_t resultLength,
     90                    const int32_t *resultOffsets,
     91                    UErrorCode resultErrorCode);
     92 
     93     UBool
     94     checkFromUnicode(ConversionCase &cc, UConverter *cnv, const char *name,
     95                      const uint8_t *result, int32_t resultLength,
     96                      const int32_t *resultOffsets,
     97                      UErrorCode resultErrorCode);
     98 
     99     UConverter *
    100     cnv_open(const char *name, UErrorCode &errorCode);
    101 
    102     /* for testing direct UTF-8 conversion */
    103     UConverter *utf8Cnv;
    104 };
    105 
    106 #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */
    107 
    108 #endif
    109