1 /* 2 * Copyright 2011 Google Inc. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ 18 #define SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ 19 20 // Must include this before ICU to avoid stdint redefinition issue. 21 #include "sfntly/port/type.h" 22 23 #include <unicode/ucnv.h> 24 25 #include <string> 26 27 #include "sfntly/font.h" 28 #include "sfntly/data/memory_byte_array.h" 29 30 namespace sfntly { 31 class TestUtils { 32 TestUtils(); 33 34 public: 35 // Compare sections of two byte arrays for equality 36 // @param b1 byte array 1 37 // @param offset1 offset for comparison in byte array 1 38 // @param b2 byte array 2 39 // @param offset2 offset for comparison in byte array 2 40 // @param length the length of the byte arrays to compare 41 // @return true if the array segments are equal; false otherwise 42 // TODO(dfilimon): implement 43 static bool Equals(ByteArray* b1, 44 int32_t offset1, 45 ByteArray* b2, 46 int32_t offset2); 47 48 // @param offset1 offset to start comparing the first ByteArray from 49 // @param ba1 the first ByteArray 50 // @param offset2 offset to start comparing the second ByteArray from 51 // @param ba2 the second ByteArray 52 // @param length the number of bytes to compare 53 // @return true if all bytes in the ranges given are equal; false otherwise 54 // TODO(dfilimon): implement 55 static bool Equals(ByteArray* b1, 56 int32_t offset1, 57 ByteArray* b2, 58 int32_t offset2, 59 int32_t length); 60 61 // TODO(dfilimon): implement FileOutputStream in port/file_output_stream.* 62 // static OutputStream createOutputStream(const char* file_path); 63 64 // TODO(dfilimon): adapt & implement 65 // static FileChannel createFilechannelForWriting(File file); 66 67 // Creates a new file including deleting an already existing file with the 68 // same path and name and creating any needed directories. 69 // TODO(dfilimon): implement 70 static void CreateNewFile(const char* file_path); 71 72 // Converts an integer into a 4 character string using the ASCII encoding. 73 // @param i the value to convert 74 // @return the String based on the number 75 // TODO(dfilimon): implement 76 static void DumpLongAsString(int32_t i, std::string* result); 77 78 // Calculate an OpenType checksum from the array. 79 // @param b the array to calculate checksum on 80 // @param offset the starting index in the array 81 // @param length the number of bytes to check; must be a multiple of 4 82 // @return checksum 83 // TODO(dfilimon): implement 84 static int64_t CheckSum(ByteArray* b, int32_t offset, int32_t length); 85 86 // Encode a single character in UTF-16. 87 // We only support the BMP for now 88 // @param encoder the encoder to use for the encoding 89 // @param uchar the Unicode character to encode 90 // @return the encoded character 91 static int32_t EncodeOneChar(UConverter* encoder, int16_t uchar); 92 93 // Get an encoder for the charset name. 94 // If the name is null or the empty string then just return null. 95 // @param charsetName the charset to get an encoder for 96 // @return an encoder or null if no encoder available for charset name 97 static UConverter* GetEncoder(const char* charsetName); 98 99 private: 100 static const char EXTENSION_SEPARATOR = '.'; 101 102 public: 103 // Get the extension of a file's name. 104 // @param file the whose name to process 105 // @return string containing the extension or an empty string if 106 // there is no extension 107 static const char* Extension(const char* file_path); 108 }; 109 } 110 #endif // SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ 111