Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/GlyphBufferTest.cpp

Issue 2714413003: Remove GlyphBuffer (Closed)
Patch Set: format Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/fonts/GlyphBuffer.h"
6
7 #include "platform/fonts/SimpleFontData.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "wtf/PassRefPtr.h"
10 #include "wtf/RefPtr.h"
11
12 namespace blink {
13
14 namespace {
15
16 // Minimal TestSimpleFontData implementation.
17 // Font has no glyphs, but that's okay.
18 class TestSimpleFontData : public SimpleFontData {
19 public:
20 static PassRefPtr<TestSimpleFontData> create() {
21 return adoptRef(new TestSimpleFontData);
22 }
23
24 private:
25 TestSimpleFontData() : SimpleFontData(nullptr, 10, false, false) {}
26 };
27
28 } // anonymous namespace
29
30 TEST(GlyphBufferTest, StartsEmpty) {
31 GlyphBuffer glyphBuffer;
32 EXPECT_TRUE(glyphBuffer.isEmpty());
33 EXPECT_EQ(0u, glyphBuffer.size());
34 }
35
36 TEST(GlyphBufferTest, StoresGlyphs) {
37 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create();
38 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create();
39
40 GlyphBuffer glyphBuffer;
41 glyphBuffer.add(42, font1.get(), 10);
42 glyphBuffer.add(43, font1.get(), 15);
43 glyphBuffer.add(44, font2.get(), 22);
44
45 EXPECT_FALSE(glyphBuffer.isEmpty());
46 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets());
47 EXPECT_EQ(3u, glyphBuffer.size());
48
49 EXPECT_EQ(42, glyphBuffer.glyphAt(0));
50 EXPECT_EQ(43, glyphBuffer.glyphAt(1));
51 EXPECT_EQ(44, glyphBuffer.glyphAt(2));
52
53 const Glyph* glyphs = glyphBuffer.glyphs(0);
54 EXPECT_EQ(42, glyphs[0]);
55 EXPECT_EQ(43, glyphs[1]);
56 EXPECT_EQ(44, glyphs[2]);
57 }
58
59 TEST(GlyphBufferTest, StoresVerticalOffsets) {
60 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create();
61 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create();
62
63 GlyphBuffer glyphBuffer;
64 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets());
65
66 glyphBuffer.add(42, font1.get(), FloatPoint(10, 0));
67 glyphBuffer.add(43, font1.get(), FloatPoint(15, 0));
68 glyphBuffer.add(44, font2.get(), FloatPoint(12, 2));
69
70 EXPECT_FALSE(glyphBuffer.isEmpty());
71 EXPECT_TRUE(glyphBuffer.hasVerticalOffsets());
72 EXPECT_EQ(3u, glyphBuffer.size());
73
74 const float* offsets = glyphBuffer.offsets(0);
75 EXPECT_EQ(10, glyphBuffer.xOffsetAt(0));
76 EXPECT_EQ(0, glyphBuffer.yOffsetAt(0));
77 EXPECT_EQ(15, glyphBuffer.xOffsetAt(1));
78 EXPECT_EQ(0, glyphBuffer.yOffsetAt(1));
79 EXPECT_EQ(12, glyphBuffer.xOffsetAt(2));
80 EXPECT_EQ(2, glyphBuffer.yOffsetAt(2));
81
82 EXPECT_EQ(10, offsets[0]);
83 EXPECT_EQ(0, offsets[1]);
84 EXPECT_EQ(15, offsets[2]);
85 EXPECT_EQ(0, offsets[3]);
86 EXPECT_EQ(12, offsets[4]);
87 EXPECT_EQ(2, offsets[5]);
88 }
89
90 TEST(GlyphBufferTest, StoresOffsets) {
91 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create();
92 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create();
93
94 GlyphBuffer glyphBuffer;
95 glyphBuffer.add(42, font1.get(), 10);
96 glyphBuffer.add(43, font1.get(), 15);
97 glyphBuffer.add(44, font2.get(), 20);
98
99 EXPECT_FALSE(glyphBuffer.isEmpty());
100 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets());
101 EXPECT_EQ(3u, glyphBuffer.size());
102
103 EXPECT_EQ(10, glyphBuffer.xOffsetAt(0));
104 EXPECT_EQ(15, glyphBuffer.xOffsetAt(1));
105 EXPECT_EQ(20, glyphBuffer.xOffsetAt(2));
106
107 const float* offsets = glyphBuffer.offsets(0);
108 EXPECT_EQ(10, offsets[0]);
109 EXPECT_EQ(15, offsets[1]);
110 EXPECT_EQ(20, offsets[2]);
111 }
112
113 TEST(GlyphBufferTest, StoresSimpleFontData) {
114 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create();
115 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create();
116
117 GlyphBuffer glyphBuffer;
118 glyphBuffer.add(42, font1.get(), 10);
119 glyphBuffer.add(43, font1.get(), 15);
120 glyphBuffer.add(44, font2.get(), 12);
121
122 EXPECT_FALSE(glyphBuffer.isEmpty());
123 EXPECT_EQ(3u, glyphBuffer.size());
124
125 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(0));
126 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(1));
127 EXPECT_EQ(font2.get(), glyphBuffer.fontDataAt(2));
128 }
129
130 TEST(GlyphBufferTest, GlyphArrayWithOffset) {
131 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create();
132 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create();
133
134 GlyphBuffer glyphBuffer;
135 glyphBuffer.add(42, font1.get(), 10);
136 glyphBuffer.add(43, font1.get(), 15);
137 glyphBuffer.add(44, font2.get(), 12);
138
139 EXPECT_FALSE(glyphBuffer.isEmpty());
140 EXPECT_EQ(3u, glyphBuffer.size());
141
142 const Glyph* glyphs = glyphBuffer.glyphs(1);
143 EXPECT_EQ(43, glyphs[0]);
144 EXPECT_EQ(44, glyphs[1]);
145 }
146
147 TEST(GlyphBufferTest, OffsetArrayWithNonZeroIndex) {
148 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create();
149 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create();
150
151 {
152 GlyphBuffer glyphBuffer;
153 glyphBuffer.add(42, font1.get(), 10);
154 glyphBuffer.add(43, font1.get(), 15);
155 glyphBuffer.add(43, font2.get(), 12);
156
157 EXPECT_FALSE(glyphBuffer.isEmpty());
158 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets());
159 EXPECT_EQ(3u, glyphBuffer.size());
160
161 const float* offsets = glyphBuffer.offsets(1);
162 EXPECT_EQ(15, offsets[0]);
163 EXPECT_EQ(12, offsets[1]);
164 }
165
166 {
167 GlyphBuffer glyphBuffer;
168 glyphBuffer.add(42, font1.get(), FloatPoint(10, 0));
169 glyphBuffer.add(43, font1.get(), FloatPoint(15, 0));
170 glyphBuffer.add(43, font2.get(), FloatPoint(12, 2));
171
172 EXPECT_FALSE(glyphBuffer.isEmpty());
173 EXPECT_TRUE(glyphBuffer.hasVerticalOffsets());
174 EXPECT_EQ(3u, glyphBuffer.size());
175
176 const float* offsets = glyphBuffer.offsets(1);
177 EXPECT_EQ(15, offsets[0]);
178 EXPECT_EQ(0, offsets[1]);
179 EXPECT_EQ(12, offsets[2]);
180 EXPECT_EQ(2, offsets[3]);
181 }
182 }
183
184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698