1 {{header}} 2 {{object 1 0}} << 3 /Type /Catalog 4 /Pages 2 0 R 5 /OpenAction 10 0 R 6 >> 7 endobj 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 >> 18 endobj 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 >> 59 stream 60 BT 61 20 50 Td 62 /F1 12 Tf 63 (Hello, world!) Tj 64 0 50 Td 65 endstream 66 endobj 67 % Info 68 {{object 9 0}} << 69 /Author (Joe Random Author) 70 /Creator (Joe Random Creator) 71 >> 72 endobj 73 % OpenAction action 74 {{object 10 0}} << 75 /Type /Action 76 /S /JavaScript 77 /JS 11 0 R 78 >> 79 endobj 80 % JS program to exexute 81 {{object 11 0}} << 82 >> 83 stream 84 function 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 97 function 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. 108 function testUnsupported(str) { 109 expect('typeof ' + str, 'function'); 110 expect(str + '()', undefined); 111 expect(str + '(1, 2, "clams", [1, 2, 3])', undefined); 112 } 113 114 function 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 126 // TODO(tsepez): test success cases. 127 } 128 129 function testCalculateNow() { 130 // Method is present. 131 expect('typeof this.calculateNow', 'function'); 132 133 // TODO(tsepez): test with no permissions. 134 // TODO(tsepez): test success cases. 135 } 136 137 function testDeletePages() { 138 // Method is present. 139 expect('typeof this.deletePages', 'function'); 140 141 // TODO(tsepez): test with no permissions. 142 // TODO(tsepez): test success cases. 143 } 144 145 function testGetField() { 146 // Method is present. 147 expect('typeof this.getField', 'function'); 148 149 // Method needs at least one argument. 150 expectError('this.getField()'); 151 152 // TODO(tsepez): test success cases. 153 } 154 155 function testGetIcon() { 156 // Method is present. 157 expect('typeof this.getIcon', 'function'); 158 159 // Method needs exactly one argument. 160 expectError('this.getIcon()'); 161 expectError('this.getIcon(1, 2)'); 162 163 // TODO(tsepez): test success cases. 164 } 165 166 function testGetNthFieldName() { 167 // Method is present. 168 expect('typeof this.getNthFieldName', 'function'); 169 170 // Method needs at least one argument. 171 expectError('this.getNthFieldName()'); 172 173 // Argument can not be negative. 174 expectError('this.getNthFieldName(-1)'); 175 176 // TODO(tsepez): test success cases. 177 } 178 179 function testGetPageNthWord() { 180 // Method is present. 181 expect('typeof this.getPageNthWord', 'function'); 182 183 // Method accepts any number of parameters. 184 expect('this.getPageNthWord(0, 0, true, "clams", [1, 2])', 'Hello,'); 185 186 // Arguments can't be negative or out of range. 187 expectError('this.getPageNthWord(-1, 0, true)'); 188 expectError('this.getPageNthWord(6, 0, true)'); 189 190 // TODO(tsepez): test with no permissions. 191 // TODO(tsepez): test success cases. 192 } 193 194 function testGetPageNthWordQuads() { 195 // Method is present. 196 expect('typeof this.getPageNthWordQuads', 'function'); 197 198 // TODO(tsepez): test with no permissions. 199 // TODO(tsepez): test success cases. 200 } 201 202 function testGetPageNumWords() { 203 // Method is present. 204 expect('typeof this.getPageNumWords', 'function'); 205 206 // Method accepts any number of parameters. 207 expect('this.getPageNumWords(0, "clams", [1, 2])', 2); 208 209 // Arguments can't be negative or out of range. 210 expectError('this.getPageNumWords(-1)'); 211 expectError('this.getPageNumWords(6)'); 212 213 // TODO(tsepez): test with no permissions. 214 // TODO(tsepez): test success cases. 215 } 216 217 function testGetPrintParams() { 218 // Method is present. 219 expect('typeof this.getPrintParams', 'function'); 220 221 // TODO(tsepez): test success cases. 222 } 223 224 function testMailDoc() { 225 // Method is present. 226 expect('typeof this.mailDoc', 'function'); 227 228 // TODO(tsepez): test with no permissions. 229 // TODO(tsepez): test success cases. 230 } 231 232 function testMailForm() { 233 // Method is present. 234 expect('typeof this.mailForm', 'function'); 235 236 // TODO(tsepez): test with no permissions. 237 // TODO(tsepez): test success cases. 238 } 239 240 function testPrint() { 241 // Method is present. 242 expect('typeof this.print', 'function'); 243 244 // TODO(tsepez): test success cases. 245 } 246 247 function testRemoveField() { 248 // Method is present. 249 expect('typeof this.removeField', 'function'); 250 251 // Method requires at least one argument. 252 expectError('this.removeField()'); 253 254 // TODO(tsepez): test with no permissions. 255 // TODO(tsepez): test success cases. 256 } 257 258 function testRemoveIcon() { 259 // Method is present. 260 expect('typeof this.removeIcon', 'function'); 261 262 // Method requires at least one argument. 263 expectError('this.removeIcon()'); 264 265 // TODO(tsepez): test success cases. 266 } 267 268 function testResetForm() { 269 // Method is present. 270 expect('typeof this.resetForm', 'function'); 271 272 // TODO(tsepez): test with no permissions. 273 // TODO(tsepez): test success cases. 274 } 275 276 function testSubmitForm() { 277 // Method is present. 278 expect('typeof this.submitForm', 'function'); 279 280 // Method requires at least one argument. 281 expectError('this.submitForm()'); 282 283 // TODO(tsepez): test success cases. 284 } 285 286 try { 287 app.alert('*** Testing Unsupported Methods ***'); 288 testUnsupported('this.addAnnot'); 289 testUnsupported('this.addField'); 290 testUnsupported('this.addLink'); 291 testUnsupported('this.closeDoc'); 292 testUnsupported('this.createDataObject'); 293 testUnsupported('this.exportAsFDF'); 294 testUnsupported('this.exportAsText'); 295 testUnsupported('this.exportAsXFDF'); 296 testUnsupported('this.extractPages'); 297 testUnsupported('this.getAnnot'); 298 testUnsupported('this.getAnnot3D'); 299 testUnsupported('this.getAnnots'); 300 testUnsupported('this.getLinks'); 301 testUnsupported('this.getOCGs'); 302 testUnsupported('this.getPageBox'); 303 testUnsupported('this.getURL'); 304 testUnsupported('this.importAnFDF'); 305 testUnsupported('this.importAnXFDF'); 306 testUnsupported('this.importTextData'); 307 testUnsupported('this.insertPages'); 308 testUnsupported('this.replacePages'); 309 testUnsupported('this.saveAs'); 310 311 app.alert('*** Testing Supported Methods ***'); 312 testAddIcon(); 313 testCalculateNow(); 314 testDeletePages(); 315 testGetField(); 316 testGetIcon(); 317 testGetNthFieldName(); 318 testGetPageNthWord(); 319 testGetPageNthWordQuads(); 320 testGetPageNumWords(); 321 testGetPrintParams(); 322 testMailDoc(); 323 testMailForm(); 324 testPrint(); 325 testRemoveField(); 326 testRemoveIcon(); 327 testResetForm(); 328 testSubmitForm(); 329 } catch (e) { 330 app.alert('FATAL: ' + e.toString()); 331 } 332 endstream 333 endobj 334 {{xref}} 335 trailer << 336 /Root 1 0 R 337 /Info 9 0 R 338 >> 339 {{startxref}} 340 %%EOF 341