1 /* -*-mode:java; c-basic-offset:2; -*- */
3 * Copyright (C) 2000 ymnk, JCraft,Inc.
5 * Written by: 2000 ymnk<ymnk@jcraft.com>
8 * Monty <monty@xiph.org> and
9 * The XIPHOPHORUS Company http://www.xiph.org/ .
10 * JOrbis has been based on their awesome works, Vorbis codec.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public License
14 * as published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 package com.jcraft.jogg;
30 private static int[] crc_lookup=new int[256];
32 for(int i=0; i<crc_lookup.length; i++){
33 crc_lookup[i]=crc_entry(i);
37 private static int crc_entry(int index){
39 for(int i=0; i<8; i++){
40 if((r& 0x80000000)!=0){
41 r=(r << 1)^0x04c11db7; /* The same as the ethernet generator
42 polynomial, although we use an
43 unreflected alg and an init/final
44 of 0, not 0xffffffff */
53 public byte[] header_base;
55 public int header_len;
56 public byte[] body_base;
61 return header_base[header+4]&0xff;
64 return (header_base[header+5]&0x01);
67 return (header_base[header+5]&0x02);
70 return (header_base[header+5]&0x04);
72 public long granulepos(){
73 long foo=header_base[header+13]&0xff;
74 foo=(foo<<8)|(header_base[header+12]&0xff);
75 foo=(foo<<8)|(header_base[header+11]&0xff);
76 foo=(foo<<8)|(header_base[header+10]&0xff);
77 foo=(foo<<8)|(header_base[header+9]&0xff);
78 foo=(foo<<8)|(header_base[header+8]&0xff);
79 foo=(foo<<8)|(header_base[header+7]&0xff);
80 foo=(foo<<8)|(header_base[header+6]&0xff);
83 public int serialno(){
84 return (header_base[header+14]&0xff)|
85 ((header_base[header+15]&0xff)<<8)|
86 ((header_base[header+16]&0xff)<<16)|
87 ((header_base[header+17]&0xff)<<24);
90 return (header_base[header+18]&0xff)|
91 ((header_base[header+19]&0xff)<<8)|
92 ((header_base[header+20]&0xff)<<16)|
93 ((header_base[header+21]&0xff)<<24);
99 // for(int i=0;i<header_len;i++){
100 // System.err.println("chksum: "+Integer.toHexString(header_base[header+i]&0xff));
103 for(int i=0;i<header_len;i++){
104 crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg>>>24)&0xff)^(header_base[header+i]&0xff)];
106 for(int i=0;i<body_len;i++){
107 crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg>>>24)&0xff)^(body_base[body+i]&0xff)];
109 header_base[header+22]=(byte)crc_reg/*&0xff*/;
110 header_base[header+23]=(byte)(crc_reg>>>8)/*&0xff*/;
111 header_base[header+24]=(byte)(crc_reg>>>16)/*&0xff*/;
112 header_base[header+25]=(byte)(crc_reg>>>24)/*&0xff*/;
115 return copy(new Page());
117 public Page copy(Page p){
118 byte[] tmp=new byte[header_len];
119 System.arraycopy(header_base, header, tmp, 0, header_len);
120 p.header_len=header_len;
123 tmp=new byte[body_len];
124 System.arraycopy(body_base, body, tmp, 0, body_len);
132 static StreamState os_en, os_de;
134 void check_page(byte[] data_base, int data, int[] _header){
136 for(int j=0;j<body_len;j++)
137 if(body_base[body+j]!=data_base[data+j]){
138 System.err.println("body data mismatch at pos "+j+": "+data_base[data+j]+"!="+body_base[body+j]+"!\n");
143 for(int j=0;j<header_len;j++){
144 if((header_base[header+j]&0xff)!=_header[j]){
145 System.err.println("header content mismatch at pos "+j);
146 for(int jj=0;jj<_header[26]+27;jj++)
147 System.err.print(" ("+jj+")"+Integer.toHexString(_header[jj])+":"+Integer.toHexString(header_base[header+jj]));
148 System.err.println("");
152 if(header_len!=_header[26]+27){
153 System.err.print("header length incorrect! ("+header_len+"!="+(_header[26]+27)+")");
159 System.err.println("\nHEADER:");
160 System.err.println(" capture: "+
161 (header_base[header+0]&0xff)+" "+
162 (header_base[header+1]&0xff)+" "+
163 (header_base[header+2]&0xff)+" "+
164 (header_base[header+3]&0xff)+" "+
165 " version: "+(header_base[header+4]&0xff)+" flags: "+
166 (header_base[header+5]&0xff));
167 System.err.println(" pcmpos: "+
168 (((header_base[header+9]&0xff)<<24)|
169 ((header_base[header+8]&0xff)<<16)|
170 ((header_base[header+7]&0xff)<<8)|
171 ((header_base[header+6]&0xff)))+
173 (((header_base[header+17]&0xff)<<24)|
174 ((header_base[header+16]&0xff)<<16)|
175 ((header_base[header+15]&0xff)<<8)|
176 ((header_base[header+14]&0xff)))+
178 (((header_base[header+21]&0xff)<<24)|
179 ((header_base[header+20]&0xff)<<16)|
180 ((header_base[header+19]&0xff)<<8)|
181 ((header_base[header+18]&0xff))));
183 System.err.println(" checksum: "+
184 (header_base[header+22]&0xff)+":"+
185 (header_base[header+23]&0xff)+":"+
186 (header_base[header+24]&0xff)+":"+
187 (header_base[header+25]&0xff)+"\n segments: "+
188 (header_base[header+26]&0xff)+" (");
189 for(int j=27;j<header_len;j++){
190 System.err.println((header_base[header+j]&0xff)+" ");
192 System.err.println(")\n");
196 byte[] tmp=new byte[header_len];
197 System.arraycopy(header_base, header, tmp, 0, header_len);
200 tmp=new byte[body_len];
201 System.arraycopy(body_base, body, tmp, 0, body_len);
206 static void test_pack(int[] pl, int[][] headers){
207 byte[] data=new byte[1024*1024]; // for scripted test cases only
213 int packets,pageno=0,pageout=0;
221 for(packets=0;;packets++){
222 if(pl[packets]==-1)break;
225 for(int i=0;i<packets;i++){
226 // construct a test packet
227 Packet op=new Packet();
232 op.e_o_s=(pl[i+1]<0?1:0);
233 op.granulepos=pcm_pos;
237 for(int j=0;j<len;j++){
238 data[inptr++]=(byte)(i+j);
241 // submit the test packet
244 // retrieve any finished pages
248 while(os_en.pageout(og)!=0){
249 // We have a page. Check it carefully
250 //System.err.print(pageno+", ");
251 if(headers[pageno]==null){
252 System.err.println("coded too many pages!");
255 og.check_page(data, outptr, headers[pageno]);
260 //System.err.println("1# pageno="+pageno+", pageout="+pageout);
262 // have a complete page; submit it to sync/decode
265 Page og_de=new Page();
266 Packet op_de=new Packet();
267 int index=oy.buffer(og.header_len+og.body_len);
269 System.arraycopy(og.header_base, og.header, buf, index, og.header_len);
270 System.arraycopy(og.body_base, og.body, buf, index+og.header_len, og.body_len);
271 oy.wrote(og.header_len+og.body_len);
273 //System.err.println("2# pageno="+pageno+", pageout="+pageout);
275 while(oy.pageout(og_de)>0){
276 // got a page. Happy happy. Verify that it's good.
278 og_de.check_page(data, deptr, headers[pageout]);
279 deptr+=og_de.body_len;
282 // submit it to deconstitution
286 while(os_de.packetout(op_de)>0){
288 // verify the packet!
291 for(int ii=0; ii<op_de.bytes; ii++){
292 if(data[depacket+ii]!=op_de.packet_base[op_de.packet+ii]){
298 System.err.println("packet data mismatch in decode! pos="+
304 if(bosflag==0 && op_de.b_o_s==0){
305 System.err.println("b_o_s flag not set on packet!");
308 if(bosflag!=0 && op_de.b_o_s!=0){
309 System.err.println("b_o_s flag incorrectly set on packet!");
314 depacket+=op_de.bytes;
318 System.err.println("Multiple decoded packets with eos flag!");
322 if(op_de.e_o_s!=0)eosflag=1;
325 if(op_de.granulepos!=-1){
326 System.err.print(" pcm:"+op_de.granulepos+" ");
335 if(headers[pageno]!=null){
336 System.err.println("did not write last page!");
339 if(headers[pageout]!=null){
340 System.err.println("did not decode last page!");
344 System.err.println("encoded page data incomplete!");
348 System.err.println("decoded page data incomplete!");
352 System.err.println("decoded packet data incomplete!");
356 System.err.println("Never got a packet with EOS set!");
358 System.err.println("ok.");
362 System.err.println("error!");
365 public static void main(String[] arg){
367 os_en=new StreamState(0x04030201);
368 os_de=new StreamState(0x04030201);
372 // Exercise each code path in the framing code. Also verify that
373 // the checksums are working.
377 int[] packets={17, -1};
378 int[] head1={0x4f,0x67,0x67,0x53,0,0x06,
379 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
380 0x01,0x02,0x03,0x04,0,0,0,0,
384 int[][] headret={head1, null};
386 System.err.print("testing single page encoding... ");
387 test_pack(packets,headret);
391 // 17, 254, 255, 256, 500, 510, 600 byte, pad
392 int[] packets={17, 254, 255, 256, 500, 510, 600, -1};
393 int[] head1={0x4f,0x67,0x67,0x53,0,0x02,
394 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
395 0x01,0x02,0x03,0x04,0,0,0,0,
399 int[] head2={0x4f,0x67,0x67,0x53,0,0x04,
400 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
401 0x01,0x02,0x03,0x04,1,0,0,0,
404 254,255,0,255,1,255,245,255,255,0,
406 int[][] headret={head1,head2,null};
408 System.err.print("testing basic page encoding... ");
409 test_pack(packets,headret);
413 // nil packets; beginning,middle,end
414 int[] packets={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
416 int[] head1={0x4f,0x67,0x67,0x53,0,0x02,
417 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
418 0x01,0x02,0x03,0x04,0,0,0,0,
422 int[] head2={0x4f,0x67,0x67,0x53,0,0x04,
423 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
424 0x01,0x02,0x03,0x04,1,0,0,0,
427 17,254,255,0,0,255,1,0,255,245,255,255,0,
429 int[][] headret={head1,head2,null};
431 System.err.print("testing basic nil packets... ");
432 test_pack(packets,headret);
436 // large initial packet
437 int[] packets={4345,259,255,-1};
439 int[] head1={0x4f,0x67,0x67,0x53,0,0x02,
440 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
441 0x01,0x02,0x03,0x04,0,0,0,0,
444 255,255,255,255,255,255,255,255,
445 255,255,255,255,255,255,255,255,255,10};
447 int[] head2={0x4f,0x67,0x67,0x53,0,0x04,
448 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
449 0x01,0x02,0x03,0x04,1,0,0,0,
453 int[][] headret={head1,head2,null};
455 System.err.print("testing initial-packet lacing > 4k... ");
456 test_pack(packets,headret);
460 // continuing packet test
461 int[] packets={0,4345,259,255,-1};
463 int[] head1={0x4f,0x67,0x67,0x53,0,0x02,
464 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
465 0x01,0x02,0x03,0x04,0,0,0,0,
470 int[] head2={0x4f,0x67,0x67,0x53,0,0x00,
471 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
472 0x01,0x02,0x03,0x04,1,0,0,0,
475 255,255,255,255,255,255,255,255,
476 255,255,255,255,255,255,255,255,255};
478 int[] head3={0x4f,0x67,0x67,0x53,0,0x05,
479 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
480 0x01,0x02,0x03,0x04,2,0,0,0,
484 int[][] headret={head1,head2,head3,null};
486 System.err.print("testing single packet page span... ");
487 test_pack(packets,headret);
490 // page with the 255 segment limit
493 int[] packets={0,10,10,10,10,10,10,10,10,
494 10,10,10,10,10,10,10,10,
495 10,10,10,10,10,10,10,10,
496 10,10,10,10,10,10,10,10,
497 10,10,10,10,10,10,10,10,
498 10,10,10,10,10,10,10,10,
499 10,10,10,10,10,10,10,10,
500 10,10,10,10,10,10,10,10,
501 10,10,10,10,10,10,10,10,
502 10,10,10,10,10,10,10,10,
503 10,10,10,10,10,10,10,10,
504 10,10,10,10,10,10,10,10,
505 10,10,10,10,10,10,10,10,
506 10,10,10,10,10,10,10,10,
507 10,10,10,10,10,10,10,10,
508 10,10,10,10,10,10,10,10,
509 10,10,10,10,10,10,10,10,
510 10,10,10,10,10,10,10,10,
511 10,10,10,10,10,10,10,10,
512 10,10,10,10,10,10,10,10,
513 10,10,10,10,10,10,10,10,
514 10,10,10,10,10,10,10,10,
515 10,10,10,10,10,10,10,10,
516 10,10,10,10,10,10,10,10,
517 10,10,10,10,10,10,10,10,
518 10,10,10,10,10,10,10,10,
519 10,10,10,10,10,10,10,10,
520 10,10,10,10,10,10,10,10,
521 10,10,10,10,10,10,10,10,
522 10,10,10,10,10,10,10,10,
523 10,10,10,10,10,10,10,10,
524 10,10,10,10,10,10,10,50,-1};
526 int[] head1={0x4f,0x67,0x67,0x53,0,0x02,
527 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
528 0x01,0x02,0x03,0x04,0,0,0,0,
533 int[] head2={0x4f,0x67,0x67,0x53,0,0x00,
534 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
535 0x01,0x02,0x03,0x04,1,0,0,0,
538 10,10,10,10,10,10,10,10,
539 10,10,10,10,10,10,10,10,
540 10,10,10,10,10,10,10,10,
541 10,10,10,10,10,10,10,10,
542 10,10,10,10,10,10,10,10,
543 10,10,10,10,10,10,10,10,
544 10,10,10,10,10,10,10,10,
545 10,10,10,10,10,10,10,10,
546 10,10,10,10,10,10,10,10,
547 10,10,10,10,10,10,10,10,
548 10,10,10,10,10,10,10,10,
549 10,10,10,10,10,10,10,10,
550 10,10,10,10,10,10,10,10,
551 10,10,10,10,10,10,10,10,
552 10,10,10,10,10,10,10,10,
553 10,10,10,10,10,10,10,10,
554 10,10,10,10,10,10,10,10,
555 10,10,10,10,10,10,10,10,
556 10,10,10,10,10,10,10,10,
557 10,10,10,10,10,10,10,10,
558 10,10,10,10,10,10,10,10,
559 10,10,10,10,10,10,10,10,
560 10,10,10,10,10,10,10,10,
561 10,10,10,10,10,10,10,10,
562 10,10,10,10,10,10,10,10,
563 10,10,10,10,10,10,10,10,
564 10,10,10,10,10,10,10,10,
565 10,10,10,10,10,10,10,10,
566 10,10,10,10,10,10,10,10,
567 10,10,10,10,10,10,10,10,
568 10,10,10,10,10,10,10,10,
569 10,10,10,10,10,10,10};
571 int[] head3={0x4f,0x67,0x67,0x53,0,0x04,
572 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
573 0x01,0x02,0x03,0x04,2,0,0,0,
577 int[][] headret={head1,head2,head3,null};
579 System.err.print("testing max packet segments... ");
580 test_pack(packets,headret);
584 // packet that overspans over an entire page
586 int[] packets={0,100,9000,259,255,-1};
588 int[] head1={0x4f,0x67,0x67,0x53,0,0x02,
589 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
590 0x01,0x02,0x03,0x04,0,0,0,0,
595 int[] head2={0x4f,0x67,0x67,0x53,0,0x00,
596 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
597 0x01,0x02,0x03,0x04,1,0,0,0,
600 100,255,255,255,255,255,255,255,255,
601 255,255,255,255,255,255,255,255};
603 int[] head3={0x4f,0x67,0x67,0x53,0,0x01,
604 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
605 0x01,0x02,0x03,0x04,2,0,0,0,
608 255,255,255,255,255,255,255,255,
609 255,255,255,255,255,255,255,255,255};
611 int[] head4={0x4f,0x67,0x67,0x53,0,0x05,
612 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
613 0x01,0x02,0x03,0x04,3,0,0,0,
616 255,255,75,255,4,255,0};
617 int[][] headret={head1,head2,head3,head4,null};
619 System.err.print("testing very large packets... ");
620 test_pack(packets,headret);
624 // term only page. why not?
626 int[] packets={0,100,4080,-1};
628 int[] head1={0x4f,0x67,0x67,0x53,0,0x02,
629 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
630 0x01,0x02,0x03,0x04,0,0,0,0,
635 int[] head2={0x4f,0x67,0x67,0x53,0,0x00,
636 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
637 0x01,0x02,0x03,0x04,1,0,0,0,
640 100,255,255,255,255,255,255,255,255,
641 255,255,255,255,255,255,255,255};
643 int[] head3={0x4f,0x67,0x67,0x53,0,0x05,
644 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
645 0x01,0x02,0x03,0x04,2,0,0,0,
649 int[][] headret={head1,head2,head3,null};
651 System.err.print("testing zero data page (1 nil packet)... ");
652 test_pack(packets,headret);
656 // build a bunch of pages for testing
657 byte[] data=new byte[1024*1024];
658 int[] pl={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
660 Page[] og=new Page[5];
661 for(int i=0; i<5; i++){
667 for(int i=0;pl[i]!=-1;i++){
668 Packet op=new Packet();
674 op.e_o_s=(pl[i+1]<0?1:0);
675 op.granulepos=(i+1)*1000;
677 for(int j=0;j<len;j++)data[inptr++]=(byte)(i+j);
683 // retrieve finished pages
684 for(int i=0;i<5;i++){
685 if(os_en.pageout(og[i])==0){
686 System.err.print("Too few pages output building sync tests!\n");
692 // Test lost pages on pagein/packetout: no rollback
694 Page temp=new Page();
695 Packet test=new Packet();
697 System.err.print("Testing loss of pages... ");
701 for(int i=0;i<5;i++){
702 int index=oy.buffer(og[i].header_len);
703 System.arraycopy(og[i].header_base, og[i].header,
704 oy.data, index, og[i].header_len);
705 oy.wrote(og[i].header_len);
706 index=oy.buffer(og[i].body_len);
707 System.arraycopy(og[i].body_base, og[i].body,
708 oy.data, index, og[i].body_len);
709 oy.wrote(og[i].body_len);
722 // do we get the expected results/packets?
724 if(os_de.packetout(test)!=1)error();
725 test.checkpacket(0,0,0);
726 if(os_de.packetout(test)!=1)error();
727 test.checkpacket(100,1,-1);
728 if(os_de.packetout(test)!=1)error();
729 test.checkpacket(4079,2,3000);
730 if(os_de.packetout(test)!=-1){
731 System.err.println("Error: loss of page did not return error");
734 if(os_de.packetout(test)!=1)error();
735 test.checkpacket(76,5,-1);
736 if(os_de.packetout(test)!=1)error();
737 test.checkpacket(34,6,-1);
738 System.err.println("ok.");
741 // Test lost pages on pagein/packetout: rollback with continuation
743 Page temp=new Page();
744 Packet test=new Packet();
746 System.err.print("Testing loss of pages (rollback required)... ");
750 for(int i=0;i<5;i++){
751 int index=oy.buffer(og[i].header_len);
752 System.arraycopy(og[i].header_base, og[i].header,
753 oy.data, index, og[i].header_len);
754 oy.wrote(og[i].header_len);
755 index=oy.buffer(og[i].body_len);
756 System.arraycopy(og[i].body_base, og[i].body,
757 oy.data, index, og[i].body_len);
758 oy.wrote(og[i].body_len);
772 // do we get the expected results/packets?
774 if(os_de.packetout(test)!=1)error();
775 test.checkpacket(0,0,0);
776 if(os_de.packetout(test)!=1)error();
777 test.checkpacket(100,1,-1);
778 if(os_de.packetout(test)!=1)error();
779 test.checkpacket(4079,2,3000);
780 if(os_de.packetout(test)!=1)error();
781 test.checkpacket(2956,3,4000);
782 if(os_de.packetout(test)!=-1){
783 System.err.println("Error: loss of page did not return error");
786 if(os_de.packetout(test)!=1)error();
787 test.checkpacket(300,13,14000);
788 System.err.println("ok.");
791 // the rest only test sync
793 Page og_de=new Page();
794 // Test fractional page inputs: incomplete capture
795 System.err.print("Testing sync on partial inputs... ");
797 int index=oy.buffer(og[1].header_len);
798 System.arraycopy(og[1].header_base, og[1].header,
801 if(oy.pageout(og_de)>0)error();
803 // Test fractional page inputs: incomplete fixed header
804 index=oy.buffer(og[1].header_len);
805 System.arraycopy(og[1].header_base, og[1].header+3,
809 if(oy.pageout(og_de)>0)error();
811 // Test fractional page inputs: incomplete header
812 index=oy.buffer(og[1].header_len);
813 System.arraycopy(og[1].header_base, og[1].header+23,
816 if(oy.pageout(og_de)>0)error();
818 // Test fractional page inputs: incomplete body
819 index=oy.buffer(og[1].header_len);
820 System.arraycopy(og[1].header_base, og[1].header+28,
821 oy.data, index, og[1].header_len-28);
822 oy.wrote(og[1].header_len-28);
823 if(oy.pageout(og_de)>0)error();
825 index=oy.buffer(og[1].body_len);
826 System.arraycopy(og[1].body_base, og[1].body,
827 oy.data, index, 1000);
829 if(oy.pageout(og_de)>0)error();
831 index=oy.buffer(og[1].body_len);
832 System.arraycopy(og[1].body_base, og[1].body+1000,
833 oy.data, index, og[1].body_len-1000);
834 oy.wrote(og[1].body_len-1000);
835 if(oy.pageout(og_de)<=0)error();
836 System.err.println("ok.");
839 // Test fractional page inputs: page + incomplete capture
841 Page og_de=new Page();
842 System.err.print("Testing sync on 1+partial inputs... ");
845 int index=oy.buffer(og[1].header_len);
846 System.arraycopy(og[1].header_base, og[1].header,
847 oy.data, index, og[1].header_len);
848 oy.wrote(og[1].header_len);
850 index=oy.buffer(og[1].body_len);
851 System.arraycopy(og[1].body_base, og[1].body,
852 oy.data, index, og[1].body_len);
853 oy.wrote(og[1].body_len);
855 index=oy.buffer(og[1].header_len);
856 System.arraycopy(og[1].header_base, og[1].header,
859 if(oy.pageout(og_de)<=0)error();
860 if(oy.pageout(og_de)>0)error();
862 index=oy.buffer(og[1].header_len);
863 System.arraycopy(og[1].header_base, og[1].header+20,
864 oy.data, index, og[1].header_len-20);
865 oy.wrote(og[1].header_len-20);
866 index=oy.buffer(og[1].body_len);
867 System.arraycopy(og[1].body_base, og[1].body,
868 oy.data, index, og[1].body_len);
870 oy.wrote(og[1].body_len);
871 if(oy.pageout(og_de)<=0)error();
873 System.err.println("ok.");
876 // // // // // // // // //
877 // Test recapture: garbage + page
879 Page og_de=new Page();
880 System.err.print("Testing search for capture... ");
884 int index=oy.buffer(og[1].body_len);
885 System.arraycopy(og[1].body_base, og[1].body,
886 oy.data, index, og[1].body_len);
887 oy.wrote(og[1].body_len);
889 index=oy.buffer(og[1].header_len);
890 System.arraycopy(og[1].header_base, og[1].header,
891 oy.data, index, og[1].header_len);
892 oy.wrote(og[1].header_len);
894 index=oy.buffer(og[1].body_len);
895 System.arraycopy(og[1].body_base, og[1].body,
896 oy.data, index, og[1].body_len);
897 oy.wrote(og[1].body_len);
899 index=oy.buffer(og[2].header_len);
900 System.arraycopy(og[2].header_base, og[2].header,
904 if(oy.pageout(og_de)>0)error();
905 if(oy.pageout(og_de)<=0)error();
906 if(oy.pageout(og_de)>0)error();
908 index=oy.buffer(og[2].header_len);
909 System.arraycopy(og[2].header_base, og[2].header+20,
910 oy.data, index, og[2].header_len-20);
911 oy.wrote(og[2].header_len-20);
912 index=oy.buffer(og[2].body_len);
913 System.arraycopy(og[2].body_base, og[2].body,
914 oy.data, index, og[2].body_len);
915 oy.wrote(og[2].body_len);
916 if(oy.pageout(og_de)<=0)error();
918 System.err.println("ok.");
921 // Test recapture: page + garbage + page
923 Page og_de=new Page();
924 System.err.print("Testing recapture... ");
927 int index=oy.buffer(og[1].header_len);
928 System.arraycopy(og[1].header_base, og[1].header,
929 oy.data, index, og[1].header_len);
930 oy.wrote(og[1].header_len);
932 index=oy.buffer(og[1].body_len);
933 System.arraycopy(og[1].body_base, og[1].body,
934 oy.data, index, og[1].body_len);
935 oy.wrote(og[1].body_len);
937 index=oy.buffer(og[2].header_len);
938 System.arraycopy(og[2].header_base, og[2].header,
939 oy.data, index, og[2].header_len);
940 oy.wrote(og[2].header_len);
942 index=oy.buffer(og[2].header_len);
943 System.arraycopy(og[2].header_base, og[2].header,
944 oy.data, index, og[2].header_len);
945 oy.wrote(og[2].header_len);
947 if(oy.pageout(og_de)<=0)error();
949 index=oy.buffer(og[2].body_len);
950 System.arraycopy(og[2].body_base, og[2].body,
951 oy.data, index, og[2].body_len-5);
952 oy.wrote(og[2].body_len-5);
954 index=oy.buffer(og[3].header_len);
955 System.arraycopy(og[3].header_base, og[3].header,
956 oy.data, index, og[3].header_len);
957 oy.wrote(og[3].header_len);
959 index=oy.buffer(og[3].body_len);
960 System.arraycopy(og[3].body_base, og[3].body,
961 oy.data, index, og[3].body_len);
962 oy.wrote(og[3].body_len);
964 if(oy.pageout(og_de)>0)error();
965 if(oy.pageout(og_de)<=0)error();
967 System.err.println("ok.");