[LIB-9] Fix name of chesshog-dbetude module
[chesshog.git] / chesshog-qrcode / src / test / java / org / hedgecode / chess / qrcode / ChessQRCodeWriterTest.java
1 /*
2  * Copyright (c) 2018-2019. 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.io.File;
20
21 import javax.imageio.ImageIO;
22
23 import org.hedgecode.chess.img.DiagramBuilder;
24 import org.hedgecode.chess.img.ImageFormat;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.JUnit4;
29
30 import org.hedgecode.chess.Builders;
31 import org.hedgecode.chess.Parsers;
32 import org.hedgecode.chess.position.Position;
33
34 /**
35  * Tests for {@link ChessQRCodeWriter}.
36  *
37  * @author Dmitry Samoshin aka gotty
38  */
39 @RunWith(JUnit4.class)
40 public class ChessQRCodeWriterTest extends Assert {
41
42     private static final String QR_CODE_IMAGE_PATH = "./QRCodeTest.png";
43
44     @Test
45     public void generate() throws Exception {
46         //String expected = "rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2";
47         String expected = "1r2k1r1/pbppnp1p/1b3P2/8/Q7/B1PB1q2/P4PPP/3R2K1 w - - 0 21";
48         //String expected = "4kb1r/p2n1ppp/4q3/4p1B1/4P3/1Q6/PPP2PPP/2KR4 w k - 0 16";
49
50         Position expectedPosition = Parsers.FEN.parser().parse(
51                 expected
52         );
53
54         ChessQRCodeWriter.getInstance().write(
55                 ChessQRCodeMode.TCD,
56                 Builders.TCD.builder().build(expectedPosition),
57                 ImageFormat.PNG,
58                 QR_CODE_IMAGE_PATH
59         );
60
61         File file = new File(QR_CODE_IMAGE_PATH);
62         String actual = ChessQRCodeReader.getInstance().read(
63                 file
64         ).getContents();
65
66         Position actualPosition = Parsers.TCD.parser().parse(
67                 actual
68         );
69
70
71 /*
72         assertNotNull(actual);
73         assertEquals(expected, actual);
74 */
75
76         System.out.println(actual);
77
78         ImageIO.write(
79                 DiagramBuilder.getInstance().build(actualPosition, "test", "shade"),
80                 "PNG",
81                 new File("chessboard.png")
82         );
83
84
85         System.out.println(
86                 Builders.ASCII.builder().build(actualPosition)
87         );
88
89
90     }
91
92 }