aboutsummaryrefslogtreecommitdiff
path: root/test/table_dependencies_test.cc
blob: bbaaa30bb3cb4e2b1a0239ec642a2d54a8105867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <gtest/gtest.h>

#include "gsub.h"
#include "ots.h"
#include "ots-memory-stream.h"
#include "vhea.h"
#include "vmtx.h"

#define SET_TABLE(name, capname) \
  do { file.name = new ots::OpenType##capname; } while (0)
#define SET_LAYOUT_TABLE(name, capname)                    \
  do {                                                     \
    if (!file.name) {                                      \
      SET_TABLE(name, capname);                            \
    }                                                      \
    file.name->data = reinterpret_cast<const uint8_t*>(1); \
    file.name->length = 1;                                 \
  } while (0)
#define DROP_TABLE(name) \
  do { delete file.name; file.name = NULL; } while (0)
#define DROP_LAYOUT_TABLE(name) \
  do { file.name->data = NULL; file.name->length = 0; } while (0)

namespace {

class TableDependenciesTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    SET_LAYOUT_TABLE(gsub, GSUB);
    SET_TABLE(vhea, VHEA);
    SET_TABLE(vmtx, VMTX);
  }

  virtual void TearDown() {
    DROP_TABLE(gsub);
    DROP_TABLE(vhea);
    DROP_TABLE(vmtx);
  }
  ots::OpenTypeFile file;
};
}  // namespace

TEST_F(TableDependenciesTest, TestVhea) {
  EXPECT_TRUE(ots::ots_vhea_should_serialise(&file));
}

TEST_F(TableDependenciesTest, TestVmtx) {
  EXPECT_TRUE(ots::ots_vmtx_should_serialise(&file));
}

TEST_F(TableDependenciesTest, TestVheaVmtx) {
  DROP_TABLE(vmtx);
  EXPECT_FALSE(ots::ots_vhea_should_serialise(&file));
}

TEST_F(TableDependenciesTest, TestVmtxVhea) {
  DROP_TABLE(vhea);
  EXPECT_FALSE(ots::ots_vmtx_should_serialise(&file));
}

TEST_F(TableDependenciesTest, TestVheaGsub) {
  DROP_LAYOUT_TABLE(gsub);
  EXPECT_FALSE(ots::ots_vhea_should_serialise(&file));
  DROP_TABLE(gsub);
  EXPECT_FALSE(ots::ots_vhea_should_serialise(&file));
}

TEST_F(TableDependenciesTest, TestVmtxGsub) {
  DROP_LAYOUT_TABLE(gsub);
  EXPECT_FALSE(ots::ots_vmtx_should_serialise(&file));
  DROP_TABLE(gsub);
  EXPECT_FALSE(ots::ots_vmtx_should_serialise(&file));
}