forked from I2P_Developers/i2p.i2p
2005-03-23 Comwiz
* Phase 1 of the unit test bounty completed. (The router build script was modified not to build the router tests because of a broken dependancy on the core tests. This should be fixed in phase 3 of the unit test bounty.)
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package net.i2p.util;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
/**
|
||||
* Check to make sure the updates to the logger.config are
|
||||
* honored.
|
||||
*
|
||||
*/
|
||||
public class LogSettings {
|
||||
private static I2PAppContext _context;
|
||||
|
||||
public static void main(String args[]) {
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
Log log = _context.logManager().getLog(LogSettings.class);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
setLevel(Log.DEBUG);
|
||||
test("DEBUG", log);
|
||||
setLevel(Log.INFO);
|
||||
test("INFO", log);
|
||||
setLevel(Log.WARN);
|
||||
test("WARN", log);
|
||||
setLevel(Log.ERROR);
|
||||
test("ERROR", log);
|
||||
setLevel(Log.CRIT);
|
||||
test("CRIT", log);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setLevel(int level) {
|
||||
try {
|
||||
Properties p = new Properties();
|
||||
File f = new File("logger.config");
|
||||
DataHelper.loadProps(p, f);
|
||||
p.setProperty("logger.record.net.i2p.util.LogSettings", Log.toLevelString(level));
|
||||
DataHelper.storeProps(p, f);
|
||||
try { Thread.sleep(90*1000); } catch (InterruptedException ie) {}
|
||||
//_context.logManager().rereadConfig();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(String setting, Log log) {
|
||||
log.debug(setting + ": debug");
|
||||
log.info(setting + ": info");
|
||||
log.warn(setting + ": warn");
|
||||
log.error(setting + ": error");
|
||||
log.log(Log.CRIT, setting + ": crit");
|
||||
}
|
||||
}
|
||||
|
249
core/java/test/net/i2p/util/LogSettingsTest.java
Normal file
249
core/java/test/net/i2p/util/LogSettingsTest.java
Normal file
@@ -0,0 +1,249 @@
|
||||
package net.i2p.util;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.Properties;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @author Comwiz
|
||||
*/
|
||||
public class LogSettingsTest extends TestCase {
|
||||
|
||||
|
||||
private Properties p;
|
||||
private Log log;
|
||||
private I2PAppContext _context;
|
||||
private File f;
|
||||
|
||||
private String origMinimumOnScreenLevel;
|
||||
private String origLogSettings;
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*/
|
||||
protected void setUp() throws IOException {
|
||||
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
log = _context.logManager().getLog(LogSettingsTest.class);
|
||||
p = new Properties();
|
||||
f = new File("logger.config");
|
||||
if(!f.exists()){
|
||||
FileWriter temp = new FileWriter(f);
|
||||
temp.close();
|
||||
}
|
||||
DataHelper.loadProps(p, f);
|
||||
origMinimumOnScreenLevel = p.getProperty("logger.record.net.i2p.util.LogSettings", Log.STR_ERROR);
|
||||
origLogSettings = p.getProperty("logger.minimumOnScreenLevel", Log.STR_CRIT);
|
||||
}
|
||||
|
||||
protected void tearDown() throws IOException{
|
||||
p.setProperty("logger.record.net.i2p.util.LogSettings", origMinimumOnScreenLevel);
|
||||
p.setProperty("logger.minimumOnScreenLevel", origLogSettings);
|
||||
DataHelper.storeProps(p, f);
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
public void testDebug() throws IOException {
|
||||
p.setProperty("logger.record.net.i2p.util.LogSettings", Log.toLevelString(Log.DEBUG));
|
||||
p.setProperty("logger.minimumOnScreenLevel", Log.toLevelString(Log.DEBUG));
|
||||
|
||||
DataHelper.storeProps(p, f);
|
||||
|
||||
_context.logManager().rereadConfig();
|
||||
|
||||
PipedInputStream pin = new PipedInputStream();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(pin));
|
||||
|
||||
PrintStream systemOut = System.out;
|
||||
PrintStream pout = new PrintStream(new PipedOutputStream(pin));
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("DEBUG" + ": debug");
|
||||
log.info("DEBUG" + ": info");
|
||||
log.warn("DEBUG" + ": warn");
|
||||
log.error("DEBUG" + ": error");
|
||||
log.log(Log.CRIT, "DEBUG" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
String l4 = in.readLine();
|
||||
String l5 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*DEBUG: debug") &&
|
||||
l2.matches(".*DEBUG: info") &&
|
||||
l3.matches(".*DEBUG: warn") &&
|
||||
l4.matches(".*DEBUG: error") &&
|
||||
l5.matches(".*DEBUG: crit")
|
||||
);
|
||||
|
||||
System.setOut(systemOut);
|
||||
|
||||
}
|
||||
|
||||
public void testInfo() throws IOException {
|
||||
p.setProperty("logger.record.net.i2p.util.LogSettings", Log.toLevelString(Log.INFO));
|
||||
p.setProperty("logger.minimumOnScreenLevel", Log.toLevelString(Log.DEBUG));
|
||||
|
||||
DataHelper.storeProps(p, f);
|
||||
_context.logManager().rereadConfig();
|
||||
|
||||
PipedInputStream pin = new PipedInputStream();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(pin));
|
||||
|
||||
PrintStream systemOut = System.out;
|
||||
PrintStream pout = new PrintStream(new PipedOutputStream(pin));
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("INFO" + ": debug");
|
||||
log.info("INFO" + ": info");
|
||||
log.warn("INFO" + ": warn");
|
||||
log.error("INFO" + ": error");
|
||||
log.log(Log.CRIT, "INFO" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
String l4 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*INFO: info") &&
|
||||
l2.matches(".*INFO: warn") &&
|
||||
l3.matches(".*INFO: error") &&
|
||||
l4.matches(".*INFO: crit")
|
||||
);
|
||||
|
||||
System.setOut(systemOut);
|
||||
|
||||
}
|
||||
|
||||
public void testWarn() throws IOException {
|
||||
p.setProperty("logger.record.net.i2p.util.LogSettings", Log.toLevelString(Log.WARN));
|
||||
p.setProperty("logger.minimumOnScreenLevel", Log.toLevelString(Log.DEBUG));
|
||||
|
||||
DataHelper.storeProps(p, f);
|
||||
_context.logManager().rereadConfig();
|
||||
|
||||
PipedInputStream pin = new PipedInputStream();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(pin));
|
||||
|
||||
PrintStream systemOut = System.out;
|
||||
PrintStream pout = new PrintStream(new PipedOutputStream(pin));
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("WARN" + ": debug");
|
||||
log.info("WARN" + ": info");
|
||||
log.warn("WARN" + ": warn");
|
||||
log.error("WARN" + ": error");
|
||||
log.log(Log.CRIT, "WARN" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*WARN: warn") &&
|
||||
l2.matches(".*WARN: error") &&
|
||||
l3.matches(".*WARN: crit")
|
||||
);
|
||||
|
||||
System.setOut(systemOut);
|
||||
}
|
||||
|
||||
public void testError() throws IOException{
|
||||
p.setProperty("logger.record.net.i2p.util.LogSettings", Log.toLevelString(Log.ERROR));
|
||||
p.setProperty("logger.minimumOnScreenLevel", Log.toLevelString(Log.DEBUG));
|
||||
|
||||
DataHelper.storeProps(p, f);
|
||||
_context.logManager().rereadConfig();
|
||||
|
||||
PipedInputStream pin = new PipedInputStream();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(pin));
|
||||
|
||||
PrintStream systemOut = System.out;
|
||||
PrintStream pout = new PrintStream(new PipedOutputStream(pin));
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("ERROR" + ": debug");
|
||||
log.info("ERROR" + ": info");
|
||||
log.warn("ERROR" + ": warn");
|
||||
log.error("ERROR" + ": error");
|
||||
log.log(Log.CRIT, "ERROR" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*ERROR: error") &&
|
||||
l2.matches(".*ERROR: crit")
|
||||
);
|
||||
|
||||
System.setOut(systemOut);
|
||||
}
|
||||
|
||||
public void testCrit() throws IOException {
|
||||
p.setProperty("logger.record.net.i2p.util.LogSettings", Log.toLevelString(Log.CRIT));
|
||||
p.setProperty("logger.minimumOnScreenLevel", Log.toLevelString(Log.DEBUG));
|
||||
|
||||
DataHelper.storeProps(p, f);
|
||||
_context.logManager().rereadConfig();
|
||||
|
||||
PipedInputStream pin = new PipedInputStream();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(pin));
|
||||
|
||||
PrintStream systemOut = System.out;
|
||||
PrintStream pout = new PrintStream(new PipedOutputStream(pin));
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("CRIT" + ": debug");
|
||||
log.info("CRIT" + ": info");
|
||||
log.warn("CRIT" + ": warn");
|
||||
log.error("CRIT" + ": error");
|
||||
log.log(Log.CRIT, "CRIT" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*CRIT: crit")
|
||||
);
|
||||
|
||||
System.setOut(systemOut);
|
||||
}
|
||||
|
||||
|
||||
}
|
50
core/java/test/net/i2p/util/LookAheadInputStreamTest.java
Normal file
50
core/java/test/net/i2p/util/LookAheadInputStreamTest.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package net.i2p.util;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class LookAheadInputStreamTest extends TestCase {
|
||||
public void testLookAheadInputStream() throws Exception{
|
||||
byte buf[] = new byte[32];
|
||||
for (int i = 0; i < 32; i++)
|
||||
buf[i] = (byte)i;
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
|
||||
|
||||
LookaheadInputStream lis = new LookaheadInputStream(8);
|
||||
lis.initialize(bais);
|
||||
byte rbuf[] = new byte[32];
|
||||
int read = lis.read(rbuf);
|
||||
assertEquals(read,24);
|
||||
for (int i = 0; i < 24; i++)
|
||||
assertEquals(rbuf[i],(byte)i);
|
||||
for (int i = 0; i < 8; i++)
|
||||
assertEquals(lis.getFooter()[i],(byte)(i+24));
|
||||
|
||||
|
||||
for (int size = 9; size < 32*1024; size+=100) {
|
||||
buf = new byte[size];
|
||||
new java.util.Random().nextBytes(buf);
|
||||
bais = new ByteArrayInputStream(buf);
|
||||
|
||||
lis = new LookaheadInputStream(8);
|
||||
lis.initialize(bais);
|
||||
rbuf = new byte[size];
|
||||
read = lis.read(rbuf);
|
||||
assertEquals(read,(size-8));
|
||||
for (int i = 0; i < (size-8); i++)
|
||||
assertEquals(rbuf[i],buf[i]);
|
||||
for (int i = 0; i < 8; i++)
|
||||
assertEquals(lis.getFooter()[i],buf[i+(size-8)]);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
package net.i2p.util;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class ResettableGZIPInputStreamTest extends TestCase {
|
||||
public void testResettableGZIPInputStream() throws Exception{
|
||||
for (int size = 129; size < 64*1024; size+=100) {
|
||||
byte b[] = new byte[size];
|
||||
new java.util.Random().nextBytes(b);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(size);
|
||||
GZIPOutputStream o = new GZIPOutputStream(baos);
|
||||
o.write(b);
|
||||
o.finish();
|
||||
o.flush();
|
||||
byte compressed[] = baos.toByteArray();
|
||||
|
||||
ResettableGZIPInputStream in = new ResettableGZIPInputStream(new ByteArrayInputStream(compressed));
|
||||
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(size);
|
||||
byte rbuf[] = new byte[512];
|
||||
while (true) {
|
||||
int read = in.read(rbuf);
|
||||
if (read == -1)
|
||||
break;
|
||||
baos2.write(rbuf, 0, read);
|
||||
}
|
||||
byte rv[] = baos2.toByteArray();
|
||||
assertEquals(rv.length,b.length);
|
||||
|
||||
assertTrue(DataHelper.eq(rv, 0, b, 0, b.length));
|
||||
|
||||
}
|
||||
|
||||
byte orig[] = "ho ho ho, merry christmas".getBytes();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
|
||||
GZIPOutputStream o = new GZIPOutputStream(baos);
|
||||
o.write(orig);
|
||||
o.finish();
|
||||
o.flush();
|
||||
o.close();
|
||||
byte compressed[] = baos.toByteArray();
|
||||
|
||||
ResettableGZIPInputStream i = new ResettableGZIPInputStream();
|
||||
i.initialize(new ByteArrayInputStream(compressed));
|
||||
byte readBuf[] = new byte[128];
|
||||
int read = i.read(readBuf);
|
||||
assertEquals(read,orig.length);
|
||||
for (int j = 0; j < read; j++)
|
||||
assertEquals(readBuf[j],orig[j]);
|
||||
assertEquals(-1,i.read());
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package net.i2p.util;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class ResettableGZIPOutputStreamTest extends TestCase {
|
||||
public void testResettableGZIPOutputStream() throws Exception{
|
||||
byte b[] = "hi, how are you today?".getBytes();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos);
|
||||
o.write(b);
|
||||
o.finish();
|
||||
o.flush();
|
||||
byte compressed[] = baos.toByteArray();
|
||||
|
||||
/*ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzo = new GZIPOutputStream(baos2);
|
||||
gzo.write(b);
|
||||
gzo.finish();
|
||||
gzo.flush();
|
||||
byte compressed2[] = baos2.toByteArray();
|
||||
|
||||
assertTrue(DataHelper.eq(compressed, compressed2));*/
|
||||
|
||||
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
|
||||
byte rv[] = new byte[128];
|
||||
int read = in.read(rv);
|
||||
assertTrue(DataHelper.eq(rv, 0, b, 0, b.length));
|
||||
|
||||
}
|
||||
}
|
65
core/java/test/net/i2p/util/ReusableGZIPInputStreamTest.java
Normal file
65
core/java/test/net/i2p/util/ReusableGZIPInputStreamTest.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package net.i2p.util;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class ReusableGZIPInputStreamTest extends TestCase {
|
||||
public void testReusableGZIPInputStream() throws Exception{
|
||||
{
|
||||
byte b[] = "hi, how are you today?".getBytes();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
|
||||
GZIPOutputStream o = new GZIPOutputStream(baos);
|
||||
o.write(b);
|
||||
o.finish();
|
||||
o.flush();
|
||||
byte compressed[] = baos.toByteArray();
|
||||
|
||||
ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire();
|
||||
in.initialize(new ByteArrayInputStream(compressed));
|
||||
byte rv[] = new byte[128];
|
||||
int read = in.read(rv);
|
||||
assertTrue(DataHelper.eq(rv, 0, b, 0, b.length));
|
||||
ReusableGZIPInputStream.release(in);
|
||||
}
|
||||
|
||||
for (int size = 0; size < 64*1024; size+=100) {
|
||||
byte b[] = new byte[size];
|
||||
new java.util.Random().nextBytes(b);
|
||||
|
||||
ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire();
|
||||
o.write(b);
|
||||
o.finish();
|
||||
o.flush();
|
||||
byte compressed[] = o.getData();
|
||||
ReusableGZIPOutputStream.release(o);
|
||||
|
||||
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
|
||||
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(256*1024);
|
||||
byte rbuf[] = new byte[128];
|
||||
while (true) {
|
||||
int read = in.read(rbuf);
|
||||
if (read == -1)
|
||||
break;
|
||||
baos2.write(rbuf, 0, read);
|
||||
}
|
||||
byte rv[] = baos2.toByteArray();
|
||||
assertTrue(DataHelper.eq(rv, 0, b, 0, b.length));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
package net.i2p.util;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class ReusableGZIPOutputStreamTest extends TestCase {
|
||||
public void testReusableGZIPOutputStream() throws Exception{
|
||||
{
|
||||
byte b[] = "hi, how are you today?".getBytes();
|
||||
ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire();
|
||||
o.write(b);
|
||||
o.finish();
|
||||
o.flush();
|
||||
byte compressed[] = o.getData();
|
||||
ReusableGZIPOutputStream.release(o);
|
||||
|
||||
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
|
||||
byte rv[] = new byte[128];
|
||||
int read = in.read(rv);
|
||||
assertTrue(DataHelper.eq(rv, 0, b, 0, b.length));
|
||||
}
|
||||
|
||||
for (int size = 500; size < 64*1024; size+=100) {
|
||||
byte b[] = new byte[size];
|
||||
new java.util.Random().nextBytes(b);
|
||||
|
||||
ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire();
|
||||
o.write(b);
|
||||
o.finish();
|
||||
o.flush();
|
||||
byte compressed[] = o.getData();
|
||||
ReusableGZIPOutputStream.release(o);
|
||||
|
||||
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
|
||||
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(256*1024);
|
||||
byte rbuf[] = new byte[128];
|
||||
while (true) {
|
||||
int read = in.read(rbuf);
|
||||
if (read == -1)
|
||||
break;
|
||||
baos2.write(rbuf, 0, read);
|
||||
}
|
||||
byte rv[] = baos2.toByteArray();
|
||||
assertTrue(DataHelper.eq(rv, 0, b, 0, b.length));
|
||||
}
|
||||
}
|
||||
}
|
25
core/java/test/net/i2p/util/UtilTestSuite.java
Normal file
25
core/java/test/net/i2p/util/UtilTestSuite.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package net.i2p.util;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Test suite for all available tests in the net.i2p.util package
|
||||
*
|
||||
* @author comwiz
|
||||
*/
|
||||
public class UtilTestSuite {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("net.i2p.util.UtilTestSuite");
|
||||
|
||||
suite.addTestSuite(LogSettingsTest.class);
|
||||
suite.addTestSuite(LookAheadInputStreamTest.class);
|
||||
suite.addTestSuite(ResettableGZIPInputStreamTest.class);
|
||||
suite.addTestSuite(ResettableGZIPOutputStreamTest.class);
|
||||
suite.addTestSuite(ReusableGZIPInputStreamTest.class);
|
||||
suite.addTestSuite(ReusableGZIPOutputStreamTest.class);
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user