@@ -32,14 +32,19 @@ class TableKeyedDiffTest : public ::testing::Test {
32
32
std::string tag1_str = FontHelper::ToString(tag1);
33
33
std::string tag2_str = FontHelper::ToString(tag2);
34
34
std::string tag3_str = FontHelper::ToString(tag3);
35
+
36
+ std::string header{
37
+ ' i' , ' f' , ' t' , ' k' , 0 , 0 , 0 , 0 , // reserved
38
+
39
+ 0 , 0 , 0 , 1 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 4 , // compat id
40
+ };
35
41
};
36
42
37
43
StatusOr<std::string> diff_table (std::string before, std::string after) {
38
44
FontData base, derived;
39
45
base.copy (before);
40
46
derived.copy (after);
41
47
42
- ;
43
48
BrotliBinaryDiff differ;
44
49
FontData patch;
45
50
auto sc = differ.Diff (base, derived, &patch);
@@ -53,32 +58,25 @@ StatusOr<std::string> diff_table(std::string before, std::string after) {
53
58
TEST_F (TableKeyedDiffTest, BasicDiff) {
54
59
char second_offset = 38 + 9 + diff_table (" foo" , " fooo" )->length ();
55
60
char third_offset = second_offset + 9 + diff_table (" bar" , " baar" )->length ();
56
- std::string expected =
57
- std::string{
58
- ' i' , ' f' , ' t' , ' k' ,
59
- 0 , 0 , 0 , 0 , // reserved
60
-
61
- 0 , 0 , 0 , 1 ,
62
- 0 , 0 , 0 , 2 ,
63
- 0 , 0 , 0 , 3 ,
64
- 0 , 0 , 0 , 4 , // compat id
65
-
66
- 0 , 2 , // patches count
67
- 0 , 0 , 0 , 38 , // patches offset[0]
68
- 0 , 0 , 0 , second_offset, // patches offset[1]
69
- 0 , 0 , 0 , third_offset, // patches offset[2]
70
-
71
- ' t' , ' a' , ' g' , ' 1' ,
72
- 0 , // flags
73
- 0 , 0 , 0 , 4 , // uncompressed size
74
- } +
75
- *diff_table (" foo" , " fooo" ) +
76
- std::string{
77
- ' t' , ' a' , ' g' , ' 2' ,
78
- 0 , // flags
79
- 0 , 0 , 0 , 4 , // uncompressed size
80
- } +
81
- *diff_table (" bar" , " baar" );
61
+ std::string expected = header +
62
+ std::string{
63
+ 0 , 2 , // patches count
64
+ 0 , 0 , 0 , 38 , // patches offset[0]
65
+ 0 , 0 , 0 , second_offset, // patches offset[1]
66
+ 0 , 0 , 0 , third_offset, // patches offset[2]
67
+ } +
68
+ std::string{
69
+ ' t' , ' a' , ' g' , ' 1' ,
70
+ 0 , // flags
71
+ 0 , 0 , 0 , 4 , // uncompressed size
72
+ } +
73
+ *diff_table (" foo" , " fooo" ) +
74
+ std::string{
75
+ ' t' , ' a' , ' g' , ' 2' ,
76
+ 0 , // flags
77
+ 0 , 0 , 0 , 4 , // uncompressed size
78
+ } +
79
+ *diff_table (" bar" , " baar" );
82
80
83
81
FontData before = FontHelper::BuildFont ({
84
82
{tag1, " foo" },
@@ -97,6 +95,38 @@ TEST_F(TableKeyedDiffTest, BasicDiff) {
97
95
ASSERT_EQ (patch.string (), expected);
98
96
}
99
97
98
+ TEST_F (TableKeyedDiffTest, BasicDiff_IgnoreUnchanged) {
99
+ char second_offset = 34 + 9 + diff_table (" bar" , " baar" )->length ();
100
+ std::string expected = header +
101
+ std::string{
102
+ 0 , 1 , // patches count
103
+ 0 , 0 , 0 , 34 , // patches offset[0]
104
+ 0 , 0 , 0 , second_offset, // patches offset[1]
105
+ } +
106
+ std::string{
107
+ ' t' , ' a' , ' g' , ' 2' ,
108
+ 0 , // flags
109
+ 0 , 0 , 0 , 4 , // uncompressed size
110
+ } +
111
+ *diff_table (" bar" , " baar" );
112
+
113
+ FontData before = FontHelper::BuildFont ({
114
+ {tag1, " foo" },
115
+ {tag2, " bar" },
116
+ });
117
+
118
+ FontData after = FontHelper::BuildFont ({
119
+ {tag1, " foo" },
120
+ {tag2, " baar" },
121
+ });
122
+
123
+ TableKeyedDiff differ (CompatId (1 , 2 , 3 , 4 ));
124
+ FontData patch;
125
+ auto sc = differ.Diff (before, after, &patch);
126
+ ASSERT_TRUE (sc.ok ()) << sc;
127
+ ASSERT_EQ (patch.string (), expected);
128
+ }
129
+
100
130
/*
101
131
TODO reimplement these against the new format.
102
132
TEST_F(TableKeyedDiffTest, ReplacementDiff) {
@@ -158,37 +188,48 @@ TEST_F(TableKeyedDiffTest, RemoveTable) {
158
188
ASSERT_TRUE(new_table.ok()) << new_table.status();
159
189
ASSERT_EQ(*new_table, "foo");
160
190
}
191
+ */
161
192
162
193
TEST_F (TableKeyedDiffTest, AddTable) {
194
+ char second_offset = 38 + 9 + diff_table (" foo" , " fooo" )->length ();
195
+ char third_offset = second_offset + 9 + diff_table (" bar" , " baar" )->length ();
196
+ std::string expected = header +
197
+ std::string{
198
+ 0 , 2 , // patches count
199
+ 0 , 0 , 0 , 38 , // patches offset[0]
200
+ 0 , 0 , 0 , second_offset, // patches offset[1]
201
+ 0 , 0 , 0 , third_offset, // patches offset[2]
202
+ } +
203
+ std::string{
204
+ ' t' , ' a' , ' g' , ' 1' ,
205
+ 0b00000001 , // flags
206
+ 0 , 0 , 0 , 4 , // uncompressed size
207
+ } +
208
+ *diff_table (" foo" , " fooo" ) +
209
+ std::string{
210
+ ' t' , ' a' , ' g' , ' 2' ,
211
+ 0 , // flags
212
+ 0 , 0 , 0 , 4 , // uncompressed size
213
+ } +
214
+ *diff_table (" bar" , " baar" );
215
+
163
216
FontData before = FontHelper::BuildFont ({
164
- {tag1 , "foo "},
217
+ {tag2 , " bar " },
165
218
});
166
219
167
220
FontData after = FontHelper::BuildFont ({
168
- {tag1, "foo "},
169
- {tag2, "bar "},
221
+ {tag1, " fooo " },
222
+ {tag2, " baar " },
170
223
});
171
224
172
- TableKeyedDiff differ;
225
+ TableKeyedDiff differ ( CompatId ( 1 , 2 , 3 , 4 )) ;
173
226
FontData patch;
174
227
auto sc = differ.Diff (before, after, &patch);
175
228
ASSERT_TRUE (sc.ok ()) << sc;
176
-
177
- PerTablePatch patch_proto;
178
- ASSERT_TRUE(patch_proto.ParseFromArray(patch.data(), patch.size()));
179
- ASSERT_TRUE(patch_proto.removed_tables().empty());
180
-
181
- ASSERT_EQ(patch_proto.table_patches_size(), 2);
182
-
183
- auto new_table = patch_table("foo", patch_proto.table_patches().at(tag1_str));
184
- ASSERT_TRUE(new_table.ok()) << new_table.status();
185
- ASSERT_EQ(*new_table, "foo");
186
-
187
- new_table = patch_table("", patch_proto.table_patches().at(tag2_str));
188
- ASSERT_TRUE(new_table.ok()) << new_table.status();
189
- ASSERT_EQ(*new_table, "bar");
229
+ ASSERT_EQ (patch.string (), expected);
190
230
}
191
231
232
+ /*
192
233
TEST_F(TableKeyedDiffTest, FilteredDiff) {
193
234
FontData before = FontHelper::BuildFont({
194
235
{tag1, "foo"},
0 commit comments