mirror of
https://github.com/pierre42100/comunic
synced 2025-07-04 07:35:02 +00:00
First commit
This commit is contained in:
242
3rdparty/pdf.js/test/unit/api_spec.js
vendored
Executable file
242
3rdparty/pdf.js/test/unit/api_spec.js
vendored
Executable file
@ -0,0 +1,242 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
/* globals PDFJS, expect, it, describe, Promise, combineUrl, waitsFor,
|
||||
isArray, MissingPDFException */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('api', function() {
|
||||
var basicApiUrl = combineUrl(window.location.href, '../pdfs/basicapi.pdf');
|
||||
var basicApiFileLength = 105779; // bytes
|
||||
function waitsForPromiseResolved(promise, successCallback) {
|
||||
var data;
|
||||
promise.then(function(val) {
|
||||
data = val;
|
||||
successCallback(data);
|
||||
},
|
||||
function(error) {
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
});
|
||||
waitsFor(function() {
|
||||
return data !== undefined;
|
||||
}, 20000);
|
||||
}
|
||||
function waitsForPromiseRejected(promise, failureCallback) {
|
||||
var data;
|
||||
promise.then(function(val) {
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
},
|
||||
function(error) {
|
||||
data = error;
|
||||
failureCallback(data);
|
||||
});
|
||||
waitsFor(function() {
|
||||
return data !== undefined;
|
||||
}, 20000);
|
||||
}
|
||||
describe('PDFJS', function() {
|
||||
describe('getDocument', function() {
|
||||
it('creates pdf doc from URL', function() {
|
||||
var promise = PDFJS.getDocument(basicApiUrl);
|
||||
waitsForPromiseResolved(promise, function(data) {
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
it('creates pdf doc from typed array', function() {
|
||||
var nonBinaryRequest = PDFJS.disableWorker;
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('GET', basicApiUrl, false);
|
||||
if (!nonBinaryRequest) {
|
||||
try {
|
||||
request.responseType = 'arraybuffer';
|
||||
nonBinaryRequest = request.responseType !== 'arraybuffer';
|
||||
} catch (e) {
|
||||
nonBinaryRequest = true;
|
||||
}
|
||||
}
|
||||
if (nonBinaryRequest && request.overrideMimeType) {
|
||||
request.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
}
|
||||
request.send(null);
|
||||
|
||||
var typedArrayPdf;
|
||||
if (nonBinaryRequest) {
|
||||
var data = Array.prototype.map.call(request.responseText,
|
||||
function (ch) {
|
||||
return ch.charCodeAt(0) & 0xFF;
|
||||
});
|
||||
typedArrayPdf = new Uint8Array(data);
|
||||
} else {
|
||||
typedArrayPdf = new Uint8Array(request.response);
|
||||
}
|
||||
// Sanity check to make sure that we fetched the entire PDF file.
|
||||
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
||||
|
||||
var promise = PDFJS.getDocument(typedArrayPdf);
|
||||
waitsForPromiseResolved(promise, function(data) {
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
it('creates pdf doc from non-existent URL', function() {
|
||||
var nonExistentUrl = combineUrl(window.location.href,
|
||||
'../pdfs/non-existent.pdf');
|
||||
var promise = PDFJS.getDocument(nonExistentUrl);
|
||||
waitsForPromiseRejected(promise, function(error) {
|
||||
expect(error instanceof MissingPDFException).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('PDFDocument', function() {
|
||||
var promise = PDFJS.getDocument(basicApiUrl);
|
||||
var doc;
|
||||
waitsForPromiseResolved(promise, function(data) {
|
||||
doc = data;
|
||||
});
|
||||
it('gets number of pages', function() {
|
||||
expect(doc.numPages).toEqual(3);
|
||||
});
|
||||
it('gets fingerprint', function() {
|
||||
expect(typeof doc.fingerprint).toEqual('string');
|
||||
});
|
||||
it('gets page', function() {
|
||||
var promise = doc.getPage(1);
|
||||
waitsForPromiseResolved(promise, function(data) {
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
});
|
||||
it('gets page index', function() {
|
||||
// reference to second page
|
||||
var ref = {num: 17, gen: 0};
|
||||
var promise = doc.getPageIndex(ref);
|
||||
waitsForPromiseResolved(promise, function(pageIndex) {
|
||||
expect(pageIndex).toEqual(1);
|
||||
});
|
||||
});
|
||||
it('gets destinations', function() {
|
||||
var promise = doc.getDestinations();
|
||||
waitsForPromiseResolved(promise, function(data) {
|
||||
expect(data).toEqual({ chapter1: [{ gen: 0, num: 17 }, { name: 'XYZ' },
|
||||
0, 841.89, null] });
|
||||
});
|
||||
});
|
||||
it('gets a destination', function() {
|
||||
var promise = doc.getDestination('chapter1');
|
||||
waitsForPromiseResolved(promise, function(data) {
|
||||
expect(data).toEqual([{ gen: 0, num: 17 }, { name: 'XYZ' },
|
||||
0, 841.89, null]);
|
||||
});
|
||||
});
|
||||
it('gets attachments', function() {
|
||||
var promise = doc.getAttachments();
|
||||
waitsForPromiseResolved(promise, function (data) {
|
||||
expect(data).toEqual(null);
|
||||
});
|
||||
});
|
||||
it('gets javascript', function() {
|
||||
var promise = doc.getJavaScript();
|
||||
waitsForPromiseResolved(promise, function (data) {
|
||||
expect(data).toEqual([]);
|
||||
});
|
||||
});
|
||||
it('gets outline', function() {
|
||||
var promise = doc.getOutline();
|
||||
waitsForPromiseResolved(promise, function(outline) {
|
||||
// Two top level entries.
|
||||
expect(outline.length).toEqual(2);
|
||||
// Make sure some basic attributes are set.
|
||||
expect(outline[1].title).toEqual('Chapter 1');
|
||||
expect(outline[1].items.length).toEqual(1);
|
||||
expect(outline[1].items[0].title).toEqual('Paragraph 1.1');
|
||||
});
|
||||
});
|
||||
it('gets metadata', function() {
|
||||
var promise = doc.getMetadata();
|
||||
waitsForPromiseResolved(promise, function(metadata) {
|
||||
expect(metadata.info['Title']).toEqual('Basic API Test');
|
||||
expect(metadata.info['PDFFormatVersion']).toEqual('1.7');
|
||||
expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test');
|
||||
});
|
||||
});
|
||||
it('gets data', function() {
|
||||
var promise = doc.getData();
|
||||
waitsForPromiseResolved(promise, function (data) {
|
||||
expect(data instanceof Uint8Array).toEqual(true);
|
||||
expect(data.length).toEqual(basicApiFileLength);
|
||||
});
|
||||
});
|
||||
it('gets filesize in bytes', function() {
|
||||
var promise = doc.getDownloadInfo();
|
||||
waitsForPromiseResolved(promise, function (data) {
|
||||
expect(data.length).toEqual(basicApiFileLength);
|
||||
});
|
||||
});
|
||||
it('gets stats', function() {
|
||||
var promise = doc.getStats();
|
||||
waitsForPromiseResolved(promise, function (stats) {
|
||||
expect(isArray(stats.streamTypes)).toEqual(true);
|
||||
expect(isArray(stats.fontTypes)).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Page', function() {
|
||||
var resolvePromise;
|
||||
var promise = new Promise(function (resolve) {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
PDFJS.getDocument(basicApiUrl).then(function(doc) {
|
||||
doc.getPage(1).then(function(data) {
|
||||
resolvePromise(data);
|
||||
});
|
||||
});
|
||||
var page;
|
||||
waitsForPromiseResolved(promise, function(data) {
|
||||
page = data;
|
||||
});
|
||||
it('gets page number', function () {
|
||||
expect(page.pageNumber).toEqual(1);
|
||||
});
|
||||
it('gets rotate', function () {
|
||||
expect(page.rotate).toEqual(0);
|
||||
});
|
||||
it('gets ref', function () {
|
||||
expect(page.ref).toEqual({ num: 15, gen: 0 });
|
||||
});
|
||||
it('gets view', function () {
|
||||
expect(page.view).toEqual([0, 0, 595.28, 841.89]);
|
||||
});
|
||||
it('gets viewport', function () {
|
||||
var viewport = page.getViewport(1.5, 90);
|
||||
expect(viewport.viewBox).toEqual(page.view);
|
||||
expect(viewport.scale).toEqual(1.5);
|
||||
expect(viewport.rotation).toEqual(90);
|
||||
expect(viewport.transform).toEqual([0, 1.5, 1.5, 0, 0, 0]);
|
||||
expect(viewport.width).toEqual(1262.835);
|
||||
expect(viewport.height).toEqual(892.92);
|
||||
});
|
||||
it('gets annotations', function () {
|
||||
var promise = page.getAnnotations();
|
||||
waitsForPromiseResolved(promise, function (data) {
|
||||
expect(data.length).toEqual(4);
|
||||
});
|
||||
});
|
||||
it('gets text content', function () {
|
||||
var promise = page.getTextContent();
|
||||
waitsForPromiseResolved(promise, function (data) {
|
||||
expect(!!data.items).toEqual(true);
|
||||
expect(data.items.length).toEqual(7);
|
||||
expect(!!data.styles).toEqual(true);
|
||||
});
|
||||
});
|
||||
it('gets operator list', function() {
|
||||
var promise = page.getOperatorList();
|
||||
waitsForPromiseResolved(promise, function (oplist) {
|
||||
expect(!!oplist.fnArray).toEqual(true);
|
||||
expect(!!oplist.argsArray).toEqual(true);
|
||||
expect(oplist.lastChunk).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
129
3rdparty/pdf.js/test/unit/cmap_spec.js
vendored
Executable file
129
3rdparty/pdf.js/test/unit/cmap_spec.js
vendored
Executable file
@ -0,0 +1,129 @@
|
||||
/* -*- 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, CMapFactory, Name, CMap,
|
||||
IdentityCMap */
|
||||
|
||||
'use strict';
|
||||
|
||||
var cMapUrl = '../../external/bcmaps/';
|
||||
var cMapPacked = true;
|
||||
|
||||
describe('cmap', function() {
|
||||
it('parses beginbfchar', function() {
|
||||
var str = '2 beginbfchar\n' +
|
||||
'<03> <00>\n' +
|
||||
'<04> <01>\n' +
|
||||
'endbfchar\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x03)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x04)).toEqual(String.fromCharCode(0x01));
|
||||
expect(cmap.lookup(0x05)).toBeUndefined();
|
||||
});
|
||||
it('parses beginbfrange with range', function() {
|
||||
var str = '1 beginbfrange\n' +
|
||||
'<06> <0B> 0\n' +
|
||||
'endbfrange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x05)).toBeUndefined();
|
||||
expect(cmap.lookup(0x06)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x0B)).toEqual(String.fromCharCode(0x05));
|
||||
expect(cmap.lookup(0x0C)).toBeUndefined();
|
||||
});
|
||||
it('parses beginbfrange with array', function() {
|
||||
var str = '1 beginbfrange\n' +
|
||||
'<0D> <12> [ 0 1 2 3 4 5 ]\n' +
|
||||
'endbfrange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x0C)).toBeUndefined();
|
||||
expect(cmap.lookup(0x0D)).toEqual(0x00);
|
||||
expect(cmap.lookup(0x12)).toEqual(0x05);
|
||||
expect(cmap.lookup(0x13)).toBeUndefined();
|
||||
});
|
||||
it('parses begincidchar', function() {
|
||||
var str = '1 begincidchar\n' +
|
||||
'<14> 0\n' +
|
||||
'endcidchar\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x14)).toEqual(0x00);
|
||||
expect(cmap.lookup(0x15)).toBeUndefined();
|
||||
});
|
||||
it('parses begincidrange', function() {
|
||||
var str = '1 begincidrange\n' +
|
||||
'<0016> <001B> 0\n' +
|
||||
'endcidrange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x15)).toBeUndefined();
|
||||
expect(cmap.lookup(0x16)).toEqual(0x00);
|
||||
expect(cmap.lookup(0x1B)).toEqual(0x05);
|
||||
expect(cmap.lookup(0x1C)).toBeUndefined();
|
||||
});
|
||||
it('decodes codespace ranges', function() {
|
||||
var str = '1 begincodespacerange\n' +
|
||||
'<01> <02>\n' +
|
||||
'<00000003> <00000004>\n' +
|
||||
'endcodespacerange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
var c = {};
|
||||
cmap.readCharCode(String.fromCharCode(1), 0, c);
|
||||
expect(c.charcode).toEqual(1);
|
||||
expect(c.length).toEqual(1);
|
||||
cmap.readCharCode(String.fromCharCode(0, 0, 0, 3), 0, c);
|
||||
expect(c.charcode).toEqual(3);
|
||||
expect(c.length).toEqual(4);
|
||||
});
|
||||
it('decodes 4 byte codespace ranges', function() {
|
||||
var str = '1 begincodespacerange\n' +
|
||||
'<8EA1A1A1> <8EA1FEFE>\n' +
|
||||
'endcodespacerange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
var c = {};
|
||||
cmap.readCharCode(String.fromCharCode(0x8E, 0xA1, 0xA1, 0xA1), 0, c);
|
||||
expect(c.charcode).toEqual(0x8EA1A1A1);
|
||||
expect(c.length).toEqual(4);
|
||||
});
|
||||
it('read usecmap', function() {
|
||||
var str = '/Adobe-Japan1-1 usecmap\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream,
|
||||
{ url: cMapUrl, packed: cMapPacked }, null);
|
||||
expect(cmap instanceof CMap).toEqual(true);
|
||||
expect(cmap.useCMap).not.toBeNull();
|
||||
expect(cmap.builtInCMap).toBeFalsy();
|
||||
expect(cmap.isIdentityCMap).toEqual(false);
|
||||
});
|
||||
it('parses cmapname', function() {
|
||||
var str = '/CMapName /Identity-H def\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.name).toEqual('Identity-H');
|
||||
});
|
||||
it('parses wmode', function() {
|
||||
var str = '/WMode 1 def\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.vertical).toEqual(true);
|
||||
});
|
||||
it('loads built in cmap', function() {
|
||||
var cmap = CMapFactory.create(new Name('Adobe-Japan1-1'),
|
||||
{ url: cMapUrl, packed: cMapPacked }, null);
|
||||
expect(cmap instanceof CMap).toEqual(true);
|
||||
expect(cmap.useCMap).toBeNull();
|
||||
expect(cmap.builtInCMap).toBeTruthy();
|
||||
expect(cmap.isIdentityCMap).toEqual(false);
|
||||
});
|
||||
it('loads built in identity cmap', function() {
|
||||
var cmap = CMapFactory.create(new Name('Identity-H'),
|
||||
{ url: cMapUrl, packed: cMapPacked }, null);
|
||||
expect(cmap instanceof IdentityCMap).toEqual(true);
|
||||
expect(cmap.vertical).toEqual(false);
|
||||
expect(function() { return cmap.isIdentityCMap; }).toThrow(
|
||||
new Error('should not access .isIdentityCMap'));
|
||||
});
|
||||
});
|
651
3rdparty/pdf.js/test/unit/crypto_spec.js
vendored
Executable file
651
3rdparty/pdf.js/test/unit/crypto_spec.js
vendored
Executable file
@ -0,0 +1,651 @@
|
||||
/* -*- 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, calculateMD5, ARCFourCipher, Name,
|
||||
CipherTransformFactory, calculateSHA256, calculateSHA384,
|
||||
calculateSHA512, AES128Cipher, AES256Cipher, PDF17, PDF20,
|
||||
PasswordException, PasswordResponses */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('crypto', function() {
|
||||
function string2binary(s) {
|
||||
var n = s.length, i;
|
||||
var result = new Uint8Array(n);
|
||||
for (i = 0; i < n; ++i) {
|
||||
result[i] = s.charCodeAt(i) % 0xFF;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function hex2binary(s) {
|
||||
var digits = '0123456789ABCDEF';
|
||||
s = s.toUpperCase();
|
||||
var n = s.length >> 1, i, j;
|
||||
var result = new Uint8Array(n);
|
||||
for (i = 0, j = 0; i < n; ++i) {
|
||||
var d1 = s.charAt(j++);
|
||||
var d2 = s.charAt(j++);
|
||||
var value = (digits.indexOf(d1) << 4) | (digits.indexOf(d2));
|
||||
result[i] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// RFC 1321, A.5 Test suite
|
||||
describe('calculateMD5', function() {
|
||||
it('should pass RFC 1321 test #1', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('');
|
||||
result = calculateMD5(input, 0, input.length);
|
||||
expected = hex2binary('d41d8cd98f00b204e9800998ecf8427e');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass RFC 1321 test #2', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('a');
|
||||
result = calculateMD5(input, 0, input.length);
|
||||
expected = hex2binary('0cc175b9c0f1b6a831c399e269772661');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass RFC 1321 test #3', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abc');
|
||||
result = calculateMD5(input, 0, input.length);
|
||||
expected = hex2binary('900150983cd24fb0d6963f7d28e17f72');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass RFC 1321 test #4', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('message digest');
|
||||
result = calculateMD5(input, 0, input.length);
|
||||
expected = hex2binary('f96b697d7cb7938d525a2f31aaf161d0');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass RFC 1321 test #5', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abcdefghijklmnopqrstuvwxyz');
|
||||
result = calculateMD5(input, 0, input.length);
|
||||
expected = hex2binary('c3fcd3d76192e4007dfb496cca67e13b');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass RFC 1321 test #6', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv' +
|
||||
'wxyz0123456789');
|
||||
result = calculateMD5(input, 0, input.length);
|
||||
expected = hex2binary('d174ab98d277d9f5a5611c2c9f419d9f');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass RFC 1321 test #7', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('123456789012345678901234567890123456789012345678' +
|
||||
'90123456789012345678901234567890');
|
||||
result = calculateMD5(input, 0, input.length);
|
||||
expected = hex2binary('57edf4a22be3c955ac49da2e2107b67a');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
// http://www.freemedialibrary.com/index.php/RC4_test_vectors are used
|
||||
describe('ARCFourCipher', function() {
|
||||
it('should pass test #1', function() {
|
||||
var key, input, result, expected, cipher;
|
||||
key = hex2binary('0123456789abcdef');
|
||||
input = hex2binary('0123456789abcdef');
|
||||
cipher = new ARCFourCipher(key);
|
||||
result = cipher.encryptBlock(input);
|
||||
expected = hex2binary('75b7878099e0c596');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass test #2', function() {
|
||||
var key, input, result, expected, cipher;
|
||||
key = hex2binary('0123456789abcdef');
|
||||
input = hex2binary('0000000000000000');
|
||||
cipher = new ARCFourCipher(key);
|
||||
result = cipher.encryptBlock(input);
|
||||
expected = hex2binary('7494c2e7104b0879');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass test #3', function() {
|
||||
var key, input, result, expected, cipher;
|
||||
key = hex2binary('0000000000000000');
|
||||
input = hex2binary('0000000000000000');
|
||||
cipher = new ARCFourCipher(key);
|
||||
result = cipher.encryptBlock(input);
|
||||
expected = hex2binary('de188941a3375d3a');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass test #4', function() {
|
||||
var key, input, result, expected, cipher;
|
||||
key = hex2binary('ef012345');
|
||||
input = hex2binary('00000000000000000000');
|
||||
cipher = new ARCFourCipher(key);
|
||||
result = cipher.encryptBlock(input);
|
||||
expected = hex2binary('d6a141a7ec3c38dfbd61');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass test #5', function() {
|
||||
var key, input, result, expected, cipher;
|
||||
key = hex2binary('0123456789abcdef');
|
||||
input = hex2binary('010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'10101010101010101010101010101010101010101010101010101010101010101010' +
|
||||
'101010101010101010101');
|
||||
cipher = new ARCFourCipher(key);
|
||||
result = cipher.encryptBlock(input);
|
||||
expected = hex2binary('7595c3e6114a09780c4ad452338e1ffd9a1be9498f813d76' +
|
||||
'533449b6778dcad8c78a8d2ba9ac66085d0e53d59c26c2d1c490c1ebbe0ce66d1b6b' +
|
||||
'1b13b6b919b847c25a91447a95e75e4ef16779cde8bf0a95850e32af9689444fd377' +
|
||||
'108f98fdcbd4e726567500990bcc7e0ca3c4aaa304a387d20f3b8fbbcd42a1bd311d' +
|
||||
'7a4303dda5ab078896ae80c18b0af66dff319616eb784e495ad2ce90d7f772a81747' +
|
||||
'b65f62093b1e0db9e5ba532fafec47508323e671327df9444432cb7367cec82f5d44' +
|
||||
'c0d00b67d650a075cd4b70dedd77eb9b10231b6b5b741347396d62897421d43df9b4' +
|
||||
'2e446e358e9c11a9b2184ecbef0cd8e7a877ef968f1390ec9b3d35a5585cb009290e' +
|
||||
'2fcde7b5ec66d9084be44055a619d9dd7fc3166f9487f7cb272912426445998514c1' +
|
||||
'5d53a18c864ce3a2b7555793988126520eacf2e3066e230c91bee4dd5304f5fd0405' +
|
||||
'b35bd99c73135d3d9bc335ee049ef69b3867bf2d7bd1eaa595d8bfc0066ff8d31509' +
|
||||
'eb0c6caa006c807a623ef84c3d33c195d23ee320c40de0558157c822d4b8c569d849' +
|
||||
'aed59d4e0fd7f379586b4b7ff684ed6a189f7486d49b9c4bad9ba24b96abf924372c' +
|
||||
'8a8fffb10d55354900a77a3db5f205e1b99fcd8660863a159ad4abe40fa48934163d' +
|
||||
'dde542a6585540fd683cbfd8c00f12129a284deacc4cdefe58be7137541c047126c8' +
|
||||
'd49e2755ab181ab7e940b0c0');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass test #6', function() {
|
||||
var key, input, result, expected, cipher;
|
||||
key = hex2binary('fb029e3031323334');
|
||||
input = hex2binary('aaaa0300000008004500004e661a00008011be640a0001220af' +
|
||||
'fffff00890089003a000080a601100001000000000000204543454a4548454346434' +
|
||||
'550464545494546464343414341434143414341414100002000011bd0b604');
|
||||
cipher = new ARCFourCipher(key);
|
||||
result = cipher.encryptBlock(input);
|
||||
expected = hex2binary('f69c5806bd6ce84626bcbefb9474650aad1f7909b0f64d5f' +
|
||||
'58a503a258b7ed22eb0ea64930d3a056a55742fcce141d485f8aa836dea18df42c53' +
|
||||
'80805ad0c61a5d6f58f41040b24b7d1a693856ed0d4398e7aee3bf0e2a2ca8f7');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should pass test #7', function() {
|
||||
var key, input, result, expected, cipher;
|
||||
key = hex2binary('0123456789abcdef');
|
||||
input = hex2binary('123456789abcdef0123456789abcdef0123456789abcdef0123' +
|
||||
'45678');
|
||||
cipher = new ARCFourCipher(key);
|
||||
result = cipher.encryptBlock(input);
|
||||
expected = hex2binary('66a0949f8af7d6891f7f832ba833c00c892ebe30143ce287' +
|
||||
'40011ecf');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateSHA256', function() {
|
||||
it('should properly hash abc', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abc');
|
||||
result = calculateSHA256(input, 0, input.length);
|
||||
expected = hex2binary('BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9C' +
|
||||
'B410FF61F20015AD');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should properly hash a multiblock input', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmno' +
|
||||
'mnopnopq');
|
||||
result = calculateSHA256(input, 0, input.length);
|
||||
expected = hex2binary('248D6A61D20638B8E5C026930C3E6039A33CE45964FF2167' +
|
||||
'F6ECEDD419DB06C1');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateSHA384', function() {
|
||||
it('should properly hash abc', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abc');
|
||||
result = calculateSHA384(input, 0, input.length);
|
||||
expected = hex2binary('CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED163' +
|
||||
'1A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should properly hash a multiblock input', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abcdefghbcdefghicdefghijdefghijkefghijklfghijklm' +
|
||||
'ghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrs' +
|
||||
'mnopqrstnopqrstu');
|
||||
result = calculateSHA384(input, 0, input.length);
|
||||
expected = hex2binary('09330C33F71147E83D192FC782CD1B4753111B173B3B05D2' +
|
||||
'2FA08086E3B0F712FCC7C71A557E2DB966C3E9FA91746039');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateSHA512', function() {
|
||||
it('should properly hash abc', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abc');
|
||||
result = calculateSHA512(input, 0, input.length);
|
||||
expected = hex2binary('DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA2' +
|
||||
'0A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD' +
|
||||
'454D4423643CE80E2A9AC94FA54CA49F');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should properly hash a multiblock input', function() {
|
||||
var input, result, expected;
|
||||
input = string2binary('abcdefghbcdefghicdefghijdefghijkefghijklfghijklm' +
|
||||
'ghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrs' +
|
||||
'mnopqrstnopqrstu');
|
||||
result = calculateSHA512(input, 0, input.length);
|
||||
expected = hex2binary('8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7FA1' +
|
||||
'7299AEADB6889018501D289E4900F7E4331B99DEC4B5433A' +
|
||||
'C7D329EEB6DD26545E96E55B874BE909');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('AES128', function() {
|
||||
describe('Encryption', function() {
|
||||
it('should be able to encrypt a block', function() {
|
||||
var input, key, result, expected, iv, cipher;
|
||||
input = hex2binary('00112233445566778899aabbccddeeff');
|
||||
key = hex2binary('000102030405060708090a0b0c0d0e0f');
|
||||
iv = hex2binary('00000000000000000000000000000000');
|
||||
cipher = new AES128Cipher(key);
|
||||
result = cipher.encrypt(input,iv);
|
||||
expected = hex2binary('69c4e0d86a7b0430d8cdb78070b4c55a');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Decryption', function() {
|
||||
it('should be able to decrypt a block with IV in stream', function() {
|
||||
var input, key, result, expected, cipher;
|
||||
input = hex2binary('0000000000000000000000000000000069c4e0d86a7b0430d' +
|
||||
'8cdb78070b4c55a');
|
||||
key = hex2binary('000102030405060708090a0b0c0d0e0f');
|
||||
cipher = new AES128Cipher(key);
|
||||
result = cipher.decryptBlock(input);
|
||||
expected = hex2binary('00112233445566778899aabbccddeeff');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('AES256', function() {
|
||||
describe('Encryption', function() {
|
||||
it('should be able to encrypt a block', function() {
|
||||
var input, key, result, expected, iv, cipher;
|
||||
input = hex2binary('00112233445566778899aabbccddeeff');
|
||||
key = hex2binary('000102030405060708090a0b0c0d0e0f101112131415161718' +
|
||||
'191a1b1c1d1e1f');
|
||||
iv = hex2binary('00000000000000000000000000000000');
|
||||
cipher = new AES256Cipher(key);
|
||||
result = cipher.encrypt(input,iv);
|
||||
expected = hex2binary('8ea2b7ca516745bfeafc49904b496089');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Decryption', function() {
|
||||
it('should be able to decrypt a block with specified iv', function() {
|
||||
var input, key, result, expected, cipher, iv;
|
||||
input = hex2binary('8ea2b7ca516745bfeafc49904b496089');
|
||||
key = hex2binary('000102030405060708090a0b0c0d0e0f101112131415161718' +
|
||||
'191a1b1c1d1e1f');
|
||||
iv = hex2binary('00000000000000000000000000000000');
|
||||
cipher = new AES256Cipher(key);
|
||||
result = cipher.decryptBlock(input,false,iv);
|
||||
expected = hex2binary('00112233445566778899aabbccddeeff');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should be able to decrypt a block with IV in stream', function() {
|
||||
var input, key, result, expected, cipher;
|
||||
input = hex2binary('000000000000000000000000000000008ea2b7ca516745bf' +
|
||||
'eafc49904b496089');
|
||||
key = hex2binary('000102030405060708090a0b0c0d0e0f101112131415161718' +
|
||||
'191a1b1c1d1e1f');
|
||||
cipher = new AES256Cipher(key);
|
||||
result = cipher.decryptBlock(input,false);
|
||||
expected = hex2binary('00112233445566778899aabbccddeeff');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PDF17Algorithm', function() {
|
||||
it('should correctly check a user key', function() {
|
||||
var password, userValidation, userPassword, alg, result;
|
||||
alg = new PDF17();
|
||||
password = new Uint8Array([117, 115, 101, 114]);
|
||||
userValidation = new Uint8Array([117, 169, 4, 32, 159, 101, 22, 220]);
|
||||
userPassword = new Uint8Array([
|
||||
131, 242, 143, 160, 87, 2, 138, 134, 79,
|
||||
253, 189, 173, 224, 73, 144, 241, 190, 81,
|
||||
197, 15, 249, 105, 145, 151, 15, 194, 65,
|
||||
3, 1, 126, 187, 221]);
|
||||
result = alg.checkUserPassword(password, userValidation, userPassword);
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
it('should correctly check an owner key', function () {
|
||||
var password, ownerValidation, ownerPassword, alg, result, uBytes;
|
||||
alg = new PDF17();
|
||||
password = new Uint8Array([111, 119, 110, 101, 114]);
|
||||
ownerValidation = new Uint8Array([243, 118, 71, 153, 128, 17, 101, 62]);
|
||||
ownerPassword = new Uint8Array([60, 98, 137, 35, 51, 101, 200, 152, 210,
|
||||
178, 226, 228, 134, 205, 163, 24, 204,
|
||||
126, 177, 36, 106, 50, 36, 125, 210, 172,
|
||||
171, 120, 222, 108, 139, 115]);
|
||||
uBytes = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79, 253,
|
||||
189, 173, 224, 73, 144, 241, 190, 81, 197, 15,
|
||||
249, 105, 145, 151, 15, 194, 65, 3, 1, 126, 187,
|
||||
221, 117, 169, 4, 32, 159, 101, 22, 220, 168,
|
||||
94, 215, 192, 100, 38, 188, 40]);
|
||||
result = alg.checkOwnerPassword(password, ownerValidation, uBytes,
|
||||
ownerPassword);
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
it('should generate a file encryption key from the user key', function () {
|
||||
var password, userKeySalt, expected, alg, result, userEncryption;
|
||||
alg = new PDF17();
|
||||
password = new Uint8Array([117, 115, 101, 114]);
|
||||
userKeySalt = new Uint8Array([168, 94, 215, 192, 100, 38, 188, 40]);
|
||||
userEncryption = new Uint8Array([35, 150, 195, 169, 245, 51, 51, 255,
|
||||
158, 158, 33, 242, 231, 75, 125, 190,
|
||||
25, 126, 172, 114, 195, 244, 137, 245,
|
||||
234, 165, 42, 74, 60, 38, 17, 17]);
|
||||
result = alg.getUserKey(password, userKeySalt, userEncryption);
|
||||
expected = new Uint8Array([63, 114, 136, 209, 87, 61, 12, 30, 249, 1,
|
||||
186, 144, 254, 248, 163, 153, 151, 51, 133,
|
||||
10, 80, 152, 206, 15, 72, 187, 231, 33, 224,
|
||||
239, 13, 213]);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should generate a file encryption key from the owner key', function () {
|
||||
var password, ownerKeySalt, expected, alg, result, ownerEncryption;
|
||||
var uBytes;
|
||||
alg = new PDF17();
|
||||
password = new Uint8Array([111, 119, 110, 101, 114]);
|
||||
ownerKeySalt = new Uint8Array([200, 245, 242, 12, 218, 123, 24, 120]);
|
||||
ownerEncryption = new Uint8Array([213, 202, 14, 189, 110, 76, 70, 191, 6,
|
||||
195, 10, 190, 157, 100, 144, 85, 8, 62,
|
||||
123, 178, 156, 229, 50, 40, 229, 216,
|
||||
54, 222, 34, 38, 106, 223]);
|
||||
uBytes = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79, 253,
|
||||
189, 173, 224, 73, 144, 241, 190, 81, 197, 15,
|
||||
249, 105, 145, 151, 15, 194, 65, 3, 1, 126, 187,
|
||||
221, 117, 169, 4, 32, 159, 101, 22, 220, 168,
|
||||
94, 215, 192, 100, 38, 188, 40]);
|
||||
result = alg.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
|
||||
expected = new Uint8Array([63, 114, 136, 209, 87, 61, 12, 30, 249, 1,
|
||||
186, 144, 254, 248, 163, 153, 151, 51, 133,
|
||||
10, 80, 152, 206, 15, 72, 187, 231, 33, 224,
|
||||
239, 13, 213]);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PDF20Algorithm', function() {
|
||||
it('should correctly check a user key', function () {
|
||||
var password, userValidation, userPassword, alg, result;
|
||||
alg = new PDF20();
|
||||
password = new Uint8Array([117, 115, 101, 114]);
|
||||
userValidation = new Uint8Array([83, 245, 146, 101, 198, 247, 34, 198]);
|
||||
userPassword = new Uint8Array([
|
||||
94, 230, 205, 75, 166, 99, 250, 76, 219,
|
||||
128, 17, 85, 57, 17, 33, 164, 150, 46,
|
||||
103, 176, 160, 156, 187, 233, 166, 223,
|
||||
163, 253, 147, 235, 95, 184]);
|
||||
result = alg.checkUserPassword(password, userValidation, userPassword);
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
it('should correctly check an owner key', function () {
|
||||
var password, ownerValidation, ownerPassword, alg, result, uBytes;
|
||||
alg = new PDF20();
|
||||
password = new Uint8Array([111, 119, 110, 101, 114]);
|
||||
ownerValidation = new Uint8Array([142, 232, 169, 208, 202, 214, 5, 185]);
|
||||
ownerPassword = new Uint8Array([88, 232, 62, 54, 245, 26, 245, 209, 137,
|
||||
123, 221, 72, 199, 49, 37, 217, 31, 74,
|
||||
115, 167, 127, 158, 176, 77, 45, 163, 87,
|
||||
47, 39, 90, 217, 141]);
|
||||
uBytes = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219, 128,
|
||||
17, 85, 57, 17, 33, 164, 150, 46, 103, 176, 160,
|
||||
156, 187, 233, 166, 223, 163, 253, 147, 235, 95,
|
||||
184, 83, 245, 146, 101, 198, 247, 34, 198, 191,
|
||||
11, 16, 94, 237, 216, 20, 175]);
|
||||
result = alg.checkOwnerPassword(password, ownerValidation, uBytes,
|
||||
ownerPassword);
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
it('should generate a file encryption key from the user key', function () {
|
||||
var password, userKeySalt, expected, alg, result, userEncryption;
|
||||
alg = new PDF20();
|
||||
password = new Uint8Array([117, 115, 101, 114]);
|
||||
userKeySalt = new Uint8Array([191, 11, 16, 94, 237, 216, 20, 175]);
|
||||
userEncryption = new Uint8Array([121, 208, 2, 181, 230, 89, 156, 60, 253,
|
||||
143, 212, 28, 84, 180, 196, 177, 173,
|
||||
128, 221, 107, 46, 20, 94, 186, 135, 51,
|
||||
95, 24, 20, 223, 254, 36]);
|
||||
result = alg.getUserKey(password, userKeySalt, userEncryption);
|
||||
expected = new Uint8Array([42, 218, 213, 39, 73, 91, 72, 79, 67, 38, 248,
|
||||
133, 18, 189, 61, 34, 107, 79, 29, 56, 59,
|
||||
181, 213, 118, 113, 34, 65, 210, 87, 174, 22,
|
||||
239]);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should generate a file encryption key from the owner key', function () {
|
||||
var password, ownerKeySalt, expected, alg, result, ownerEncryption;
|
||||
var uBytes;
|
||||
alg = new PDF20();
|
||||
password = new Uint8Array([111, 119, 110, 101, 114]);
|
||||
ownerKeySalt = new Uint8Array([29, 208, 185, 46, 11, 76, 135, 149]);
|
||||
ownerEncryption = new Uint8Array([209, 73, 224, 77, 103, 155, 201, 181,
|
||||
190, 68, 223, 20, 62, 90, 56, 210, 5,
|
||||
240, 178, 128, 238, 124, 68, 254, 253,
|
||||
244, 62, 108, 208, 135, 10, 251]);
|
||||
uBytes = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219, 128,
|
||||
17, 85, 57, 17, 33, 164, 150, 46, 103, 176, 160,
|
||||
156, 187, 233, 166, 223, 163, 253, 147, 235, 95,
|
||||
184, 83, 245, 146, 101, 198, 247, 34, 198, 191,
|
||||
11, 16, 94, 237, 216, 20, 175]);
|
||||
result = alg.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
|
||||
expected = new Uint8Array([42, 218, 213, 39, 73, 91, 72, 79, 67, 38, 248,
|
||||
133, 18, 189, 61, 34, 107, 79, 29, 56, 59,
|
||||
181, 213, 118, 113, 34, 65, 210, 87, 174, 22,
|
||||
239]);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('CipherTransformFactory', function() {
|
||||
function DictMock(map) {
|
||||
this.map = map;
|
||||
}
|
||||
DictMock.prototype = {
|
||||
get: function(key) {
|
||||
return this.map[key];
|
||||
}
|
||||
};
|
||||
|
||||
function ensureCipherTransformFactoryPasswordIncorrect(
|
||||
dict, fileId, password) {
|
||||
var exception = null;
|
||||
try {
|
||||
new CipherTransformFactory(dict, fileId, password);
|
||||
} catch (ex) {
|
||||
exception = ex;
|
||||
}
|
||||
expect(exception instanceof PasswordException).toEqual(true);
|
||||
expect(exception.code).toEqual(PasswordResponses.INCORRECT_PASSWORD);
|
||||
}
|
||||
|
||||
var map1 = {
|
||||
Filter: Name.get('Standard'),
|
||||
V: 2,
|
||||
Length: 128,
|
||||
O: unescape('%80%C3%04%96%91o%20sl%3A%E6%1B%13T%91%F2%0DV%12%E3%FF%5E%BB%' +
|
||||
'E9VO%D8k%9A%CA%7C%5D'),
|
||||
U: unescape('j%0C%8D%3EY%19%00%BCjd%7D%91%BD%AA%00%18%00%00%00%00%00%00%0' +
|
||||
'0%00%00%00%00%00%00%00%00%00'),
|
||||
P: -1028,
|
||||
R: 3
|
||||
};
|
||||
var fileID1 = unescape('%F6%C6%AF%17%F3rR%8DRM%9A%80%D1%EF%DF%18');
|
||||
|
||||
var map2 = {
|
||||
Filter: Name.get('Standard'),
|
||||
V: 4,
|
||||
Length: 128,
|
||||
O: unescape('sF%14v.y5%27%DB%97%0A5%22%B3%E1%D4%AD%BD%9B%3C%B4%A5%89u%15%' +
|
||||
'B2Y%F1h%D9%E9%F4'),
|
||||
U: unescape('%93%04%89%A9%BF%8AE%A6%88%A2%DB%C2%A0%A8gn%00%00%00%00%00%00' +
|
||||
'%00%00%00%00%00%00%00%00%00%00'),
|
||||
P: -1084,
|
||||
R: 4
|
||||
};
|
||||
|
||||
var aes256Map = {
|
||||
Filter: Name.get('Standard'),
|
||||
V: 5,
|
||||
Length: 256,
|
||||
O: unescape('%3Cb%89%233e%C8%98%D2%B2%E2%E4%86%CD%A3%18%CC%7E%B1%24j2%24%' +
|
||||
'7D%D2%AC%ABx%DEl%8Bs%F3vG%99%80%11e%3E%C8%F5%F2%0C%DA%7B%18x'),
|
||||
U: unescape('%83%F2%8F%A0W%02%8A%86O%FD%BD%AD%E0I%90%F1%BEQ%C5%0F%F9i%91%' +
|
||||
'97%0F%C2A%03%01%7E%BB%DDu%A9%04%20%9Fe%16%DC%A8%5E%D7%C0d%26' +
|
||||
'%BC%28'),
|
||||
OE: unescape('%D5%CA%0E%BDnLF%BF%06%C3%0A%BE%9Dd%90U%08%3E%7B%B2%9C%E52%2' +
|
||||
'8%E5%D86%DE%22%26j%DF'),
|
||||
UE: unescape('%23%96%C3%A9%F533%FF%9E%9E%21%F2%E7K%7D%BE%19%7E%ACr%C3%F4%' +
|
||||
'89%F5%EA%A5*J%3C%26%11%11'),
|
||||
Perms: unescape('%D8%FC%844%E5e%0DB%5D%7Ff%FD%3COMM'),
|
||||
P: -1084,
|
||||
R: 5
|
||||
};
|
||||
|
||||
var aes256IsoMap = {
|
||||
Filter: Name.get('Standard'),
|
||||
V: 5,
|
||||
Length: 256,
|
||||
O: unescape('X%E8%3E6%F5%1A%F5%D1%89%7B%DDH%C71%25%D9%1FJs%A7%7F%9E%B0M-%' +
|
||||
'A3W/%27Z%D9%8D%8E%E8%A9%D0%CA%D6%05%B9%1D%D0%B9.%0BL%87%95'),
|
||||
U: unescape('%5E%E6%CDK%A6c%FAL%DB%80%11U9%11%21%A4%96.g%B0%A0%9C%BB%E9%A' +
|
||||
'6%DF%A3%FD%93%EB_%B8S%F5%92e%C6%F7%22%C6%BF%0B%10%5E%ED%D8%1' +
|
||||
'4%AF'),
|
||||
OE: unescape('%D1I%E0Mg%9B%C9%B5%BED%DF%14%3EZ8%D2%05%F0%B2%80%EE%7CD%FE%' +
|
||||
'FD%F4%3El%D0%87%0A%FB'),
|
||||
UE: unescape('y%D0%02%B5%E6Y%9C%3C%FD%8F%D4%1CT%B4%C4%B1%AD%80%DDk.%14%5E' +
|
||||
'%BA%873_%18%14%DF%FE%24'),
|
||||
Perms: unescape('l%AD%0F%A0%EBM%86WM%3E%CB%B5%E0X%C97'),
|
||||
P: -1084,
|
||||
R: 6
|
||||
};
|
||||
|
||||
var aes256BlankMap = {
|
||||
Filter: Name.get('Standard'),
|
||||
V: 5,
|
||||
Length: 256,
|
||||
O: unescape('%B8p%04%C3g%26%FCW%CCN%D4%16%A1%E8%950YZ%C9%9E%B1-%97%F3%FE%' +
|
||||
'03%13%19ffZn%8F%F5%EB%EC%CC5sV%10e%CEl%B5%E9G%C1'),
|
||||
U: unescape('%83%D4zi%F1O0%961%12%CC%82%CB%CA%BF5y%FD%21%EB%E4%D1%B5%1D%D' +
|
||||
'6%FA%14%F3%BE%8Fqs%EF%88%DE%E2%E8%DC%F55%E4%B8%16%C8%14%8De%' +
|
||||
'1E'),
|
||||
OE: unescape('%8F%19%E8%D4%27%D5%07%CA%C6%A1%11%A6a%5Bt%F4%DF%0F%84%29%0F' +
|
||||
'%E4%EFF7%5B%5B%11%A0%8F%17e'),
|
||||
UE: unescape('%81%F5%5D%B0%28%81%E4%7F_%7C%8F%85b%A0%7E%10%D0%88lx%7B%7EJ' +
|
||||
'%5E%912%B6d%12%27%05%F6'),
|
||||
Perms: unescape('%86%1562%0D%AE%A2%FB%5D%3B%22%3Dq%12%B2H'),
|
||||
P: -1084,
|
||||
R: 5
|
||||
};
|
||||
|
||||
var aes256IBlankMap = {
|
||||
Filter: Name.get('Standard'),
|
||||
V: 5,
|
||||
Length: 256,
|
||||
O: unescape('%F7%DB%99U%A6M%ACk%AF%CF%D7AFw%E9%C1%91%CBDgI%23R%CF%0C%15r%' +
|
||||
'D74%0D%CE%E9%91@%E4%98QF%BF%88%7Ej%DE%AD%8F%F4@%C1'),
|
||||
U: unescape('%1A%A9%DC%918%83%93k%29%5B%117%B16%DB%E8%8E%FE%28%E5%89%D4%0' +
|
||||
'E%AD%12%3B%7DN_6fez%8BG%18%05YOh%7DZH%A3Z%87%17*'),
|
||||
OE: unescape('%A4a%88%20h%1B%7F%CD%D5%CAc%D8R%83%E5%D6%1C%D2%98%07%984%BA' +
|
||||
'%AF%1B%B4%7FQ%F8%1EU%7D'),
|
||||
UE: unescape('%A0%0AZU%27%1D%27%2C%0B%FE%0E%A2L%F9b%5E%A1%B9%D6v7b%B26%A9' +
|
||||
'N%99%F1%A4Deq'),
|
||||
Perms: unescape('%03%F2i%07%0D%C3%F9%F2%28%80%B7%F5%DD%D1c%EB'),
|
||||
P: -1084,
|
||||
R: 6
|
||||
};
|
||||
|
||||
var fileID2 = unescape('%3CL_%3AD%96%AF@%9A%9D%B3%3Cx%1Cv%AC');
|
||||
|
||||
describe('#ctor', function() {
|
||||
describe('AES256 Revision 5', function () {
|
||||
it('should accept user password', function () {
|
||||
new CipherTransformFactory(new DictMock(aes256Map), fileID1, 'user');
|
||||
});
|
||||
it('should accept owner password', function () {
|
||||
new CipherTransformFactory(new DictMock(aes256Map), fileID1, 'owner');
|
||||
});
|
||||
it('should not accept wrong password', function () {
|
||||
ensureCipherTransformFactoryPasswordIncorrect(
|
||||
new DictMock(aes256Map), fileID1, 'wrong');
|
||||
});
|
||||
it('should accept blank password', function () {
|
||||
new CipherTransformFactory(new DictMock(aes256BlankMap), fileID1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('AES256 Revision 6', function () {
|
||||
it('should accept user password', function () {
|
||||
new CipherTransformFactory(new DictMock(aes256IsoMap), fileID1,
|
||||
'user');
|
||||
});
|
||||
it('should accept owner password', function () {
|
||||
new CipherTransformFactory(new DictMock(aes256IsoMap), fileID1,
|
||||
'owner');
|
||||
});
|
||||
it('should not accept wrong password', function () {
|
||||
ensureCipherTransformFactoryPasswordIncorrect(
|
||||
new DictMock(aes256IsoMap), fileID1, 'wrong');
|
||||
});
|
||||
it('should accept blank password', function () {
|
||||
new CipherTransformFactory(new DictMock(aes256IBlankMap), fileID1);
|
||||
});
|
||||
});
|
||||
it('should accept user password', function() {
|
||||
new CipherTransformFactory(new DictMock(map1), fileID1, '123456');
|
||||
});
|
||||
|
||||
it('should accept owner password', function() {
|
||||
new CipherTransformFactory(new DictMock(map1), fileID1, '654321');
|
||||
});
|
||||
|
||||
it('should not accept wrong password', function() {
|
||||
ensureCipherTransformFactoryPasswordIncorrect(
|
||||
new DictMock(map1), fileID1, 'wrong');
|
||||
});
|
||||
|
||||
it('should accept no password', function() {
|
||||
new CipherTransformFactory(new DictMock(map2), fileID2);
|
||||
});
|
||||
});
|
||||
});
|
231
3rdparty/pdf.js/test/unit/evaluator_spec.js
vendored
Executable file
231
3rdparty/pdf.js/test/unit/evaluator_spec.js
vendored
Executable file
@ -0,0 +1,231 @@
|
||||
/* -*- 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, PartialEvaluator, StringStream, OPS,
|
||||
OperatorList, waitsFor, runs */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('evaluator', function() {
|
||||
function XrefMock(queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
XrefMock.prototype = {
|
||||
fetchIfRef: function() {
|
||||
return this.queue.shift();
|
||||
}
|
||||
};
|
||||
function HandlerMock() {
|
||||
this.inputs = [];
|
||||
}
|
||||
HandlerMock.prototype = {
|
||||
send: function(name, data) {
|
||||
this.inputs.push({name: name, data: data});
|
||||
}
|
||||
};
|
||||
function ResourcesMock() { }
|
||||
ResourcesMock.prototype = {
|
||||
get: function(name) {
|
||||
return this[name];
|
||||
}
|
||||
};
|
||||
|
||||
function PdfManagerMock() { }
|
||||
|
||||
function runOperatorListCheck(evaluator, stream, resources, check) {
|
||||
var done = false;
|
||||
runs(function () {
|
||||
var result = new OperatorList();
|
||||
evaluator.getOperatorList(stream, resources, result).then(function () {
|
||||
check(result);
|
||||
done = true;
|
||||
});
|
||||
});
|
||||
waitsFor(function () {
|
||||
return done;
|
||||
});
|
||||
}
|
||||
|
||||
describe('splitCombinedOperations', function() {
|
||||
it('should reject unknown operations', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('fTT');
|
||||
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function(result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(1);
|
||||
expect(result.fnArray[0]).toEqual(OPS.fill);
|
||||
expect(result.argsArray[0]).toEqual(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle one operations', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('Q');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function(result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(1);
|
||||
expect(result.fnArray[0]).toEqual(OPS.restore);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle two glued operations', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var resources = new ResourcesMock();
|
||||
resources.Res1 = {};
|
||||
var stream = new StringStream('/Res1 DoQ');
|
||||
runOperatorListCheck(evaluator, stream, resources, function (result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(2);
|
||||
expect(result.fnArray[0]).toEqual(OPS.paintXObject);
|
||||
expect(result.fnArray[1]).toEqual(OPS.restore);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle tree glued operations', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('fff');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(3);
|
||||
expect(result.fnArray[0]).toEqual(OPS.fill);
|
||||
expect(result.fnArray[1]).toEqual(OPS.fill);
|
||||
expect(result.fnArray[2]).toEqual(OPS.fill);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle three glued operations #2', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var resources = new ResourcesMock();
|
||||
resources.Res1 = {};
|
||||
var stream = new StringStream('B*Bf*');
|
||||
runOperatorListCheck(evaluator, stream, resources, function (result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(3);
|
||||
expect(result.fnArray[0]).toEqual(OPS.eoFillStroke);
|
||||
expect(result.fnArray[1]).toEqual(OPS.fillStroke);
|
||||
expect(result.fnArray[2]).toEqual(OPS.eoFill);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle glued operations and operands', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('f5 Ts');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(2);
|
||||
expect(result.fnArray[0]).toEqual(OPS.fill);
|
||||
expect(result.fnArray[1]).toEqual(OPS.setTextRise);
|
||||
expect(result.argsArray.length).toEqual(2);
|
||||
expect(result.argsArray[1].length).toEqual(1);
|
||||
expect(result.argsArray[1][0]).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle glued operations and literals', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('trueifalserinulln');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(3);
|
||||
expect(result.fnArray[0]).toEqual(OPS.setFlatness);
|
||||
expect(result.fnArray[1]).toEqual(OPS.setRenderingIntent);
|
||||
expect(result.fnArray[2]).toEqual(OPS.endPath);
|
||||
expect(result.argsArray.length).toEqual(3);
|
||||
expect(result.argsArray[0].length).toEqual(1);
|
||||
expect(result.argsArray[0][0]).toEqual(true);
|
||||
expect(result.argsArray[1].length).toEqual(1);
|
||||
expect(result.argsArray[1][0]).toEqual(false);
|
||||
expect(result.argsArray[2]).toEqual(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateNumberOfArgs', function() {
|
||||
it('should execute if correct number of arguments', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('5 1 d0');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(result.argsArray[0][0]).toEqual(5);
|
||||
expect(result.argsArray[0][1]).toEqual(1);
|
||||
expect(result.fnArray[0]).toEqual(OPS.setCharWidth);
|
||||
});
|
||||
});
|
||||
it('should execute if too many arguments', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('5 1 4 d0');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(result.argsArray[0][0]).toEqual(1);
|
||||
expect(result.argsArray[0][1]).toEqual(4);
|
||||
expect(result.fnArray[0]).toEqual(OPS.setCharWidth);
|
||||
});
|
||||
});
|
||||
it('should execute if nested commands', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('/F2 /GS2 gs 5.711 Tf');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(result.fnArray.length).toEqual(3);
|
||||
expect(result.fnArray[0]).toEqual(OPS.setGState);
|
||||
expect(result.fnArray[1]).toEqual(OPS.dependency);
|
||||
expect(result.fnArray[2]).toEqual(OPS.setFont);
|
||||
expect(result.argsArray.length).toEqual(3);
|
||||
expect(result.argsArray[0].length).toEqual(1);
|
||||
expect(result.argsArray[1].length).toEqual(1);
|
||||
expect(result.argsArray[2].length).toEqual(2);
|
||||
});
|
||||
});
|
||||
it('should skip if too few arguments', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('5 d0');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(result.argsArray).toEqual([]);
|
||||
expect(result.fnArray).toEqual([]);
|
||||
});
|
||||
});
|
||||
it('should close opened saves', function() {
|
||||
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||
new XrefMock(), new HandlerMock(),
|
||||
'prefix');
|
||||
var stream = new StringStream('qq');
|
||||
runOperatorListCheck(evaluator, stream, new ResourcesMock(),
|
||||
function (result) {
|
||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||
expect(result.fnArray.length).toEqual(4);
|
||||
expect(result.fnArray[0]).toEqual(OPS.save);
|
||||
expect(result.fnArray[1]).toEqual(OPS.save);
|
||||
expect(result.fnArray[2]).toEqual(OPS.restore);
|
||||
expect(result.fnArray[3]).toEqual(OPS.restore);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
380
3rdparty/pdf.js/test/unit/font_spec.js
vendored
Executable file
380
3rdparty/pdf.js/test/unit/font_spec.js
vendored
Executable file
@ -0,0 +1,380 @@
|
||||
/* -*- 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, CFFCompiler, CFFParser, CFFIndex, CFFStrings,
|
||||
SEAC_ANALYSIS_ENABLED:true, Type1Parser, StringStream */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('font', function() {
|
||||
// This example font comes from the CFF spec:
|
||||
// http://www.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5176.CFF.pdf
|
||||
var exampleFont = '0100040100010101134142434445462b' +
|
||||
'54696d65732d526f6d616e000101011f' +
|
||||
'f81b00f81c02f81d03f819041c6f000d' +
|
||||
'fb3cfb6efa7cfa1605e911b8f1120003' +
|
||||
'01010813183030312e30303754696d65' +
|
||||
'7320526f6d616e54696d657300000002' +
|
||||
'010102030e0e7d99f92a99fb7695f773' +
|
||||
'8b06f79a93fc7c8c077d99f85695f75e' +
|
||||
'9908fb6e8cf87393f7108b09a70adf0b' +
|
||||
'f78e14';
|
||||
var fontData = [];
|
||||
for (var i = 0; i < exampleFont.length; i += 2) {
|
||||
var hex = exampleFont.substr(i, 2);
|
||||
fontData.push(parseInt(hex, 16));
|
||||
}
|
||||
var bytes = new Uint8Array(fontData);
|
||||
fontData = {
|
||||
getBytes: function() {
|
||||
return bytes;
|
||||
}
|
||||
};
|
||||
|
||||
describe('CFFParser', function() {
|
||||
var parser = new CFFParser(fontData, {});
|
||||
var cff = parser.parse();
|
||||
|
||||
it('parses header', function() {
|
||||
var header = cff.header;
|
||||
expect(header.major).toEqual(1);
|
||||
expect(header.minor).toEqual(0);
|
||||
expect(header.hdrSize).toEqual(4);
|
||||
expect(header.offSize).toEqual(1);
|
||||
});
|
||||
|
||||
it('parses name index', function() {
|
||||
var names = cff.names;
|
||||
expect(names.length).toEqual(1);
|
||||
expect(names[0]).toEqual('ABCDEF+Times-Roman');
|
||||
});
|
||||
|
||||
it('sanitizes name index', function() {
|
||||
var index = new CFFIndex();
|
||||
index.add(['['.charCodeAt(0), 'a'.charCodeAt(0)]);
|
||||
|
||||
var names = parser.parseNameIndex(index);
|
||||
expect(names).toEqual(['_a']);
|
||||
|
||||
index = new CFFIndex();
|
||||
var longName = [];
|
||||
for (var i = 0; i < 129; i++) {
|
||||
longName.push(0);
|
||||
}
|
||||
index.add(longName);
|
||||
names = parser.parseNameIndex(index);
|
||||
expect(names[0].length).toEqual(127);
|
||||
});
|
||||
|
||||
it('parses string index', function() {
|
||||
var strings = cff.strings;
|
||||
expect(strings.count).toEqual(3);
|
||||
expect(strings.get(0)).toEqual('.notdef');
|
||||
expect(strings.get(391)).toEqual('001.007');
|
||||
});
|
||||
|
||||
it('parses top dict', function() {
|
||||
var topDict = cff.topDict;
|
||||
// 391 version 392 FullName 393 FamilyName 389 Weight 28416 UniqueID
|
||||
// -168 -218 1000 898 FontBBox 94 CharStrings 45 102 Private
|
||||
expect(topDict.getByName('version')).toEqual(391);
|
||||
expect(topDict.getByName('FullName')).toEqual(392);
|
||||
expect(topDict.getByName('FamilyName')).toEqual(393);
|
||||
expect(topDict.getByName('Weight')).toEqual(389);
|
||||
expect(topDict.getByName('UniqueID')).toEqual(28416);
|
||||
expect(topDict.getByName('FontBBox')).toEqual([-168, -218, 1000, 898]);
|
||||
expect(topDict.getByName('CharStrings')).toEqual(94);
|
||||
expect(topDict.getByName('Private')).toEqual([45, 102]);
|
||||
});
|
||||
|
||||
it('parses a CharString having cntrmask', function() {
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
38, // end
|
||||
149, 149, 149, 149, 149, 149, 149, 149,
|
||||
149, 149, 149, 149, 149, 149, 149, 149,
|
||||
1, // hstem
|
||||
149, 149, 149, 149, 149, 149, 149, 149,
|
||||
149, 149, 149, 149, 149, 149, 149, 149,
|
||||
3, // vstem
|
||||
20, // cntrmask
|
||||
22, 22, // fail if misparsed as hmoveto
|
||||
14 // endchar
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var charStrings = parser.parseCharStrings(0).charStrings;
|
||||
expect(charStrings.count).toEqual(1);
|
||||
// shoudn't be sanitized
|
||||
expect(charStrings.get(0).length).toEqual(38);
|
||||
});
|
||||
|
||||
it('parses a CharString endchar with 4 args w/seac enabled', function() {
|
||||
var seacAnalysisState = SEAC_ANALYSIS_ENABLED;
|
||||
try {
|
||||
SEAC_ANALYSIS_ENABLED = true;
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
237, 247, 22, 247, 72, 204, 247, 86, 14]);
|
||||
parser.bytes = bytes;
|
||||
var result = parser.parseCharStrings(0);
|
||||
expect(result.charStrings.count).toEqual(1);
|
||||
expect(result.charStrings.get(0).length).toEqual(1);
|
||||
expect(result.seacs.length).toEqual(1);
|
||||
expect(result.seacs[0].length).toEqual(4);
|
||||
expect(result.seacs[0][0]).toEqual(130);
|
||||
expect(result.seacs[0][1]).toEqual(180);
|
||||
expect(result.seacs[0][2]).toEqual(65);
|
||||
expect(result.seacs[0][3]).toEqual(194);
|
||||
} finally {
|
||||
SEAC_ANALYSIS_ENABLED = seacAnalysisState;
|
||||
}
|
||||
});
|
||||
|
||||
it('parses a CharString endchar with 4 args w/seac disabled', function() {
|
||||
var seacAnalysisState = SEAC_ANALYSIS_ENABLED;
|
||||
try {
|
||||
SEAC_ANALYSIS_ENABLED = false;
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
237, 247, 22, 247, 72, 204, 247, 86, 14]);
|
||||
parser.bytes = bytes;
|
||||
var result = parser.parseCharStrings(0);
|
||||
expect(result.charStrings.count).toEqual(1);
|
||||
expect(result.charStrings.get(0).length).toEqual(9);
|
||||
expect(result.seacs.length).toEqual(0);
|
||||
} finally {
|
||||
SEAC_ANALYSIS_ENABLED = seacAnalysisState;
|
||||
}
|
||||
});
|
||||
|
||||
it('parses a CharString endchar no args', function() {
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
14]);
|
||||
parser.bytes = bytes;
|
||||
var result = parser.parseCharStrings(0);
|
||||
expect(result.charStrings.count).toEqual(1);
|
||||
expect(result.charStrings.get(0)[0]).toEqual(14);
|
||||
expect(result.seacs.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('parses predefined charsets', function() {
|
||||
var charset = parser.parseCharsets(0, 0, null, true);
|
||||
expect(charset.predefined).toEqual(true);
|
||||
});
|
||||
|
||||
it('parses charset format 0', function() {
|
||||
// The first three bytes make the offset large enough to skip predefined.
|
||||
var bytes = new Uint8Array([0x00, 0x00, 0x00,
|
||||
0x00, // format
|
||||
0x00, 0x02 // sid/cid
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var charset = parser.parseCharsets(3, 2, new CFFStrings(), false);
|
||||
expect(charset.charset[1]).toEqual('exclam');
|
||||
|
||||
// CID font
|
||||
charset = parser.parseCharsets(3, 2, new CFFStrings(), true);
|
||||
expect(charset.charset[1]).toEqual(2);
|
||||
});
|
||||
|
||||
it('parses charset format 1', function() {
|
||||
// The first three bytes make the offset large enough to skip predefined.
|
||||
var bytes = new Uint8Array([0x00, 0x00, 0x00,
|
||||
0x01, // format
|
||||
0x00, 0x08, // sid/cid start
|
||||
0x01 // sid/cid left
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var charset = parser.parseCharsets(3, 2, new CFFStrings(), false);
|
||||
expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']);
|
||||
|
||||
// CID font
|
||||
charset = parser.parseCharsets(3, 2, new CFFStrings(), true);
|
||||
expect(charset.charset).toEqual(['.notdef', 8, 9]);
|
||||
});
|
||||
|
||||
it('parses charset format 2', function() {
|
||||
// format 2 is the same as format 1 but the left is card16
|
||||
// The first three bytes make the offset large enough to skip predefined.
|
||||
var bytes = new Uint8Array([0x00, 0x00, 0x00,
|
||||
0x02, // format
|
||||
0x00, 0x08, // sid/cid start
|
||||
0x00, 0x01 // sid/cid left
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var charset = parser.parseCharsets(3, 2, new CFFStrings(), false);
|
||||
expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']);
|
||||
|
||||
// CID font
|
||||
charset = parser.parseCharsets(3, 2, new CFFStrings(), true);
|
||||
expect(charset.charset).toEqual(['.notdef', 8, 9]);
|
||||
});
|
||||
|
||||
it('parses encoding format 0', function() {
|
||||
// The first two bytes make the offset large enough to skip predefined.
|
||||
var bytes = new Uint8Array([0x00, 0x00,
|
||||
0x00, // format
|
||||
0x01, // count
|
||||
0x08 // start
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var encoding = parser.parseEncoding(2, {}, new CFFStrings(), null);
|
||||
expect(encoding.encoding).toEqual({0x8: 1});
|
||||
});
|
||||
|
||||
it('parses encoding format 1', function() {
|
||||
// The first two bytes make the offset large enough to skip predefined.
|
||||
var bytes = new Uint8Array([0x00, 0x00,
|
||||
0x01, // format
|
||||
0x01, // num ranges
|
||||
0x07, // range1 start
|
||||
0x01 // range2 left
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var encoding = parser.parseEncoding(2, {}, new CFFStrings(), null);
|
||||
expect(encoding.encoding).toEqual({0x7: 0x01, 0x08: 0x02});
|
||||
});
|
||||
|
||||
it('parses fdselect format 0', function() {
|
||||
var bytes = new Uint8Array([0x00, // format
|
||||
0x00, // gid: 0 fd: 0
|
||||
0x01 // gid: 1 fd: 1
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var fdSelect = parser.parseFDSelect(0, 2);
|
||||
expect(fdSelect.fdSelect).toEqual([0, 1]);
|
||||
});
|
||||
|
||||
it('parses fdselect format 3', function() {
|
||||
var bytes = new Uint8Array([0x03, // format
|
||||
0x00, 0x02, // range count
|
||||
0x00, 0x00, // first gid
|
||||
0x09, // font dict 1 id
|
||||
0x00, 0x02, // nex gid
|
||||
0x0a, // font dict 2 gid
|
||||
0x00, 0x04 // sentinel (last gid)
|
||||
]);
|
||||
parser.bytes = bytes;
|
||||
var fdSelect = parser.parseFDSelect(0, 2);
|
||||
expect(fdSelect.fdSelect).toEqual([9, 9, 0xa, 0xa]);
|
||||
});
|
||||
// TODO fdArray
|
||||
});
|
||||
describe('CFFCompiler', function() {
|
||||
it('encodes integers', function() {
|
||||
var c = new CFFCompiler();
|
||||
// all the examples from the spec
|
||||
expect(c.encodeInteger(0)).toEqual([0x8b]);
|
||||
expect(c.encodeInteger(100)).toEqual([0xef]);
|
||||
expect(c.encodeInteger(-100)).toEqual([0x27]);
|
||||
expect(c.encodeInteger(1000)).toEqual([0xfa, 0x7c]);
|
||||
expect(c.encodeInteger(-1000)).toEqual([0xfe, 0x7c]);
|
||||
expect(c.encodeInteger(10000)).toEqual([0x1c, 0x27, 0x10]);
|
||||
expect(c.encodeInteger(-10000)).toEqual([0x1c, 0xd8, 0xf0]);
|
||||
expect(c.encodeInteger(100000)).toEqual([0x1d, 0x00, 0x01, 0x86, 0xa0]);
|
||||
expect(c.encodeInteger(-100000)).toEqual([0x1d, 0xff, 0xfe, 0x79, 0x60]);
|
||||
});
|
||||
it('encodes floats', function() {
|
||||
var c = new CFFCompiler();
|
||||
expect(c.encodeFloat(-2.25)).toEqual([0x1e, 0xe2, 0xa2, 0x5f]);
|
||||
expect(c.encodeFloat(5e-11)).toEqual([0x1e, 0x5c, 0x11, 0xff]);
|
||||
});
|
||||
// TODO a lot more compiler tests
|
||||
});
|
||||
|
||||
describe('Type1Parser', function() {
|
||||
|
||||
it('splits tokens', function() {
|
||||
var stream = new StringStream('/BlueValues[-17 0]noaccess def');
|
||||
var parser = new Type1Parser(stream);
|
||||
expect(parser.getToken()).toEqual('/');
|
||||
expect(parser.getToken()).toEqual('BlueValues');
|
||||
expect(parser.getToken()).toEqual('[');
|
||||
expect(parser.getToken()).toEqual('-17');
|
||||
expect(parser.getToken()).toEqual('0');
|
||||
expect(parser.getToken()).toEqual(']');
|
||||
expect(parser.getToken()).toEqual('noaccess');
|
||||
expect(parser.getToken()).toEqual('def');
|
||||
expect(parser.getToken()).toEqual(null);
|
||||
});
|
||||
it('handles glued tokens', function() {
|
||||
var stream = new StringStream('dup/CharStrings');
|
||||
var parser = new Type1Parser(stream);
|
||||
expect(parser.getToken()).toEqual('dup');
|
||||
expect(parser.getToken()).toEqual('/');
|
||||
expect(parser.getToken()).toEqual('CharStrings');
|
||||
});
|
||||
it('ignores whitespace', function() {
|
||||
var stream = new StringStream('\nab c\t');
|
||||
var parser = new Type1Parser(stream);
|
||||
expect(parser.getToken()).toEqual('ab');
|
||||
expect(parser.getToken()).toEqual('c');
|
||||
});
|
||||
it('parses numbers', function() {
|
||||
var stream = new StringStream('123');
|
||||
var parser = new Type1Parser(stream);
|
||||
expect(parser.readNumber()).toEqual(123);
|
||||
});
|
||||
it('parses booleans', function() {
|
||||
var stream = new StringStream('true false');
|
||||
var parser = new Type1Parser(stream);
|
||||
expect(parser.readBoolean()).toEqual(1);
|
||||
expect(parser.readBoolean()).toEqual(0);
|
||||
});
|
||||
it('parses number arrays', function() {
|
||||
var stream = new StringStream('[1 2]');
|
||||
var parser = new Type1Parser(stream);
|
||||
expect(parser.readNumberArray()).toEqual([1, 2]);
|
||||
// Variation on spacing.
|
||||
stream = new StringStream('[ 1 2 ]');
|
||||
parser = new Type1Parser(stream);
|
||||
expect(parser.readNumberArray()).toEqual([1, 2]);
|
||||
});
|
||||
it('skips comments', function() {
|
||||
var stream = new StringStream(
|
||||
'%!PS-AdobeFont-1.0: CMSY10 003.002\n' +
|
||||
'%%Title: CMSY10\n' +
|
||||
'%Version: 003.002\n' +
|
||||
'FontDirectory');
|
||||
var parser = new Type1Parser(stream);
|
||||
expect(parser.getToken()).toEqual('FontDirectory');
|
||||
});
|
||||
it('parses font program', function() {
|
||||
var stream = new StringStream(
|
||||
'/ExpansionFactor 99\n' +
|
||||
'/Subrs 1 array\n' +
|
||||
'dup 0 1 RD x noaccess put\n'+
|
||||
'end\n' +
|
||||
'/CharStrings 46 dict dup begin\n' +
|
||||
'/.notdef 1 RD x ND' + '\n' +
|
||||
'end');
|
||||
var parser = new Type1Parser(stream);
|
||||
var program = parser.extractFontProgram();
|
||||
expect(program.charstrings.length).toEqual(1);
|
||||
expect(program.properties.privateData.ExpansionFactor).toEqual(99);
|
||||
});
|
||||
it('parses font header font matrix', function() {
|
||||
var stream = new StringStream(
|
||||
'/FontMatrix [0.001 0 0 0.001 0 0 ]readonly def\n');
|
||||
var parser = new Type1Parser(stream);
|
||||
var props = {};
|
||||
parser.extractFontHeader(props);
|
||||
expect(props.fontMatrix).toEqual([0.001, 0, 0, 0.001, 0, 0]);
|
||||
});
|
||||
it('parses font header encoding', function() {
|
||||
var stream = new StringStream(
|
||||
'/Encoding 256 array\n' +
|
||||
'0 1 255 {1 index exch /.notdef put} for\n' +
|
||||
'dup 33 /arrowright put\n' +
|
||||
'readonly def\n');
|
||||
var parser = new Type1Parser(stream);
|
||||
var props = { overridableEncoding: true };
|
||||
parser.extractFontHeader(props);
|
||||
expect(props.builtInEncoding[33]).toEqual('arrowright');
|
||||
});
|
||||
});
|
||||
});
|
522
3rdparty/pdf.js/test/unit/function_spec.js
vendored
Executable file
522
3rdparty/pdf.js/test/unit/function_spec.js
vendored
Executable file
@ -0,0 +1,522 @@
|
||||
/* -*- 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, beforeEach, isArray, StringStream,
|
||||
PostScriptParser, PostScriptLexer, PostScriptEvaluator,
|
||||
PostScriptCompiler*/
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('function', function() {
|
||||
beforeEach(function() {
|
||||
this.addMatchers({
|
||||
toMatchArray: function(expected) {
|
||||
var actual = this.actual;
|
||||
if (actual.length !== expected.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < expected.length; i++) {
|
||||
var a = actual[i], b = expected[i];
|
||||
if (isArray(b)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (var j = 0; j < a.length; j++) {
|
||||
var suba = a[j], subb = b[j];
|
||||
if (suba !== subb) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (a !== b) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('PostScriptParser', function() {
|
||||
function parse(program) {
|
||||
var stream = new StringStream(program);
|
||||
var parser = new PostScriptParser(new PostScriptLexer(stream));
|
||||
return parser.parse();
|
||||
}
|
||||
it('parses empty programs', function() {
|
||||
var output = parse('{}');
|
||||
expect(output.length).toEqual(0);
|
||||
});
|
||||
it('parses positive numbers', function() {
|
||||
var number = 999;
|
||||
var program = parse('{ ' + number + ' }');
|
||||
var expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses negative numbers', function() {
|
||||
var number = -999;
|
||||
var program = parse('{ ' + number + ' }');
|
||||
var expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses negative floats', function() {
|
||||
var number = 3.3;
|
||||
var program = parse('{ ' + number + ' }');
|
||||
var expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses operators', function() {
|
||||
var program = parse('{ sub }');
|
||||
var expectedProgram = ['sub'];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses if statements', function() {
|
||||
var program = parse('{ { 99 } if }');
|
||||
var expectedProgram = [3, 'jz', 99];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('parses ifelse statements', function() {
|
||||
var program = parse('{ { 99 } { 44 } ifelse }');
|
||||
var expectedProgram = [5, 'jz', 99, 6, 'j', 44];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
it('handles missing brackets', function() {
|
||||
expect(function() { parse('{'); }).toThrow(
|
||||
new Error('Unexpected symbol: found undefined expected 1.'));
|
||||
});
|
||||
it('handles junk after the end', function() {
|
||||
var number = 3.3;
|
||||
var program = parse('{ ' + number + ' }#');
|
||||
var expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PostScriptEvaluator', function() {
|
||||
function evaluate(program) {
|
||||
var stream = new StringStream(program);
|
||||
var parser = new PostScriptParser(new PostScriptLexer(stream));
|
||||
var code = parser.parse();
|
||||
var evaluator = new PostScriptEvaluator(code);
|
||||
var output = evaluator.execute();
|
||||
return output;
|
||||
}
|
||||
|
||||
it('pushes stack', function() {
|
||||
var stack = evaluate('{ 99 }');
|
||||
var expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles if with true', function() {
|
||||
var stack = evaluate('{ 1 {99} if }');
|
||||
var expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles if with false', function() {
|
||||
var stack = evaluate('{ 0 {99} if }');
|
||||
var expectedStack = [];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles ifelse with true', function() {
|
||||
var stack = evaluate('{ 1 {99} {77} ifelse }');
|
||||
var expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles ifelse with false', function() {
|
||||
var stack = evaluate('{ 0 {99} {77} ifelse }');
|
||||
var expectedStack = [77];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles nested if', function() {
|
||||
var stack = evaluate('{ 1 {1 {77} if} if }');
|
||||
var expectedStack = [77];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
|
||||
it('abs', function() {
|
||||
var stack = evaluate('{ -2 abs }');
|
||||
var expectedStack = [2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('adds', function() {
|
||||
var stack = evaluate('{ 1 2 add }');
|
||||
var expectedStack = [3];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('boolean and', function() {
|
||||
var stack = evaluate('{ true false and }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('bitwise and', function() {
|
||||
var stack = evaluate('{ 254 1 and }');
|
||||
var expectedStack = [254 & 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates the inverse tangent of a number', function() {
|
||||
var stack = evaluate('{ 90 atan }');
|
||||
var expectedStack = [Math.atan(90)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles bitshifting ', function() {
|
||||
var stack = evaluate('{ 50 2 bitshift }');
|
||||
var expectedStack = [200];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates the ceiling value', function() {
|
||||
var stack = evaluate('{ 9.9 ceiling }');
|
||||
var expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('copies', function() {
|
||||
var stack = evaluate('{ 99 98 2 copy }');
|
||||
var expectedStack = [99, 98, 99, 98];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates the cosine of a number', function() {
|
||||
var stack = evaluate('{ 90 cos }');
|
||||
var expectedStack = [Math.cos(90)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('converts to int', function() {
|
||||
var stack = evaluate('{ 9.9 cvi }');
|
||||
var expectedStack = [9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('converts negatives to int', function() {
|
||||
var stack = evaluate('{ -9.9 cvi }');
|
||||
var expectedStack = [-9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('converts to real', function() {
|
||||
var stack = evaluate('{ 55.34 cvr }');
|
||||
var expectedStack = [55.34];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('divides', function() {
|
||||
var stack = evaluate('{ 6 5 div }');
|
||||
var expectedStack = [1.2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('maps division by zero to infinity', function() {
|
||||
var stack = evaluate('{ 6 0 div }');
|
||||
var expectedStack = [Infinity];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('duplicates', function() {
|
||||
var stack = evaluate('{ 99 dup }');
|
||||
var expectedStack = [99, 99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('accepts an equality', function() {
|
||||
var stack = evaluate('{ 9 9 eq }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rejects an inequality', function() {
|
||||
var stack = evaluate('{ 9 8 eq }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('exchanges', function() {
|
||||
var stack = evaluate('{ 44 99 exch }');
|
||||
var expectedStack = [99, 44];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles exponentiation', function() {
|
||||
var stack = evaluate('{ 10 2 exp }');
|
||||
var expectedStack = [100];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('pushes false onto the stack', function() {
|
||||
var stack = evaluate('{ false }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates the floor value', function() {
|
||||
var stack = evaluate('{ 9.9 floor }');
|
||||
var expectedStack = [9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles greater than or equal to', function() {
|
||||
var stack = evaluate('{ 10 9 ge }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rejects less than for greater than or equal to', function() {
|
||||
var stack = evaluate('{ 8 9 ge }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles greater than', function() {
|
||||
var stack = evaluate('{ 10 9 gt }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rejects less than or equal for greater than', function() {
|
||||
var stack = evaluate('{ 9 9 gt }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('divides to integer', function() {
|
||||
var stack = evaluate('{ 2 3 idiv }');
|
||||
var expectedStack = [0];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('divides to negative integer', function() {
|
||||
var stack = evaluate('{ -2 3 idiv }');
|
||||
var expectedStack = [0];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('duplicates index', function() {
|
||||
var stack = evaluate('{ 4 3 2 1 2 index }');
|
||||
var expectedStack = [4, 3, 2, 1, 3];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles less than or equal to', function() {
|
||||
var stack = evaluate('{ 9 10 le }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rejects greater than for less than or equal to', function() {
|
||||
var stack = evaluate('{ 10 9 le }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates the natural logarithm', function() {
|
||||
var stack = evaluate('{ 10 ln }');
|
||||
var expectedStack = [Math.log(10)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates the base 10 logarithm', function() {
|
||||
var stack = evaluate('{ 100 log }');
|
||||
var expectedStack = [2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('handles less than', function() {
|
||||
var stack = evaluate('{ 9 10 lt }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rejects greater than or equal to for less than', function() {
|
||||
var stack = evaluate('{ 10 9 lt }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('performs the modulo operation', function() {
|
||||
var stack = evaluate('{ 4 3 mod }');
|
||||
var expectedStack = [1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('multiplies two numbers (positive result)', function() {
|
||||
var stack = evaluate('{ 9 8 mul }');
|
||||
var expectedStack = [72];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('multiplies two numbers (negative result)', function() {
|
||||
var stack = evaluate('{ 9 -8 mul }');
|
||||
var expectedStack = [-72];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('accepts an inequality', function() {
|
||||
var stack = evaluate('{ 9 8 ne }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rejects an equality', function() {
|
||||
var stack = evaluate('{ 9 9 ne }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('negates', function() {
|
||||
var stack = evaluate('{ 4.5 neg }');
|
||||
var expectedStack = [-4.5];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('boolean not', function() {
|
||||
var stack = evaluate('{ true not }');
|
||||
var expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('bitwise not', function() {
|
||||
var stack = evaluate('{ 12 not }');
|
||||
var expectedStack = [-13];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('boolean or', function() {
|
||||
var stack = evaluate('{ true false or }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('bitwise or', function() {
|
||||
var stack = evaluate('{ 254 1 or }');
|
||||
var expectedStack = [254 | 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('pops stack', function() {
|
||||
var stack = evaluate('{ 1 2 pop }');
|
||||
var expectedStack = [1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rolls stack right', function() {
|
||||
var stack = evaluate('{ 1 3 2 2 4 1 roll }');
|
||||
var expectedStack = [2, 1, 3, 2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rolls stack left', function() {
|
||||
var stack = evaluate('{ 1 3 2 2 4 -1 roll }');
|
||||
var expectedStack = [3, 2, 2, 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('rounds a number', function() {
|
||||
var stack = evaluate('{ 9.52 round }');
|
||||
var expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates the sine of a number', function() {
|
||||
var stack = evaluate('{ 90 sin }');
|
||||
var expectedStack = [Math.sin(90)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates a square root (integer)', function() {
|
||||
var stack = evaluate('{ 100 sqrt }');
|
||||
var expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates a square root (float)', function() {
|
||||
var stack = evaluate('{ 99 sqrt }');
|
||||
var expectedStack = [Math.sqrt(99)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('subtracts (positive result)', function() {
|
||||
var stack = evaluate('{ 6 4 sub }');
|
||||
var expectedStack = [2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('subtracts (negative result)', function() {
|
||||
var stack = evaluate('{ 4 6 sub }');
|
||||
var expectedStack = [-2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('pushes true onto the stack', function() {
|
||||
var stack = evaluate('{ true }');
|
||||
var expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('truncates a number', function() {
|
||||
var stack = evaluate('{ 35.004 truncate }');
|
||||
var expectedStack = [35];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
it('calculates an exclusive or value', function() {
|
||||
var stack = evaluate('{ 3 9 xor }');
|
||||
var expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('PostScriptCompiler', function() {
|
||||
function check(code, domain, range, samples) {
|
||||
var compiler = new PostScriptCompiler();
|
||||
var compiledCode = compiler.compile(code, domain, range);
|
||||
if (samples === null) {
|
||||
expect(compiledCode).toBeNull();
|
||||
} else {
|
||||
expect(compiledCode).not.toBeNull();
|
||||
/*jshint -W054 */
|
||||
var fn = new Function('src', 'srcOffset', 'dest', 'destOffset',
|
||||
compiledCode);
|
||||
for (var i = 0; i < samples.length; i++) {
|
||||
var out = new Float32Array(samples[i].output.length);
|
||||
fn(samples[i].input, 0, out, 0);
|
||||
expect(Array.prototype.slice.call(out, 0)).
|
||||
toMatchArray(samples[i].output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it('check compiled add', function() {
|
||||
check([0.25, 0.5, 'add'], [], [0, 1], [{input: [], output: [0.75]}]);
|
||||
check([0, 'add'], [0, 1], [0, 1], [{input: [0.25], output: [0.25]}]);
|
||||
check([0.5, 'add'], [0, 1], [0, 1], [{input: [0.25], output: [0.75]}]);
|
||||
check([0, 'exch', 'add'], [0, 1], [0, 1],
|
||||
[{input: [0.25], output: [0.25]}]);
|
||||
check([0.5, 'exch', 'add'], [0, 1], [0, 1],
|
||||
[{input: [0.25], output: [0.75]}]);
|
||||
check(['add'], [0, 1, 0, 1], [0, 1],
|
||||
[{input: [0.25, 0.5], output: [0.75]}]);
|
||||
check(['add'], [0, 1], [0, 1], null);
|
||||
});
|
||||
it('check compiled sub', function() {
|
||||
check([0.5, 0.25, 'sub'], [], [0, 1], [{input: [], output: [0.25]}]);
|
||||
check([0, 'sub'], [0, 1], [0, 1], [{input: [0.25], output: [0.25]}]);
|
||||
check([0.5, 'sub'], [0, 1], [0, 1], [{input: [0.75], output: [0.25]}]);
|
||||
check([0, 'exch', 'sub'], [0, 1], [-1, 1],
|
||||
[{input: [0.25], output: [-0.25]}]);
|
||||
check([0.75, 'exch', 'sub'], [0, 1], [-1, 1],
|
||||
[{input: [0.25], output: [0.5]}]);
|
||||
check(['sub'], [0, 1, 0, 1], [-1, 1],
|
||||
[{input: [0.25, 0.5], output: [-0.25]}]);
|
||||
check(['sub'], [0, 1], [0, 1], null);
|
||||
|
||||
check([1, 'dup', 3, 2, 'roll', 'sub', 'sub'], [0, 1], [0, 1],
|
||||
[{input: [0.75], output: [0.75]}]);
|
||||
});
|
||||
it('check compiled mul', function() {
|
||||
check([0.25, 0.5, 'mul'], [], [0, 1], [{input: [], output: [0.125]}]);
|
||||
check([0, 'mul'], [0, 1], [0, 1], [{input: [0.25], output: [0]}]);
|
||||
check([0.5, 'mul'], [0, 1], [0, 1], [{input: [0.25], output: [0.125]}]);
|
||||
check([1, 'mul'], [0, 1], [0, 1], [{input: [0.25], output: [0.25]}]);
|
||||
check([0, 'exch', 'mul'], [0, 1], [0, 1], [{input: [0.25], output: [0]}]);
|
||||
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
|
||||
[{input: [0.25], output: [0.125]}]);
|
||||
check([1, 'exch', 'mul'], [0, 1], [0, 1],
|
||||
[{input: [0.25], output: [0.25]}]);
|
||||
check(['mul'], [0, 1, 0, 1], [0, 1],
|
||||
[{input: [0.25, 0.5], output: [0.125]}]);
|
||||
check(['mul'], [0, 1], [0, 1], null);
|
||||
});
|
||||
it('check compiled max', function() {
|
||||
check(['dup', 0.75, 'gt', 7, 'jz', 'pop', 0.75], [0, 1], [0, 1],
|
||||
[{input: [0.5], output: [0.5]}]);
|
||||
check(['dup', 0.75, 'gt', 7, 'jz', 'pop', 0.75], [0, 1], [0, 1],
|
||||
[{input: [1], output: [0.75]}]);
|
||||
check(['dup', 0.75, 'gt', 5, 'jz', 'pop', 0.75], [0, 1], [0, 1], null);
|
||||
});
|
||||
it('check pop/roll/index', function() {
|
||||
check([1, 'pop'], [0, 1], [0, 1], [{input: [0.5], output: [0.5]}]);
|
||||
check([1, 3, -1, 'roll'], [0, 1, 0, 1], [0, 1, 0, 1, 0, 1],
|
||||
[{input: [0.25, 0.5], output: [0.5, 1, 0.25]}]);
|
||||
check([1, 3, 1, 'roll'], [0, 1, 0, 1], [0, 1, 0, 1, 0, 1],
|
||||
[{input: [0.25, 0.5], output: [1, 0.25, 0.5]}]);
|
||||
check([1, 3, 1.5, 'roll'], [0, 1, 0, 1], [0, 1, 0, 1, 0, 1], null);
|
||||
check([1, 1, 'index'], [0, 1], [0, 1, 0, 1, 0, 1],
|
||||
[{input: [0.5], output: [0.5, 1, 0.5]}]);
|
||||
check([1, 3, 'index', 'pop'], [0, 1], [0, 1], null);
|
||||
check([1, 0.5, 'index', 'pop'], [0, 1], [0, 1], null);
|
||||
});
|
||||
it('check input boundaries', function () {
|
||||
check([], [0, 0.5], [0, 1], [{input: [1], output: [0.5]}]);
|
||||
check([], [0.5, 1], [0, 1], [{input: [0], output: [0.5]}]);
|
||||
check(['dup'], [0.5, 0.75], [0, 1, 0, 1],
|
||||
[{input: [0], output: [0.5, 0.5]}]);
|
||||
check([], [100, 1001], [0, 10000], [{input: [1000], output: [1000]}]);
|
||||
});
|
||||
it('check output boundaries', function () {
|
||||
check([], [0, 1], [0, 0.5], [{input: [1], output: [0.5]}]);
|
||||
check([], [0, 1], [0.5, 1], [{input: [0], output: [0.5]}]);
|
||||
check(['dup'], [0, 1], [0.5, 1, 0.75, 1],
|
||||
[{input: [0], output: [0.5, 0.75]}]);
|
||||
check([], [0, 10000], [100, 1001], [{input: [1000], output: [1000]}]);
|
||||
});
|
||||
it('compile optimized', function () {
|
||||
var compiler = new PostScriptCompiler();
|
||||
var code = [0, 'add', 1, 1, 3, -1, 'roll', 'sub', 'sub', 1, 'mul'];
|
||||
var compiledCode = compiler.compile(code, [0, 1], [0, 1]);
|
||||
expect(compiledCode).toEqual(
|
||||
'dest[destOffset + 0] = Math.max(0, Math.min(1, src[srcOffset + 0]));');
|
||||
|
||||
});
|
||||
});
|
||||
});
|
19
3rdparty/pdf.js/test/unit/metadata_spec.js
vendored
Executable file
19
3rdparty/pdf.js/test/unit/metadata_spec.js
vendored
Executable file
@ -0,0 +1,19 @@
|
||||
/* -*- 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, Metadata */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('metadata', function() {
|
||||
describe('incorrect_xmp', function() {
|
||||
it('should fix the incorrect XMP data', function() {
|
||||
var invalidXMP = '<x:xmpmeta xmlns:x=\'adobe:ns:meta/\'>' +
|
||||
'<rdf:RDF xmlns:rdf=\'http://www.w3.org/1999/02/22-rdf-syntax-ns#\'>' +
|
||||
'<rdf:Description xmlns:dc=\'http://purl.org/dc/elements/1.1/\'>' +
|
||||
'<dc:title>\\376\\377\\000P\\000D\\000F\\000&</dc:title>' +
|
||||
'</rdf:Description></rdf:RDF></x:xmpmeta>';
|
||||
var meta = new Metadata(invalidXMP);
|
||||
expect(meta.get('dc:title')).toEqual('PDF&');
|
||||
});
|
||||
});
|
||||
});
|
150
3rdparty/pdf.js/test/unit/obj_spec.js
vendored
Executable file
150
3rdparty/pdf.js/test/unit/obj_spec.js
vendored
Executable file
@ -0,0 +1,150 @@
|
||||
/* -*- 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, beforeEach, Name, Dict, Ref, RefSet, Cmd,
|
||||
jasmine */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('obj', function() {
|
||||
|
||||
describe('Name', function() {
|
||||
it('should retain the given name', function() {
|
||||
var givenName = 'Font';
|
||||
var name = Name.get(givenName);
|
||||
expect(name.name).toEqual(givenName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Cmd', function() {
|
||||
it('should retain the given cmd name', function() {
|
||||
var givenCmd = 'BT';
|
||||
var cmd = new Cmd(givenCmd);
|
||||
expect(cmd.cmd).toEqual(givenCmd);
|
||||
});
|
||||
|
||||
it('should create only one object for a command and cache it', function() {
|
||||
var firstBT = Cmd.get('BT');
|
||||
var secondBT = Cmd.get('BT');
|
||||
var firstET = Cmd.get('ET');
|
||||
var secondET = Cmd.get('ET');
|
||||
expect(firstBT).toBe(secondBT);
|
||||
expect(firstET).toBe(secondET);
|
||||
expect(firstBT).not.toBe(firstET);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Dict', function() {
|
||||
var checkInvalidHasValues = function(dict) {
|
||||
expect(dict.has()).toBeFalsy();
|
||||
expect(dict.has('Prev')).toBeFalsy();
|
||||
};
|
||||
|
||||
var checkInvalidKeyValues = function(dict) {
|
||||
expect(dict.get()).toBeUndefined();
|
||||
expect(dict.get('Prev')).toBeUndefined();
|
||||
expect(dict.get('Decode', 'D')).toBeUndefined();
|
||||
|
||||
// Note that the getter with three arguments breaks the pattern here.
|
||||
expect(dict.get('FontFile', 'FontFile2', 'FontFile3')).toBeNull();
|
||||
};
|
||||
|
||||
var emptyDict, dictWithSizeKey, dictWithManyKeys;
|
||||
var storedSize = 42;
|
||||
var testFontFile = 'file1';
|
||||
var testFontFile2 = 'file2';
|
||||
var testFontFile3 = 'file3';
|
||||
|
||||
beforeEach(function() {
|
||||
emptyDict = new Dict();
|
||||
|
||||
dictWithSizeKey = new Dict();
|
||||
dictWithSizeKey.set('Size', storedSize);
|
||||
|
||||
dictWithManyKeys = new Dict();
|
||||
dictWithManyKeys.set('FontFile', testFontFile);
|
||||
dictWithManyKeys.set('FontFile2', testFontFile2);
|
||||
dictWithManyKeys.set('FontFile3', testFontFile3);
|
||||
});
|
||||
|
||||
it('should return invalid values for unknown keys', function() {
|
||||
checkInvalidHasValues(emptyDict);
|
||||
checkInvalidKeyValues(emptyDict);
|
||||
});
|
||||
|
||||
it('should return correct value for stored Size key', function() {
|
||||
expect(dictWithSizeKey.has('Size')).toBeTruthy();
|
||||
|
||||
expect(dictWithSizeKey.get('Size')).toEqual(storedSize);
|
||||
expect(dictWithSizeKey.get('Prev', 'Size')).toEqual(storedSize);
|
||||
expect(dictWithSizeKey.get('Prev', 'Root', 'Size')).toEqual(storedSize);
|
||||
});
|
||||
|
||||
it('should return invalid values for unknown keys when Size key is stored',
|
||||
function() {
|
||||
checkInvalidHasValues(dictWithSizeKey);
|
||||
checkInvalidKeyValues(dictWithSizeKey);
|
||||
});
|
||||
|
||||
it('should return correct value for stored Size key with undefined value',
|
||||
function() {
|
||||
var dict = new Dict();
|
||||
dict.set('Size');
|
||||
|
||||
expect(dict.has('Size')).toBeTruthy();
|
||||
|
||||
checkInvalidKeyValues(dict);
|
||||
});
|
||||
|
||||
it('should return correct values for multiple stored keys', function() {
|
||||
expect(dictWithManyKeys.has('FontFile')).toBeTruthy();
|
||||
expect(dictWithManyKeys.has('FontFile2')).toBeTruthy();
|
||||
expect(dictWithManyKeys.has('FontFile3')).toBeTruthy();
|
||||
|
||||
expect(dictWithManyKeys.get('FontFile3')).toEqual(testFontFile3);
|
||||
expect(dictWithManyKeys.get('FontFile2', 'FontFile3'))
|
||||
.toEqual(testFontFile2);
|
||||
expect(dictWithManyKeys.get('FontFile', 'FontFile2', 'FontFile3'))
|
||||
.toEqual(testFontFile);
|
||||
});
|
||||
|
||||
it('should callback for each stored key', function() {
|
||||
var callbackSpy = jasmine.createSpy('spy on callback in dictionary');
|
||||
|
||||
dictWithManyKeys.forEach(callbackSpy);
|
||||
|
||||
expect(callbackSpy).wasCalled();
|
||||
expect(callbackSpy.argsForCall[0]).toEqual(['FontFile', testFontFile]);
|
||||
expect(callbackSpy.argsForCall[1]).toEqual(['FontFile2', testFontFile2]);
|
||||
expect(callbackSpy.argsForCall[2]).toEqual(['FontFile3', testFontFile3]);
|
||||
expect(callbackSpy.callCount).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ref', function() {
|
||||
it('should retain the stored values', function() {
|
||||
var storedNum = 4;
|
||||
var storedGen = 2;
|
||||
var ref = new Ref(storedNum, storedGen);
|
||||
expect(ref.num).toEqual(storedNum);
|
||||
expect(ref.gen).toEqual(storedGen);
|
||||
});
|
||||
});
|
||||
|
||||
describe('RefSet', function() {
|
||||
it('should have a stored value', function() {
|
||||
var ref = new Ref(4, 2);
|
||||
var refset = new RefSet();
|
||||
refset.put(ref);
|
||||
expect(refset.has(ref)).toBeTruthy();
|
||||
});
|
||||
it('should not have an unknown value', function() {
|
||||
var ref = new Ref(4, 2);
|
||||
var refset = new RefSet();
|
||||
expect(refset.has(ref)).toBeFalsy();
|
||||
|
||||
refset.put(ref);
|
||||
var anotherRef = new Ref(2, 4);
|
||||
expect(refset.has(anotherRef)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
76
3rdparty/pdf.js/test/unit/parser_spec.js
vendored
Executable file
76
3rdparty/pdf.js/test/unit/parser_spec.js
vendored
Executable file
@ -0,0 +1,76 @@
|
||||
/* -*- 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 */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('parser', function() {
|
||||
describe('Lexer', function() {
|
||||
it('should stop parsing numbers at the end of stream', function() {
|
||||
var input = new StringStream('11.234');
|
||||
var lexer = new Lexer(input);
|
||||
var result = lexer.getNumber();
|
||||
|
||||
expect(result).toEqual(11.234);
|
||||
});
|
||||
|
||||
it('should parse PostScript numbers', function() {
|
||||
var numbers = ['-.002', '34.5', '-3.62', '123.6e10', '1E-5', '-1.', '0.0',
|
||||
'123', '-98', '43445', '0', '+17'];
|
||||
for (var i = 0, ii = numbers.length; i < ii; i++) {
|
||||
var num = numbers[i];
|
||||
var input = new StringStream(num);
|
||||
var lexer = new Lexer(input);
|
||||
var result = lexer.getNumber();
|
||||
|
||||
expect(result).toEqual(parseFloat(num));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
it('should handle glued numbers and operators', function() {
|
||||
var input = new StringStream('123ET');
|
||||
var lexer = new Lexer(input);
|
||||
var value = lexer.getNumber();
|
||||
|
||||
expect(value).toEqual(123);
|
||||
// The lexer must not have consumed the 'E'
|
||||
expect(lexer.currentChar).toEqual(0x45); // 'E'
|
||||
});
|
||||
|
||||
it('should stop parsing strings at the end of stream', function() {
|
||||
var input = new StringStream('(1$4)');
|
||||
input.getByte = function(super_getByte) {
|
||||
// simulating end of file using null (see issue 2766)
|
||||
var ch = super_getByte.call(input);
|
||||
return (ch === 0x24 /* '$' */ ? -1 : ch);
|
||||
}.bind(input, input.getByte);
|
||||
var lexer = new Lexer(input);
|
||||
var result = lexer.getString();
|
||||
|
||||
expect(result).toEqual('1');
|
||||
});
|
||||
|
||||
it('should not throw exception on bad input', function() {
|
||||
// '8 0 2 15 5 2 2 2 4 3 2 4'
|
||||
// should be parsed as
|
||||
// '80 21 55 22 24 32'
|
||||
var input = new StringStream('<7 0 2 15 5 2 2 2 4 3 2 4>');
|
||||
var lexer = new Lexer(input);
|
||||
var result = lexer.getHexString();
|
||||
|
||||
expect(result).toEqual('p!U"$2');
|
||||
});
|
||||
|
||||
it('should ignore escaped CR and LF', function() {
|
||||
// '(\101\<CR><LF>\102)'
|
||||
// should be parsed as
|
||||
// "AB"
|
||||
var input = new StringStream('(\\101\\\r\n\\102\\\r\\103\\\n\\104)');
|
||||
var lexer = new Lexer(input);
|
||||
var result = lexer.getString();
|
||||
|
||||
expect(result).toEqual('ABCD');
|
||||
});
|
||||
});
|
||||
});
|
43
3rdparty/pdf.js/test/unit/stream_spec.js
vendored
Executable file
43
3rdparty/pdf.js/test/unit/stream_spec.js
vendored
Executable file
@ -0,0 +1,43 @@
|
||||
/* -*- 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, beforeEach, Stream, PredictorStream, Dict */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('stream', function() {
|
||||
beforeEach(function() {
|
||||
this.addMatchers({
|
||||
toMatchTypedArray: function(expected) {
|
||||
var actual = this.actual;
|
||||
if (actual.length !== expected.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0, ii = expected.length; i < ii; i++) {
|
||||
var a = actual[i], b = expected[i];
|
||||
if (a !== b) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
describe('PredictorStream', function() {
|
||||
it('should decode simple predictor data', function() {
|
||||
var dict = new Dict();
|
||||
dict.set('Predictor', 12);
|
||||
dict.set('Colors', 1);
|
||||
dict.set('BitsPerComponent', 8);
|
||||
dict.set('Columns', 2);
|
||||
|
||||
var input = new Stream(new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]),
|
||||
0, 9, dict);
|
||||
var predictor = new PredictorStream(input, /* length = */ 9, dict);
|
||||
var result = predictor.getBytes(6);
|
||||
|
||||
expect(result).toMatchTypedArray(
|
||||
new Uint8Array([100, 3, 101, 2, 102, 1])
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
82
3rdparty/pdf.js/test/unit/testreporter.js
vendored
Executable file
82
3rdparty/pdf.js/test/unit/testreporter.js
vendored
Executable file
@ -0,0 +1,82 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'use strict';
|
||||
|
||||
var TestReporter = function(browser, appPath) {
|
||||
function send(action, json, cb) {
|
||||
var r = new XMLHttpRequest();
|
||||
// (The POST URI is ignored atm.)
|
||||
r.open('POST', action, true);
|
||||
r.setRequestHeader('Content-Type', 'application/json');
|
||||
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
|
||||
if (r.readyState === 4) {
|
||||
// Retry until successful
|
||||
if (r.status !== 200) {
|
||||
send(action, json, cb);
|
||||
} else {
|
||||
if (cb) {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
json['browser'] = browser;
|
||||
r.send(JSON.stringify(json));
|
||||
}
|
||||
|
||||
function sendInfo(message) {
|
||||
send('/info', {message: message});
|
||||
}
|
||||
|
||||
function sendResult(status, description, error) {
|
||||
var message = {
|
||||
status: status,
|
||||
description: description
|
||||
};
|
||||
if (typeof error !== 'undefined') {
|
||||
message['error'] = error;
|
||||
}
|
||||
send('/submit_task_results', message);
|
||||
}
|
||||
|
||||
function sendQuitRequest() {
|
||||
send('/tellMeToQuit?path=' + escape(appPath), {});
|
||||
}
|
||||
|
||||
this.now = function() {
|
||||
return new Date().getTime();
|
||||
};
|
||||
|
||||
this.reportRunnerStarting = function() {
|
||||
this.runnerStartTime = this.now();
|
||||
sendInfo('Started unit tests for ' + browser + '.');
|
||||
};
|
||||
|
||||
this.reportSpecStarting = function() { };
|
||||
|
||||
this.reportSpecResults = function(spec) {
|
||||
var results = spec.results();
|
||||
if (results.skipped) {
|
||||
sendResult('TEST-SKIPPED', results.description);
|
||||
} else if (results.passed()) {
|
||||
sendResult('TEST-PASSED', results.description);
|
||||
} else {
|
||||
var failedMessages = '';
|
||||
var items = results.getItems();
|
||||
for (var i = 0, ii = items.length; i < ii; i++) {
|
||||
if (!items[i].passed()) {
|
||||
failedMessages += items[i].message + ' ';
|
||||
}
|
||||
}
|
||||
sendResult('TEST-UNEXPECTED-FAIL', results.description, failedMessages);
|
||||
}
|
||||
};
|
||||
|
||||
this.reportSuiteResults = function(suite) { };
|
||||
|
||||
this.reportRunnerResults = function(runner) {
|
||||
// Give the test.py some time process any queued up requests
|
||||
setTimeout(sendQuitRequest, 500);
|
||||
};
|
||||
};
|
37
3rdparty/pdf.js/test/unit/ui_utils_spec.js
vendored
Executable file
37
3rdparty/pdf.js/test/unit/ui_utils_spec.js
vendored
Executable file
@ -0,0 +1,37 @@
|
||||
/* -*- 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, binarySearchFirstItem */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('ui_utils', function() {
|
||||
|
||||
describe('binary search', function() {
|
||||
function isTrue(boolean) {
|
||||
return boolean;
|
||||
}
|
||||
function isGreater3(number) {
|
||||
return number > 3;
|
||||
}
|
||||
|
||||
it('empty array', function() {
|
||||
expect(binarySearchFirstItem([], isTrue)).toEqual(0);
|
||||
});
|
||||
it('single boolean entry', function() {
|
||||
expect(binarySearchFirstItem([false], isTrue)).toEqual(1);
|
||||
expect(binarySearchFirstItem([true], isTrue)).toEqual(0);
|
||||
});
|
||||
it('three boolean entries', function() {
|
||||
expect(binarySearchFirstItem([true, true, true], isTrue)).toEqual(0);
|
||||
expect(binarySearchFirstItem([false, true, true], isTrue)).toEqual(1);
|
||||
expect(binarySearchFirstItem([false, false, true], isTrue)).toEqual(2);
|
||||
expect(binarySearchFirstItem([false, false, false], isTrue)).toEqual(3);
|
||||
});
|
||||
it('three numeric entries', function() {
|
||||
expect(binarySearchFirstItem([0, 1, 2], isGreater3)).toEqual(3);
|
||||
expect(binarySearchFirstItem([2, 3, 4], isGreater3)).toEqual(2);
|
||||
expect(binarySearchFirstItem([4, 5, 6], isGreater3)).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
108
3rdparty/pdf.js/test/unit/unit_test.html
vendored
Executable file
108
3rdparty/pdf.js/test/unit/unit_test.html
vendored
Executable file
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>pdf.js unit test</title>
|
||||
|
||||
<link rel="shortcut icon" type="image/png" href="../../external/jasmine/jasmine_favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="../../external/jasmine/jasmine.css">
|
||||
|
||||
<script src="../../external/jasmine/jasmine.js"></script>
|
||||
<script src="../../external/jasmine/jasmine-html.js"></script>
|
||||
<script src="testreporter.js"></script>
|
||||
|
||||
<!-- include source files here... -->
|
||||
<script src="../../src/core/network.js"></script>
|
||||
<script src="../../src/core/chunked_stream.js"></script>
|
||||
<script src="../../src/core/pdf_manager.js"></script>
|
||||
<script src="../../src/core/core.js"></script>
|
||||
<script src="../../src/shared/util.js"></script>
|
||||
<script src="../../src/display/api.js"></script>
|
||||
<script src="../../src/display/canvas.js"></script>
|
||||
<script src="../../src/display/webgl.js"></script>
|
||||
<script src="../../src/core/obj.js"></script>
|
||||
<script src="../../src/core/annotation.js"></script>
|
||||
<script src="../../src/core/function.js"></script>
|
||||
<script src="../../src/core/charsets.js"></script>
|
||||
<script src="../../src/core/colorspace.js"></script>
|
||||
<script src="../../src/core/crypto.js"></script>
|
||||
<script src="../../src/core/pattern.js"></script>
|
||||
<script src="../../src/core/evaluator.js"></script>
|
||||
<script src="../../src/core/cmap.js"></script>
|
||||
<script src="../../src/core/fonts.js"></script>
|
||||
<script src="../../src/core/glyphlist.js"></script>
|
||||
<script src="../../src/core/image.js"></script>
|
||||
<script src="../../src/core/metrics.js"></script>
|
||||
<script src="../../src/core/parser.js"></script>
|
||||
<script src="../../src/core/ps_parser.js"></script>
|
||||
<script src="../../src/display/pattern_helper.js"></script>
|
||||
<script src="../../src/display/annotation_helper.js"></script>
|
||||
<script src="../../src/core/stream.js"></script>
|
||||
<script src="../../src/core/worker.js"></script>
|
||||
<script src="../../src/display/metadata.js"></script>
|
||||
<script src="../../src/core/jpg.js"></script>
|
||||
<script src="../../web/ui_utils.js"></script>
|
||||
<script>PDFJS.workerSrc = '../../src/worker_loader.js';</script>
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="obj_spec.js"></script>
|
||||
<script src="font_spec.js"></script>
|
||||
<script src="function_spec.js"></script>
|
||||
<script src="crypto_spec.js"></script>
|
||||
<script src="evaluator_spec.js"></script>
|
||||
<script src="stream_spec.js"></script>
|
||||
<script src="parser_spec.js"></script>
|
||||
<script src="api_spec.js"></script>
|
||||
<script src="metadata_spec.js"></script>
|
||||
<script src="ui_utils_spec.js"></script>
|
||||
<script src="util_spec.js"></script>
|
||||
<script src="cmap_spec.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
(function pdfJsUnitTest() {
|
||||
function queryParams() {
|
||||
var qs = window.location.search.substring(1);
|
||||
var kvs = qs.split('&');
|
||||
var params = { };
|
||||
for (var i = 0; i < kvs.length; ++i) {
|
||||
var kv = kvs[i].split('=');
|
||||
params[unescape(kv[0])] = unescape(kv[1]);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.updateInterval = 1000;
|
||||
|
||||
var trivialReporter = new jasmine.TrivialReporter();
|
||||
|
||||
jasmineEnv.addReporter(trivialReporter);
|
||||
|
||||
var params = queryParams();
|
||||
if (params['browser']) {
|
||||
var testReporter = new TestReporter(params['browser'], params['path']);
|
||||
jasmineEnv.addReporter(testReporter);
|
||||
}
|
||||
|
||||
jasmineEnv.specFilter = function pdfJsUnitTestSpecFilter(spec) {
|
||||
return trivialReporter.specFilter(spec);
|
||||
};
|
||||
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function pdfJsUnitTestOnload() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
execJasmine();
|
||||
};
|
||||
|
||||
function execJasmine() {
|
||||
jasmineEnv.execute();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
80
3rdparty/pdf.js/test/unit/util_spec.js
vendored
Executable file
80
3rdparty/pdf.js/test/unit/util_spec.js
vendored
Executable file
@ -0,0 +1,80 @@
|
||||
/* -*- 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, combineUrl, Dict, isDict, Name */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('util', function() {
|
||||
|
||||
describe('combineUrl', function() {
|
||||
it('absolute url with protocol stays as is', function() {
|
||||
var baseUrl = 'http://server/index.html';
|
||||
var url = 'http://server2/test2.html';
|
||||
var result = combineUrl(baseUrl, url);
|
||||
var expected = 'http://server2/test2.html';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('absolute url without protocol uses prefix from base', function() {
|
||||
var baseUrl = 'http://server/index.html';
|
||||
var url = '/test2.html';
|
||||
var result = combineUrl(baseUrl, url);
|
||||
var expected = 'http://server/test2.html';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('combines relative url with base', function() {
|
||||
var baseUrl = 'http://server/index.html';
|
||||
var url = 'test2.html';
|
||||
var result = combineUrl(baseUrl, url);
|
||||
var expected = 'http://server/test2.html';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('combines relative url (w/hash) with base', function() {
|
||||
var baseUrl = 'http://server/index.html#!/test';
|
||||
var url = 'test2.html';
|
||||
var result = combineUrl(baseUrl, url);
|
||||
var expected = 'http://server/test2.html';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('combines relative url (w/query) with base', function() {
|
||||
var baseUrl = 'http://server/index.html?search=/test';
|
||||
var url = 'test2.html';
|
||||
var result = combineUrl(baseUrl, url);
|
||||
var expected = 'http://server/test2.html';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('returns base url when url is empty', function() {
|
||||
var baseUrl = 'http://server/index.html';
|
||||
var url = '';
|
||||
var result = combineUrl(baseUrl, url);
|
||||
var expected = 'http://server/index.html';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('returns base url when url is undefined', function() {
|
||||
var baseUrl = 'http://server/index.html';
|
||||
var url;
|
||||
var result = combineUrl(baseUrl, url);
|
||||
var expected = 'http://server/index.html';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isDict', function() {
|
||||
it('handles empty dictionaries with type check', function() {
|
||||
var dict = new Dict();
|
||||
expect(isDict(dict, 'Page')).toEqual(false);
|
||||
});
|
||||
|
||||
it('handles dictionaries with type check', function() {
|
||||
var dict = new Dict();
|
||||
dict.set('Type', Name.get('Page'));
|
||||
expect(isDict(dict, 'Page')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user