Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuhikoarase committed Aug 8, 2014
1 parent b541737 commit 0ae4314
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.project
/.classpath
/.settings
/build
5 changes: 3 additions & 2 deletions java/src/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@

<javac
classpath="${SERVLET_API}"
bootclasspath=""
srcdir="${src.java}"
includes="**/*.java"
excludes="**/*Test*.java"
destdir="${build.java}"
debug="true"
encoding="UTF-8"/>
encoding="UTF-8"
includeantruntime="false" />

</target>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
package com.d_project.qrcode;

import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;

public class BitBufferTest extends TestCase {
public class BitBufferTest {

@Test
public void test1() {
BitBuffer bb = new BitBuffer();
QRData qd = new QR8BitByte("534TEST!!!あ");
qd.write(bb);

assertEquals(96, bb.getLengthInBits() );
Assert.assertEquals(96, bb.getLengthInBits() );
}

@Test
public void test2() {
BitBuffer bb = new BitBuffer();
QRData qd = new QRAlphaNum("534TEST $%*+-./:");
qd.write(bb);

assertEquals(88, bb.getLengthInBits() );
Assert.assertEquals(88, bb.getLengthInBits() );
}

@Test
public void test3() {
BitBuffer bb = new BitBuffer();
QRData qd = new QRKanji("あいうえお");
qd.write(bb);

assertEquals(65, bb.getLengthInBits() );
Assert.assertEquals(65, bb.getLengthInBits() );
}

@Test
public void test4() {
BitBuffer bb = new BitBuffer();
QRData qd = new QRNumber("0123456789");
qd.write(bb);

assertEquals(34, bb.getLengthInBits() );
Assert.assertEquals(34, bb.getLengthInBits() );
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.d_project.qrcode;

import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;

public class PolynomialTest extends TestCase {
public class PolynomialTest {

@Test
public void test1() {

int[] rs = new int[] {0, 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136};
Expand All @@ -18,9 +20,9 @@ public void test1() {
assertEquals(new int[]{32,65,205,69,41,220,46,128,236,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, e2);
assertEquals(new int[]{1,119,66,83,120,119,22,197,83,249,41,143,134,85,53,125,99,79}, e);
assertEquals(new int[]{42,159,74,221,244,169,239,150,138,70,237,85,224,96,74,219,61}, e2.mod(e) );

}


@Test
public void test2() {

Polynomial a = new Polynomial(new int[]{1}, 0);
Expand All @@ -29,16 +31,16 @@ public void test2() {
}

int[] log = {0,87,229,146,149,238,102,21};
assertEquals(log.length, a.getLength() );
Assert.assertEquals(log.length, a.getLength() );
for (int i = 0; i < a.getLength(); i++) {
assertEquals(log[i], QRMath.glog(a.get(i) ) );
Assert.assertEquals(log[i], QRMath.glog(a.get(i) ) );
}
}

private void assertEquals(int[] num, Polynomial p) {
assertEquals(num.length, p.getLength() );
protected void assertEquals(int[] num, Polynomial p) {
Assert.assertEquals(num.length, p.getLength() );
for (int i = 0; i < num.length; i++) {
assertEquals(num[i], p.get(i) );
Assert.assertEquals(num[i], p.get(i) );
}
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
package com.d_project.qrcode;

import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;

public class QRCodeTest extends TestCase {
public class QRCodeTest {

@Test
public void test1() {
QRNumber data = new QRNumber("0123");
byte[] act = QRCode.createData(1, ErrorCorrectLevel.H, new QRData[]{data} );
byte[] exp = new byte[]{16,16,12,48,-20,17,-20,17,-20,-50,-20,-24,66,-27,44,-31,-124,-111,13,-69,-37,15,-16,36,-69,104};
assertEquals(exp, act);
}

@Test
public void test2() {
QRAlphaNum data = new QRAlphaNum("AB01");
byte[] act = QRCode.createData(1, ErrorCorrectLevel.H, new QRData[]{data} );
byte[] exp = new byte[]{32,33,-51,0,32,-20,17,-20,17,105,-125,-85,106,65,-91,54,-123,-112,-11,-73,21,-13,-106,-89,114,-25};
assertEquals(exp, act);
}

@Test
public void test3() {
QRKanji data = new QRKanji("漢字");
byte[] act = QRCode.createData(1, ErrorCorrectLevel.H, new QRData[]{data} );
byte[] exp = new byte[]{-128,35,-97,-88,104,0,-20,17,-20,-11,-82,108,-126,119,-6,118,-128,99,-41,-105,117,-68,-107,-120,47,-5};
assertEquals(exp, act);
}

@Test
public void test4() {
QR8BitByte data = new QR8BitByte("ab01");
byte[] act = QRCode.createData(1, ErrorCorrectLevel.H, new QRData[]{data} );
byte[] exp = new byte[]{64,70,22,35,3,16,-20,17,-20,91,-25,80,48,-87,54,40,-83,84,-117,33,87,54,-57,50,-84,49};
assertEquals(exp, act);
}

public void assertEquals(byte[] expected, byte[] actual) {
assertEquals(expected.length, actual.length);
protected void assertEquals(byte[] expected, byte[] actual) {
Assert.assertEquals(expected.length, actual.length);
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], actual[i]);
Assert.assertEquals(expected[i], actual[i]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import java.io.ByteArrayOutputStream;

import junit.framework.TestCase;
import org.junit.Test;

public class GIFImageTest extends TestCase {
public class GIFImageTest {

@Test
public void test() throws Exception {

GIFImage g = new GIFImage(2, 2);
Expand Down
12 changes: 6 additions & 6 deletions java/src/java/com/d_project/qrcode/QRCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class QRCode {

private int errorCorrectLevel;

private List qrDataList;
private List<QRData> qrDataList;

/**
* コンストラクタ
Expand All @@ -38,7 +38,7 @@ public class QRCode {
public QRCode() {
this.typeNumber = 1;
this.errorCorrectLevel = ErrorCorrectLevel.H;
this.qrDataList = new ArrayList(1);
this.qrDataList = new ArrayList<QRData>(1);
}

/**
Expand Down Expand Up @@ -122,15 +122,15 @@ public void clearData() {
qrDataList.clear();
}

private void addData(QRData qrData) {
protected void addData(QRData qrData) {
qrDataList.add(qrData);
}

private int getDataCount() {
protected int getDataCount() {
return qrDataList.size();
}
private QRData getData(int index) {

protected QRData getData(int index) {
return (QRData)qrDataList.get(index);
}

Expand Down
2 changes: 1 addition & 1 deletion java/src/java/com/d_project/qrcode/RSBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static RSBlock[] getRSBlocks(int typeNumber, int errorCorrectLevel) {
int length = rsBlock.length / 3;


List list = new ArrayList();
List<RSBlock> list = new ArrayList<RSBlock>();

for (int i = 0; i < length; i++) {

Expand Down
6 changes: 3 additions & 3 deletions java/src/java/com/d_project/qrcode/web/GIFImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ private static void write(OutputStream out, int i) throws IOException {

private static class LZWTable {

private Map map;
private Map<String,Integer> map;

public LZWTable() {
map = new HashMap();
map = new HashMap<String,Integer>();
}

public void add(String key) {
if (contains(key) ) {
throw new IllegalArgumentException("dup key:" + key);
}
map.put(key, new Integer(map.size() ) );
map.put(key, map.size() );
}

public int size() {
Expand Down
1 change: 1 addition & 0 deletions java/src/java/com/d_project/qrcode/web/QRCodeServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @see com.d_project.qrcode.Mode
* @see com.d_project.qrcode.ErrorCorrectLevel
*/
@SuppressWarnings("serial")
public class QRCodeServlet extends HttpServlet {

private String defaultCharacterEncoding;
Expand Down

0 comments on commit 0ae4314

Please sign in to comment.