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

Side by Side Diff: test/layout_common_table_test.cc

Issue 6410047: OTS: Adds more layout common table supports.... (Closed) Base URL: http://ots.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « test/SConstruct ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 <cmath>
6 #include <vector>
7 #include <gtest/gtest.h>
8
9 #include "layout.h"
10 #include "ots-memory-stream.h"
11
12 namespace {
13
14 const uint32_t kFakeTag = 0x00000000;
15 const size_t kScriptRecordSize = 6;
16 const size_t kLangSysRecordSize = 6;
17
18 bool BuildFakeScriptListTable(ots::OTSStream *out, const uint16_t script_count,
19 const uint16_t langsys_count,
20 const uint16_t feature_count) {
21 if (!out->WriteU16(script_count)) {
22 return false;
23 }
24 const off_t script_record_end = out->Tell() +
25 kScriptRecordSize * script_count;
26 const size_t script_table_size = 4 + kLangSysRecordSize * langsys_count;
27 for (unsigned i = 0; i < script_count; ++i) {
28 if (!out->WriteU32(kFakeTag) ||
29 !out->WriteU16(script_record_end + i * script_table_size)) {
30 return false;
31 }
32 }
33
34 // Offsets to LangSys tables are measured from the beginning of each
35 // script table.
36 const off_t langsys_record_end = 4 + kLangSysRecordSize * langsys_count;
37 const size_t langsys_table_size = 6 + 2 * feature_count;
38 // Write Fake Script tables.
39 for (unsigned i = 0; i < script_count; ++i) {
40 if (!out->WriteU16(0x0000) ||
41 !out->WriteU16(langsys_count)) {
42 return false;
43 }
44 for (unsigned j = 0; j < langsys_count; ++j) {
45 if (!out->WriteU32(kFakeTag) ||
46 !out->WriteU16(langsys_record_end + j * langsys_table_size)) {
47 return false;
48 }
49 }
50 }
51
52 // Write Fake LangSys tables.
53 for (unsigned i = 0; i < langsys_count; ++i) {
54 if (!out->WriteU16(0x0000) ||
55 !out->WriteU16(0xFFFF) ||
56 !out->WriteU16(feature_count)) {
57 return false;
58 }
59 for (unsigned j = 0; j < feature_count; ++j) {
60 if (!out->WriteU16(j)) {
61 return false;
62 }
63 }
64 }
65 return true;
66 }
67
68 const size_t kFeatureRecordSize = 6;
69
70 bool BuildFakeFeatureListTable(ots::OTSStream *out,
71 const uint16_t feature_count,
72 const uint16_t lookup_count) {
73 if (!out->WriteU16(feature_count)) {
74 return false;
75 }
76 const off_t feature_record_end = out->Tell() +
77 kFeatureRecordSize * feature_count;
78 const size_t feature_table_size = 4 + 2 * lookup_count;
79 for (unsigned i = 0; i < feature_count; ++i) {
80 if (!out->WriteU32(kFakeTag) ||
81 !out->WriteU16(feature_record_end + i * feature_table_size)) {
82 return false;
83 }
84 }
85
86 // Write FeatureTable
87 for (unsigned i = 0; i < feature_count; ++i) {
88 if (!out->WriteU16(0x0000) ||
89 !out->WriteU16(lookup_count)) {
90 return false;
91 }
92 for (uint16_t j = 0; j < lookup_count; ++j) {
93 if (!out->WriteU16(j)) {
94 return false;
95 }
96 }
97 }
98 return true;
99 }
100
101 bool BuildFakeLookupListTable(ots::OTSStream *out, const uint16_t lookup_count,
102 const uint16_t subtable_count) {
103 if (!out->WriteU16(lookup_count)) {
104 return false;
105 }
106 const off_t base_offset_lookup = out->Tell();
107 if (!out->Pad(2 * lookup_count)) {
108 return false;
109 }
110
111 std::vector<off_t> offsets_lookup(lookup_count, 0);
112 for (uint16_t i = 0; i < lookup_count; ++i) {
113 offsets_lookup[i] = out->Tell();
114 if (!out->WriteU16(i + 1) ||
115 !out->WriteU16(0) ||
116 !out->WriteU16(subtable_count) ||
117 !out->Pad(2 * subtable_count) ||
118 !out->WriteU16(0)) {
119 return false;
120 }
121 }
122
123 const off_t offset_lookup_table_end = out->Tell();
124 // Allocate 256 bytes for each subtable.
125 if (!out->Pad(256 * lookup_count * subtable_count)) {
126 return false;
127 }
128
129 if (!out->Seek(base_offset_lookup)) {
130 return false;
131 }
132 for (unsigned i = 0; i < lookup_count; ++i) {
133 if (!out->WriteU16(offsets_lookup[i])) {
134 return false;
135 }
136 }
137
138 for (unsigned i = 0; i < lookup_count; ++i) {
139 if (!out->Seek(offsets_lookup[i] + 6)) {
140 return false;
141 }
142 for (unsigned j = 0; j < subtable_count; ++j) {
143 if (!out->WriteU16(offset_lookup_table_end +
144 256*i*subtable_count + 256*j)) {
145 return false;
146 }
147 }
148 }
149 return true;
150 }
151
152 bool BuildFakeCoverageFormat1(ots::OTSStream *out, const uint16_t glyph_count) {
153 if (!out->WriteU16(1) || !out->WriteU16(glyph_count)) {
154 return false;
155 }
156 for (uint16_t glyph_id = 1; glyph_id <= glyph_count; ++glyph_id) {
157 if (!out->WriteU16(glyph_id)) {
158 return false;
159 }
160 }
161 return true;
162 }
163
164 bool BuildFakeCoverageFormat2(ots::OTSStream *out, const uint16_t range_count) {
165 if (!out->WriteU16(2) || !out->WriteU16(range_count)) {
166 return false;
167 }
168 uint16_t glyph_id = 1;
169 uint16_t start_coverage_index = 0;
170 for (unsigned i = 0; i < range_count; ++i) {
171 // Write consecutive ranges in which each range consists of two glyph id.
172 if (!out->WriteU16(glyph_id) ||
173 !out->WriteU16(glyph_id + 1) ||
174 !out->WriteU16(start_coverage_index)) {
175 return false;
176 }
177 glyph_id += 2;
178 start_coverage_index += 2;
179 }
180 return true;
181 }
182
183 bool BuildFakeClassDefFormat1(ots::OTSStream *out, const uint16_t glyph_count) {
184 if (!out->WriteU16(1) ||
185 !out->WriteU16(1) ||
186 !out->WriteU16(glyph_count)) {
187 return false;
188 }
189 for (uint16_t class_value = 1; class_value <= glyph_count; ++class_value) {
190 if (!out->WriteU16(class_value)) {
191 return false;
192 }
193 }
194 return true;
195 }
196
197 bool BuildFakeClassDefFormat2(ots::OTSStream *out, const uint16_t range_count) {
198 if (!out->WriteU16(2) || !out->WriteU16(range_count)) {
199 return false;
200 }
201 uint16_t glyph_id = 1;
202 for (uint16_t class_value = 1; class_value <= range_count; ++class_value) {
203 // Write consecutive ranges in which each range consists of one glyph id.
204 if (!out->WriteU16(glyph_id) ||
205 !out->WriteU16(glyph_id + 1) ||
206 !out->WriteU16(class_value)) {
207 return false;
208 }
209 glyph_id += 2;
210 }
211 return true;
212 }
213
214 bool BuildFakeDeviceTable(ots::OTSStream *out, const uint16_t start_size,
215 const uint16_t end_size, const uint16_t format) {
216 if (!out->WriteU16(start_size) ||
217 !out->WriteU16(end_size) ||
218 !out->WriteU16(format)) {
219 return false;
220 }
221
222 const unsigned num_values = std::abs(end_size - start_size) + 1;
223 const unsigned num_bits = (1 << format) * num_values;
224 const unsigned num_units = (num_bits - 1) / 16 + 1;
225 if (!out->Pad(num_units * 2)) {
226 return false;
227 }
228 return true;
229 }
230
231 class TestStream : public ots::MemoryStream {
232 public:
233 TestStream()
234 : ots::MemoryStream(data_, sizeof(data_)), size_(0) {
235 std::memset(reinterpret_cast<char*>(data_), 0, sizeof(data_));
236 }
237
238 uint8_t* data() { return data_; }
239 size_t size() const { return size_; }
240
241 virtual bool WriteRaw(const void *data, size_t length) {
242 if (Tell() + length > size_) {
243 size_ = Tell() + length;
244 }
245 return ots::MemoryStream::WriteRaw(data, length);
246 }
247
248 private:
249 size_t size_;
250 uint8_t data_[4096];
251 };
252
253 class ScriptListTableTest : public ::testing::Test {
254 protected:
255
256 TestStream out;
257 ots::OpenTypeFile file;
258 };
259
260 class FeatureListTableTest : public ::testing::Test {
261 protected:
262
263 virtual void SetUp() {
264 num_features = 0;
265 }
266
267 TestStream out;
268 ots::OpenTypeFile file;
269 uint16_t num_features;
270 };
271
272 bool fakeLookupParser(const ots::OpenTypeFile*, const uint8_t *, const size_t) {
273 return true;
274 }
275
276 // Lookup Type parsers doesn't check anything.
277 const ots::LookupTypeParser FakeLookupParsers[] = {
278 {1, fakeLookupParser},
279 {2, fakeLookupParser},
280 {3, fakeLookupParser},
281 {4, fakeLookupParser},
282 {5, fakeLookupParser}
283 };
284
285 class LookupListTableTest : public ::testing::Test {
286 protected:
287
288 virtual void SetUp() {
289 num_lookups = 0;
290 }
291
292 bool Parse() {
293 return ots::ParseLookupListTable(&file, out.data(), out.size(), 5,
294 FakeLookupParsers, &num_lookups);
295 }
296
297 TestStream out;
298 ots::OpenTypeFile file;
299 uint16_t num_lookups;
300 };
301
302 } // namespace
303
304 TEST_F(ScriptListTableTest, TestSuccess) {
305 BuildFakeScriptListTable(&out, 1, 1, 1);
306 EXPECT_TRUE(ots::ParseScriptListTable(out.data(), out.size(), 1));
307 }
308
309 TEST_F(ScriptListTableTest, TestBadScriptCount) {
310 BuildFakeScriptListTable(&out, 1, 1, 1);
311 // Set too large script count.
312 out.Seek(0);
313 out.WriteU16(2);
314 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
315 }
316
317 TEST_F(ScriptListTableTest, TestScriptRecordOffsetUnderflow) {
318 BuildFakeScriptListTable(&out, 1, 1, 1);
319 // Set bad offset to ScriptRecord[0].
320 out.Seek(6);
321 out.WriteU16(0);
322 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
323 }
324
325 TEST_F(ScriptListTableTest, TestScriptRecordOffsetOverflow) {
326 BuildFakeScriptListTable(&out, 1, 1, 1);
327 // Set bad offset to ScriptRecord[0].
328 out.Seek(6);
329 out.WriteU16(out.size());
330 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
331 }
332
333 TEST_F(ScriptListTableTest, TestBadLangSysCount) {
334 BuildFakeScriptListTable(&out, 1, 1, 1);
335 // Set too large langsys count.
336 out.Seek(10);
337 out.WriteU16(2);
338 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
339 }
340
341 TEST_F(ScriptListTableTest, TestLangSysRecordOffsetUnderflow) {
342 BuildFakeScriptListTable(&out, 1, 1, 1);
343 // Set bad offset to LangSysRecord[0].
344 out.Seek(16);
345 out.WriteU16(0);
346 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
347 }
348
349 TEST_F(ScriptListTableTest, TestLangSysRecordOffsetOverflow) {
350 BuildFakeScriptListTable(&out, 1, 1, 1);
351 // Set bad offset to LangSysRecord[0].
352 out.Seek(16);
353 out.WriteU16(out.size());
354 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
355 }
356
357 TEST_F(ScriptListTableTest, TestBadReqFeatureIndex) {
358 BuildFakeScriptListTable(&out, 1, 1, 1);
359 // Set too large feature index to ReqFeatureIndex of LangSysTable[0].
360 out.Seek(20);
361 out.WriteU16(2);
362 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
363 }
364
365 TEST_F(ScriptListTableTest, TestBadFeatureCount) {
366 BuildFakeScriptListTable(&out, 1, 1, 1);
367 // Set too large feature count to LangSysTable[0].
368 out.Seek(22);
369 out.WriteU16(2);
370 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
371 }
372
373 TEST_F(ScriptListTableTest, TestBadFeatureIndex) {
374 BuildFakeScriptListTable(&out, 1, 1, 1);
375 // Set too large feature index to ReatureIndex[0] of LangSysTable[0].
376 out.Seek(24);
377 out.WriteU16(2);
378 EXPECT_FALSE(ots::ParseScriptListTable(out.data(), out.size(), 1));
379 }
380
381 TEST_F(FeatureListTableTest, TestSuccess) {
382 BuildFakeFeatureListTable(&out, 1, 1);
383 EXPECT_TRUE(ots::ParseFeatureListTable(out.data(), out.size(), 1,
384 &num_features));
385 EXPECT_EQ(num_features, 1);
386 }
387
388 TEST_F(FeatureListTableTest, TestSuccess2) {
389 BuildFakeFeatureListTable(&out, 5, 1);
390 EXPECT_TRUE(ots::ParseFeatureListTable(out.data(), out.size(), 1,
391 &num_features));
392 EXPECT_EQ(num_features, 5);
393 }
394
395 TEST_F(FeatureListTableTest, TestBadFeatureCount) {
396 BuildFakeFeatureListTable(&out, 1, 1);
397 // Set too large feature count.
398 out.Seek(0);
399 out.WriteU16(2);
400 EXPECT_FALSE(ots::ParseFeatureListTable(out.data(), out.size(), 1,
401 &num_features));
402 }
403
404 TEST_F(FeatureListTableTest, TestOffsetFeatureUnderflow) {
405 BuildFakeFeatureListTable(&out, 1, 1);
406 // Set bad offset to FeatureRecord[0].
407 out.Seek(6);
408 out.WriteU16(0);
409 EXPECT_FALSE(ots::ParseFeatureListTable(out.data(), out.size(), 1,
410 &num_features));
411 }
412
413 TEST_F(FeatureListTableTest, TestOffsetFeatureOverflow) {
414 BuildFakeFeatureListTable(&out, 1, 1);
415 // Set bad offset to FeatureRecord[0].
416 out.Seek(6);
417 out.WriteU16(out.size());
418 EXPECT_FALSE(ots::ParseFeatureListTable(out.data(), out.size(), 1,
419 &num_features));
420 }
421
422 TEST_F(FeatureListTableTest, TestBadLookupCount) {
423 BuildFakeFeatureListTable(&out, 1, 1);
424 // Set too large lookup count to FeatureTable[0].
425 out.Seek(10);
426 out.WriteU16(2);
427 EXPECT_FALSE(ots::ParseFeatureListTable(out.data(), out.size(), 1,
428 &num_features));
429 }
430
431 TEST_F(LookupListTableTest, TestSuccess) {
432 BuildFakeLookupListTable(&out, 1, 1);
433 EXPECT_TRUE(Parse());
434 EXPECT_EQ(num_lookups, 1);
435 }
436
437 TEST_F(LookupListTableTest, TestSuccess2) {
438 BuildFakeLookupListTable(&out, 5, 1);
439 EXPECT_TRUE(Parse());
440 EXPECT_EQ(num_lookups, 5);
441 }
442
443 TEST_F(LookupListTableTest, TestOffsetLookupTableUnderflow) {
444 BuildFakeLookupListTable(&out, 1, 1);
445 // Set bad offset to Lookup[0].
446 out.Seek(2);
447 out.WriteU16(0);
448 EXPECT_FALSE(Parse());
449 }
450
451 TEST_F(LookupListTableTest, TestOffsetLookupTableOverflow) {
452 BuildFakeLookupListTable(&out, 1, 1);
453 // Set bad offset to Lookup[0].
454 out.Seek(2);
455 out.WriteU16(out.size());
456 EXPECT_FALSE(Parse());
457 }
458
459 TEST_F(LookupListTableTest, TestOffsetSubtableUnderflow) {
460 BuildFakeLookupListTable(&out, 1, 1);
461 // Set bad offset to SubTable[0] of LookupTable[0].
462 out.Seek(10);
463 out.WriteU16(0);
464 EXPECT_FALSE(Parse());
465 }
466
467 TEST_F(LookupListTableTest, TestOffsetSubtableOverflow) {
468 BuildFakeLookupListTable(&out, 1, 1);
469 // Set bad offset to SubTable[0] of LookupTable[0].
470 out.Seek(10);
471 out.WriteU16(out.size());
472 EXPECT_FALSE(Parse());
473 }
474
475 TEST_F(LookupListTableTest, TesBadLookupCount) {
476 BuildFakeLookupListTable(&out, 1, 1);
477 // Set too large lookup count of LookupTable[0].
478 out.Seek(0);
479 out.WriteU16(2);
480 EXPECT_FALSE(Parse());
481 }
482
483 TEST_F(LookupListTableTest, TesBadLookupType) {
484 BuildFakeLookupListTable(&out, 1, 1);
485 // Set too large lookup type of LookupTable[0].
486 out.Seek(4);
487 out.WriteU16(6);
488 EXPECT_FALSE(Parse());
489 }
490
491 TEST_F(LookupListTableTest, TesBadSubtableCount) {
492 BuildFakeLookupListTable(&out, 1, 1);
493 // Set too large sutable count of LookupTable[0].
494 out.Seek(8);
495 out.WriteU16(2);
496 EXPECT_FALSE(Parse());
497 }
498
499 TEST(CoverageTableTest, TestSuccessFormat1) {
500 TestStream out;
501 BuildFakeCoverageFormat1(&out, 1);
502 EXPECT_TRUE(ots::ParseCoverageTable(out.data(), out.size(), 1));
503 }
504
505 TEST(CoverageTableTest, TestSuccessFormat2) {
506 TestStream out;
507 BuildFakeCoverageFormat2(&out, 1);
508 EXPECT_TRUE(ots::ParseCoverageTable(out.data(), out.size(), 1));
509 }
510
511 TEST(CoverageTableTest, TestBadFormat) {
512 TestStream out;
513 BuildFakeCoverageFormat1(&out, 1);
514 // Set bad format.
515 out.Seek(0);
516 out.WriteU16(3);
517 EXPECT_FALSE(ots::ParseCoverageTable(out.data(), out.size(), 1));
518 }
519
520 TEST(CoverageFormat1Test, TestBadGlyphCount) {
521 TestStream out;
522 BuildFakeCoverageFormat1(&out, 1);
523 // Set too large glyph count.
524 out.Seek(2);
525 out.WriteU16(2);
526 EXPECT_FALSE(ots::ParseCoverageTable(out.data(), out.size(), 1));
527 }
528
529 TEST(CoverageFormat1Test, TestBadGlyphId) {
530 TestStream out;
531 BuildFakeCoverageFormat1(&out, 1);
532 // Set too large glyph id.
533 out.Seek(4);
534 out.WriteU16(2);
535 EXPECT_FALSE(ots::ParseCoverageTable(out.data(), out.size(), 1));
536 }
537
538 TEST(CoverageFormat2Test, TestBadRangeCount) {
539 TestStream out;
540 BuildFakeCoverageFormat2(&out, 1);
541 // Set too large range count.
542 out.Seek(2);
543 out.WriteU16(2);
544 EXPECT_FALSE(ots::ParseCoverageTable(out.data(), out.size(), 1));
545 }
546
547 TEST(CoverageFormat2Test, TestBadRange) {
548 TestStream out;
549 BuildFakeCoverageFormat2(&out, 1);
550 // Set reverse order glyph id to start/end fields.
551 out.Seek(4);
552 out.WriteU16(2);
553 out.WriteU16(1);
554 EXPECT_FALSE(ots::ParseCoverageTable(out.data(), out.size(), 1));
555 }
556
557 TEST(CoverageFormat2Test, TestRangeOverlap) {
558 TestStream out;
559 BuildFakeCoverageFormat2(&out, 2);
560 // Set overlapping glyph id to an end field.
561 out.Seek(12);
562 out.WriteU16(1);
563 EXPECT_FALSE(ots::ParseCoverageTable(out.data(), out.size(), 2));
564 }
565
566 TEST(CoverageFormat2Test, TestRangeOverlap2) {
567 TestStream out;
568 BuildFakeCoverageFormat2(&out, 2);
569 // Set overlapping range.
570 out.Seek(10);
571 out.WriteU16(1);
572 out.WriteU16(2);
573 EXPECT_FALSE(ots::ParseCoverageTable(out.data(), out.size(), 2));
574 }
575
576 TEST(ClassDefTableTest, TestSuccessFormat1) {
577 TestStream out;
578 BuildFakeClassDefFormat1(&out, 1);
579 EXPECT_TRUE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
580 }
581
582 TEST(ClassDefTableTest, TestSuccessFormat2) {
583 TestStream out;
584 BuildFakeClassDefFormat2(&out, 1);
585 EXPECT_TRUE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
586 }
587
588 TEST(ClassDefTableTest, TestBadFormat) {
589 TestStream out;
590 BuildFakeClassDefFormat1(&out, 1);
591 // Set bad format.
592 out.Seek(0);
593 out.WriteU16(3);
594 EXPECT_FALSE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
595 }
596
597 TEST(ClassDefFormat1Test, TestBadStartGlyph) {
598 TestStream out;
599 BuildFakeClassDefFormat1(&out, 1);
600 // Set too large start glyph id.
601 out.Seek(2);
602 out.WriteU16(2);
603 EXPECT_FALSE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
604 }
605
606 TEST(ClassDefFormat1Test, TestBadGlyphCount) {
607 TestStream out;
608 BuildFakeClassDefFormat1(&out, 1);
609 // Set too large glyph count.
610 out.Seek(4);
611 out.WriteU16(2);
612 EXPECT_FALSE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
613 }
614
615 TEST(ClassDefFormat1Test, TestBadClassValue) {
616 TestStream out;
617 BuildFakeClassDefFormat1(&out, 1);
618 // Set too large class value.
619 out.Seek(6);
620 out.WriteU16(2);
621 EXPECT_FALSE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
622 }
623
624 TEST(ClassDefFormat2Test, TestBadRangeCount) {
625 TestStream out;
626 BuildFakeClassDefFormat2(&out, 1);
627 // Set too large range count.
628 out.Seek(2);
629 out.WriteU16(2);
630 EXPECT_FALSE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
631 }
632
633 TEST(ClassDefFormat2Test, TestRangeOverlap) {
634 TestStream out;
635 BuildFakeClassDefFormat2(&out, 2);
636 // Set overlapping glyph id to an end field.
637 out.Seek(12);
638 out.WriteU16(1);
639 EXPECT_FALSE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
640 }
641
642 TEST(ClassDefFormat2Test, TestRangeOverlap2) {
643 TestStream out;
644 BuildFakeClassDefFormat2(&out, 2);
645 // Set overlapping range.
646 out.Seek(10);
647 out.WriteU16(1);
648 out.WriteU16(2);
649 EXPECT_FALSE(ots::ParseClassDefTable(out.data(), out.size(), 1, 1));
650 }
651
652 TEST(DeviceTableTest, TestDeltaFormat1Success) {
653 {
654 TestStream out;
655 BuildFakeDeviceTable(&out, 1, 8, 1);
656 EXPECT_TRUE(ots::ParseDeviceTable(out.data(), out.size()));
657 }
658 {
659 TestStream out;
660 BuildFakeDeviceTable(&out, 1, 9, 1);
661 EXPECT_TRUE(ots::ParseDeviceTable(out.data(), out.size()));
662 }
663 }
664
665 TEST(DeviceTableTest, TestDeltaFormat1Fail) {
666 // Pass shorter length than expected.
667 {
668 TestStream out;
669 BuildFakeDeviceTable(&out, 1, 8, 1);
670 EXPECT_FALSE(ots::ParseDeviceTable(out.data(), out.size() - 1));
671 }
672 {
673 TestStream out;
674 BuildFakeDeviceTable(&out, 1, 9, 1);
675 EXPECT_FALSE(ots::ParseDeviceTable(out.data(), out.size() - 1));
676 }
677 }
678
679 TEST(DeviceTableTest, TestDeltaFormat2Success) {
680 {
681 TestStream out;
682 BuildFakeDeviceTable(&out, 1, 1, 2);
683 EXPECT_TRUE(ots::ParseDeviceTable(out.data(), out.size()));
684 }
685 {
686 TestStream out;
687 BuildFakeDeviceTable(&out, 1, 8, 2);
688 EXPECT_TRUE(ots::ParseDeviceTable(out.data(), out.size()));
689 }
690 }
691
692 TEST(DeviceTableTest, TestDeltaFormat2Fail) {
693 // Pass shorter length than expected.
694 {
695 TestStream out;
696 BuildFakeDeviceTable(&out, 1, 8, 2);
697 EXPECT_FALSE(ots::ParseDeviceTable(out.data(), out.size() - 1));
698 }
699 {
700 TestStream out;
701 BuildFakeDeviceTable(&out, 1, 9, 2);
702 EXPECT_FALSE(ots::ParseDeviceTable(out.data(), out.size() - 1));
703 }
704 }
705
706 TEST(DeviceTableTest, TestDeltaFormat3Success) {
707 {
708 TestStream out;
709 BuildFakeDeviceTable(&out, 1, 1, 3);
710 EXPECT_TRUE(ots::ParseDeviceTable(out.data(), out.size()));
711 }
712 {
713 TestStream out;
714 BuildFakeDeviceTable(&out, 1, 8, 3);
715 EXPECT_TRUE(ots::ParseDeviceTable(out.data(), out.size()));
716 }
717 }
718
719 TEST(DeviceTableTest, TestDeltaFormat3Fail) {
720 // Pass shorter length than expected.
721 {
722 TestStream out;
723 BuildFakeDeviceTable(&out, 1, 8, 3);
724 EXPECT_FALSE(ots::ParseDeviceTable(out.data(), out.size() - 1));
725 }
726 {
727 TestStream out;
728 BuildFakeDeviceTable(&out, 1, 9, 3);
729 EXPECT_FALSE(ots::ParseDeviceTable(out.data(), out.size() - 1));
730 }
731 }
732
OLDNEW
« no previous file with comments | « test/SConstruct ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698