1090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com/*
2090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * Copyright 2011 Google Inc. All Rights Reserved.
3090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com *
4090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * Licensed under the Apache License, Version 2.0 (the "License");
5090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * you may not use this file except in compliance with the License.
6090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * You may obtain a copy of the License at
7090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com *
8090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com *      http://www.apache.org/licenses/LICENSE-2.0
9090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com *
10090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * Unless required by applicable law or agreed to in writing, software
11090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * distributed under the License is distributed on an "AS IS" BASIS,
12090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * See the License for the specific language governing permissions and
14090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com * limitations under the License.
15090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com */
16090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
17090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com// Must include this before ICU to avoid stdint redefinition issue.
18090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include "sfntly/port/type.h"
19090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
20090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include <unicode/ustring.h>
21090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include <unicode/unistr.h>
22090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
23090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include "gtest/gtest.h"
245af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#include "sfntly/data/memory_byte_array.h"
25090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include "sfntly/font.h"
26090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include "sfntly/font_factory.h"
27b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com#include "sfntly/port/memory_input_stream.h"
28b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com#include "sfntly/port/memory_output_stream.h"
295af34fd773f8cfee82321393504f558ddf67c628arthurhsu@google.com#include "sfntly/table/core/name_table.h"
30090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include "sfntly/tag.h"
31090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include "test/test_data.h"
32090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com#include "test/test_font_utils.h"
33090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
34090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.comnamespace sfntly {
35090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
36090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.comstatic ByteVector input_buffer;
37090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
38246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.comvoid LoadTestFile(FontFactory* factory, FontBuilderArray* font_builders) {
39090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  assert(factory);
40090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  assert(font_builders);
416a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  if (input_buffer.empty()) {
42246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com    LoadFile(SAMPLE_TTF_FILE, &input_buffer);
43090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  }
44b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  factory->LoadFontsForBuilding(&input_buffer, font_builders);
45090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com}
46090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
47246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.combool TestChangeOneName() {
486a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  FontFactoryPtr factory;
496a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  factory.Attach(FontFactory::GetInstance());
50090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderArray font_builder_array;
51246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  LoadTestFile(factory, &font_builder_array);
52090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderPtr font_builder = font_builder_array[0];
53090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
54090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameTableBuilderPtr name_builder = down_cast<NameTable::Builder*>(
55246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com      font_builder->GetTableBuilder(Tag::name));
56090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
57090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Change the font name.
58090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameEntryBuilderPtr neb =
59246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com      name_builder->NameBuilder(PlatformId::kWindows,
60090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsEncodingId::kUnicodeUCS2,
61090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsLanguageId::kEnglish_UnitedStates,
62090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                NameId::kFontFamilyName);
63090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  U_STRING_DECL(new_name, "Timothy", 7);
64246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  neb->SetName(new_name);
65090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
66090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Build the font.
676a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  FontPtr font;
686a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  font.Attach(font_builder->Build());
69090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
70090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Serialize and reload the serialized font.
71090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  MemoryOutputStream os;
72246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  factory->SerializeFont(font, &os);
73b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  MemoryInputStream is;
74b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  is.Attach(os.Get(), os.Size());
75090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontArray font_array;
76b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  factory->LoadFonts(&is, &font_array);
77090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontPtr new_font = font_array[0];
78090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
79090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Check the font name.
80246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  NameTablePtr name_table = down_cast<NameTable*>(font->GetTable(Tag::name));
81246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  UChar* name = name_table->Name(PlatformId::kWindows,
82090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsEncodingId::kUnicodeUCS2,
83090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsLanguageId::kEnglish_UnitedStates,
84090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 NameId::kFontFamilyName);
85090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_TRUE(name != NULL);
86090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_EQ(u_strcmp(name, new_name), 0);
87090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  delete[] name;
88090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  return true;
89090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com}
90090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
91246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.combool TestModifyNameTableAndRevert() {
926a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  FontFactoryPtr factory;
936a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  factory.Attach(FontFactory::GetInstance());
94090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderArray font_builder_array;
95246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  LoadTestFile(factory, &font_builder_array);
96090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderPtr font_builder = font_builder_array[0];
97090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
98090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameTableBuilderPtr name_builder = down_cast<NameTable::Builder*>(
99246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com      font_builder->GetTableBuilder(Tag::name));
100090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
101090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Change the font name.
102090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameEntryBuilderPtr neb =
103246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com      name_builder->NameBuilder(PlatformId::kWindows,
104090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsEncodingId::kUnicodeUCS2,
105090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsLanguageId::kEnglish_UnitedStates,
106090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                NameId::kFontFamilyName);
107246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  NameTable::NameEntry* neb_entry = neb->name_entry();
108246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  UChar* original_name = neb_entry->Name();
109090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_TRUE(original_name != NULL);
110090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
111090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  U_STRING_DECL(new_name, "Timothy", 7);
112246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  neb->SetName(new_name);
113246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  name_builder->RevertNames();
114090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
115090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Build the font.
1166a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  FontPtr font;
1176a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  font.Attach(font_builder->Build());
118090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
119090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Serialize and reload the serialized font.
120090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  MemoryOutputStream os;
121246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  factory->SerializeFont(font, &os);
122b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  MemoryInputStream is;
123b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  is.Attach(os.Get(), os.Size());
124090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontArray font_array;
125b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  factory->LoadFonts(&is, &font_array);
126090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontPtr new_font = font_array[0];
127090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
128090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Check the font name.
129246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  NameTablePtr name_table = down_cast<NameTable*>(font->GetTable(Tag::name));
130246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  UChar* name = name_table->Name(PlatformId::kWindows,
131090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsEncodingId::kUnicodeUCS2,
132090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsLanguageId::kEnglish_UnitedStates,
133090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 NameId::kFontFamilyName);
134090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
135090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_EQ(u_strcmp(name, original_name), 0);
136246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  delete[] name;
137246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  delete[] original_name;
138090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
139090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  return true;
140090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com}
141090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
142246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.combool TestRemoveOneName() {
1436a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  FontFactoryPtr factory;
1446a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  factory.Attach(FontFactory::GetInstance());
145090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderArray font_builder_array;
146246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  LoadTestFile(factory, &font_builder_array);
147090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderPtr font_builder = font_builder_array[0];
148090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
149090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameTableBuilderPtr name_builder = down_cast<NameTable::Builder*>(
150246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com      font_builder->GetTableBuilder(Tag::name));
151090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
152246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  EXPECT_TRUE(name_builder->Has(PlatformId::kWindows,
153090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsEncodingId::kUnicodeUCS2,
154090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsLanguageId::kEnglish_UnitedStates,
155090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                NameId::kFontFamilyName));
156246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  EXPECT_TRUE(name_builder->Remove(PlatformId::kWindows,
157090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                   WindowsEncodingId::kUnicodeUCS2,
158090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                   WindowsLanguageId::kEnglish_UnitedStates,
159090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                   NameId::kFontFamilyName));
160090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
161090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Build the font.
1626a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  FontPtr font;
1636a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  font.Attach(font_builder->Build());
164090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
165090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Serialize and reload the serialized font.
166090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  MemoryOutputStream os;
167246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  factory->SerializeFont(font, &os);
168b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  MemoryInputStream is;
169b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  is.Attach(os.Get(), os.Size());
170090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontArray font_array;
171b54cce09c1fc2b09e2adae43d7eb017b47b0cccfarthurhsu@google.com  factory->LoadFonts(&is, &font_array);
172090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontPtr new_font = font_array[0];
173090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
174090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Check the font name.
175246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  NameTablePtr name_table = down_cast<NameTable*>(font->GetTable(Tag::name));
176246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  UChar* name = name_table->Name(PlatformId::kWindows,
177090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsEncodingId::kUnicodeUCS2,
178090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsLanguageId::kEnglish_UnitedStates,
179090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 NameId::kFontFamilyName);
180090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_TRUE(name == NULL);
181090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
182090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  return true;
183090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com}
184090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
185090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com// Note: Function is not implemented but the test case is built.  Uncomment
186090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com//       when NameTable::clear() is implemented.
187090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com/*
188246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.combool TestClearAllNamesAndSetOne() {
1896a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  FontFactoryPtr factory;
1906a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  factory.Attach(FontFactory::GetInstance());
191090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderArray font_builder_array;
192246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  LoadTestFile(factory, &font_builder_array);
193090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontBuilderPtr font_builder = font_builder_array[0];
194090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
195090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameTableBuilderPtr name_builder = down_cast<NameTable::Builder*>(
196246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com      font_builder->GetTableBuilder(Tag::name));
197090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
198090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_GT(name_builder->builderCount(), 0);
199090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  name_builder->clear();
200090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_EQ(name_builder->builderCount(), 0);
201090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
202090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Change the font name.
203090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameEntryBuilderPtr neb =
204246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com      name_builder->NameBuilder(PlatformId::kWindows,
205090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsEncodingId::kUnicodeUCS2,
206090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                WindowsLanguageId::kEnglish_UnitedStates,
207090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                NameId::kFontFamilyName);
208090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  U_STRING_DECL(new_name, "Fred", 4);
209246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  neb->SetName(new_name);
210090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
211090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Build the font.
212246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  FontPtr font = font_builder->Build();
213090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
214090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Serialize and reload the serialized font.
215090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  MemoryOutputStream os;
216246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  factory->SerializeFont(font, &os);
217090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontArray font_array;
218246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  ByteArrayPtr new_ba = new MemoryByteArray(os.Get(), os.Size());
219246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  factory->LoadFonts(new_ba, &font_array);
220090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  FontPtr new_font = font_array[0];
221090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
222090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  // Check the font name.
223090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  NameTablePtr name_table = down_cast<NameTable*>(font->table(Tag::name));
224246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  UChar* name = name_table->Name(PlatformId::kWindows,
225090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsEncodingId::kUnicodeUCS2,
226090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 WindowsLanguageId::kEnglish_UnitedStates,
227090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com                                 NameId::kFontFamilyName);
228246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  EXPECT_EQ(name_table->NameCount(), 1);
229090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  EXPECT_EQ(u_strcmp(name, new_name), 0);
230246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com
231246300f7fab1f2539c3207ce5ec28cc355465be8arthurhsu@google.com  delete[] name;
232090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com  return true;
233090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com}
234090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com*/
235090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com
236090ea9e59646e627865c40f9758cfed067a575a1arthurhsu@google.com}  // namespace sfntly
2376a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com
2386a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.comTEST(NameEditing, All) {
2396a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  EXPECT_TRUE(sfntly::TestChangeOneName());
2406a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  EXPECT_TRUE(sfntly::TestModifyNameTableAndRevert());
2416a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com  EXPECT_TRUE(sfntly::TestRemoveOneName());
2426a22b959c06e66a039c630e6ac514234114b46cbarthurhsu@google.com}
243