[Pkg-javascript-commits] [pdf.js] 57/109: Add unit-tests for Linearization dictionary parsing (PR 5023 follow-up)
David Prévot
taffit at moszumanska.debian.org
Fri Sep 25 03:04:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 0edb520a10e80127619c1ce2ea8fd1861167c98f
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date: Sun Aug 30 14:03:21 2015 +0200
Add unit-tests for Linearization dictionary parsing (PR 5023 follow-up)
This should *really* have been part of 5023, but better late than never I suppose.
---
test/unit/parser_spec.js | 173 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 172 insertions(+), 1 deletion(-)
diff --git a/test/unit/parser_spec.js b/test/unit/parser_spec.js
index 24e18de..df98cae 100644
--- a/test/unit/parser_spec.js
+++ b/test/unit/parser_spec.js
@@ -1,6 +1,6 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
-/* globals expect, it, describe, StringStream, Lexer */
+/* globals expect, it, describe, StringStream, Lexer, Linearization */
'use strict';
@@ -80,4 +80,175 @@ describe('parser', function() {
expect(result).toEqual('ABCD');
});
});
+
+ describe('Linearization', function() {
+ it('should not find a linearization dictionary', function () {
+ // Not an actual linearization dictionary.
+ var stream1 = new StringStream(
+ '3 0 obj\n' +
+ '<<\n' +
+ '/Length 4622\n' +
+ '/Filter /FlateDecode\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(Linearization.create(stream1)).toEqual(null);
+
+ // Linearization dictionary with invalid version number.
+ var stream2 = new StringStream(
+ '1 0 obj\n' +
+ '<<\n' +
+ '/Linearized 0\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(Linearization.create(stream2)).toEqual(null);
+ });
+
+ it('should accept a valid linearization dictionary', function () {
+ var stream = new StringStream(
+ '131 0 obj\n' +
+ '<<\n' +
+ '/Linearized 1\n' +
+ '/O 133\n' +
+ '/H [ 1388 863 ]\n' +
+ '/L 90\n' +
+ '/E 43573\n' +
+ '/N 18\n' +
+ '/T 193883\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ var expectedLinearizationDict = {
+ length: 90,
+ hints: [1388, 863],
+ objectNumberFirst: 133,
+ endFirst: 43573,
+ numPages: 18,
+ mainXRefEntriesOffset: 193883,
+ pageFirst: 0,
+ };
+ expect(Linearization.create(stream)).toEqual(expectedLinearizationDict);
+ });
+
+ it('should reject a linearization dictionary with invalid ' +
+ 'integer parameters', function () {
+ // The /L parameter should be equal to the stream length.
+ var stream1 = new StringStream(
+ '1 0 obj\n' +
+ '<<\n' +
+ '/Linearized 1\n' +
+ '/O 133\n' +
+ '/H [ 1388 863 ]\n' +
+ '/L 196622\n' +
+ '/E 43573\n' +
+ '/N 18\n' +
+ '/T 193883\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(function () {
+ return Linearization.create(stream1);
+ }).toThrow(new Error('The "L" parameter in the linearization ' +
+ 'dictionary does not equal the stream length.'));
+
+ // The /E parameter should not be zero.
+ var stream2 = new StringStream(
+ '1 0 obj\n' +
+ '<<\n' +
+ '/Linearized 1\n' +
+ '/O 133\n' +
+ '/H [ 1388 863 ]\n' +
+ '/L 84\n' +
+ '/E 0\n' +
+ '/N 18\n' +
+ '/T 193883\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(function () {
+ return Linearization.create(stream2);
+ }).toThrow(new Error('The "E" parameter in the linearization ' +
+ 'dictionary is invalid.'));
+
+ // The /O parameter should be an integer.
+ var stream3 = new StringStream(
+ '1 0 obj\n' +
+ '<<\n' +
+ '/Linearized 1\n' +
+ '/O /abc\n' +
+ '/H [ 1388 863 ]\n' +
+ '/L 89\n' +
+ '/E 43573\n' +
+ '/N 18\n' +
+ '/T 193883\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(function () {
+ return Linearization.create(stream3);
+ }).toThrow(new Error('The "O" parameter in the linearization ' +
+ 'dictionary is invalid.'));
+ });
+
+ it('should reject a linearization dictionary with invalid hint parameters',
+ function () {
+ // The /H parameter should be an array.
+ var stream1 = new StringStream(
+ '1 0 obj\n' +
+ '<<\n' +
+ '/Linearized 1\n' +
+ '/O 133\n' +
+ '/H 1388\n' +
+ '/L 80\n' +
+ '/E 43573\n' +
+ '/N 18\n' +
+ '/T 193883\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(function () {
+ return Linearization.create(stream1);
+ }).toThrow(new Error('Hint array in the linearization dictionary ' +
+ 'is invalid.'));
+
+ // The hint array should contain two, or four, elements.
+ var stream2 = new StringStream(
+ '1 0 obj\n' +
+ '<<\n' +
+ '/Linearized 1\n' +
+ '/O 133\n' +
+ '/H [ 1388 ]\n' +
+ '/L 84\n' +
+ '/E 43573\n' +
+ '/N 18\n' +
+ '/T 193883\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(function () {
+ return Linearization.create(stream2);
+ }).toThrow(new Error('Hint array in the linearization dictionary ' +
+ 'is invalid.'));
+
+ // The hint array should not contain zero.
+ var stream3 = new StringStream(
+ '1 0 obj\n' +
+ '<<\n' +
+ '/Linearized 1\n' +
+ '/O 133\n' +
+ '/H [ 1388 863 0 234]\n' +
+ '/L 93\n' +
+ '/E 43573\n' +
+ '/N 18\n' +
+ '/T 193883\n' +
+ '>>\n' +
+ 'endobj'
+ );
+ expect(function () {
+ return Linearization.create(stream3);
+ }).toThrow(new Error('Hint (2) in the linearization dictionary ' +
+ 'is invalid.'));
+ });
+ });
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list