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#include "gtest/gtest.h"
18#include "sfntly/font.h"
19#include "sfntly/table/core/name_table.h"
20#include "test/serialization_test.h"
21
22namespace sfntly {
23
24const int32_t NAME_FORMAT = 0;
25const int32_t NAME_COUNT = 75;
26const NameTable::NameEntryId NAME_IDS[] = {
27    NameTable::NameEntryId(1, 0, 0, 0),  // 0
28    NameTable::NameEntryId(1, 0, 0, 1),  // 1
29    NameTable::NameEntryId(1, 0, 0, 2),  // 2
30    NameTable::NameEntryId(1, 0, 0, 3),  // 3
31    NameTable::NameEntryId(1, 0, 0, 4),  // 4
32    NameTable::NameEntryId(1, 0, 0, 5),  // 5
33    NameTable::NameEntryId(1, 0, 0, 6),  // 6
34    NameTable::NameEntryId(1, 0, 0, 9),  // 7
35    NameTable::NameEntryId(1, 0, 0, 11),  // 8
36    NameTable::NameEntryId(1, 0, 0, 12),  // 9
37};
38const int32_t NAME_IDS_TEST = 10;
39
40static bool VerifyNAME(Table* table) {
41  // TODO(arthurhsu): Better testing can be done here.  Right now we just
42  //                  iterate through the entries and get entry ids.
43  NameTablePtr name = down_cast<NameTable*>(table);
44  if (name == NULL) {
45    return false;
46  }
47
48  EXPECT_EQ(name->Format(), NAME_FORMAT);
49  EXPECT_EQ(name->NameCount(), NAME_COUNT);
50  fprintf(stderr, "checking name entry: ");
51  for (int32_t i = 0; i < NAME_IDS_TEST; ++i) {
52    fprintf(stderr, "%d ", i);
53    EXPECT_EQ(name->PlatformId(i), NAME_IDS[i].platform_id());
54    EXPECT_EQ(name->EncodingId(i), NAME_IDS[i].encoding_id());
55    EXPECT_EQ(name->LanguageId(i), NAME_IDS[i].language_id());
56    EXPECT_EQ(name->NameId(i), NAME_IDS[i].name_id());
57  }
58  fprintf(stderr, "\n");
59  return true;
60}
61
62bool VerifyNAME(Table* original, Table* target) {
63  EXPECT_TRUE(VerifyNAME(original));
64  EXPECT_TRUE(VerifyNAME(target));
65  return true;
66}
67
68}  // namespace sfntly
69