document_methods.in revision 4d3acf4ec42bf6e838f9060103aff98fbf170794
1{{header}}
2{{object 1 0}} <<
3  /Type /Catalog
4  /Pages 2 0 R
5  /OpenAction 10 0 R
6>>
7endobj
8{{object 2 0}} <<
9  /Type /Pages
10  /Count 4
11  /Kids [
12    3 0 R
13    4 0 R
14    5 0 R
15    6 0 R
16  ]
17>>
18endobj
19% Page number 0.
20{{object 3 0}} <<
21  /Type /Page
22  /Parent 2 0 R
23  /Resources <<
24    /Font <</F1 15 0 R>>
25  >>
26  /MediaBox [0 0 612 792]
27  /Contents 8 0 R
28>>
29% Page number 1.
30{{object 4 0}} <<
31  /Type /Page
32  /Parent 2 0 R
33  /Resources <<
34    /Font <</F1 15 0 R>>
35  >>
36  /MediaBox [0 0 612 792]
37>>
38% Page number 2.
39{{object 5 0}} <<
40  /Type /Page
41  /Parent 2 0 R
42  /Resources <<
43    /Font <</F1 15 0 R>>
44  >>
45  /MediaBox [0 0 612 792]
46>>
47% Page number 3.
48{{object 6 0}} <<
49  /Type /Page
50  /Parent 2 0 R
51  /Resources <<
52    /Font <</F1 15 0 R>>
53  >>
54  /MediaBox [0 0 612 792]
55>>
56% Contents of the page.
57{{object 8 0}} <<
58>>
59stream
60BT
6120 50 Td
62/F1 12 Tf
63(Hello, world!) Tj
640 50 Td
65endstream
66endobj
67% Info
68{{object 9 0}} <<
69  /Author (Joe Random Author)
70  /Creator (Joe Random Creator)
71>>
72endobj
73% OpenAction action
74{{object 10 0}} <<
75  /Type /Action
76  /S /JavaScript
77  /JS 11 0 R
78>>
79endobj
80% JS program to exexute
81{{object 11 0}} <<
82>>
83stream
84function expect(str, expected) {
85  try {
86    var result = eval(str);
87    if (result == expected) {
88      app.alert('PASS: ' + str + ' = ' + result);
89    } else {
90      app.alert('FAIL: ' + str + ' = ' + result + ', expected = ' + expected);
91    }
92  } catch (e) {
93    app.alert('ERROR: ' + e.toString());
94  }
95}
96
97function expectError(str) {
98  try {
99    var result = eval(str);
100    app.alert('FAIL: ' + str + ' = ' + result + ', expected to throw error');
101  } catch (e) {
102    app.alert('PASS: ' + str + ' threw error ' + e.toString());
103  }
104}
105
106// "Unsupported" methods are present in the document object, but not
107// implemented. They always return |undefined| regardless of arguments.
108function testUnsupported(str) {
109  expect('typeof ' + str, 'function');
110  expect(str + '()', undefined);
111  expect(str + '(1, 2, "clams", [1, 2, 3])', undefined);
112}
113
114function testAddIcon() {
115   // Method is present.
116   expect('typeof this.addIcon', 'function');
117
118   // Method takes exactly two arguments.
119   expectError('this.addIcon()');
120   expectError('this.addIcon(1)');
121   expectError('this.addIcon(1, 2, 3)');
122
123   // Second argument must actually be an icon.
124   expectError('this.addIcon("myicon", 3)');
125   expectError('this.addIcon("myicon", undefined)');
126
127   // TODO(tsepez): test success cases.
128}
129
130function testCalculateNow() {
131   // Method is present.
132   expect('typeof this.calculateNow', 'function');
133
134   // TODO(tsepez): test with no permissions.
135   // TODO(tsepez): test success cases.
136}
137
138function testGetAnnot() {
139   // Method is present.
140   expect('typeof this.getAnnot', 'function');
141
142   // Method needs two arguments.
143   expectError('this.getAnnot()');
144   expectError('this.getAnnot(0)');
145   expectError('this.getAnnot(0, "test", 0)');
146
147   // TODO(tonikitoo): test success cases.
148}
149
150function testGetAnnots() {
151   // Method is present.
152   expect('typeof this.getAnnots', 'function');
153
154   // TODO(tonikitoo): test success cases.
155}
156
157function testGetField() {
158   // Method is present.
159   expect('typeof this.getField', 'function');
160
161   // Method needs at least one argument.
162   expectError('this.getField()');
163
164   // TODO(tsepez): test success cases.
165}
166
167function testGetIcon() {
168   // Method is present.
169   expect('typeof this.getIcon', 'function');
170
171   // Method needs exactly one argument.
172   expectError('this.getIcon()');
173   expectError('this.getIcon(1, 2)');
174
175  // TODO(tsepez): test success cases.
176}
177
178function testGetNthFieldName() {
179  // Method is present.
180  expect('typeof this.getNthFieldName', 'function');
181
182  // Method needs at least one argument.
183  expectError('this.getNthFieldName()');
184
185  // Argument can not be negative.
186  expectError('this.getNthFieldName(-1)');
187
188  // TODO(tsepez): test success cases.
189}
190
191function testGetPageNthWord() {
192  // Method is present.
193  expect('typeof this.getPageNthWord', 'function');
194
195  // Method accepts any number of parameters.
196  expect('this.getPageNthWord(0, 0, true, "clams", [1, 2])', 'Hello,');
197
198  // Arguments can't be negative or out of range.
199  expectError('this.getPageNthWord(-1, 0, true)');
200  expectError('this.getPageNthWord(6, 0, true)');
201
202  // TODO(tsepez): test with no permissions.
203  // TODO(tsepez): test success cases.
204}
205
206function testGetPageNthWordQuads() {
207   // Method is present.
208   expect('typeof this.getPageNthWordQuads', 'function');
209
210  // TODO(tsepez): test with no permissions.
211  // TODO(tsepez): test success cases.
212}
213
214function testGetPageNumWords() {
215   // Method is present.
216   expect('typeof this.getPageNumWords', 'function');
217
218  // Method accepts any number of parameters.
219  expect('this.getPageNumWords(0, "clams", [1, 2])', 2);
220
221  // Arguments can't be negative or out of range.
222  expectError('this.getPageNumWords(-1)');
223  expectError('this.getPageNumWords(6)');
224
225  // TODO(tsepez): test with no permissions.
226  // TODO(tsepez): test success cases.
227}
228
229function testGetPrintParams() {
230   // Method is present.
231   expect('typeof this.getPrintParams', 'function');
232
233  // TODO(tsepez): test success cases.
234}
235
236function testGotoNamedDest() {
237   // Method is present.
238   expect('typeof this.gotoNamedDest', 'function');
239
240   // Method needs exactly one argument.
241   expectError('this.gotoNamedDest()');
242   expectError('this.gotoNamedDest(1, 2)');
243
244   // TODO(tonikitoo): test success cases.
245}
246
247function testMailDoc() {
248   // Method is present.
249   expect('typeof this.mailDoc', 'function');
250
251  // TODO(tsepez): test with no permissions.
252  // TODO(tsepez): test success cases.
253}
254
255function testMailForm() {
256   // Method is present.
257   expect('typeof this.mailForm', 'function');
258
259  // TODO(tsepez): test with no permissions.
260  // TODO(tsepez): test success cases.
261}
262
263function testPrint() {
264   // Method is present.
265   expect('typeof this.print', 'function');
266
267  // TODO(tsepez): test success cases.
268}
269
270function testRemoveField() {
271  // Method is present.
272  expect('typeof this.removeField', 'function');
273
274  // Method requires at least one argument.
275  expectError('this.removeField()');
276
277  // TODO(tsepez): test with no permissions.
278  // TODO(tsepez): test success cases.
279}
280
281function testResetForm() {
282   // Method is present.
283   expect('typeof this.resetForm', 'function');
284
285  // TODO(tsepez): test with no permissions.
286  // TODO(tsepez): test success cases.
287}
288
289function testSubmitForm() {
290   // Method is present.
291   expect('typeof this.submitForm', 'function');
292
293  // Method requires at least one argument.
294  expectError('this.submitForm()');
295
296  // TODO(tsepez): test success cases.
297}
298
299try {
300  app.alert('*** Testing Unsupported Methods ***');
301  testUnsupported('this.addAnnot');
302  testUnsupported('this.addField');
303  testUnsupported('this.addLink');
304  testUnsupported('this.closeDoc');
305  testUnsupported('this.createDataObject');
306  testUnsupported('this.deletePages');
307  testUnsupported('this.exportAsFDF');
308  testUnsupported('this.exportAsText');
309  testUnsupported('this.exportAsXFDF');
310  testUnsupported('this.extractPages');
311  testUnsupported('this.getAnnot3D');
312  testUnsupported('this.getLinks');
313  testUnsupported('this.getOCGs');
314  testUnsupported('this.getPageBox');
315  testUnsupported('this.getURL');
316  testUnsupported('this.importAnFDF');
317  testUnsupported('this.importAnXFDF');
318  testUnsupported('this.importTextData');
319  testUnsupported('this.insertPages');
320  testUnsupported('this.removeIcon');
321  testUnsupported('this.replacePages');
322  testUnsupported('this.saveAs');
323  testUnsupported('this.syncAnnotScan');
324
325  app.alert('*** Testing Supported Methods ***');
326  testAddIcon();
327  testCalculateNow();
328  testGetAnnot();
329  testGetAnnots();
330  testGetField();
331  testGetIcon();
332  testGetNthFieldName();
333  testGetPageNthWord();
334  testGetPageNthWordQuads();
335  testGetPageNumWords();
336  testGetPrintParams();
337  testGotoNamedDest();
338  testMailDoc();
339  testMailForm();
340  testPrint();
341  testRemoveField();
342  testResetForm();
343  testSubmitForm();
344} catch (e) {
345  app.alert('FATAL: ' + e.toString());
346}
347endstream
348endobj
349{{xref}}
350trailer <<
351  /Root 1 0 R
352  /Info 9 0 R
353>>
354{{startxref}}
355%%EOF
356