2 * Copyright (c) 2018-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.qrcode;
19 import java.awt.image.RenderedImage;
22 import javax.imageio.ImageIO;
24 import org.hedgecode.chess.img.DiagramBuilder;
25 import org.hedgecode.chess.img.ImageFormat;
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.JUnit4;
31 import org.hedgecode.chess.Builders;
32 import org.hedgecode.chess.Parsers;
33 import org.hedgecode.chess.position.Position;
36 * Tests for {@link ChessQRCodeWriter}.
38 * @author Dmitry Samoshin aka gotty
40 @RunWith(JUnit4.class)
41 public class ChessQRCodeWriterTest extends Assert {
43 private static final String QR_CODE_IMAGE_PATH = "./QRCodeTest.png";
46 public void generate() throws Exception {
47 //String expected = "rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2";
48 String expected = "1r2k1r1/pbppnp1p/1b3P2/8/Q7/B1PB1q2/P4PPP/3R2K1 w - - 0 21";
49 //String expected = "4kb1r/p2n1ppp/4q3/4p1B1/4P3/1Q6/PPP2PPP/2KR4 w k - 0 16";
51 Position expectedPosition = Parsers.FEN.parser().parse(
55 ChessQRCodeWriter.getInstance().write(
57 Builders.TCD.builder().build(expectedPosition),
62 File file = new File(QR_CODE_IMAGE_PATH);
63 String actual = ChessQRCodeReader.getInstance().read(
67 Position actualPosition = Parsers.TCD.parser().parse(
73 assertNotNull(actual);
74 assertEquals(expected, actual);
77 System.out.println(actual);
79 File outFile = new File("chessboard.png");
80 RenderedImage image = DiagramBuilder.getInstance().build(
81 actualPosition, "test", "shade"
91 Builders.ASCII.builder().build(actualPosition)