1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge remote-tracking branch 'upstream/master' into dev

Conflicts:
	Makefile
	test/unit/unit_test.html
This commit is contained in:
Kalervo Kujala 2012-01-05 21:16:15 +02:00
commit 09eed8d971
51 changed files with 3644 additions and 828 deletions

View file

@ -139,6 +139,11 @@ function nextPage(task, loadError) {
if (task.skipPages && task.skipPages.indexOf(task.pageNum) >= 0) {
log(' skipping page ' + task.pageNum + '/' + task.pdfDoc.numPages +
'... ');
// empty the canvas
canvas.width = 1;
canvas.height = 1;
clear(canvas.getContext('2d'));
snapshotCurrentPage(task, '');
return;
}
@ -160,12 +165,24 @@ function nextPage(task, loadError) {
canvas.height = pageHeight * pdfToCssUnitsCoef;
clear(ctx);
// using the text layer builder that does nothing to test
// text layer creation operations
var textLayerBuilder = {
beginLayout: function nullTextLayerBuilderBeginLayout() {},
endLayout: function nullTextLayerBuilderEndLayout() {},
appendText: function nullTextLayerBuilderAppendText(text, fontName,
fontSize) {}
};
page.startRendering(
ctx,
function nextPageStartRendering(e) {
snapshotCurrentPage(task, (!failure && e) ?
('render : ' + e) : failure);
}
function nextPageStartRendering(error) {
var failureMessage = false;
if (error)
failureMessage = 'render : ' + error.message;
snapshotCurrentPage(task, failureMessage);
},
textLayerBuilder
);
} catch (e) {
failure = 'page setup : ' + e.toString();

View file

@ -16,3 +16,9 @@
!alphatrans.pdf
!devicen.pdf
!cmykjpeg.pdf
!issue840.pdf
!scan-bad.pdf
!freeculture.pdf
!issue918.pdf
!smaskdim.pdf
!type4psfunc.pdf

View file

@ -0,0 +1 @@
http://greenhousechallenge.org/media/item/313/38/About-Stacks.pdf

View file

@ -0,0 +1 @@
http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13210/bpl13210.pdf

BIN
test/pdfs/freeculture.pdf Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
http://geothermal.inel.gov/publications/future_of_geothermal_energy.pdf

View file

@ -0,0 +1 @@
http://www.myhillsapartment.com/island_club/floorplans/images/links/Island_IC_brochure.pdf

View file

@ -0,0 +1 @@
http://faculty.washington.edu/fidelr/RayaPubs/TheCaseStudyMethod.pdf

BIN
test/pdfs/issue840.pdf Normal file

Binary file not shown.

BIN
test/pdfs/issue918.pdf Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
http://agb.traviangames.com/Travian_AR_Terms.pdf

View file

@ -0,0 +1 @@
http://www.lfg.com.br/concursodebolsas/lista_preliminar_classificao.pdf

1
test/pdfs/ocs.pdf.link Normal file
View file

@ -0,0 +1 @@
http://www.unibuc.ro/uploads_en/29535/10/Cyrillic_Alphabets-Chars.pdf

View file

@ -0,0 +1 @@
http://www.erowid.org/archive/rhodium/chemistry/3base/piperonal.pepper/piperine.pepper/465e03piperine.pdf

View file

@ -0,0 +1 @@
http://leahy.senate.gov/imo/media/doc/BillText-PROTECTIPAct.pdf

BIN
test/pdfs/scan-bad.pdf Executable file

Binary file not shown.

BIN
test/pdfs/smaskdim.pdf Executable file

Binary file not shown.

View file

@ -0,0 +1 @@
http://cplusplus.com/files/tutorial.pdf

BIN
test/pdfs/type4psfunc.pdf Executable file

Binary file not shown.

View file

@ -12,6 +12,7 @@ DOC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
ANAL = True
DEFAULT_MANIFEST_FILE = 'test_manifest.json'
EQLOG_FILE = 'eq.log'
BROWSERLOG_FILE = 'browser.log'
REFDIR = 'ref'
TMPDIR = 'tmp'
VERBOSE = False
@ -229,6 +230,7 @@ class BaseBrowserCommand(object):
def setup(self):
self.tempDir = tempfile.mkdtemp()
self.profileDir = os.path.join(self.tempDir, "profile")
self.browserLog = open(BROWSERLOG_FILE, "w")
def teardown(self):
# If the browser is still running, wait up to ten seconds for it to quit
@ -245,6 +247,8 @@ class BaseBrowserCommand(object):
if self.tempDir is not None and os.path.exists(self.tempDir):
shutil.rmtree(self.tempDir)
self.browserLog.close()
def start(self, url):
raise Exception("Can't start BaseBrowserCommand")
@ -262,7 +266,7 @@ class FirefoxBrowserCommand(BaseBrowserCommand):
if platform.system() == "Darwin":
cmds.append("-foreground")
cmds.extend(["-no-remote", "-profile", self.profileDir, url])
self.process = subprocess.Popen(cmds)
self.process = subprocess.Popen(cmds, stdout = self.browserLog, stderr = self.browserLog)
class ChromeBrowserCommand(BaseBrowserCommand):
def _fixupMacPath(self):
@ -272,7 +276,7 @@ class ChromeBrowserCommand(BaseBrowserCommand):
cmds = [self.path]
cmds.extend(["--user-data-dir=%s" % self.profileDir,
"--no-first-run", "--disable-sync", url])
self.process = subprocess.Popen(cmds)
self.process = subprocess.Popen(cmds, stdout = self.browserLog, stderr = self.browserLog)
def makeBrowserCommand(browser):
path = browser["path"].lower()

View file

@ -17,13 +17,13 @@
"rounds": 1,
"type": "load"
},
{ "id": "intelisa-load",
{ "id": "intelisa-eq",
"file": "pdfs/intelisa.pdf",
"md5": "f5712097d29287a97f1278839814f682",
"md5": "f3ed5487d1afa34d8b77c0c734a95c79",
"link": true,
"pageLimit": 100,
"rounds": 1,
"type": "load"
"type": "eq"
},
{ "id": "pdfspec-load",
"file": "pdfs/pdf.pdf",
@ -88,6 +88,13 @@
"rounds": 1,
"type": "eq"
},
{ "id": "freeculture",
"file": "pdfs/freeculture.pdf",
"md5": "dcdf3a8268e6a18938a42d5149efcfca",
"rounds": 1,
"pageLimit": 5,
"type": "eq"
},
{ "id": "wnv_chinese-pdf",
"file": "pdfs/wnv_chinese.pdf",
"md5": "db682638e68391125e8982d3c984841e",
@ -221,6 +228,12 @@
"rounds": 1,
"type": "load"
},
{ "id": "scan-bad",
"file": "pdfs/scan-bad.pdf",
"md5": "4cf988f01ab83f61aca57f406dfd6584",
"rounds": 1,
"type": "load"
},
{ "id": "ibwa-bad",
"file": "pdfs/ibwa-bad.pdf",
"md5": "6ca059d32b74ac2688ae06f727fee755",
@ -276,5 +289,111 @@
"link": false,
"rounds": 1,
"type": "eq"
},
{ "id": "protectip",
"file": "pdfs/protectip.pdf",
"md5": "676e7a7b8f96d04825361832b1838a93",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "piperine",
"file": "pdfs/piperine.pdf",
"md5": "603ca43dc5732dbba1579f122958c0c2",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "issue840",
"file": "pdfs/issue840.pdf",
"md5": "20d88011dd7e3c4fb5274979094dab93",
"rounds": 1,
"type": "eq"
},
{ "id": "bpl13210",
"file": "pdfs/bpl13210.pdf",
"md5": "8a08512baa9fa95378d9ad4b995947c7",
"link": true,
"pageLimit": 5,
"rounds": 1,
"type": "eq"
},
{ "id": "tutorial",
"file": "pdfs/tutorial.pdf",
"md5": "6e122f618c27f3aa9a689423e3be6b8d",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "geothermal.pdf",
"file": "pdfs/geothermal.pdf",
"md5": "ecffc0ce38ffdf1e90dc952f186e9a91",
"rounds": 1,
"link": true,
"pageLimit": 5,
"skipPages": [1],
"type": "eq"
},
{ "id": "lista_preliminar",
"file": "pdfs/lista_preliminar.pdf",
"md5": "4eff251319eeb660ba8a7a5cfac7787d",
"rounds": 1,
"link": true,
"pageLimit": 3,
"type": "eq"
},
{ "id": "issue919",
"file": "pdfs/issue919.pdf",
"md5": "3a1716a512aca4d7a8d6106bd4885d14",
"rounds": 1,
"link": true,
"pageLimit": 3,
"type": "eq"
},
{ "id": "issue918",
"file": "pdfs/issue918.pdf",
"md5": "d582cc0f2592ae82936589ced2a47e55",
"rounds": 1,
"type": "eq"
},
{ "id": "issue1001",
"file": "pdfs/issue1001.pdf",
"md5": "0f1496e80a82a923e91d9e74c55ad94e",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "aboutstacks",
"file": "pdfs/aboutstacks.pdf",
"md5": "6e7c8416a293ba2d83bc8dd20c6ccf51",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "smaskdim",
"file": "pdfs/smaskdim.pdf",
"md5": "de80aeca7cbf79940189fd34d59671ee",
"rounds": 1,
"type": "eq"
},
{ "id": "type4psfunc",
"file": "pdfs/type4psfunc.pdf",
"md5": "7e6027a02ff78577f74dccdf84e37189",
"rounds": 1,
"type": "eq"
},
{ "id": "ocs",
"file": "pdfs/ocs.pdf",
"md5": "2ade57e954ae7632749cf328daeaa7a8",
"rounds": 1,
"link": true,
"type": "load"
},
{ "id": "issue1015",
"file": "pdfs/issue1015.pdf",
"md5": "b61503d1b445742b665212866afb60e2",
"rounds": 1,
"link": true,
"type": "eq"
}
]

225
test/unit/function_spec.js Normal file
View file

@ -0,0 +1,225 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'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.'));
});
});
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 ands', function() {
var stack = evaluate('{ true false and }');
var expectedStack = [false];
expect(stack).toMatchArray(expectedStack);
});
it('bitwise ands', function() {
var stack = evaluate('{ 254 1 and }');
var expectedStack = [254 & 1];
expect(stack).toMatchArray(expectedStack);
});
// TODO atan
// TODO bitshift
// TODO ceiling
// TODO copy
// TODO cos
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);
});
// TODO cvr
// TODO div
it('duplicates', function() {
var stack = evaluate('{ 99 dup }');
var expectedStack = [99, 99];
expect(stack).toMatchArray(expectedStack);
});
// TODO eq
it('exchanges', function() {
var stack = evaluate('{ 44 99 exch }');
var expectedStack = [99, 44];
expect(stack).toMatchArray(expectedStack);
});
// TODO exp
// TODO false
// TODO floor
// TODO ge
// TODO gt
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);
});
// TODO le
// TODO ln
// TODO log
// TODO lt
// TODO mod
// TODO mul
// TODO ne
// TODO neg
// TODO not
// TODO or
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);
});
// TODO round
// TODO sin
// TODO sqrt
// TODO sub
// TODO true
// TODO truncate
// TODO xor
});
});

View file

@ -12,5 +12,120 @@ describe('obj', function() {
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);
});
});
});