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.
7 #include <gtest/gtest.h>
10 #include "ots-memory-stream.h"
14 const uint32_t kFakeTag
= 0x00000000;
15 const size_t kScriptRecordSize
= 6;
16 const size_t kLangSysRecordSize
= 6;
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
)) {
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
)) {
34 // Offsets to LangSys tables are measured from the beginning of each
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
)) {
44 for (unsigned j
= 0; j
< langsys_count
; ++j
) {
45 if (!out
->WriteU32(kFakeTag
) ||
46 !out
->WriteU16(langsys_record_end
+ j
* langsys_table_size
)) {
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
)) {
59 for (unsigned j
= 0; j
< feature_count
; ++j
) {
60 if (!out
->WriteU16(j
)) {
68 const size_t kFeatureRecordSize
= 6;
70 bool BuildFakeFeatureListTable(ots::OTSStream
*out
,
71 const uint16_t feature_count
,
72 const uint16_t lookup_count
) {
73 if (!out
->WriteU16(feature_count
)) {
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
)) {
87 for (unsigned i
= 0; i
< feature_count
; ++i
) {
88 if (!out
->WriteU16(0x0000) ||
89 !out
->WriteU16(lookup_count
)) {
92 for (uint16_t j
= 0; j
< lookup_count
; ++j
) {
93 if (!out
->WriteU16(j
)) {
101 bool BuildFakeLookupListTable(ots::OTSStream
*out
, const uint16_t lookup_count
,
102 const uint16_t subtable_count
) {
103 if (!out
->WriteU16(lookup_count
)) {
106 const off_t base_offset_lookup
= out
->Tell();
107 if (!out
->Pad(2 * lookup_count
)) {
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) ||
116 !out
->WriteU16(subtable_count
) ||
117 !out
->Pad(2 * subtable_count
) ||
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
)) {
129 if (!out
->Seek(base_offset_lookup
)) {
132 for (unsigned i
= 0; i
< lookup_count
; ++i
) {
133 if (!out
->WriteU16(offsets_lookup
[i
])) {
138 for (unsigned i
= 0; i
< lookup_count
; ++i
) {
139 if (!out
->Seek(offsets_lookup
[i
] + 6)) {
142 for (unsigned j
= 0; j
< subtable_count
; ++j
) {
143 if (!out
->WriteU16(offset_lookup_table_end
+
144 256*i
*subtable_count
+ 256*j
)) {
152 bool BuildFakeCoverageFormat1(ots::OTSStream
*out
, const uint16_t glyph_count
) {
153 if (!out
->WriteU16(1) || !out
->WriteU16(glyph_count
)) {
156 for (uint16_t glyph_id
= 1; glyph_id
<= glyph_count
; ++glyph_id
) {
157 if (!out
->WriteU16(glyph_id
)) {
164 bool BuildFakeCoverageFormat2(ots::OTSStream
*out
, const uint16_t range_count
) {
165 if (!out
->WriteU16(2) || !out
->WriteU16(range_count
)) {
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
)) {
178 start_coverage_index
+= 2;
183 bool BuildFakeClassDefFormat1(ots::OTSStream
*out
, const uint16_t glyph_count
) {
184 if (!out
->WriteU16(1) ||
186 !out
->WriteU16(glyph_count
)) {
189 for (uint16_t class_value
= 1; class_value
<= glyph_count
; ++class_value
) {
190 if (!out
->WriteU16(class_value
)) {
197 bool BuildFakeClassDefFormat2(ots::OTSStream
*out
, const uint16_t range_count
) {
198 if (!out
->WriteU16(2) || !out
->WriteU16(range_count
)) {
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
)) {
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
)) {
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)) {
231 class TestStream
: public ots::MemoryStream
{
234 : ots::MemoryStream(data_
, sizeof(data_
)), size_(0) {
235 std::memset(reinterpret_cast<char*>(data_
), 0, sizeof(data_
));
238 uint8_t* data() { return data_
; }
239 size_t size() const { return size_
; }
241 virtual bool WriteRaw(const void *d
, size_t length
) {
242 if (Tell() + length
> size_
) {
243 size_
= Tell() + length
;
245 return ots::MemoryStream::WriteRaw(d
, length
);
253 class TableTest
: public ::testing::Test
{
256 virtual void SetUp() {
257 file
= new ots::OpenTypeFile();
258 file
->context
= new ots::OTSContext();
262 ots::OpenTypeFile
*file
;
265 class ScriptListTableTest
: public TableTest
{ };
266 class DeviceTableTest
: public TableTest
{ };
267 class CoverageTableTest
: public TableTest
{ };
268 class CoverageFormat1Test
: public TableTest
{ };
269 class CoverageFormat2Test
: public TableTest
{ };
270 class ClassDefTableTest
: public TableTest
{ };
271 class ClassDefFormat1Test
: public TableTest
{ };
272 class ClassDefFormat2Test
: public TableTest
{ };
273 class LookupSubtableParserTest
: public TableTest
{ };
275 class FeatureListTableTest
: public TableTest
{
278 virtual void SetUp() {
282 uint16_t num_features
;
285 bool fakeTypeParserReturnsTrue(const ots::OpenTypeFile
*, const uint8_t *,
290 bool fakeTypeParserReturnsFalse(const ots::OpenTypeFile
*, const uint8_t *,
295 const ots::LookupSubtableParser::TypeParser TypeParsersReturnTrue
[] = {
296 {1, fakeTypeParserReturnsTrue
},
297 {2, fakeTypeParserReturnsTrue
},
298 {3, fakeTypeParserReturnsTrue
},
299 {4, fakeTypeParserReturnsTrue
},
300 {5, fakeTypeParserReturnsTrue
}
303 // Fake lookup subtable parser which always returns true.
304 const ots::LookupSubtableParser FakeLookupParserReturnsTrue
= {
305 5, 5, TypeParsersReturnTrue
,
308 const ots::LookupSubtableParser::TypeParser TypeParsersReturnFalse
[] = {
309 {1, fakeTypeParserReturnsFalse
}
312 // Fake lookup subtable parser which always returns false.
313 const ots::LookupSubtableParser FakeLookupParserReturnsFalse
= {
314 1, 1, TypeParsersReturnFalse
317 class LookupListTableTest
: public TableTest
{
320 virtual void SetUp() {
325 return ots::ParseLookupListTable(file
, out
.data(), out
.size(),
326 &FakeLookupParserReturnsTrue
,
330 uint16_t num_lookups
;
335 TEST_F(ScriptListTableTest
, TestSuccess
) {
336 BuildFakeScriptListTable(&out
, 1, 1, 1);
337 EXPECT_TRUE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
340 TEST_F(ScriptListTableTest
, TestBadScriptCount
) {
341 BuildFakeScriptListTable(&out
, 1, 1, 1);
342 // Set too large script count.
345 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
348 TEST_F(ScriptListTableTest
, TestScriptRecordOffsetUnderflow
) {
349 BuildFakeScriptListTable(&out
, 1, 1, 1);
350 // Set bad offset to ScriptRecord[0].
353 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
356 TEST_F(ScriptListTableTest
, TestScriptRecordOffsetOverflow
) {
357 BuildFakeScriptListTable(&out
, 1, 1, 1);
358 // Set bad offset to ScriptRecord[0].
360 out
.WriteU16(out
.size());
361 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
364 TEST_F(ScriptListTableTest
, TestBadLangSysCount
) {
365 BuildFakeScriptListTable(&out
, 1, 1, 1);
366 // Set too large langsys count.
369 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
372 TEST_F(ScriptListTableTest
, TestLangSysRecordOffsetUnderflow
) {
373 BuildFakeScriptListTable(&out
, 1, 1, 1);
374 // Set bad offset to LangSysRecord[0].
377 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
380 TEST_F(ScriptListTableTest
, TestLangSysRecordOffsetOverflow
) {
381 BuildFakeScriptListTable(&out
, 1, 1, 1);
382 // Set bad offset to LangSysRecord[0].
384 out
.WriteU16(out
.size());
385 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
388 TEST_F(ScriptListTableTest
, TestBadReqFeatureIndex
) {
389 BuildFakeScriptListTable(&out
, 1, 1, 1);
390 // Set too large feature index to ReqFeatureIndex of LangSysTable[0].
393 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
396 TEST_F(ScriptListTableTest
, TestBadFeatureCount
) {
397 BuildFakeScriptListTable(&out
, 1, 1, 1);
398 // Set too large feature count to LangSysTable[0].
401 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
404 TEST_F(ScriptListTableTest
, TestBadFeatureIndex
) {
405 BuildFakeScriptListTable(&out
, 1, 1, 1);
406 // Set too large feature index to ReatureIndex[0] of LangSysTable[0].
409 EXPECT_FALSE(ots::ParseScriptListTable(file
, out
.data(), out
.size(), 1));
412 TEST_F(FeatureListTableTest
, TestSuccess
) {
413 BuildFakeFeatureListTable(&out
, 1, 1);
414 EXPECT_TRUE(ots::ParseFeatureListTable(file
, out
.data(), out
.size(), 1,
416 EXPECT_EQ(num_features
, 1);
419 TEST_F(FeatureListTableTest
, TestSuccess2
) {
420 BuildFakeFeatureListTable(&out
, 5, 1);
421 EXPECT_TRUE(ots::ParseFeatureListTable(file
, out
.data(), out
.size(), 1,
423 EXPECT_EQ(num_features
, 5);
426 TEST_F(FeatureListTableTest
, TestBadFeatureCount
) {
427 BuildFakeFeatureListTable(&out
, 1, 1);
428 // Set too large feature count.
431 EXPECT_FALSE(ots::ParseFeatureListTable(file
, out
.data(), out
.size(), 1,
435 TEST_F(FeatureListTableTest
, TestOffsetFeatureUnderflow
) {
436 BuildFakeFeatureListTable(&out
, 1, 1);
437 // Set bad offset to FeatureRecord[0].
440 EXPECT_FALSE(ots::ParseFeatureListTable(file
, out
.data(), out
.size(), 1,
444 TEST_F(FeatureListTableTest
, TestOffsetFeatureOverflow
) {
445 BuildFakeFeatureListTable(&out
, 1, 1);
446 // Set bad offset to FeatureRecord[0].
448 out
.WriteU16(out
.size());
449 EXPECT_FALSE(ots::ParseFeatureListTable(file
, out
.data(), out
.size(), 1,
453 TEST_F(FeatureListTableTest
, TestBadLookupCount
) {
454 BuildFakeFeatureListTable(&out
, 1, 1);
455 // Set too large lookup count to FeatureTable[0].
458 EXPECT_FALSE(ots::ParseFeatureListTable(file
, out
.data(), out
.size(), 1,
462 TEST_F(LookupListTableTest
, TestSuccess
) {
463 BuildFakeLookupListTable(&out
, 1, 1);
464 EXPECT_TRUE(Parse());
465 EXPECT_EQ(num_lookups
, 1);
468 TEST_F(LookupListTableTest
, TestSuccess2
) {
469 BuildFakeLookupListTable(&out
, 5, 1);
470 EXPECT_TRUE(Parse());
471 EXPECT_EQ(num_lookups
, 5);
474 TEST_F(LookupListTableTest
, TestOffsetLookupTableUnderflow
) {
475 BuildFakeLookupListTable(&out
, 1, 1);
476 // Set bad offset to Lookup[0].
479 EXPECT_FALSE(Parse());
482 TEST_F(LookupListTableTest
, TestOffsetLookupTableOverflow
) {
483 BuildFakeLookupListTable(&out
, 1, 1);
484 // Set bad offset to Lookup[0].
486 out
.WriteU16(out
.size());
487 EXPECT_FALSE(Parse());
490 TEST_F(LookupListTableTest
, TestOffsetSubtableUnderflow
) {
491 BuildFakeLookupListTable(&out
, 1, 1);
492 // Set bad offset to SubTable[0] of LookupTable[0].
495 EXPECT_FALSE(Parse());
498 TEST_F(LookupListTableTest
, TestOffsetSubtableOverflow
) {
499 BuildFakeLookupListTable(&out
, 1, 1);
500 // Set bad offset to SubTable[0] of LookupTable[0].
502 out
.WriteU16(out
.size());
503 EXPECT_FALSE(Parse());
506 TEST_F(LookupListTableTest
, TesBadLookupCount
) {
507 BuildFakeLookupListTable(&out
, 1, 1);
508 // Set too large lookup count of LookupTable[0].
511 EXPECT_FALSE(Parse());
514 TEST_F(LookupListTableTest
, TesBadLookupType
) {
515 BuildFakeLookupListTable(&out
, 1, 1);
516 // Set too large lookup type of LookupTable[0].
519 EXPECT_FALSE(Parse());
522 TEST_F(LookupListTableTest
, TesBadLookupFlag
) {
523 BuildFakeLookupListTable(&out
, 1, 1);
524 // Set IgnoreBaseGlyphs(0x0002) to the lookup flag of LookupTable[0].
526 out
.WriteU16(0x0002);
527 EXPECT_FALSE(Parse());
530 TEST_F(LookupListTableTest
, TesBadSubtableCount
) {
531 BuildFakeLookupListTable(&out
, 1, 1);
532 // Set too large sutable count of LookupTable[0].
535 EXPECT_FALSE(Parse());
538 TEST_F(CoverageTableTest
, TestSuccessFormat1
) {
539 BuildFakeCoverageFormat1(&out
, 1);
540 EXPECT_TRUE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 1));
543 TEST_F(CoverageTableTest
, TestSuccessFormat2
) {
544 BuildFakeCoverageFormat2(&out
, 1);
545 EXPECT_TRUE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 1));
548 TEST_F(CoverageTableTest
, TestBadFormat
) {
549 BuildFakeCoverageFormat1(&out
, 1);
553 EXPECT_FALSE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 1));
556 TEST_F(CoverageFormat1Test
, TestBadGlyphCount
) {
557 BuildFakeCoverageFormat1(&out
, 1);
558 // Set too large glyph count.
561 EXPECT_FALSE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 1));
564 TEST_F(CoverageFormat1Test
, TestBadGlyphId
) {
565 BuildFakeCoverageFormat1(&out
, 1);
566 // Set too large glyph id.
569 EXPECT_FALSE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 1));
572 TEST_F(CoverageFormat2Test
, TestBadRangeCount
) {
573 BuildFakeCoverageFormat2(&out
, 1);
574 // Set too large range count.
577 EXPECT_FALSE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 1));
580 TEST_F(CoverageFormat2Test
, TestBadRange
) {
581 BuildFakeCoverageFormat2(&out
, 1);
582 // Set reverse order glyph id to start/end fields.
586 EXPECT_FALSE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 1));
589 TEST_F(CoverageFormat2Test
, TestRangeOverlap
) {
590 BuildFakeCoverageFormat2(&out
, 2);
591 // Set overlapping glyph id to an end field.
594 EXPECT_FALSE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 2));
597 TEST_F(CoverageFormat2Test
, TestRangeOverlap2
) {
598 BuildFakeCoverageFormat2(&out
, 2);
599 // Set overlapping range.
603 EXPECT_FALSE(ots::ParseCoverageTable(file
, out
.data(), out
.size(), 2));
606 TEST_F(ClassDefTableTest
, TestSuccessFormat1
) {
607 BuildFakeClassDefFormat1(&out
, 1);
608 EXPECT_TRUE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
611 TEST_F(ClassDefTableTest
, TestSuccessFormat2
) {
612 BuildFakeClassDefFormat2(&out
, 1);
613 EXPECT_TRUE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
616 TEST_F(ClassDefTableTest
, TestBadFormat
) {
617 BuildFakeClassDefFormat1(&out
, 1);
621 EXPECT_FALSE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
624 TEST_F(ClassDefFormat1Test
, TestBadStartGlyph
) {
625 BuildFakeClassDefFormat1(&out
, 1);
626 // Set too large start glyph id.
629 EXPECT_FALSE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
632 TEST_F(ClassDefFormat1Test
, TestBadGlyphCount
) {
633 BuildFakeClassDefFormat1(&out
, 1);
634 // Set too large glyph count.
637 EXPECT_FALSE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
640 TEST_F(ClassDefFormat1Test
, TestBadClassValue
) {
641 BuildFakeClassDefFormat1(&out
, 1);
642 // Set too large class value.
645 EXPECT_FALSE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
648 TEST_F(ClassDefFormat2Test
, TestBadRangeCount
) {
649 BuildFakeClassDefFormat2(&out
, 1);
650 // Set too large range count.
653 EXPECT_FALSE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
656 TEST_F(ClassDefFormat2Test
, TestRangeOverlap
) {
657 BuildFakeClassDefFormat2(&out
, 2);
658 // Set overlapping glyph id to an end field.
661 EXPECT_FALSE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
664 TEST_F(ClassDefFormat2Test
, TestRangeOverlap2
) {
665 BuildFakeClassDefFormat2(&out
, 2);
666 // Set overlapping range.
670 EXPECT_FALSE(ots::ParseClassDefTable(file
, out
.data(), out
.size(), 1, 1));
673 TEST_F(DeviceTableTest
, TestDeltaFormat1Success
) {
674 BuildFakeDeviceTable(&out
, 1, 8, 1);
675 EXPECT_TRUE(ots::ParseDeviceTable(file
, out
.data(), out
.size()));
678 TEST_F(DeviceTableTest
, TestDeltaFormat1Success2
) {
679 BuildFakeDeviceTable(&out
, 1, 9, 1);
680 EXPECT_TRUE(ots::ParseDeviceTable(file
, out
.data(), out
.size()));
683 TEST_F(DeviceTableTest
, TestDeltaFormat1Fail
) {
684 // Pass shorter length than expected.
685 BuildFakeDeviceTable(&out
, 1, 8, 1);
686 EXPECT_FALSE(ots::ParseDeviceTable(file
, out
.data(), out
.size() - 1));
689 TEST_F(DeviceTableTest
, TestDeltaFormat1Fail2
) {
690 // Pass shorter length than expected.
691 BuildFakeDeviceTable(&out
, 1, 9, 1);
692 EXPECT_FALSE(ots::ParseDeviceTable(file
, out
.data(), out
.size() - 1));
695 TEST_F(DeviceTableTest
, TestDeltaFormat2Success
) {
696 BuildFakeDeviceTable(&out
, 1, 1, 2);
697 EXPECT_TRUE(ots::ParseDeviceTable(file
, out
.data(), out
.size()));
700 TEST_F(DeviceTableTest
, TestDeltaFormat2Success2
) {
701 BuildFakeDeviceTable(&out
, 1, 8, 2);
702 EXPECT_TRUE(ots::ParseDeviceTable(file
, out
.data(), out
.size()));
705 TEST_F(DeviceTableTest
, TestDeltaFormat2Fail
) {
706 // Pass shorter length than expected.
707 BuildFakeDeviceTable(&out
, 1, 8, 2);
708 EXPECT_FALSE(ots::ParseDeviceTable(file
, out
.data(), out
.size() - 1));
711 TEST_F(DeviceTableTest
, TestDeltaFormat2Fail2
) {
712 // Pass shorter length than expected.
713 BuildFakeDeviceTable(&out
, 1, 9, 2);
714 EXPECT_FALSE(ots::ParseDeviceTable(file
, out
.data(), out
.size() - 1));
717 TEST_F(DeviceTableTest
, TestDeltaFormat3Success
) {
718 BuildFakeDeviceTable(&out
, 1, 1, 3);
719 EXPECT_TRUE(ots::ParseDeviceTable(file
, out
.data(), out
.size()));
722 TEST_F(DeviceTableTest
, TestDeltaFormat3Success2
) {
723 BuildFakeDeviceTable(&out
, 1, 8, 3);
724 EXPECT_TRUE(ots::ParseDeviceTable(file
, out
.data(), out
.size()));
727 TEST_F(DeviceTableTest
, TestDeltaFormat3Fail
) {
728 // Pass shorter length than expected.
729 BuildFakeDeviceTable(&out
, 1, 8, 3);
730 EXPECT_FALSE(ots::ParseDeviceTable(file
, out
.data(), out
.size() - 1));
733 TEST_F(DeviceTableTest
, TestDeltaFormat3Fail2
) {
734 // Pass shorter length than expected.
735 BuildFakeDeviceTable(&out
, 1, 9, 3);
736 EXPECT_FALSE(ots::ParseDeviceTable(file
, out
.data(), out
.size() - 1));
739 TEST_F(LookupSubtableParserTest
, TestSuccess
) {
741 EXPECT_TRUE(FakeLookupParserReturnsTrue
.Parse(file
, 0, 0, 1));
744 EXPECT_TRUE(FakeLookupParserReturnsTrue
.Parse(file
, 0, 0, 5));
748 TEST_F(LookupSubtableParserTest
, TestFail
) {
750 // Pass bad lookup type which less than the smallest type.
751 EXPECT_FALSE(FakeLookupParserReturnsTrue
.Parse(file
, 0, 0, 0));
754 // Pass bad lookup type which greater than the maximum type.
755 EXPECT_FALSE(FakeLookupParserReturnsTrue
.Parse(file
, 0, 0, 6));
758 // Check the type parser failure.
759 EXPECT_FALSE(FakeLookupParserReturnsFalse
.Parse(file
, 0, 0, 1));