1633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com/* 2633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved. 3633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * 4633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 5633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * you may not use this file except in compliance with the License. 6633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * You may obtain a copy of the License at 7633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * 8633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * http://www.apache.org/licenses/LICENSE-2.0 9633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * 10633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * Unless required by applicable law or agreed to in writing, software 11633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS, 12633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * See the License for the specific language governing permissions and 14633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com * limitations under the License. 15633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com */ 16633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 17633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com#include "gtest/gtest.h" 18ca72e2646f852b6c39ef1b07fa9b250988ce9d54arthurhsu@google.com#include "sample/chromium/font_subsetter.h" 19633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com#include "test/test_data.h" 20633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com#include "test/test_font_utils.h" 21633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 22633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.comnamespace { 23633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com // Use an additional variable to easily change name for testing. 24633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com const char* kInputFileName = sfntly::SAMPLE_TTF_FILE; 25633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com const char* kFontName = "Tuffy"; 26633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com const char* kOutputFileName = "tuffy-s.ttf"; 27633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com // The subset we want: Hello, world! 28633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com // The array is unsorted to verify that the subsetter gets the glyph id 29633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com // correctly. 30633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com const unsigned int kGlyphIds[] = { 43, 72, 79, 82, 15, 3, 90, 85, 71, 4 }; 31633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com const unsigned int kGlyphIdsCount = sizeof(kGlyphIds) / sizeof(unsigned int); 32633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com} 33633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 34633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com// This function is deliberately located at global namespace. 35633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.combool TestChromeSubsetter() { 36633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com sfntly::ByteVector input_buffer; 37633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com sfntly::LoadFile(kInputFileName, &input_buffer); 38633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com EXPECT_GT(input_buffer.size(), (size_t)0); 39633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 40633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com unsigned char* output_buffer = NULL; 41633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com int output_length = 42633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com SfntlyWrapper::SubsetFont(kFontName, 43633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com &(input_buffer[0]), 44633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com input_buffer.size(), 45633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com kGlyphIds, 46633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com kGlyphIdsCount, 47633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com &output_buffer); 48633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 49633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com EXPECT_GT(output_length, 0); 50633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 51633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com if (output_length > 0) { 52633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com FILE* output_file = NULL; 53633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com#if defined WIN32 54633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com fopen_s(&output_file, kOutputFileName, "wb"); 55633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com#else 56633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com output_file = fopen(kOutputFileName, "wb"); 57633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com#endif 58633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com EXPECT_TRUE((output_file != NULL)); 59633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com if (output_file) { 60633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com int byte_count = fwrite(output_buffer, 1, output_length, output_file); 61633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com EXPECT_EQ(byte_count, output_length); 62633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com fflush(output_file); 63633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com fclose(output_file); 64633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com } 65633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 66633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com delete[] output_buffer; 67633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com return true; 68633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com } 69633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 70633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com return false; 71633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com} 72633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com 73633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.comTEST(ChromeSubsetter, All) { 74633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com EXPECT_TRUE(TestChromeSubsetter()); 75633131f1440aad16805eefd9ff04455f93429433arthurhsu@google.com} 76