[LIB-9] Modify ChessQRCodeWriterTest
[chesshog.git] / chesshog-qrcode / src / test / java / org / hedgecode / chess / qrcode / ChessQRCodeWriterTest.java
1 /*
2  * Copyright (c) 2018-2020. Developed by Hedgecode.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.hedgecode.chess.qrcode;
18
19 import java.awt.image.RenderedImage;
20 import java.io.File;
21
22 import javax.imageio.ImageIO;
23
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;
30
31 import org.hedgecode.chess.Builders;
32 import org.hedgecode.chess.Parsers;
33 import org.hedgecode.chess.position.Position;
34
35 /**
36  * Tests for {@link ChessQRCodeWriter}.
37  *
38  * @author Dmitry Samoshin aka gotty
39  */
40 @RunWith(JUnit4.class)
41 public class ChessQRCodeWriterTest extends Assert {
42
43     private static final String QR_CODE_IMAGE_PATH = "./QRCodeTest.png";
44
45     @Test
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";
50
51         Position expectedPosition = Parsers.FEN.parser().parse(
52                 expected
53         );
54
55         ChessQRCodeWriter.getInstance().write(
56                 ChessQRCodeMode.TCD,
57                 Builders.TCD.builder().build(expectedPosition),
58                 ImageFormat.PNG,
59                 QR_CODE_IMAGE_PATH
60         );
61
62         File file = new File(QR_CODE_IMAGE_PATH);
63         String actual = ChessQRCodeReader.getInstance().read(
64                 file
65         ).getContents();
66
67         Position actualPosition = Parsers.TCD.parser().parse(
68                 actual
69         );
70
71
72 /*
73         assertNotNull(actual);
74         assertEquals(expected, actual);
75 */
76
77         System.out.println(actual);
78
79         File outFile = new File("chessboard.png");
80         RenderedImage image = DiagramBuilder.getInstance().build(
81                 actualPosition, "test", "shade"
82         ).getImage();
83
84         ImageIO.write(
85                 image,
86                 "PNG",
87                 outFile
88         );
89
90         System.out.println(
91                 Builders.ASCII.builder().build(actualPosition)
92         );
93
94
95     }
96
97 }