convert-test-data.h (3643B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "common/iconv.h" 21 22/** 23 * Representation of test string data and its length in bytes. 24 */ 25typedef struct test_string { 26 27 /** 28 * The raw content of the test string. 29 */ 30 unsigned char* buffer; 31 32 /** 33 * The number of bytes within the test string, including null terminator. 34 */ 35 int size; 36 37} test_string; 38 39/** 40 * Convenience macro which statically-initializes a test_string with the given 41 * string value, automatically calculating its size in bytes. 42 * 43 * @param value 44 * The string value. 45 */ 46#define TEST_STRING(value) { \ 47 .buffer = (unsigned char*) (value), \ 48 .size = sizeof(value) \ 49} 50 51/** 52 * The parameters applicable to a unit test for a particular encoding supported 53 * by guac_iconv(). 54 */ 55typedef struct encoding_test_parameters { 56 57 /** 58 * The human-readable name of this encoding. This will be logged to the 59 * test suite log to assist with debugging test failures. 60 */ 61 const char* name; 62 63 /** 64 * Reader function which reads using this encoding and does not perform any 65 * transformation on newline characters. 66 */ 67 guac_iconv_read* reader; 68 69 /** 70 * Reader function which reads using this encoding and automatically 71 * normalizes newline sequences to Unix-style newline characters. 72 */ 73 guac_iconv_read* reader_normalized; 74 75 /** 76 * Writer function which writes using this encoding and does not perform 77 * any transformation on newline characters. 78 */ 79 guac_iconv_write* writer; 80 81 /** 82 * Writer function which writes using this encoding, but writes newline 83 * characters as CRLF sequences. 84 */ 85 guac_iconv_write* writer_crlf; 86 87 /** 88 * A test string having both Windows- and Unix-style line endings. Except 89 * for the line endings, the characters represented within this test string 90 * must be identical to all other test strings. 91 */ 92 test_string test_mixed; 93 94 /** 95 * A test string having only Unix-style line endings. Except for the line 96 * endings, the characters represented within this test string must be 97 * identical to all other test strings. 98 */ 99 test_string test_unix; 100 101 /** 102 * A test string having only Windows-style line endings. Except for the 103 * line endings, the characters represented within this test string must be 104 * identical to all other test strings. 105 */ 106 test_string test_windows; 107 108} encoding_test_parameters; 109 110/** 111 * The total number of encodings supported by guac_iconv(). 112 */ 113#define NUM_SUPPORTED_ENCODINGS 4 114 115/** 116 * Test parameters for each supported encoding. The test strings included each 117 * consist of five repeated lines of "papà è bello", omitting the line ending 118 * of the final line. 119 */ 120extern encoding_test_parameters test_params[NUM_SUPPORTED_ENCODINGS]; 121