From 281aef4ae884879bcee2df781f3460d621c6708c Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Sun, 6 Sep 2015 20:07:25 +0900 Subject: [PATCH] A bit more testing --- cov.sh | 18 ++++ test/net/jaekl/qd/QDBundleFactoryTest.java | 19 ++++ .../jaekl/qd/util/InputStreamWrapperTest.java | 89 +++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 test/net/jaekl/qd/QDBundleFactoryTest.java create mode 100644 test/net/jaekl/qd/util/InputStreamWrapperTest.java diff --git a/cov.sh b/cov.sh index 0948141..ba25745 100755 --- a/cov.sh +++ b/cov.sh @@ -7,6 +7,19 @@ echo Compiling... find "${CFB_ROOT}/prod" -name "*.java" | xargs javac -g -Xlint:deprecation find "${CFB_ROOT}/test" -name "*.java" | xargs javac -g -classpath ${CFB_ROOT}/prod:${CLASSPATH} -Xlint:deprecation +if [ -d "${CFB_ROOT}/bin" ]; then + rm -rf "${CFB_ROOT}/bin" +fi +mkdir -p "${CFB_ROOT}/bin" +cd "${CFB_ROOT}/prod" +find . -name '*.class' | xargs tar zcf "${CFB_ROOT}/tmp_classes.tar.gz" +cd "${CFB_ROOT}/bin" +tar zxf "${CFB_ROOT}/tmp_classes.tar.gz" +if [ -e "${CFB_ROOT}/tmp_classes.tar.gz" ]; then + rm "${CFB_ROOT}/tmp_classes.tar.gz" +fi +cd "${CFB_ROOT}" + ##################### echo Cleaning old coverage files... for x in "${INSTR_DIR}" report @@ -49,3 +62,8 @@ java -Djcov.template=${CFB_ROOT}/template.xml -Djcov.file=${CFB_ROOT}/result.xml echo Generating HTML Report... java -jar "${CFB_ROOT}/jcov/jcov.jar" RepGen -sourcepath "${CFB_ROOT}/prod" -log.level FINE result.xml + +##################### +echo Cleaning up +find "${CFB_ROOT}/prod" -type f -name '*.class' -exec rm {} \; +find "${CFB_ROOT}/test" -type f -name '*.class' -exec rm {} \; diff --git a/test/net/jaekl/qd/QDBundleFactoryTest.java b/test/net/jaekl/qd/QDBundleFactoryTest.java new file mode 100644 index 0000000..c45bf56 --- /dev/null +++ b/test/net/jaekl/qd/QDBundleFactoryTest.java @@ -0,0 +1,19 @@ +// Copyright (C) 2004, 2014 Christian Jaekl + +package net.jaekl.qd; + +import org.junit.Assert; + +import org.junit.Test; + +public class QDBundleFactoryTest { + + @Test + public void test_getInst() { + QDBundleFactory factory = QDBundleFactory.getInst(); + + Assert.assertNotNull(factory); + Assert.assertTrue(factory instanceof QDBundleFactory); + Assert.assertTrue(factory == QDBundleFactory.getInst()); + } +} diff --git a/test/net/jaekl/qd/util/InputStreamWrapperTest.java b/test/net/jaekl/qd/util/InputStreamWrapperTest.java new file mode 100644 index 0000000..d399ce5 --- /dev/null +++ b/test/net/jaekl/qd/util/InputStreamWrapperTest.java @@ -0,0 +1,89 @@ +package net.jaekl.qd.util; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.Charset; + +import org.junit.Assert; +import org.junit.Test; + +public class InputStreamWrapperTest { + static final String[] DATA = { + "", + "\n", + "古池\n蛙飛び込む\n水の音\n", + + "arma virumque cano, Troiae qui primus ab oris\n" + + "Italiam fato profugus Laviniaque venit\n" + + "litora, multum ille et terris iactatus et alto\n" + + "vi superum, saevae memorem Iunonis ob iram,\n" + + "multa quoque et bello passus, dum conderet urbem\n" + + "inferretque deos Latio; genus unde\n" + + "Albanique patres atque altae moenia Romae.\n" + + "Musa, mihi causas memora, quo numine laeso\n" + + "quidve dolens regina deum tot volvere\n" + + "insignem pietate virum, tot adire labores\n" + + "impulerit. tantaene animis caelestibus irae?\n" + + "urbs antiqua fuit (Tyrii tenuere coloni)\n" + + "Karthago, Italiam contra Tiberinaque longe\n" + + "ostia, dives opum studiisque asperrima belli,\n" + + "quam Iuno fertur terris magis omnibus unam\n" + + "posthabita coluisse Samo. hic illius arma,\n" + + "hic currus fuit; hoc regnum dea gentibus esse,\n" + + "si qua fata sinant, iam tum tenditque fovetque.\n" + + "progeniem sed enim Troiano a sanguine duci\n" + + "audierat Tyrias olim quae verteret arces;\n" + + "hinc populum late regem belloque superbum\n" + + "venturum excidio Libyae; sic volvere Parcas.\n" + + "id metuens veterisque memor Saturnia belli,\n" + + "prima quod ad Troiam pro caris gesserat Argis_\n" + + "necdum etiam causae irarum saevique dolores\n" + + "exciderant animo; manet alta mente repostum\n" + + "iudicium Paridis spretaeque iniuria formae\n" + + "et genus invisum et rapti Ganymedis honores:\n" + + "his accensa super iactatos aequore toto\n" + + "Troas, reliquias Danaum atque immitis Achilli,\n" + + "arcebat longe Latio, multosque per annos\n" + + "errabant acti fatis maria omnia circum.\n" + }; + + @Test + public void testRead() throws IOException { + Charset utf8 = Charset.forName("UTF-8"); + StringBuilder sb = new StringBuilder(); + ByteArrayInputStream bais = null; + BufferedReader br = null; + String line; + for (String datum : DATA) { + sb.setLength(0); // reset the builder + int end = datum.length(); + if (end > InputStreamWrapper.HEAD_MAX) { + end = InputStreamWrapper.HEAD_MAX; + } + String expected = datum.substring(0, end); + + try { + bais = new ByteArrayInputStream(datum.getBytes(utf8)); + InputStreamWrapper isw = new InputStreamWrapper(bais); + br = new BufferedReader(new InputStreamReader(isw)); + line = br.readLine(); + while (null != line) { + sb.append(line).append("\n"); + line = br.readLine(); + } + String actualRead = sb.toString(); + String actualHead = new String(isw.getHeadBytes(), utf8); + + Assert.assertEquals(datum, actualRead); + Assert.assertEquals(expected, actualHead); + } + finally { + if (null != br) { + br.close(); + } + } + } + } +} -- 2.39.2