Package

Source Code of InputStreamBlockReceiverTest

import java.io.ByteArrayInputStream;
import junit.framework.TestCase;
import dijjer.io.xfer.InputStreamBlockReceiver;
import dijjer.io.xfer.PartiallyReceivedBlock;

/*
* Dijjer - A Peer to Peer HTTP Cache
* Copyright (C) 2004,2005 Change.Tv, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
/**
* @author ian
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class InputStreamBlockReceiverTest extends TestCase {
  public void testISBR() throws Exception {
    byte[] ba1 = new byte[1000];
    ByteArrayInputStream bais = new ByteArrayInputStream(ba1);
    PartiallyReceivedBlock prb1 = new PartiallyReceivedBlock(100, 10);
    InputStreamBlockReceiver isbr1 = new InputStreamBlockReceiver(prb1, bais);
    isbr1.start();
    assertTrue(prb1.allReceived());
    byte[] ba2 = prb1.getBlock();
    for(int x=0; x<ba2.length; x++) {
      assertEquals(ba1[x], ba2[x]);
    }
   
    bais.reset();
    PartiallyReceivedBlock prb2 = new PartiallyReceivedBlock(100, 11);
    InputStreamBlockReceiver isbr2 = new InputStreamBlockReceiver(prb2, bais);
    isbr2.start();
   
    byte[] ba3 = prb2.getBlock();
    for (int x=0; x<ba1.length; x++) {
      assertEquals(ba1[x], ba3[x]);
    }
    for (int x=ba1.length; x<ba3.length; x++) {
      assertEquals(ba3[x], (byte)0);
    }
  }
}
TOP

Related Classes of InputStreamBlockReceiverTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.