16b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com/* 26b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved. 36b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * 46b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 56b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * you may not use this file except in compliance with the License. 66b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * You may obtain a copy of the License at 76b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * 86b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * http://www.apache.org/licenses/LICENSE-2.0 96b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * 106b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * Unless required by applicable law or agreed to in writing, software 116b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS, 126b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * See the License for the specific language governing permissions and 146b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com * limitations under the License. 156b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com */ 166b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 175af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#ifndef SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ 185af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#define SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ 196b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 2074250f66a0f41c5f6ae15cfcebaa402f4f355d5aarthurhsu@google.com// Must include this before ICU to avoid stdint redefinition issue. 2174250f66a0f41c5f6ae15cfcebaa402f4f355d5aarthurhsu@google.com#include "sfntly/port/type.h" 2274250f66a0f41c5f6ae15cfcebaa402f4f355d5aarthurhsu@google.com 236b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com#include <unicode/ucnv.h> 2474250f66a0f41c5f6ae15cfcebaa402f4f355d5aarthurhsu@google.com 256b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com#include <string> 2674250f66a0f41c5f6ae15cfcebaa402f4f355d5aarthurhsu@google.com 276b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com#include "sfntly/font.h" 286b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com#include "sfntly/data/memory_byte_array.h" 296b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 306b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.comnamespace sfntly { 316b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.comclass TestUtils { 326b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com TestUtils(); 336b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 346b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com public: 356b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // Compare sections of two byte arrays for equality 366b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param b1 byte array 1 376b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param offset1 offset for comparison in byte array 1 386b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param b2 byte array 2 396b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param offset2 offset for comparison in byte array 2 406b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param length the length of the byte arrays to compare 416b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @return true if the array segments are equal; false otherwise 42c10c3d53cd1401f158e89697b7fe019b6828fa00arthurhsu@google.com // TODO(dfilimon): implement 43246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static bool Equals(ByteArray* b1, 44246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t offset1, 45246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com ByteArray* b2, 46246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t offset2); 476b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 486b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param offset1 offset to start comparing the first ByteArray from 496b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param ba1 the first ByteArray 506b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param offset2 offset to start comparing the second ByteArray from 516b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param ba2 the second ByteArray 526b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param length the number of bytes to compare 536b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @return true if all bytes in the ranges given are equal; false otherwise 546b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // TODO(dfilimon): implement 55246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static bool Equals(ByteArray* b1, 56246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t offset1, 57246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com ByteArray* b2, 58246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t offset2, 59246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com int32_t length); 606b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 616b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // TODO(dfilimon): implement FileOutputStream in port/file_output_stream.* 626b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // static OutputStream createOutputStream(const char* file_path); 636b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 646b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // TODO(dfilimon): adapt & implement 656b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // static FileChannel createFilechannelForWriting(File file); 666b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 676b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // Creates a new file including deleting an already existing file with the 686b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // same path and name and creating any needed directories. 696b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // TODO(dfilimon): implement 70246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static void CreateNewFile(const char* file_path); 716b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 726b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // Converts an integer into a 4 character string using the ASCII encoding. 736b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param i the value to convert 746b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @return the String based on the number 756b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // TODO(dfilimon): implement 76246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static void DumpLongAsString(int32_t i, std::string* result); 776b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 786b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // Calculate an OpenType checksum from the array. 796b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param b the array to calculate checksum on 806b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param offset the starting index in the array 816b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param length the number of bytes to check; must be a multiple of 4 826b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @return checksum 836b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // TODO(dfilimon): implement 84246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static int64_t CheckSum(ByteArray* b, int32_t offset, int32_t length); 856b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 866b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // Encode a single character in UTF-16. 876b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // We only support the BMP for now 886b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param encoder the encoder to use for the encoding 896b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param uchar the Unicode character to encode 906b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @return the encoded character 91246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static int32_t EncodeOneChar(UConverter* encoder, int16_t uchar); 926b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 936b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // Get an encoder for the charset name. 946b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // If the name is null or the empty string then just return null. 956b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param charsetName the charset to get an encoder for 966b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @return an encoder or null if no encoder available for charset name 97246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static UConverter* GetEncoder(const char* charsetName); 986b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 996b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com private: 1006b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com static const char EXTENSION_SEPARATOR = '.'; 1016b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com 1026b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com public: 1036b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // Get the extension of a file's name. 1046b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @param file the whose name to process 1056b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // @return string containing the extension or an empty string if 1066b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com // there is no extension 107246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com static const char* Extension(const char* file_path); 1086b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com}; 1096b5ae74df6b2ff199c63923219c9a18bd9c4d931arthurhsu@google.com} 1105af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#endif // SFNTLY_CPP_SRC_TEST_TEST_UTILS_H_ 111